Skip to content

Rollup of 9 pull requests #142862

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2e57845
actually use a doc comment
lcnr Jun 16, 2025
8710c1f
update comment
lcnr Jun 17, 2025
75da5c4
reevaluate: reset `encountered_overflow`
lcnr Jun 17, 2025
ecd65f8
`evaluate_goal`: accept different inputs
lcnr Jun 18, 2025
bd2dd25
Generate symbols.o for proc-macros too
bjorn3 Jun 17, 2025
a0badba
Pass -Cpanic=abort for the panic_abort crate
bjorn3 Apr 24, 2025
5babf24
integer docs: remove extraneous text
tshepang Jun 20, 2025
e51c37c
Add AttributeExt::doc_resolution_scope
dtolnay Jun 20, 2025
86f40ac
Remove style() from AttributeExt trait
dtolnay Jun 20, 2025
715e02f
Add regression test for issue 142649
dtolnay Jun 19, 2025
6729b66
All HIR attributes are outer
dtolnay Jun 20, 2025
d86d3f3
Port `#[rustc_pub_transparent]` to the new attribute system
GrigorenkoPV Jun 14, 2025
eb86d09
remove asm_goto feature annotation, for it is now stabilized
tshepang Jun 21, 2025
6854f7d
Use `sym::asterisk` to avoid a `Symbol::intern` call.
nnethercote Jun 17, 2025
4736142
Remove some dead code.
nnethercote Jun 17, 2025
9a59774
Remove some code.
nnethercote Jun 17, 2025
88388f4
Use `FromClean` more.
nnethercote Jun 17, 2025
2878e1c
Rename some methods.
nnethercote Jun 19, 2025
6ff229b
Notify `jieyouxu` on tidy changes
jieyouxu Jun 22, 2025
9499207
Rollup merge of #140254 - bjorn3:rustc_panic_abort_abort, r=petrochenkov
jhpratt Jun 22, 2025
962df64
Rollup merge of #142600 - GrigorenkoPV:attributes/rustc_pub_transpare…
jhpratt Jun 22, 2025
4ce8c2a
Rollup merge of #142617 - lcnr:search_graph-3, r=compiler-errors
jhpratt Jun 22, 2025
1b27161
Rollup merge of #142641 - bjorn3:proc_macro_symbols_o, r=jieyouxu
jhpratt Jun 22, 2025
18cf60b
Rollup merge of #142747 - nnethercote:json-conversion-cleanups, r=aDo…
jhpratt Jun 22, 2025
17d8ac8
Rollup merge of #142776 - dtolnay:hirattrstyle2, r=jdonszelmann
jhpratt Jun 22, 2025
641e666
Rollup merge of #142800 - tshepang:extraneous, r=Mark-Simulacrum
jhpratt Jun 22, 2025
932d004
Rollup merge of #142850 - tshepang:patch-1, r=jieyouxu
jhpratt Jun 22, 2025
e4e8842
Rollup merge of #142860 - jieyouxu:notify-tidy, r=jieyouxu
jhpratt Jun 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions compiler/rustc_ast/src/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,24 @@ impl AttributeExt for Attribute {
}
}

fn style(&self) -> AttrStyle {
self.style
fn doc_resolution_scope(&self) -> Option<AttrStyle> {
match &self.kind {
AttrKind::DocComment(..) => Some(self.style),
AttrKind::Normal(normal)
if normal.item.path == sym::doc && normal.item.value_str().is_some() =>
{
Some(self.style)
}
_ => None,
}
}
}

