Skip to content

Commit 44e7f04

Browse files
committed
Change how spans are emitted in the builtin macro lints
1 parent 1d8882a commit 44e7f04

File tree

2 files changed

+137
-7
lines changed

2 files changed

+137
-7
lines changed

plrustc/plrustc/src/lints/builtin_macros.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ impl PlrustBuiltinMacros {
3939
if let Some((s, ..)) = utils::check_span_against_macro_diags(cx, span, &fs_diagnostic_items)
4040
{
4141
self.lint_fs(cx, s);
42-
return;
42+
if span != s {
43+
self.lint_fs(cx, span);
44+
}
4345
}
4446
let fs_def_paths: &[&[Symbol]] = &[
4547
&[sym!(core), sym!(macros), sym!(builtin), sym!(include)],
@@ -48,15 +50,19 @@ impl PlrustBuiltinMacros {
4850
];
4951
if let Some((s, ..)) = utils::check_span_against_macro_def_paths(cx, span, &fs_def_paths) {
5052
self.lint_fs(cx, s);
51-
return;
53+
if span != s {
54+
self.lint_fs(cx, span);
55+
}
5256
}
5357

5458
let env_diagnostic_items = [sym!(env_macro), sym!(option_env_macro)];
5559
if let Some((s, ..)) =
5660
utils::check_span_against_macro_diags(cx, span, &env_diagnostic_items)
5761
{
58-
self.lint_env(cx, s);
59-
return;
62+
self.lint_env(cx, span);
63+
if span != s {
64+
self.lint_env(cx, span);
65+
}
6066
}
6167
let env_def_paths: &[&[Symbol]] = &[
6268
&[sym!(core), sym!(macros), sym!(builtin), sym!(env)],
@@ -67,8 +73,10 @@ impl PlrustBuiltinMacros {
6773
&[sym!(core), sym!(option_env)],
6874
];
6975
if let Some((s, ..)) = utils::check_span_against_macro_def_paths(cx, span, &env_def_paths) {
70-
self.lint_env(cx, s);
71-
return;
76+
self.lint_env(cx, span);
77+
if span != s {
78+
self.lint_env(cx, span);
79+
}
7280
}
7381
}
7482
}

plrustc/plrustc/uitests/fs_macros.stderr

+123-1
Original file line numberDiff line numberDiff line change
@@ -6,77 +6,199 @@ LL | const _A: &str = include_str!("fs_macros_included_file.txt");
66
|
77
= note: `-F plrust-filesystem-macros` implied by `-F plrust-lints`
88

9+
error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
10+
--> $DIR/fs_macros.rs:3:18
11+
|
12+
LL | const _A: &str = include_str!("fs_macros_included_file.txt");
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
|
15+
= note: this error originates in the macro `include_str` (in Nightly builds, run with -Z macro-backtrace for more info)
16+
17+
error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
18+
--> $DIR/fs_macros.rs:5:19
19+
|
20+
LL | const _B: &[u8] = include_bytes!("fs_macros_included_file.txt");
21+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22+
923
error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
1024
--> $DIR/fs_macros.rs:5:19
1125
|
1226
LL | const _B: &[u8] = include_bytes!("fs_macros_included_file.txt");
1327
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
28+
|
29+
= note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info)
30+
31+
error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
32+
--> $DIR/fs_macros.rs:7:18
33+
|
34+
LL | const _C: &str = core::include_str!("fs_macros_included_file.txt");
35+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1436

1537
error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
1638
--> $DIR/fs_macros.rs:7:18
1739
|
1840
LL | const _C: &str = core::include_str!("fs_macros_included_file.txt");
1941
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
42+
|
43+
= note: this error originates in the macro `core::include_str` (in Nightly builds, run with -Z macro-backtrace for more info)
44+
45+
error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
46+
--> $DIR/fs_macros.rs:8:19
47+
|
48+
LL | const _D: &[u8] = core::include_bytes!("fs_macros_included_file.txt");
49+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2050

