Skip to content

Commit 2a8b60f

Browse files
committed
Emit weird lint name lints after expansion
Previously, we were emitting weird name lints (for renamed or unknown lints) before expansion, most importantly before cfg expansion. This meant that the weird name lints would not fire for lint attributes hidden inside cfg_attr. The same applied for lint level specifications of those lints. By moving the lints for the lint names to the post-expansion phase, these issues are resolved.
1 parent cd251fb commit 2a8b60f

File tree

7 files changed

+212
-47
lines changed

7 files changed

+212
-47
lines changed

compiler/rustc_lint/src/early.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,25 @@ pub fn check_ast_node<'a>(
424424
let mut passes: Vec<_> = passes.iter().map(|p| (p)()).collect();
425425
let mut buffered = lint_buffer.unwrap_or_default();
426426

427-
if !sess.opts.debugging_opts.no_interleave_lints {
427+
if sess.opts.debugging_opts.no_interleave_lints {
428+
for (i, pass) in passes.iter_mut().enumerate() {
429+
buffered =
430+
sess.prof.extra_verbose_generic_activity("run_lint", pass.name()).run(|| {
431+
early_lint_node(
432+
sess,
433+
!pre_expansion && i == 0,
434+
lint_store,
435+
registered_tools,
436+
buffered,
437+
EarlyLintPassObjects { lints: slice::from_mut(pass) },
438+
check_node,
439+
)
440+
});
441+
}
442+
} else {
428443
buffered = early_lint_node(
429444
sess,
430-
pre_expansion,
445+
!pre_expansion,
431446
lint_store,
432447
registered_tools,
433448
buffered,
@@ -446,21 +461,6 @@ pub fn check_ast_node<'a>(
446461
check_node,
447462
);
448463
}
449-
} else {
450-
for (i, pass) in passes.iter_mut().enumerate() {
451-
buffered =
452-
sess.prof.extra_verbose_generic_activity("run_lint", pass.name()).run(|| {
453-
early_lint_node(
454-
sess,
455-
pre_expansion && i == 0,
456-
lint_store,
457-
registered_tools,
458-
buffered,
459-
EarlyLintPassObjects { lints: slice::from_mut(pass) },
460-
check_node,
461-
)
462-
});
463-
}
464464
}
465465

466466
// All of the buffered lints should have been emitted at this point.

src/test/ui-fulldeps/lint-tool-test.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ warning: lint name `test_group` is deprecated and may not have an effect in the
1818
LL | #[allow(test_group)]
1919
| ^^^^^^^^^^ help: change it to: `clippy::test_group`
2020

21-
warning: unknown lint: `this_lint_does_not_exist`
22-
--> $DIR/lint-tool-test.rs:36:8
23-
|
24-
LL | #[deny(this_lint_does_not_exist)]
25-
| ^^^^^^^^^^^^^^^^^^^^^^^^
26-
|
27-
= note: `#[warn(unknown_lints)]` on by default
28-
2921
warning: lint name `test_lint` is deprecated and may not have an effect in the future.
3022
--> $DIR/lint-tool-test.rs:9:23
3123
|
@@ -44,6 +36,14 @@ warning: lint name `test_group` is deprecated and may not have an effect in the
4436
LL | #[allow(test_group)]
4537
| ^^^^^^^^^^ help: change it to: `clippy::test_group`
4638

39+
warning: unknown lint: `this_lint_does_not_exist`
40+
--> $DIR/lint-tool-test.rs:36:8
41+
|
42+
LL | #[deny(this_lint_does_not_exist)]
43+
| ^^^^^^^^^^^^^^^^^^^^^^^^
44+
|
45+
= note: `#[warn(unknown_lints)]` on by default
46+
4747
warning: use of deprecated attribute `plugin`: compiler plugins are deprecated. See https://github.com/rust-lang/rust/pull/64675
4848
--> $DIR/lint-tool-test.rs:6:1
4949
|

