Skip to content

Commit ccd6824

Browse files
borscompiler-errors
authored andcommitted
Auto merge of rust-lang#142574 - Kobzol:rollup-ldj386u, r=Kobzol
Rollup of 12 pull requests Successful merges: - rust-lang#141639 (Expose discriminant values in stable_mir) - rust-lang#142082 (Refactor `rustc_attr_data_structures` documentation) - rust-lang#142125 (Stabilize "file_lock" feature) - rust-lang#142236 (Add documentation for `PathBuf`'s `FromIterator` and `Extend` impls) - rust-lang#142373 (Fix Debug for Location) - rust-lang#142416 (Assorted bootstrap cleanups (step 2)) - rust-lang#142431 (Add initial version of snapshot tests to bootstrap) - rust-lang#142450 (Add documentation on top of `rustc_middle/src/query/mod.rs`) - rust-lang#142528 (clarify `rustc_do_not_const_check` comment) - rust-lang#142530 (use `if let` guards where possible) - rust-lang#142561 (Remove an `njn:` comment accidentaly left behind.) - rust-lang#142566 (Fix `-nopt` CI jobs) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d9ca9bd + 78d12b7 commit ccd6824

File tree

46 files changed

+1043
-512
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1043
-512
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,24 +130,54 @@ impl Deprecation {
130130
}
131131
}
132132

