diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index e8c8729f597b9..44de48a3ada51 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -279,7 +279,7 @@ fn process_builtin_attrs( AttributeKind::StdInternalSymbol(_) => { codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL } - AttributeKind::Linkage(linkage, _) => { + AttributeKind::Linkage(linkage, span) => { let linkage = Some(*linkage); if tcx.is_foreign_item(did) { @@ -287,7 +287,7 @@ fn process_builtin_attrs( if tcx.is_mutable_static(did.into()) { let mut diag = tcx.dcx().struct_span_err( - attr.span(), + *span, "extern mutable statics are not allowed with `#[linkage]`", ); diag.note( diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index bc1c47e95c3ae..2f60a9119cbe2 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -1315,8 +1315,6 @@ impl AttributeExt for Attribute { // FIXME: should not be needed anymore when all attrs are parsed Attribute::Parsed(AttributeKind::DocComment { span, .. }) => *span, Attribute::Parsed(AttributeKind::Deprecation { span, .. }) => *span, - Attribute::Parsed(AttributeKind::AllowInternalUnsafe(span)) => *span, - Attribute::Parsed(AttributeKind::Linkage(_, span)) => *span, a => panic!("can't get the span of an arbitrary parsed attribute: {a:?}"), } } diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 8a525eb11f7bb..d14bc600f2f11 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -310,15 +310,17 @@ impl EarlyLintPass for UnsafeCode { } ast::ItemKind::MacroDef(..) => { - if let Some(attr) = AttributeParser::parse_limited( - cx.builder.sess(), - &it.attrs, - sym::allow_internal_unsafe, - it.span, - DUMMY_NODE_ID, - Some(cx.builder.features()), - ) { - self.report_unsafe(cx, attr.span(), BuiltinUnsafe::AllowInternalUnsafe); + if let Some(hir::Attribute::Parsed(AttributeKind::AllowInternalUnsafe(span))) = + AttributeParser::parse_limited( + cx.builder.sess(), + &it.attrs, + sym::allow_internal_unsafe, + it.span, + DUMMY_NODE_ID, + Some(cx.builder.features()), + ) + { + self.report_unsafe(cx, span, BuiltinUnsafe::AllowInternalUnsafe); } }