Auto merge of #43522 - alexcrichton:rewrite-lints, r=michaelwoerister
rustc: Rearchitect lints to be emitted more eagerly In preparation for incremental compilation this commit refactors the lint handling infrastructure in the compiler to be more "eager" and overall more incremental-friendly. Many passes of the compiler can emit lints at various points but before this commit all lints were buffered in a table to be emitted at the very end of compilation. This commit changes these lints to be emitted immediately during compilation using pre-calculated lint level-related data structures. Linting today is split into two phases, one set of "early" lints run on the `syntax::ast` and a "late" set of lints run on the HIR. This commit moves the "early" lints to running as late as possible in compilation, just before HIR lowering. This notably means that we're catching resolve-related lints just before HIR lowering. The early linting remains a pass very similar to how it was before, maintaining context of the current lint level as it walks the tree. Post-HIR, however, linting is structured as a method on the `TyCtxt` which transitively executes a query to calculate lint levels. Each request to lint on a `TyCtxt` will query the entire crate's 'lint level data structure' and then go from there about whether the lint should be emitted or not. The query depends on the entire HIR crate but should be very quick to calculate (just a quick walk of the HIR) and the red-green system should notice that the lint level data structure rarely changes, and should hopefully preserve incrementality. Overall this resulted in a pretty big change to the test suite now that lints are emitted much earlier in compilation (on-demand vs only at the end). This in turn necessitated the addition of many `#![allow(warnings)]` directives throughout the compile-fail test suite and a number of updates to the UI test suite. Closes https://github.com/rust-lang/rust/issues/42511
This commit is contained in:
commit
2400ebfe76
84 changed files with 1345 additions and 1067 deletions
|
|
@ -9,6 +9,7 @@
|
|||
// except according to those terms.
|
||||
|
||||
#![feature(exclusive_range_pattern)]
|
||||
#![warn(unreachable_patterns)]
|
||||
|
||||
fn main() {
|
||||
// These cases should generate no warning.
|
||||
|
|
@ -48,4 +49,4 @@ fn main() {
|
|||
9...9 => {},
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,24 @@
|
|||
warning: unreachable pattern
|
||||
--> $DIR/issue-43253.rs:36:9
|
||||
--> $DIR/issue-43253.rs:37:9
|
||||
|
|
||||
36 | 9 => {},
|
||||
37 | 9 => {},
|
||||
| ^
|
||||
|
|
||||
= note: #[warn(unreachable_patterns)] on by default
|
||||
note: lint level defined here
|
||||
--> $DIR/issue-43253.rs:12:9
|
||||
|
|
||||
12 | #![warn(unreachable_patterns)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: unreachable pattern
|
||||
--> $DIR/issue-43253.rs:42:9
|
||||
--> $DIR/issue-43253.rs:43:9
|
||||
|
|
||||
42 | 8...9 => {},
|
||||
43 | 8...9 => {},
|
||||
| ^^^^^
|
||||
|
||||
warning: unreachable pattern
|
||||
--> $DIR/issue-43253.rs:48:9
|
||||
--> $DIR/issue-43253.rs:49:9
|
||||
|
|
||||
48 | 9...9 => {},
|
||||
49 | 9...9 => {},
|
||||
| ^^^^^
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error[E0276]: impl has stricter requirements than trait
|
||||
error: impl has stricter requirements than trait
|
||||
--> $DIR/proj-outlives-region.rs:19:5
|
||||
|
|
||||
14 | fn foo() where T: 'a;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error[E0276]: impl has stricter requirements than trait
|
||||
error: impl has stricter requirements than trait
|
||||
--> $DIR/region-unrelated.rs:19:5
|
||||
|
|
||||
14 | fn foo() where T: 'a;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![warn(unused_must_use)]
|
||||
|
||||
struct MyStruct {
|
||||
n: usize
|
||||
|
|
|
|||
|
|
@ -1,14 +1,18 @@
|
|||
warning: unused return value of `need_to_use_this_value` which must be used: it's important
|
||||
--> $DIR/fn_must_use.rs:29:5
|
||||
--> $DIR/fn_must_use.rs:30:5
|
||||
|
|
||||
29 | need_to_use_this_value();
|
||||
30 | need_to_use_this_value();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: #[warn(unused_must_use)] on by default
|
||||
note: lint level defined here
|
||||
--> $DIR/fn_must_use.rs:11:9
|
||||
|
|
||||
11 | #![warn(unused_must_use)]
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
warning: unused return value of `MyStruct::need_to_use_this_method_value` which must be used
|
||||
--> $DIR/fn_must_use.rs:32:5
|
||||
--> $DIR/fn_must_use.rs:33:5
|
||||
|
|
||||
32 | m.need_to_use_this_method_value();
|
||||
33 | m.need_to_use_this_method_value();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,13 @@
|
|||
|
||||
#![forbid(unused, non_snake_case)]
|
||||
|
||||
#[allow(unused, unused_variables, bad_style)]
|
||||
#[allow(unused_variables)]
|
||||
fn foo() {}
|
||||
|
||||
#[allow(unused)]
|
||||
fn bar() {}
|
||||
|
||||
#[allow(bad_style)]
|
||||
fn main() {
|
||||
println!("hello forbidden world")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,29 @@
|
|||
error[E0453]: allow(unused) overruled by outer forbid(unused)
|
||||
error[E0453]: allow(unused_variables) overruled by outer forbid(unused)
|
||||
--> $DIR/outer-forbid.rs:19:9
|
||||
|
|
||||
17 | #![forbid(unused, non_snake_case)]
|
||||
| ------ `forbid` level set here
|
||||
18 |
|
||||
19 | #[allow(unused, unused_variables, bad_style)]
|
||||
| ^^^^^^ overruled by previous forbid
|
||||
19 | #[allow(unused_variables)]
|
||||
| ^^^^^^^^^^^^^^^^ overruled by previous forbid
|
||||
|
||||
error[E0453]: allow(unused_variables) overruled by outer forbid(unused)
|
||||
--> $DIR/outer-forbid.rs:19:17
|
||||
error[E0453]: allow(unused) overruled by outer forbid(unused)
|
||||
--> $DIR/outer-forbid.rs:22:9
|
||||
|
|
||||
17 | #![forbid(unused, non_snake_case)]
|
||||
| ------ `forbid` level set here
|
||||
18 |
|
||||
19 | #[allow(unused, unused_variables, bad_style)]
|
||||
| ^^^^^^^^^^^^^^^^ overruled by previous forbid
|
||||
...
|
||||
22 | #[allow(unused)]
|
||||
| ^^^^^^ overruled by previous forbid
|
||||
|
||||
error[E0453]: allow(bad_style) overruled by outer forbid(non_snake_case)
|
||||
--> $DIR/outer-forbid.rs:19:35
|
||||
--> $DIR/outer-forbid.rs:25:9
|
||||
|
|
||||
17 | #![forbid(unused, non_snake_case)]
|
||||
| -------------- `forbid` level set here
|
||||
18 |
|
||||
19 | #[allow(unused, unused_variables, bad_style)]
|
||||
| ^^^^^^^^^ overruled by previous forbid
|
||||
...
|
||||
25 | #[allow(bad_style)]
|
||||
| ^^^^^^^^^ overruled by previous forbid
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
// run-pass
|
||||
|
||||
#![warn(unused)]
|
||||
|
||||
// Parser test for #37765
|
||||
|
||||
fn with_parens<T: ToString>(arg: T) -> String { //~WARN function is never used: `with_parens`
|
||||
|
|
|
|||
|
|
@ -1,26 +1,31 @@
|
|||
warning: unnecessary parentheses around `return` value
|
||||
--> $DIR/path-lookahead.rs:16:10
|
||||
--> $DIR/path-lookahead.rs:18:10
|
||||
|
|
||||
16 | return (<T as ToString>::to_string(&arg)); //~WARN unnecessary parentheses around `return` value
|
||||
18 | return (<T as ToString>::to_string(&arg)); //~WARN unnecessary parentheses around `return` value
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: #[warn(unused_parens)] on by default
|
||||
|
||||
warning: function is never used: `with_parens`
|
||||
--> $DIR/path-lookahead.rs:15:1
|
||||
--> $DIR/path-lookahead.rs:17:1
|
||||
|
|
||||
15 | / fn with_parens<T: ToString>(arg: T) -> String { //~WARN function is never used: `with_parens`
|
||||
16 | | return (<T as ToString>::to_string(&arg)); //~WARN unnecessary parentheses around `return` value
|
||||
17 | | }
|
||||
17 | / fn with_parens<T: ToString>(arg: T) -> String { //~WARN function is never used: `with_parens`
|
||||
18 | | return (<T as ToString>::to_string(&arg)); //~WARN unnecessary parentheses around `return` value
|
||||
19 | | }
|
||||
| |_^
|
||||
|
|
||||
= note: #[warn(dead_code)] on by default
|
||||
note: lint level defined here
|
||||
--> $DIR/path-lookahead.rs:13:9
|
||||
|
|
||||
13 | #![warn(unused)]
|
||||
| ^^^^^^
|
||||
= note: #[warn(dead_code)] implied by #[warn(unused)]
|
||||
|
||||
warning: function is never used: `no_parens`
|
||||
--> $DIR/path-lookahead.rs:19:1
|
||||
--> $DIR/path-lookahead.rs:21:1
|
||||
|
|
||||
19 | / fn no_parens<T: ToString>(arg: T) -> String { //~WARN function is never used: `no_parens`
|
||||
20 | | return <T as ToString>::to_string(&arg);
|
||||
21 | | }
|
||||
21 | / fn no_parens<T: ToString>(arg: T) -> String { //~WARN function is never used: `no_parens`
|
||||
22 | | return <T as ToString>::to_string(&arg);
|
||||
23 | | }
|
||||
| |_^
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,20 @@
|
|||
error: unreachable expression
|
||||
--> $DIR/expr_unary.rs:18:28
|
||||
|
|
||||
18 | let x: ! = ! { return; 22 };
|
||||
| ^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/expr_unary.rs:14:9
|
||||
|
|
||||
14 | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0600]: cannot apply unary operator `!` to type `!`
|
||||
--> $DIR/expr_unary.rs:18:16
|
||||
|
|
||||
18 | let x: ! = ! { return; 22 };
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -11,10 +11,13 @@
|
|||
//! A test to ensure that helpful `note` messages aren't emitted more often
|
||||
//! than necessary.
|
||||
|
||||
// Although there are three errors, we should only get two "lint level defined
|
||||
// here" notes pointing at the `warnings` span, one for each error type.
|
||||
#![deny(warnings)]
|
||||
#![feature(rustc_attrs)]
|
||||
|
||||
// Although there are three warnings, we should only get two "lint level defined
|
||||
// here" notes pointing at the `warnings` span, one for each error type.
|
||||
#![warn(unused)]
|
||||
|
||||
#[rustc_error]
|
||||
fn main() {
|
||||
let theTwo = 2;
|
||||
let theOtherTwo = 2;
|
||||
|
|
|
|||
|
|
@ -1,34 +1,37 @@
|
|||
error: variable `theTwo` should have a snake case name such as `the_two`
|
||||
--> $DIR/issue-24690.rs:19:9
|
||||
warning: unused variable: `theOtherTwo`
|
||||
--> $DIR/issue-24690.rs:23:9
|
||||
|
|
||||
19 | let theTwo = 2;
|
||||
23 | let theOtherTwo = 2;
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/issue-24690.rs:18:9
|
||||
|
|
||||
18 | #![warn(unused)]
|
||||
| ^^^^^^
|
||||
= note: #[warn(unused_variables)] implied by #[warn(unused)]
|
||||
|
||||
warning: variable `theTwo` should have a snake case name such as `the_two`
|
||||
--> $DIR/issue-24690.rs:22:9
|
||||
|
|
||||
22 | let theTwo = 2;
|
||||
| ^^^^^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/issue-24690.rs:16:9
|
||||
|
|
||||
16 | #![deny(warnings)]
|
||||
| ^^^^^^^^
|
||||
= note: #[deny(non_snake_case)] implied by #[deny(warnings)]
|
||||
= note: #[warn(non_snake_case)] on by default
|
||||
|
||||
error: variable `theOtherTwo` should have a snake case name such as `the_other_two`
|
||||
--> $DIR/issue-24690.rs:20:9
|
||||
warning: variable `theOtherTwo` should have a snake case name such as `the_other_two`
|
||||
--> $DIR/issue-24690.rs:23:9
|
||||
|
|
||||
20 | let theOtherTwo = 2;
|
||||
23 | let theOtherTwo = 2;
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: unused variable: `theOtherTwo`
|
||||
--> $DIR/issue-24690.rs:20:9
|
||||
error: compilation successful
|
||||
--> $DIR/issue-24690.rs:21:1
|
||||
|
|
||||
20 | let theOtherTwo = 2;
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/issue-24690.rs:16:9
|
||||
|
|
||||
16 | #![deny(warnings)]
|
||||
| ^^^^^^^^
|
||||
= note: #[deny(unused_variables)] implied by #[deny(warnings)]
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
21 | / fn main() {
|
||||
22 | | let theTwo = 2;
|
||||
23 | | let theOtherTwo = 2;
|
||||
24 | | println!("{}", theTwo);
|
||||
25 | | }
|
||||
| |_^
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![warn(unused)]
|
||||
|
||||
macro_rules! m {
|
||||
($a:tt $b:tt) => {
|
||||
$b $a;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,16 @@
|
|||
warning: struct is never used: `S`
|
||||
--> $DIR/macro-span-replacement.rs:13:9
|
||||
--> $DIR/macro-span-replacement.rs:15:9
|
||||
|
|
||||
13 | $b $a;
|
||||
15 | $b $a;
|
||||
| ^^^^^^
|
||||
...
|
||||
18 | m!(S struct);
|
||||
20 | m!(S struct);
|
||||
| ------------- in this macro invocation
|
||||
|
|
||||
= note: #[warn(dead_code)] on by default
|
||||
note: lint level defined here
|
||||
--> $DIR/macro-span-replacement.rs:11:9
|
||||
|
|
||||
11 | #![warn(unused)]
|
||||
| ^^^^^^
|
||||
= note: #[warn(dead_code)] implied by #[warn(unused)]
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![warn(unused)]
|
||||
|
||||
use std::cmp::{Eq, Ord, min, PartialEq, PartialOrd};
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,13 @@
|
|||
warning: unused imports: `Eq`, `Ord`, `PartialEq`, `PartialOrd`
|
||||
--> $DIR/multispan-import-lint.rs:11:16
|
||||
--> $DIR/multispan-import-lint.rs:13:16
|
||||
|
|
||||
11 | use std::cmp::{Eq, Ord, min, PartialEq, PartialOrd};
|
||||
13 | use std::cmp::{Eq, Ord, min, PartialEq, PartialOrd};
|
||||
| ^^ ^^^ ^^^^^^^^^ ^^^^^^^^^^
|
||||
|
|
||||
= note: #[warn(unused_imports)] on by default
|
||||
note: lint level defined here
|
||||
--> $DIR/multispan-import-lint.rs:11:9
|
||||
|
|
||||
11 | #![warn(unused)]
|
||||
| ^^^^^^
|
||||
= note: #[warn(unused_imports)] implied by #[warn(unused)]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue