Skip to content

Conversation

@JonathanBrouwer
Copy link
Contributor

This PR moves attribute safety checking to be done during attribute parsing. The cfg and cfg_attr attribute no longer need special-cased safety checking, yay!

This PR is a part 1 of 2, in the second part I'd like to define attribute safety in the attribute parsers rather than getting the information from BUILTIN_ATTRIBUTE_MAP, but to keep PRs reviewable lets do that separately.

Fixes #148453 by reordering the diagnostics. The "cannot find attribute" diagnostic now appears first, but both diagnostics still appear.

r? @jdonszelmann

@rustbot
Copy link
Collaborator

rustbot commented Dec 1, 2025

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 1, 2025
@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu-llvm-20-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

---- [incremental] tests/incremental/hashes/function_interfaces.rs stdout ----
------rustc stdout------------------------------

------rustc stderr------------------------------
{"$message_type":"diagnostic","message":"`opt_hir_owner_nodes(no_mangle)` should be clean but is not","code":null,"level":"error","spans":[{"file_name":"/checkout/tests/incremental/hashes/function_interfaces.rs","byte_start":8508,"byte_end":8526,"line_start":283,"line_end":283,"column_start":1,"column_end":19,"is_primary":true,"text":[{"text":"pub fn no_mangle() {}","highlight_start":1,"highlight_end":19}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"error: `opt_hir_owner_nodes(no_mangle)` should be clean but is not\n  --> /checkout/tests/incremental/hashes/function_interfaces.rs:283:1\n   |\nLL | pub fn no_mangle() {}\n   | ^^^^^^^^^^^^^^^^^^\n\n"}
{"$message_type":"diagnostic","message":"aborting due to 1 previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to 1 previous error\n\n"}

------------------------------------------

error in revision `cfail2`: test compilation failed although it shouldn't!
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/incremental/hashes/function_interfaces.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--cfg" "cfail2" "--check-cfg" "cfg(test,FALSE,cfail1,cfail2,cfail3,cfail4,cfail5,cfail6)" "-C" "incremental=/checkout/obj/build/aarch64-unknown-linux-gnu/test/incremental/hashes/function_interfaces/function_interfaces.inc" "-Z" "incremental-verify-ich" "-O" "--error-format" "json" "--json" "future-incompat" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/incremental/hashes/function_interfaces" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "-Z" "query-dep-graph" "-O" "-Zincremental-ignore-spans"
stdout: none
--- stderr -------------------------------
error: `opt_hir_owner_nodes(no_mangle)` should be clean but is not
##[error]  --> /checkout/tests/incremental/hashes/function_interfaces.rs:283:1
   |
LL | pub fn no_mangle() {}
   | ^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error
------------------------------------------

---- [incremental] tests/incremental/hashes/function_interfaces.rs stdout end ----
---- [incremental] tests/incremental/hashes/inherent_impls.rs stdout ----
------rustc stdout------------------------------

------rustc stderr------------------------------
{"$message_type":"diagnostic","message":"`opt_hir_owner_nodes(Foo::add_no_mangle_to_method)` should be clean but is not","code":null,"level":"error","spans":[{"file_name":"/checkout/tests/incremental/hashes/inherent_impls.rs","byte_start":23382,"byte_end":23419,"line_start":667,"line_end":667,"column_start":5,"column_end":42,"is_primary":true,"text":[{"text":"    pub fn add_no_mangle_to_method(&self) { }","highlight_start":5,"highlight_end":42}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"error: `opt_hir_owner_nodes(Foo::add_no_mangle_to_method)` should be clean but is not\n  --> /checkout/tests/incremental/hashes/inherent_impls.rs:667:5\n   |\nLL |     pub fn add_no_mangle_to_method(&self) { }\n   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n"}
{"$message_type":"diagnostic","message":"aborting due to 1 previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to 1 previous error\n\n"}

------------------------------------------

error in revision `cfail2`: test compilation failed although it shouldn't!
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/incremental/hashes/inherent_impls.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--cfg" "cfail2" "--check-cfg" "cfg(test,FALSE,cfail1,cfail2,cfail3,cfail4,cfail5,cfail6)" "-C" "incremental=/checkout/obj/build/aarch64-unknown-linux-gnu/test/incremental/hashes/inherent_impls/inherent_impls.inc" "-Z" "incremental-verify-ich" "-O" "--error-format" "json" "--json" "future-incompat" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/incremental/hashes/inherent_impls" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "-Z" "query-dep-graph" "-O" "-Zincremental-ignore-spans"
stdout: none
--- stderr -------------------------------
error: `opt_hir_owner_nodes(Foo::add_no_mangle_to_method)` should be clean but is not
##[error]  --> /checkout/tests/incremental/hashes/inherent_impls.rs:667:5
   |
LL |     pub fn add_no_mangle_to_method(&self) { }
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error
------------------------------------------

---- [incremental] tests/incremental/hashes/inherent_impls.rs stdout end ----
---- [incremental] tests/incremental/hashes/statics.rs stdout ----
------rustc stdout------------------------------

------rustc stderr------------------------------
{"$message_type":"diagnostic","message":"`opt_hir_owner_nodes(STATIC_NO_MANGLE)` should be clean but is not","code":null,"level":"error","spans":[{"file_name":"/checkout/tests/incremental/hashes/statics.rs","byte_start":1950,"byte_end":1977,"line_start":70,"line_end":70,"column_start":1,"column_end":28,"is_primary":true,"text":[{"text":"static STATIC_NO_MANGLE: u8 = 0;","highlight_start":1,"highlight_end":28}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"error: `opt_hir_owner_nodes(STATIC_NO_MANGLE)` should be clean but is not\n  --> /checkout/tests/incremental/hashes/statics.rs:70:1\n   |\nLL | static STATIC_NO_MANGLE: u8 = 0;\n   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n"}
{"$message_type":"diagnostic","message":"aborting due to 1 previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to 1 previous error\n\n"}

------------------------------------------

error in revision `cfail2`: test compilation failed although it shouldn't!
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/incremental/hashes/statics.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--cfg" "cfail2" "--check-cfg" "cfg(test,FALSE,cfail1,cfail2,cfail3,cfail4,cfail5,cfail6)" "-C" "incremental=/checkout/obj/build/aarch64-unknown-linux-gnu/test/incremental/hashes/statics/statics.inc" "-Z" "incremental-verify-ich" "-O" "--error-format" "json" "--json" "future-incompat" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/incremental/hashes/statics" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "-Z" "query-dep-graph" "-O" "-Zincremental-ignore-spans"
stdout: none
--- stderr -------------------------------
error: `opt_hir_owner_nodes(STATIC_NO_MANGLE)` should be clean but is not
##[error]  --> /checkout/tests/incremental/hashes/statics.rs:70:1
   |
LL | static STATIC_NO_MANGLE: u8 = 0;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error
------------------------------------------

---- [incremental] tests/incremental/hashes/statics.rs stdout end ----
---- [incremental] tests/incremental/hashes/trait_impls.rs stdout ----
------rustc stdout------------------------------

------rustc stderr------------------------------
{"$message_type":"diagnostic","message":"`opt_hir_owner_nodes(<Foo as AddNoMangleToMethod>::add_no_mangle_to_method)` should be clean but is not","code":null,"level":"error","spans":[{"file_name":"/checkout/tests/incremental/hashes/trait_impls.rs","byte_start":16659,"byte_end":16692,"line_start":587,"line_end":587,"column_start":5,"column_end":38,"is_primary":true,"text":[{"text":"    fn add_no_mangle_to_method(&self) { }","highlight_start":5,"highlight_end":38}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"error: `opt_hir_owner_nodes(<Foo as AddNoMangleToMethod>::add_no_mangle_to_method)` should be clean but is not\n  --> /checkout/tests/incremental/hashes/trait_impls.rs:587:5\n   |\nLL |     fn add_no_mangle_to_method(&self) { }\n   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n"}
{"$message_type":"diagnostic","message":"aborting due to 1 previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to 1 previous error\n\n"}

------------------------------------------

error in revision `cfail2`: test compilation failed although it shouldn't!
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/incremental/hashes/trait_impls.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--cfg" "cfail2" "--check-cfg" "cfg(test,FALSE,cfail1,cfail2,cfail3,cfail4,cfail5,cfail6)" "-C" "incremental=/checkout/obj/build/aarch64-unknown-linux-gnu/test/incremental/hashes/trait_impls/trait_impls.inc" "-Z" "incremental-verify-ich" "-O" "--error-format" "json" "--json" "future-incompat" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/incremental/hashes/trait_impls" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "-Z" "query-dep-graph" "-O" "-Zincremental-ignore-spans"
stdout: none
--- stderr -------------------------------
error: `opt_hir_owner_nodes(<Foo as AddNoMangleToMethod>::add_no_mangle_to_method)` should be clean but is not
##[error]  --> /checkout/tests/incremental/hashes/trait_impls.rs:587:5
   |
LL |     fn add_no_mangle_to_method(&self) { }
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

@JonathanBrouwer
Copy link
Contributor Author

:c
@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 1, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 1, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@bors
Copy link
Collaborator

bors commented Dec 2, 2025

☔ The latest upstream changes (presumably #147634) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"attr is not an unsafe attribute" diagnostic is emitted even if the attribute doesn't exist

5 participants