Skip to content

Commit 79b0ab5

Browse files
committed
Scope no_mangle and export_name warnings to the declarations name
1 parent 66b2f9a commit 79b0ab5

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

compiler/rustc_lint/src/builtin.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,25 +279,25 @@ impl EarlyLintPass for UnsafeCode {
279279

280280
ast::ItemKind::Fn(..) => {
281281
if attr::contains_name(&it.attrs, sym::no_mangle) {
282-
self.report_unsafe(cx, it.span, |lint| {
282+
self.report_unsafe(cx, it.ident.span, |lint| {
283283
lint.build("declaration of a `no_mangle` function").emit();
284284
})
285285
}
286286
if attr::contains_name(&it.attrs, sym::export_name) {
287-
self.report_unsafe(cx, it.span, |lint| {
287+
self.report_unsafe(cx, it.ident.span, |lint| {
288288
lint.build("declaration of a function with `export_name`").emit();
289289
})
290290
}
291291
}
292292

293293
ast::ItemKind::Static(..) => {
294294
if attr::contains_name(&it.attrs, sym::no_mangle) {
295-
self.report_unsafe(cx, it.span, |lint| {
295+
self.report_unsafe(cx, it.ident.span, |lint| {
296296
lint.build("declaration of a `no_mangle` static").emit();
297297
})
298298
}
299299
if attr::contains_name(&it.attrs, sym::export_name) {
300-
self.report_unsafe(cx, it.span, |lint| {
300+
self.report_unsafe(cx, it.ident.span, |lint| {
301301
lint.build("declaration of a static with `export_name`").emit();
302302
})
303303
}

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

Lines changed: 16 additions & 16 deletions
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:14
2+
--> $DIR/lint-unsafe-code.rs:31:17
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
@@ -11,22 +11,22 @@ LL | #![deny(unsafe_code)]
1111
| ^^^^^^^^^^^
1212

1313
error: declaration of a `no_mangle` static
14-
--> $DIR/lint-unsafe-code.rs:32:14
14+
--> $DIR/lint-unsafe-code.rs:32:21
1515
|
1616
LL | #[no_mangle] static FOO: u32 = 5;
17-
| ^^^^^^^^^^^^^^^^^^^^
17+
| ^^^
1818

1919
error: declaration of a function with `export_name`
20-
--> $DIR/lint-unsafe-code.rs:34:24
20+
--> $DIR/lint-unsafe-code.rs:34:27
2121
|
2222
LL | #[export_name = "bar"] fn bar() {}
23-
| ^^^^^^^^^^^
23+
| ^^^
2424

2525
error: declaration of a static with `export_name`
26-
--> $DIR/lint-unsafe-code.rs:35:24
26+
--> $DIR/lint-unsafe-code.rs:35:31
2727
|
2828
LL | #[export_name = "BAR"] static BAR: u32 = 5;
29-
| ^^^^^^^^^^^^^^^^^^^^
29+
| ^^^
3030

3131
error: declaration of an `unsafe` function
3232
--> $DIR/lint-unsafe-code.rs:37:1
@@ -107,43 +107,43 @@ LL | unsafe {}
107107
| ^^^^^^^^^
108108

109109
error: declaration of a `no_mangle` function
110-
--> $DIR/lint-unsafe-code.rs:21:22
110+
--> $DIR/lint-unsafe-code.rs:21:25
111111
|
112112
LL | #[no_mangle] fn foo() {}
113-
| ^^^^^^^^^^^
113+
| ^^^
114114
...
115115
LL | unsafe_in_macro!()
116116
| ------------------ in this macro invocation
117117
|
118118
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
119119

120120
error: declaration of a `no_mangle` static
121-
--> $DIR/lint-unsafe-code.rs:22:22
121+
--> $DIR/lint-unsafe-code.rs:22:29
122122
|
123123
LL | #[no_mangle] static FOO: u32 = 5;
124-
| ^^^^^^^^^^^^^^^^^^^^
124+
| ^^^
125125
...
126126
LL | unsafe_in_macro!()
127127
| ------------------ in this macro invocation
128128
|
129129
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
130130

131131
error: declaration of a function with `export_name`
132-
--> $DIR/lint-unsafe-code.rs:23:32
132+
--> $DIR/lint-unsafe-code.rs:23:35
133133
|
134134
LL | #[export_name = "bar"] fn bar() {}
135-
| ^^^^^^^^^^^
135+
| ^^^
136136
...
137137
LL | unsafe_in_macro!()
138138
| ------------------ in this macro invocation
139139
|
140140
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
141141

142142
error: declaration of a static with `export_name`
143-
--> $DIR/lint-unsafe-code.rs:25:32
143+
--> $DIR/lint-unsafe-code.rs:25:39
144144
|
145145
LL | #[export_name = "BAR"] static BAR: u32 = 5;
146-
| ^^^^^^^^^^^^^^^^^^^^
146+
| ^^^
147147
...
148148
LL | unsafe_in_macro!()
149149
| ------------------ in this macro invocation

0 commit comments

Comments
 (0)