src/test/ui/feature-gates/issue-43106-gating-of-builtin-attrs.stderr

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
warning: `#[macro_escape]` is a deprecated synonym for `#[macro_use]`
2+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:401:17
3+
|
4+
LL | mod inner { #![macro_escape] }
5+
| ^^^^^^^^^^^^^^^^
6+
|
7+
= help: try an outer attribute: `#[macro_use]`
8+
9+
warning: `#[macro_escape]` is a deprecated synonym for `#[macro_use]`
10+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:398:1
11+
|
12+
LL | #[macro_escape]
13+
| ^^^^^^^^^^^^^^^
14+
115
warning: unknown lint: `x5400`
216
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:46:9
317
|
@@ -172,20 +186,6 @@ warning: unknown lint: `x5100`
172186
LL | #[deny(x5100)] impl S { }
173187
| ^^^^^
174188

175-
warning: `#[macro_escape]` is a deprecated synonym for `#[macro_use]`
176-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:401:17
177-
|
178-
LL | mod inner { #![macro_escape] }
179-
| ^^^^^^^^^^^^^^^^
180-
|
181-
= help: try an outer attribute: `#[macro_use]`
182-
183-
warning: `#[macro_escape]` is a deprecated synonym for `#[macro_use]`
184-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:398:1
185-
|
186-
LL | #[macro_escape]
187-
| ^^^^^^^^^^^^^^^
188-
189189
warning: use of deprecated attribute `crate_id`: no longer used.
190190
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:85:1
191191
|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
error: unknown lint: `nonex_lint_top_level`
2+
--> $DIR/issue-97094.rs:14:26
3+
|
4+
LL | #![cfg_attr(all(), allow(nonex_lint_top_level))]
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/issue-97094.rs:10:9
9+
|
10+
LL | #![deny(warnings)]
11+
| ^^^^^^^^
12+
= note: `#[deny(unknown_lints)]` implied by `#[deny(warnings)]`
13+
14+
error: lint `bare_trait_object` has been renamed to `bare_trait_objects`
15+
--> $DIR/issue-97094.rs:16:26
16+
|
17+
LL | #![cfg_attr(all(), allow(bare_trait_object))]
18+
| ^^^^^^^^^^^^^^^^^ help: use the new name: `bare_trait_objects`
19+
|
20+
= note: `#[deny(renamed_and_removed_lints)]` implied by `#[deny(warnings)]`
21+
22+
error: unknown lint: `nonex_lint_mod`
23+
--> $DIR/issue-97094.rs:19:25
24+
|
25+
LL | #[cfg_attr(all(), allow(nonex_lint_mod))]
26+
| ^^^^^^^^^^^^^^
27+
28+
error: unknown lint: `nonex_lint_mod_inner`
29+
--> $DIR/issue-97094.rs:22:30
30+
|
31+
LL | #![cfg_attr(all(), allow(nonex_lint_mod_inner))]
32+
| ^^^^^^^^^^^^^^^^^^^^
33+
34+
error: unknown lint: `nonex_lint_fn`
35+
--> $DIR/issue-97094.rs:26:25
36+
|
37+
LL | #[cfg_attr(all(), allow(nonex_lint_fn))]
38+
| ^^^^^^^^^^^^^
39+
40+
error: unknown lint: `nonex_lint_in_macro`
41+
--> $DIR/issue-97094.rs:37:29
42+
|
43+
LL | #[cfg_attr(all(), allow(nonex_lint_in_macro))]
44+
| ^^^^^^^^^^^^^^^^^^^
45+
46+
error: unknown lint: `nonex_lint_fn`
47+
--> $DIR/issue-97094.rs:56:13
48+
|
49+
LL | #[allow(nonex_lint_fn)]
50+
| ^^^^^^^^^^^^^
51+
52+
error: aborting due to 7 previous errors
53+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
error: unknown lint: `nonex_lint_top_level`
2+
--> $DIR/issue-97094.rs:14:26
3+
|
4+
LL | #![cfg_attr(all(), allow(nonex_lint_top_level))]
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/issue-97094.rs:10:9
9+
|
10+
LL | #![deny(warnings)]
11+
| ^^^^^^^^
12+
= note: `#[deny(unknown_lints)]` implied by `#[deny(warnings)]`
13+
14+
error: lint `bare_trait_object` has been renamed to `bare_trait_objects`
15+
--> $DIR/issue-97094.rs:16:26
16+
|
17+
LL | #![cfg_attr(all(), allow(bare_trait_object))]
18+
| ^^^^^^^^^^^^^^^^^ help: use the new name: `bare_trait_objects`
19+
|
20+
= note: `#[deny(renamed_and_removed_lints)]` implied by `#[deny(warnings)]`
21+
22+
error: unknown lint: `nonex_lint_mod`
23+
--> $DIR/issue-97094.rs:19:25
24+
|
25+
LL | #[cfg_attr(all(), allow(nonex_lint_mod))]
26+
| ^^^^^^^^^^^^^^
27+
28+
error: unknown lint: `nonex_lint_mod_inner`
29+
--> $DIR/issue-97094.rs:22:30
30+
|
31+
LL | #![cfg_attr(all(), allow(nonex_lint_mod_inner))]
32+
| ^^^^^^^^^^^^^^^^^^^^
33+
34+
error: unknown lint: `nonex_lint_fn`
35+
--> $DIR/issue-97094.rs:26:25
36+
|
37+
LL | #[cfg_attr(all(), allow(nonex_lint_fn))]
38+
| ^^^^^^^^^^^^^
39+
40+
error: unknown lint: `nonex_lint_in_macro`
41+
--> $DIR/issue-97094.rs:37:29
42+
|
43+
LL | #[cfg_attr(all(), allow(nonex_lint_in_macro))]
44+
| ^^^^^^^^^^^^^^^^^^^
45+
46+
error: unknown lint: `nonex_lint_fn`
47+
--> $DIR/issue-97094.rs:56:13
48+
|
49+
LL | #[allow(nonex_lint_fn)]
50+
| ^^^^^^^^^^^^^
51+
52+
error: aborting due to 7 previous errors
53+

src/test/ui/lint/issue-97094.rs

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// revisions: interleaved nointerleaved
2+
// [nointerleaved]compile-flags: -Z no-interleave-lints
3+
4+
// This test has two revisions because the logic change
5+
// needed to make this test pass had to be adjusted
6+
// for no-interleave-lints. Should the debug option
7+
// be removed one day, please don't remove this
8+
// test entirely, just remove the revision from it.
9+
10+
#![deny(warnings)]
11+
12+
// Ensure that unknown lints inside cfg-attr's are linted for
13+
14+
#![cfg_attr(all(), allow(nonex_lint_top_level))]
15+
//~^ ERROR unknown lint
16+
#![cfg_attr(all(), allow(bare_trait_object))]
17+
//~^ ERROR has been renamed
18+
19+
#[cfg_attr(all(), allow(nonex_lint_mod))]
20+
//~^ ERROR unknown lint
21+
mod baz {
22+
#![cfg_attr(all(), allow(nonex_lint_mod_inner))]
23+
//~^ ERROR unknown lint
24+
}
25+
26+
#[cfg_attr(all(), allow(nonex_lint_fn))]
27+
//~^ ERROR unknown lint
28+
pub fn main() {}
29+
30+
macro_rules! bar {
31+
($($t:tt)*) => {
32+
$($t)*
33+
};
34+
}
35+
36+
bar!(
37+
#[cfg_attr(all(), allow(nonex_lint_in_macro))]
38+
//~^ ERROR unknown lint
39+
pub fn _bar() {}
40+
);
41+
42+
// No warning for non-applying cfg
43+
#[cfg_attr(any(), allow(nonex_lint_fn))]
44+
pub fn _foo() {}
45+
46+
// Allowing unknown lints works if inside cfg_attr
47+
#[cfg_attr(all(), allow(unknown_lints))]
48+
mod bar_allowed {
49+
#[allow(nonex_lint_fn)]
50+
fn _foo() {}
51+
}
52+
53+
// ... but not if the cfg_attr doesn't evaluate
54+
#[cfg_attr(any(), allow(unknown_lints))]
55+
mod bar_not_allowed {
56+
#[allow(nonex_lint_fn)]
57+
//~^ ERROR unknown lint
58+
fn _foo() {}
59+
}

src/test/ui/lint/reasons-erroneous.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,6 @@ error[E0452]: malformed lint attribute input
5858
LL | #![warn(keyword_idents, reason = "root in rubble", macro_use_extern_crate)]
5959
| ^^^^^^^^^^^^^^^^^^^^^^^^^ reason in lint attribute must come last
6060

61-
warning: unknown lint: `reason`
62-
--> $DIR/reasons-erroneous.rs:50:39
63-
|
64-
LL | #![warn(missing_copy_implementations, reason)]
65-
| ^^^^^^
66-
|
67-
= note: `#[warn(unknown_lints)]` on by default
68-
6961
error[E0452]: malformed lint attribute input
7062
--> $DIR/reasons-erroneous.rs:3:58
7163
|
@@ -126,6 +118,14 @@ error[E0452]: malformed lint attribute input
126118
LL | #![warn(keyword_idents, reason = "root in rubble", macro_use_extern_crate)]
127119
| ^^^^^^^^^^^^^^^^^^^^^^^^^ reason in lint attribute must come last
128120

121+
warning: unknown lint: `reason`
122+
--> $DIR/reasons-erroneous.rs:50:39
123+
|
124+
LL | #![warn(missing_copy_implementations, reason)]
125+
| ^^^^^^
126+
|
127+
= note: `#[warn(unknown_lints)]` on by default
128+
129129
error: aborting due to 20 previous errors; 1 warning emitted
130130

131131
For more information about this error, try `rustc --explain E0452`.

0 commit comments

Comments
 (0)