impl Attribute {
pub fn style(&self) -> AttrStyle {
self.style
}

pub fn may_have_doc_links(&self) -> bool {
self.doc_str().is_some_and(|s| comments::may_have_doc_links(s.as_str()))
}
Expand Down Expand Up @@ -806,7 +818,14 @@ pub trait AttributeExt: Debug {
/// * `#[doc(...)]` returns `None`.
fn doc_str_and_comment_kind(&self) -> Option<(Symbol, CommentKind)>;

fn style(&self) -> AttrStyle;
/// Returns outer or inner if this is a doc attribute or a sugared doc
/// comment, otherwise None.
///
/// This is used in the case of doc comments on modules, to decide whether
/// to resolve intra-doc links against the symbols in scope within the
/// commented module (for inner doc) vs within its parent module (for outer
/// doc).
fn doc_resolution_scope(&self) -> Option<AttrStyle>;
}

// FIXME(fn_delegation): use function delegation instead of manually forwarding
Expand Down Expand Up @@ -881,8 +900,4 @@ impl Attribute {
pub fn doc_str_and_comment_kind(&self) -> Option<(Symbol, CommentKind)> {
AttributeExt::doc_str_and_comment_kind(self)
}

pub fn style(&self) -> AttrStyle {
AttributeExt::style(self)
}
}
3 changes: 3 additions & 0 deletions compiler/rustc_attr_data_structures/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ pub enum AttributeKind {
/// Represents `#[optimize(size|speed)]`
Optimize(OptimizeAttr, Span),

/// Represents `#[rustc_pub_transparent]` (used by the `repr_transparent_external_private_fields` lint).
PubTransparent(Span),

/// Represents [`#[repr]`](https://doc.rust-lang.org/stable/reference/type-layout.html#representations).
Repr(ThinVec<(ReprAttr, Span)>),

Expand Down
13 changes: 13 additions & 0 deletions compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,16 @@ impl<S: Stage> SingleAttributeParser<S> for AsPtrParser {
Some(AttributeKind::AsPtr(cx.attr_span))
}
}

pub(crate) struct PubTransparentParser;
impl<S: Stage> SingleAttributeParser<S> for PubTransparentParser {
const PATH: &[Symbol] = &[sym::rustc_pub_transparent];
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepFirst;
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
const TEMPLATE: AttributeTemplate = template!(Word);

fn convert(cx: &mut AcceptContext<'_, '_, S>, _args: &ArgParser<'_>) -> Option<AttributeKind> {
// FIXME: check that there's no args (this is currently checked elsewhere)
Some(AttributeKind::PubTransparent(cx.attr_span))
}
}
3 changes: 2 additions & 1 deletion compiler/rustc_attr_parsing/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::attributes::codegen_attrs::{ColdParser, OptimizeParser};
use crate::attributes::confusables::ConfusablesParser;
use crate::attributes::deprecation::DeprecationParser;
use crate::attributes::inline::{InlineParser, RustcForceInlineParser};
use crate::attributes::lint_helpers::AsPtrParser;
use crate::attributes::lint_helpers::{AsPtrParser, PubTransparentParser};
use crate::attributes::repr::{AlignParser, ReprParser};
use crate::attributes::semantics::MayDangleParser;
use crate::attributes::stability::{
Expand Down Expand Up @@ -113,6 +113,7 @@ attribute_parsers!(
Single<InlineParser>,
Single<MayDangleParser>,
Single<OptimizeParser>,
Single<PubTransparentParser>,
Single<RustcForceInlineParser>,
Single<TransparencyParser>,
// tidy-alphabetical-end
Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1817,8 +1817,13 @@ pub(crate) fn linked_symbols(
crate_type: CrateType,
) -> Vec<(String, SymbolExportKind)> {
match crate_type {
CrateType::Executable | CrateType::Cdylib | CrateType::Dylib | CrateType::Sdylib => (),
CrateType::Staticlib | CrateType::ProcMacro | CrateType::Rlib => {
CrateType::Executable
| CrateType::ProcMacro
| CrateType::Cdylib
| CrateType::Dylib
| CrateType::Sdylib => (),
CrateType::Staticlib | CrateType::Rlib => {
// These are not linked, so no need to generate symbols.o for them.
return Vec::new();
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
),
rustc_attr!(
rustc_pub_transparent, Normal, template!(Word),
WarnFollowing, EncodeCrossCrate::Yes,
ErrorFollowing, EncodeCrossCrate::Yes,
"used internally to mark types with a `transparent` representation when it is guaranteed by the documentation",
),

Expand Down
31 changes: 10 additions & 21 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1346,12 +1346,13 @@ impl AttributeExt for Attribute {
}
}

#[inline]
fn style(&self) -> AttrStyle {
match &self {
Attribute::Unparsed(u) => u.style,
Attribute::Parsed(AttributeKind::DocComment { style, .. }) => *style,
_ => panic!(),
fn doc_resolution_scope(&self) -> Option<AttrStyle> {
match self {
Attribute::Parsed(AttributeKind::DocComment { style, .. }) => Some(*style),
Attribute::Unparsed(attr) if self.has_name(sym::doc) && self.value_str().is_some() => {
Some(attr.style)
}
_ => None,
}
}
}
Expand Down Expand Up @@ -1442,11 +1443,6 @@ impl Attribute {
pub fn doc_str_and_comment_kind(&self) -> Option<(Symbol, CommentKind)> {
AttributeExt::doc_str_and_comment_kind(self)
}

#[inline]
pub fn style(&self) -> AttrStyle {
AttributeExt::style(self)
}
}

/// Attributes owned by a HIR owner.
Expand Down Expand Up @@ -2286,16 +2282,9 @@ pub struct Expr<'hir> {
}

impl Expr<'_> {
pub fn precedence(
&self,
for_each_attr: &dyn Fn(HirId, &mut dyn FnMut(&Attribute)),
) -> ExprPrecedence {
pub fn precedence(&self, has_attr: &dyn Fn(HirId) -> bool) -> ExprPrecedence {
let prefix_attrs_precedence = || -> ExprPrecedence {
let mut has_outer_attr = false;
for_each_attr(self.hir_id, &mut |attr: &Attribute| {
has_outer_attr |= matches!(attr.style(), AttrStyle::Outer)
});
if has_outer_attr { ExprPrecedence::Prefix } else { ExprPrecedence::Unambiguous }
if has_attr(self.hir_id) { ExprPrecedence::Prefix } else { ExprPrecedence::Unambiguous }
};

match &self.kind {
Expand Down Expand Up @@ -2351,7 +2340,7 @@ impl Expr<'_> {
| ExprKind::Use(..)
| ExprKind::Err(_) => prefix_attrs_precedence(),

ExprKind::DropTemps(expr, ..) => expr.precedence(for_each_attr),
ExprKind::DropTemps(expr, ..) => expr.precedence(has_attr),
}
}

Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::cell::LazyCell;
use std::ops::ControlFlow;

use rustc_abi::FieldIdx;
use rustc_attr_data_structures::AttributeKind;
use rustc_attr_data_structures::ReprAttr::ReprPacked;
use rustc_data_structures::unord::{UnordMap, UnordSet};
use rustc_errors::codes::*;
Expand Down Expand Up @@ -1384,7 +1385,11 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
ty::Tuple(list) => list.iter().try_for_each(|t| check_non_exhaustive(tcx, t)),
ty::Array(ty, _) => check_non_exhaustive(tcx, *ty),
ty::Adt(def, args) => {
if !def.did().is_local() && !tcx.has_attr(def.did(), sym::rustc_pub_transparent)
if !def.did().is_local()
&& !attrs::find_attr!(
tcx.get_all_attrs(def.did()),
AttributeKind::PubTransparent(_)
)
{
let non_exhaustive = def.is_variant_list_non_exhaustive()
|| def
Expand Down
Loading
Loading