Skip to content

Commit 7636de3

Browse files
committed
Point to no_mangle/export_name attribute when linting
1 parent 9ed3661 commit 7636de3

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

compiler/rustc_lint/src/builtin.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -290,34 +290,34 @@ impl EarlyLintPass for UnsafeCode {
290290
}
291291

292292
ast::ItemKind::Fn(..) => {
293-
if attr::contains_name(&it.attrs, sym::no_mangle) {
293+
if let Some(attr) = attr::find_by_name(&it.attrs, sym::no_mangle) {
294294
self.report_overriden_symbol_name(
295295
cx,
296-
it.ident.span,
296+
attr.span,
297297
"declaration of a `no_mangle` function",
298298
);
299299
}
300-
if attr::contains_name(&it.attrs, sym::export_name) {
300+
if let Some(attr) = attr::find_by_name(&it.attrs, sym::export_name) {
301301
self.report_overriden_symbol_name(
302302
cx,
303-
it.ident.span,
303+
attr.span,
304304
"declaration of a function with `export_name`",
305305
);
306306
}
307307
}
308308

309309
ast::ItemKind::Static(..) => {
310-
if attr::contains_name(&it.attrs, sym::no_mangle) {
310+
if let Some(attr) = attr::find_by_name(&it.attrs, sym::no_mangle) {
311311
self.report_overriden_symbol_name(
312312
cx,
313-
it.ident.span,
313+
attr.span,
314314
"declaration of a `no_mangle` static",
315315
);
316316
}
317-
if attr::contains_name(&it.attrs, sym::export_name) {
317+
if let Some(attr) = attr::find_by_name(&it.attrs, sym::export_name) {
318318
self.report_overriden_symbol_name(
319319
cx,
320-
it.ident.span,
320+
attr.span,
321321
"declaration of a static with `export_name`",
322322
);
323323
}

src/test/ui/lint/lint-unsafe-code.stderr

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: declaration of a `no_mangle` function
2-
--> $DIR/lint-unsafe-code.rs:31:17
2+
--> $DIR/lint-unsafe-code.rs:31:1
33
|
44
LL | #[no_mangle] fn foo() {}
5-
| ^^^
5+
| ^^^^^^^^^^^^
66
|
77
note: the lint level is defined here
88
--> $DIR/lint-unsafe-code.rs:3:9
@@ -12,26 +12,26 @@ LL | #![deny(unsafe_code)]
1212
= note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them
1313

1414
error: declaration of a `no_mangle` static
15-
--> $DIR/lint-unsafe-code.rs:32:21
15+
--> $DIR/lint-unsafe-code.rs:32:1
1616
|
1717
LL | #[no_mangle] static FOO: u32 = 5;
18-
| ^^^
18+
| ^^^^^^^^^^^^
1919
|
2020
= note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them
2121

2222
error: declaration of a function with `export_name`
23-
--> $DIR/lint-unsafe-code.rs:34:27
23+
--> $DIR/lint-unsafe-code.rs:34:1
2424
|
2525
LL | #[export_name = "bar"] fn bar() {}
26-
| ^^^
26+
| ^^^^^^^^^^^^^^^^^^^^^^
2727
|
2828
= note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them
2929

3030
error: declaration of a static with `export_name`
31-
--> $DIR/lint-unsafe-code.rs:35:31
31+
--> $DIR/lint-unsafe-code.rs:35:1
3232
|
3333
LL | #[export_name = "BAR"] static BAR: u32 = 5;
34-
| ^^^
34+
| ^^^^^^^^^^^^^^^^^^^^^^
3535
|
3636
= note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them
3737

@@ -114,10 +114,10 @@ LL | unsafe {}
114114
| ^^^^^^^^^
115115

116116
error: declaration of a `no_mangle` function
117-
--> $DIR/lint-unsafe-code.rs:21:25
117+
--> $DIR/lint-unsafe-code.rs:21:9
118118
|
119119
LL | #[no_mangle] fn foo() {}
120-
| ^^^
120+
| ^^^^^^^^^^^^
121121
...
122122
LL | unsafe_in_macro!()
123123
| ------------------ in this macro invocation
@@ -126,10 +126,10 @@ LL | unsafe_in_macro!()
126126
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
127127

128128
error: declaration of a `no_mangle` static
129-
--> $DIR/lint-unsafe-code.rs:22:29
129+
--> $DIR/lint-unsafe-code.rs:22:9
130130
|
131131
LL | #[no_mangle] static FOO: u32 = 5;
132-
| ^^^
132+
| ^^^^^^^^^^^^
133133
...
134134
LL | unsafe_in_macro!()
135135
| ------------------ in this macro invocation
@@ -138,10 +138,10 @@ LL | unsafe_in_macro!()
138138
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
139139

140140
error: declaration of a function with `export_name`
141-
--> $DIR/lint-unsafe-code.rs:23:35
141+
--> $DIR/lint-unsafe-code.rs:23:9
142142
|
143143
LL | #[export_name = "bar"] fn bar() {}
144-
| ^^^
144+
| ^^^^^^^^^^^^^^^^^^^^^^
145145
...
146146
LL | unsafe_in_macro!()
147147
| ------------------ in this macro invocation
@@ -150,10 +150,10 @@ LL | unsafe_in_macro!()
150150
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
151151

152152
error: declaration of a static with `export_name`
153-
--> $DIR/lint-unsafe-code.rs:25:39
153+
--> $DIR/lint-unsafe-code.rs:25:9
154154
|
155155
LL | #[export_name = "BAR"] static BAR: u32 = 5;
156-
| ^^^
156+
| ^^^^^^^^^^^^^^^^^^^^^^
157157
...
158158
LL | unsafe_in_macro!()
159159
| ------------------ in this macro invocation

0 commit comments

Comments
 (0)