133-
/// Represent parsed, *built in*, inert attributes.
133+
/// Represents parsed *built-in* inert attributes.
134134
///
135-
/// That means attributes that are not actually ever expanded.
136-
/// For more information on this, see the module docs on the [`rustc_attr_parsing`] crate.
137-
/// They're instead used as markers, to guide the compilation process in various way in most every stage of the compiler.
138-
/// These are kept around after the AST, into the HIR and further on.
135+
/// ## Overview
136+
/// These attributes are markers that guide the compilation process and are never expanded into other code.
137+
/// They persist throughout the compilation phases, from AST to HIR and beyond.
139138
///
140-
/// The word "parsed" could be a little misleading here, because the parser already parses
141-
/// attributes early on. However, the result, an [`ast::Attribute`]
142-
/// is only parsed at a high level, still containing a token stream in many cases. That is
143-
/// because the structure of the contents varies from attribute to attribute.
144-
/// With a parsed attribute I mean that each attribute is processed individually into a
145-
/// final structure, which on-site (the place where the attribute is useful for, think the
146-
/// the place where `must_use` is checked) little to no extra parsing or validating needs to
147-
/// happen.
139+
/// ## Attribute Processing
140+
/// While attributes are initially parsed by [`rustc_parse`] into [`ast::Attribute`], they still contain raw token streams
141+
/// because different attributes have different internal structures. This enum represents the final,
142+
/// fully parsed form of these attributes, where each variant contains contains all the information and
143+
/// structure relevant for the specific attribute.
148144
///
149-
/// For more docs, look in [`rustc_attr_parsing`].
145+
/// Some attributes can be applied multiple times to the same item, and they are "collapsed" into a single
146+
/// semantic attribute. For example:
147+
/// ```rust
148+
/// #[repr(C)]
149+
/// #[repr(packed)]
150+
/// struct S { }
151+
/// ```
152+
/// This is equivalent to `#[repr(C, packed)]` and results in a single [`AttributeKind::Repr`] containing
153+
/// both `C` and `packed` annotations. This collapsing happens during parsing and is reflected in the
154+
/// data structures defined in this enum.
150155
///
156+
/// ## Usage
157+
/// These parsed attributes are used throughout the compiler to:
158+
/// - Control code generation (e.g., `#[repr]`)
159+
/// - Mark API stability (`#[stable]`, `#[unstable]`)
160+
/// - Provide documentation (`#[doc]`)
161+
/// - Guide compiler behavior (e.g., `#[allow_internal_unstable]`)
162+
///
163+
/// ## Note on Attribute Organization
164+
/// Some attributes like `InlineAttr`, `OptimizeAttr`, and `InstructionSetAttr` are defined separately
165+
/// from this enum because they are used in specific compiler phases (like code generation) and don't
166+
/// need to persist throughout the entire compilation process. They are typically processed and
167+
/// converted into their final form earlier in the compilation pipeline.
168+
///
169+
/// For example:
170+
/// - `InlineAttr` is used during code generation to control function inlining
171+
/// - `OptimizeAttr` is used to control optimization levels
172+
/// - `InstructionSetAttr` is used for target-specific code generation
173+
///
174+
/// These attributes are handled by their respective compiler passes in the [`rustc_codegen_ssa`] crate
175+
/// and don't need to be preserved in the same way as the attributes in this enum.
176+
///
177+
/// For more details on attribute parsing, see the [`rustc_attr_parsing`] crate.
178+
///
179+
/// [`rustc_parse`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_parse/index.html
180+
/// [`rustc_codegen_ssa`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_codegen_ssa/index.html
151181
/// [`rustc_attr_parsing`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_attr_parsing/index.html
152182
#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)]
153183
pub enum AttributeKind {

compiler/rustc_attr_data_structures/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! Data structures for representing parsed attributes in the Rust compiler.
2+
//! For detailed documentation about attribute processing,
3+
//! see [rustc_attr_parsing](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_attr_parsing/index.html).
4+
15
// tidy-alphabetical-start
26
#![allow(internal_features)]
37
#![doc(rust_logo)]

compiler/rustc_builtin_macros/src/test.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,7 @@ pub(crate) fn expand_test_or_bench(
118118

119119
let (item, is_stmt) = match item {
120120
Annotatable::Item(i) => (i, false),
121-
Annotatable::Stmt(stmt) if matches!(stmt.kind, ast::StmtKind::Item(_)) => {
122-
// FIXME: Use an 'if let' guard once they are implemented
123-
if let ast::StmtKind::Item(i) = stmt.kind { (i, true) } else { unreachable!() }
124-
}
121+
Annotatable::Stmt(box ast::Stmt { kind: ast::StmtKind::Item(i), .. }) => (i, true),
125122
other => {
126123
not_testable_error(cx, attr_sp, None);
127124
return vec![other];

compiler/rustc_expand/src/base.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use crate::base::ast::MetaItemInner;
3535
use crate::errors;
3636
use crate::expand::{self, AstFragment, Invocation};
3737
use crate::module::DirOwnership;
38+
use crate::stats::MacroStat;
3839

3940
// When adding new variants, make sure to
4041
// adjust the `visit_*` / `flat_map_*` calls in `InvocationCollector`
@@ -1191,7 +1192,7 @@ pub struct ExtCtxt<'a> {
11911192
/// not to expand it again.
11921193
pub(super) expanded_inert_attrs: MarkedAttrs,
11931194
/// `-Zmacro-stats` data.
1194-
pub macro_stats: FxHashMap<(Symbol, MacroKind), crate::stats::MacroStat>, // njn: quals
1195+
pub macro_stats: FxHashMap<(Symbol, MacroKind), MacroStat>,
11951196
}
11961197

11971198
impl<'a> ExtCtxt<'a> {

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
887887
rustc_legacy_const_generics, Normal, template!(List: "N"), ErrorFollowing,
888888
EncodeCrossCrate::Yes,
889889
),
890-
// Do not const-check this function's body. It will always get replaced during CTFE.
890+
// Do not const-check this function's body. It will always get replaced during CTFE via `hook_special_const_fn`.
891891
rustc_attr!(
892892
rustc_do_not_const_check, Normal, template!(Word), WarnFollowing,
893893
EncodeCrossCrate::Yes, "`#[rustc_do_not_const_check]` skips const-check for this function's body",

0 commit comments

Comments
 (0)