forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#85788 - rylev:force-warns, r=nikomatsakis
Support for force-warns Implements rust-lang#85512. This PR adds a new command line option `force-warns` which will force the provided lints to warn even if they are allowed by some other mechanism such as `#![allow(warnings)]`. Some remaining issues: * rust-lang#85512 mentions that `force-warns` should also be capable of taking lint groups instead of individual lints. This is not implemented. * If a lint has a higher warning level than `warn`, this will cause that lint to warn instead. We probably want to allow the lint to error if it is set to a higher lint and is not allowed somewhere else. * One test is currently ignored because it's not working - when a deny-by-default lint is allowed, it does not currently warn under `force-warns`. I'm not sure why, but I wanted to get this in before the weekend. r? `@nikomatsakis`
- Loading branch information
Showing
28 changed files
with
321 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# `force-warns` | ||
|
||
The tracking issue for this feature is: [#85512](https://github.com/rust-lang/rust/issues/85512). | ||
|
||
------------------------ | ||
|
||
This feature allows you to cause any lint to produce a warning even if the lint has a different level by default or another level is set somewhere else. For instance, the `force-warns` option can be used to make a lint (e.g., `dead_code`) produce a warning even if that lint is allowed in code with `#![allow(dead_code)]`. | ||
|
||
## Example | ||
|
||
```rust,ignore (partial-example) | ||
#![allow(dead_code)] | ||
fn dead_function() {} | ||
// This would normally not produce a warning even though the | ||
// function is not used, because dead code is being allowed | ||
fn main() {} | ||
``` | ||
|
||
We can force a warning to be produced by providing `--force-warns dead_code` to rustc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
error: the `-Z unstable-options` flag must also be passed to enable the flag `--force-warns=lints` | ||
|
11 changes: 11 additions & 0 deletions
11
src/test/ui/lint/force-warn/force-allowed-by-default-lint.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// compile-flags: --force-warns elided_lifetimes_in_paths | ||
// check-pass | ||
|
||
struct Foo<'a> { | ||
x: &'a u32, | ||
} | ||
|
||
fn foo(x: &Foo) {} | ||
//~^ WARN hidden lifetime parameters in types are deprecated | ||
|
||
fn main() {} |
10 changes: 10 additions & 0 deletions
10
src/test/ui/lint/force-warn/force-allowed-by-default-lint.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
warning: hidden lifetime parameters in types are deprecated | ||
--> $DIR/force-allowed-by-default-lint.rs:8:12 | ||
| | ||
LL | fn foo(x: &Foo) {} | ||
| ^^^- help: indicate the anonymous lifetime: `<'_>` | ||
| | ||
= note: warning forced by `force-warns` commandline option | ||
|
||
warning: 1 warning emitted | ||
|
9 changes: 9 additions & 0 deletions
9
src/test/ui/lint/force-warn/force-allowed-deny-by-default-lint.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// compile-flags: --force-warns const_err | ||
// check-pass | ||
|
||
#![allow(const_err)] | ||
const C: i32 = 1 / 0; | ||
//~^ WARN any use of this value will cause an error | ||
//~| WARN this was previously accepted by the compiler | ||
|
||
fn main() {} |
14 changes: 14 additions & 0 deletions
14
src/test/ui/lint/force-warn/force-allowed-deny-by-default-lint.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
warning: any use of this value will cause an error | ||
--> $DIR/force-allowed-deny-by-default-lint.rs:5:16 | ||
| | ||
LL | const C: i32 = 1 / 0; | ||
| ---------------^^^^^- | ||
| | | ||
| attempt to divide `1_i32` by zero | ||
| | ||
= note: warning forced by `force-warns` commandline option | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800> | ||
|
||
warning: 1 warning emitted | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// compile-flags: --force-warns dead_code | ||
// check-pass | ||
|
||
#![allow(dead_code)] | ||
|
||
fn dead_function() {} | ||
//~^ WARN function is never used | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
warning: function is never used: `dead_function` | ||
--> $DIR/force-allowed-warning.rs:6:4 | ||
| | ||
LL | fn dead_function() {} | ||
| ^^^^^^^^^^^^^ | ||
| | ||
= note: warning forced by `force-warns` commandline option | ||
|
||
warning: 1 warning emitted | ||
|
Oops, something went wrong.