diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 4bc55b8717e..0a477fa5f2b 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -290,34 +290,34 @@ impl EarlyLintPass for UnsafeCode { } ast::ItemKind::Fn(..) => { - if attr::contains_name(&it.attrs, sym::no_mangle) { + if let Some(attr) = attr::find_by_name(&it.attrs, sym::no_mangle) { self.report_overriden_symbol_name( cx, - it.ident.span, + attr.span, "declaration of a `no_mangle` function", ); } - if attr::contains_name(&it.attrs, sym::export_name) { + if let Some(attr) = attr::find_by_name(&it.attrs, sym::export_name) { self.report_overriden_symbol_name( cx, - it.ident.span, + attr.span, "declaration of a function with `export_name`", ); } } ast::ItemKind::Static(..) => { - if attr::contains_name(&it.attrs, sym::no_mangle) { + if let Some(attr) = attr::find_by_name(&it.attrs, sym::no_mangle) { self.report_overriden_symbol_name( cx, - it.ident.span, + attr.span, "declaration of a `no_mangle` static", ); } - if attr::contains_name(&it.attrs, sym::export_name) { + if let Some(attr) = attr::find_by_name(&it.attrs, sym::export_name) { self.report_overriden_symbol_name( cx, - it.ident.span, + attr.span, "declaration of a static with `export_name`", ); } diff --git a/src/test/ui/lint/lint-unsafe-code.stderr b/src/test/ui/lint/lint-unsafe-code.stderr index fa22498dc0f..a8ef047e517 100644 --- a/src/test/ui/lint/lint-unsafe-code.stderr +++ b/src/test/ui/lint/lint-unsafe-code.stderr @@ -1,8 +1,8 @@ error: declaration of a `no_mangle` function - --> $DIR/lint-unsafe-code.rs:31:17 + --> $DIR/lint-unsafe-code.rs:31:1 | LL | #[no_mangle] fn foo() {} - | ^^^ + | ^^^^^^^^^^^^ | note: the lint level is defined here --> $DIR/lint-unsafe-code.rs:3:9 @@ -12,26 +12,26 @@ LL | #![deny(unsafe_code)] = note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them error: declaration of a `no_mangle` static - --> $DIR/lint-unsafe-code.rs:32:21 + --> $DIR/lint-unsafe-code.rs:32:1 | LL | #[no_mangle] static FOO: u32 = 5; - | ^^^ + | ^^^^^^^^^^^^ | = note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them error: declaration of a function with `export_name` - --> $DIR/lint-unsafe-code.rs:34:27 + --> $DIR/lint-unsafe-code.rs:34:1 | LL | #[export_name = "bar"] fn bar() {} - | ^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ | = note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them error: declaration of a static with `export_name` - --> $DIR/lint-unsafe-code.rs:35:31 + --> $DIR/lint-unsafe-code.rs:35:1 | LL | #[export_name = "BAR"] static BAR: u32 = 5; - | ^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ | = note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them @@ -114,10 +114,10 @@ LL | unsafe {} | ^^^^^^^^^ error: declaration of a `no_mangle` function - --> $DIR/lint-unsafe-code.rs:21:25 + --> $DIR/lint-unsafe-code.rs:21:9 | LL | #[no_mangle] fn foo() {} - | ^^^ + | ^^^^^^^^^^^^ ... LL | unsafe_in_macro!() | ------------------ in this macro invocation @@ -126,10 +126,10 @@ LL | unsafe_in_macro!() = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: declaration of a `no_mangle` static - --> $DIR/lint-unsafe-code.rs:22:29 + --> $DIR/lint-unsafe-code.rs:22:9 | LL | #[no_mangle] static FOO: u32 = 5; - | ^^^ + | ^^^^^^^^^^^^ ... LL | unsafe_in_macro!() | ------------------ in this macro invocation @@ -138,10 +138,10 @@ LL | unsafe_in_macro!() = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: declaration of a function with `export_name` - --> $DIR/lint-unsafe-code.rs:23:35 + --> $DIR/lint-unsafe-code.rs:23:9 | LL | #[export_name = "bar"] fn bar() {} - | ^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ ... LL | unsafe_in_macro!() | ------------------ in this macro invocation @@ -150,10 +150,10 @@ LL | unsafe_in_macro!() = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: declaration of a static with `export_name` - --> $DIR/lint-unsafe-code.rs:25:39 + --> $DIR/lint-unsafe-code.rs:25:9 | LL | #[export_name = "BAR"] static BAR: u32 = 5; - | ^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ ... LL | unsafe_in_macro!() | ------------------ in this macro invocation