1
Fork 0

Scope no_mangle and export_name warnings to the declarations name

This commit is contained in:
Wim Looman 2020-06-20 13:31:24 +02:00
parent 66b2f9acfc
commit 79b0ab5195
2 changed files with 20 additions and 20 deletions

View file

@ -279,12 +279,12 @@ impl EarlyLintPass for UnsafeCode {
ast::ItemKind::Fn(..) => { ast::ItemKind::Fn(..) => {
if attr::contains_name(&it.attrs, sym::no_mangle) { if attr::contains_name(&it.attrs, sym::no_mangle) {
self.report_unsafe(cx, it.span, |lint| { self.report_unsafe(cx, it.ident.span, |lint| {
lint.build("declaration of a `no_mangle` function").emit(); lint.build("declaration of a `no_mangle` function").emit();
}) })
} }
if attr::contains_name(&it.attrs, sym::export_name) { if attr::contains_name(&it.attrs, sym::export_name) {
self.report_unsafe(cx, it.span, |lint| { self.report_unsafe(cx, it.ident.span, |lint| {
lint.build("declaration of a function with `export_name`").emit(); lint.build("declaration of a function with `export_name`").emit();
}) })
} }
@ -292,12 +292,12 @@ impl EarlyLintPass for UnsafeCode {
ast::ItemKind::Static(..) => { ast::ItemKind::Static(..) => {
if attr::contains_name(&it.attrs, sym::no_mangle) { if attr::contains_name(&it.attrs, sym::no_mangle) {
self.report_unsafe(cx, it.span, |lint| { self.report_unsafe(cx, it.ident.span, |lint| {
lint.build("declaration of a `no_mangle` static").emit(); lint.build("declaration of a `no_mangle` static").emit();
}) })
} }
if attr::contains_name(&it.attrs, sym::export_name) { if attr::contains_name(&it.attrs, sym::export_name) {
self.report_unsafe(cx, it.span, |lint| { self.report_unsafe(cx, it.ident.span, |lint| {
lint.build("declaration of a static with `export_name`").emit(); lint.build("declaration of a static with `export_name`").emit();
}) })
} }

View file

@ -1,8 +1,8 @@
error: declaration of a `no_mangle` function error: declaration of a `no_mangle` function
--> $DIR/lint-unsafe-code.rs:31:14 --> $DIR/lint-unsafe-code.rs:31:17
| |
LL | #[no_mangle] fn foo() {} LL | #[no_mangle] fn foo() {}
| ^^^^^^^^^^^ | ^^^
| |
note: the lint level is defined here note: the lint level is defined here
--> $DIR/lint-unsafe-code.rs:3:9 --> $DIR/lint-unsafe-code.rs:3:9
@ -11,22 +11,22 @@ LL | #![deny(unsafe_code)]
| ^^^^^^^^^^^ | ^^^^^^^^^^^
error: declaration of a `no_mangle` static error: declaration of a `no_mangle` static
--> $DIR/lint-unsafe-code.rs:32:14 --> $DIR/lint-unsafe-code.rs:32:21
| |
LL | #[no_mangle] static FOO: u32 = 5; LL | #[no_mangle] static FOO: u32 = 5;
| ^^^^^^^^^^^^^^^^^^^^ | ^^^
error: declaration of a function with `export_name` error: declaration of a function with `export_name`
--> $DIR/lint-unsafe-code.rs:34:24 --> $DIR/lint-unsafe-code.rs:34:27
| |
LL | #[export_name = "bar"] fn bar() {} LL | #[export_name = "bar"] fn bar() {}
| ^^^^^^^^^^^ | ^^^
error: declaration of a static with `export_name` error: declaration of a static with `export_name`
--> $DIR/lint-unsafe-code.rs:35:24 --> $DIR/lint-unsafe-code.rs:35:31
| |
LL | #[export_name = "BAR"] static BAR: u32 = 5; LL | #[export_name = "BAR"] static BAR: u32 = 5;
| ^^^^^^^^^^^^^^^^^^^^ | ^^^
error: declaration of an `unsafe` function error: declaration of an `unsafe` function
--> $DIR/lint-unsafe-code.rs:37:1 --> $DIR/lint-unsafe-code.rs:37:1
@ -107,10 +107,10 @@ LL | unsafe {}
| ^^^^^^^^^ | ^^^^^^^^^
error: declaration of a `no_mangle` function error: declaration of a `no_mangle` function
--> $DIR/lint-unsafe-code.rs:21:22 --> $DIR/lint-unsafe-code.rs:21:25
| |
LL | #[no_mangle] fn foo() {} LL | #[no_mangle] fn foo() {}
| ^^^^^^^^^^^ | ^^^
... ...
LL | unsafe_in_macro!() LL | unsafe_in_macro!()
| ------------------ in this macro invocation | ------------------ in this macro invocation
@ -118,10 +118,10 @@ LL | unsafe_in_macro!()
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) = 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 error: declaration of a `no_mangle` static
--> $DIR/lint-unsafe-code.rs:22:22 --> $DIR/lint-unsafe-code.rs:22:29
| |
LL | #[no_mangle] static FOO: u32 = 5; LL | #[no_mangle] static FOO: u32 = 5;
| ^^^^^^^^^^^^^^^^^^^^ | ^^^
... ...
LL | unsafe_in_macro!() LL | unsafe_in_macro!()
| ------------------ in this macro invocation | ------------------ in this macro invocation
@ -129,10 +129,10 @@ LL | unsafe_in_macro!()
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) = 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` error: declaration of a function with `export_name`
--> $DIR/lint-unsafe-code.rs:23:32 --> $DIR/lint-unsafe-code.rs:23:35
| |
LL | #[export_name = "bar"] fn bar() {} LL | #[export_name = "bar"] fn bar() {}
| ^^^^^^^^^^^ | ^^^
... ...
LL | unsafe_in_macro!() LL | unsafe_in_macro!()
| ------------------ in this macro invocation | ------------------ in this macro invocation
@ -140,10 +140,10 @@ LL | unsafe_in_macro!()
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) = 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` error: declaration of a static with `export_name`
--> $DIR/lint-unsafe-code.rs:25:32 --> $DIR/lint-unsafe-code.rs:25:39
| |
LL | #[export_name = "BAR"] static BAR: u32 = 5; LL | #[export_name = "BAR"] static BAR: u32 = 5;
| ^^^^^^^^^^^^^^^^^^^^ | ^^^
... ...
LL | unsafe_in_macro!() LL | unsafe_in_macro!()
| ------------------ in this macro invocation | ------------------ in this macro invocation