2151
error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
2252
--> $DIR/fs_macros.rs:8:19
2353
|
2454
LL | const _D: &[u8] = core::include_bytes!("fs_macros_included_file.txt");
2555
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
56+
|
57+
= note: this error originates in the macro `core::include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info)
2658

2759
error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
2860
--> $DIR/fs_macros.rs:16:18
2961
|
3062
LL | const _E: &str = indirect!(include_str);
3163
| ^^^^^^^^^^^^^^^^^^^^^^
3264

65+
error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
66+
--> $DIR/fs_macros.rs:12:9
67+
|
68+
LL | $callme!("fs_macros_included_file.txt")
69+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
70+
...
71+
LL | const _E: &str = indirect!(include_str);
72+
| ---------------------- in this macro invocation
73+
|
74+
= note: this error originates in the macro `include_str` which comes from the expansion of the macro `indirect` (in Nightly builds, run with -Z macro-backtrace for more info)
75+
3376
error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
3477
--> $DIR/fs_macros.rs:17:19
3578
|
3679
LL | const _F: &[u8] = indirect!(include_bytes);
3780
| ^^^^^^^^^^^^^^^^^^^^^^^^
3881

82+
error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
83+
--> $DIR/fs_macros.rs:12:9
84+
|
85+
LL | $callme!("fs_macros_included_file.txt")
86+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
87+
...
88+
LL | const _F: &[u8] = indirect!(include_bytes);
89+
| ------------------------ in this macro invocation
90+
|
91+
= note: this error originates in the macro `include_bytes` which comes from the expansion of the macro `indirect` (in Nightly builds, run with -Z macro-backtrace for more info)
92+
3993
error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
4094
--> $DIR/fs_macros.rs:31:18
4195
|
4296
LL | const _G: &str = in_macro!();
4397
| ^^^^^^^^^^^
4498

99+
error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
100+
--> $DIR/fs_macros.rs:21:9
101+
|
102+
LL | include_str!("fs_macros_included_file.txt")
103+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
104+
...
105+
LL | const _G: &str = in_macro!();
106+
| ----------- in this macro invocation
107+
|
108+
= note: this error originates in the macro `include_str` which comes from the expansion of the macro `in_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
109+
110+
error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
111+
--> $DIR/fs_macros.rs:32:28
112+
|
113+
LL | const _H: &str = in_macro!(include_str!("fs_macros_included_file.txt"));
114+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
115+
45116
error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
46117
--> $DIR/fs_macros.rs:32:28
47118
|
48119
LL | const _H: &str = in_macro!(include_str!("fs_macros_included_file.txt"));
49120
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
121+
|
122+
= note: this error originates in the macro `include_str` (in Nightly builds, run with -Z macro-backtrace for more info)
50123

51124
error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
52125
--> $DIR/fs_macros.rs:33:29
53126
|
54127
LL | const _I: &[u8] = in_macro!(include_bytes!("fs_macros_included_file.txt"));
55128
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
56129

130+
error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
131+
--> $DIR/fs_macros.rs:33:29
132+
|
133+
LL | const _I: &[u8] = in_macro!(include_bytes!("fs_macros_included_file.txt"));
134+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
135+
|
136+
= note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info)
137+
57138
error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
58139
--> $DIR/fs_macros.rs:34:19
59140
|
60141
LL | const _J: &[u8] = in_macro!(include_bytes, "fs_macros_included_file.txt");
61142
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
62143

144+
error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
145+
--> $DIR/fs_macros.rs:27:9
146+
|
147+
LL | $mac!($arg)
148+
| ^^^^^^^^^^^
149+
...
150+
LL | const _J: &[u8] = in_macro!(include_bytes, "fs_macros_included_file.txt");
151+
| ------------------------------------------------------- in this macro invocation
152+
|
153+
= note: this error originates in the macro `include_bytes` which comes from the expansion of the macro `in_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
154+
155+
error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
156+
--> $DIR/fs_macros.rs:37:18
157+
|
158+
LL | const _L: &str = sneaky!("fs_macros_included_file.txt");
159+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
160+
63161
error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
64162
--> $DIR/fs_macros.rs:37:18
65163
|
66164
LL | const _L: &str = sneaky!("fs_macros_included_file.txt");
67165
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
166+
|
167+
= note: this error originates in the macro `sneaky` (in Nightly builds, run with -Z macro-backtrace for more info)
68168

69169
error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
70170
--> $DIR/fs_macros.rs:38:18
71171
|
72172
LL | const _M: &str = in_macro!(sneaky, "fs_macros_included_file.txt");
73173
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
74174

175+
error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
176+
--> $DIR/fs_macros.rs:27:9
177+
|
178+
LL | $mac!($arg)
179+
| ^^^^^^^^^^^
180+
...
181+
LL | const _M: &str = in_macro!(sneaky, "fs_macros_included_file.txt");
182+
| ------------------------------------------------ in this macro invocation
183+
|
184+
= note: this error originates in the macro `sneaky` which comes from the expansion of the macro `in_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
185+
75186
error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
76187
--> $DIR/fs_macros.rs:41:21
77188
|
78189
LL | format!("{:?}", in_macro!())
79190
| ^^^^^^^^^^^
80191

81-
error: aborting due to 13 previous errors
192+
error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
193+
--> $DIR/fs_macros.rs:21:9
194+
|
195+
LL | include_str!("fs_macros_included_file.txt")
196+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
197+
...
198+
LL | format!("{:?}", in_macro!())
199+
| ----------- in this macro invocation
200+
|
201+
= note: this error originates in the macro `include_str` which comes from the expansion of the macro `in_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
202+
203+
error: aborting due to 26 previous errors
82204

0 commit comments

Comments
 (0)