about summary refs log tree commit diff
path: root/compiler/rustc_parse/src
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-06-12 03:14:52 +0200
committerGitHub <noreply@github.com>2025-06-12 03:14:52 +0200
commit75c186bf43167618b7e13c8ddf47b30918bb2721 (patch)
treeec745b72fd9264851b4c19d4a3532e05c17b2220 /compiler/rustc_parse/src
parente2e201fd6b26fe0f3573c794cc569d1df1f7f641 (diff)
parent2c8257493da0e452c03f34cc6f409d98234746db (diff)
downloadrust-75c186bf43167618b7e13c8ddf47b30918bb2721.tar.gz
rust-75c186bf43167618b7e13c8ddf47b30918bb2721.zip
Rollup merge of #142261 - folkertdev:unstable-attr-correct-edition, r=compiler-errors
use correct edition when warning for unsafe attributes

fixes https://github.com/rust-lang/rust/issues/142182

If an attribute is re-emitted by a macro, the incorrect edition was used to emit warnings for unsafe attributes.

This logic was introduced in https://github.com/rust-lang/rust/pull/139718

cc `@compiler-errors` `@ehuss`
Diffstat (limited to 'compiler/rustc_parse/src')
-rw-r--r--compiler/rustc_parse/src/validate_attr.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/validate_attr.rs b/compiler/rustc_parse/src/validate_attr.rs
index 378cbb84637..555ab3cdb2b 100644
--- a/compiler/rustc_parse/src/validate_attr.rs
+++ b/compiler/rustc_parse/src/validate_attr.rs
@@ -180,9 +180,14 @@ pub fn check_attribute_safety(
             let diag_span = attr_item.span();
 
             // Attributes can be safe in earlier editions, and become unsafe in later ones.
+            //
+            // Use the span of the attribute's name to determine the edition: the span of the
+            // attribute as a whole may be inaccurate if it was emitted by a macro.
+            //
+            // See https://github.com/rust-lang/rust/issues/142182.
             let emit_error = match unsafe_since {
                 None => true,
-                Some(unsafe_since) => attr.span.edition() >= unsafe_since,
+                Some(unsafe_since) => path_span.edition() >= unsafe_since,
             };
 
             if emit_error {