Skip to content

Commit 99b73e8

Browse files
committed
Auto merge of #88134 - rylev:force-warn-improvements, r=nikomatsakis
Force warn improvements As part of stablization of the `--force-warn` option (#86516) I've made the following changes: * Error when the `warnings` lint group is based to the `--force-warn` option * Tests have been updated to make it easier to understand the semantics of `--force-warn` r? `@nikomatsakis`
2 parents b6e334d + d70056e commit 99b73e8

32 files changed

+139
-13
lines changed

compiler/rustc_error_codes/src/error_codes/E0602.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
An unknown lint was used on the command line.
1+
An unknown or invalid lint was used on the command line.
22

33
Erroneous code example:
44

compiler/rustc_lint/src/context.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,16 @@ impl LintStore {
332332
crate_attrs: &[ast::Attribute],
333333
) {
334334
let (tool_name, lint_name_only) = parse_lint_and_tool_name(lint_name);
335-
335+
if lint_name_only == crate::WARNINGS.name_lower() && level == Level::ForceWarn {
336+
return struct_span_err!(
337+
sess,
338+
DUMMY_SP,
339+
E0602,
340+
"`{}` lint group is not supported with ´--force-warn´",
341+
crate::WARNINGS.name_lower()
342+
)
343+
.emit();
344+
}
336345
let db = match self.check_lint_name(sess, lint_name_only, tool_name, crate_attrs) {
337346
CheckLintNameResult::Ok(_) => None,
338347
CheckLintNameResult::Warning(ref msg, _) => Some(sess.struct_warn(msg)),

src/test/ui/lint/force-warn/force-lint-allow-all-warnings.rs renamed to src/test/ui/lint/force-warn/allow-warnings.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// --force-warn $LINT causes $LINT (which is warn-by-default) to warn
2+
// despite allowing all warnings in module
13
// compile-flags: --force-warn dead_code -Zunstable-options
24
// check-pass
35

src/test/ui/lint/force-warn/force-allowed-warning.stderr renamed to src/test/ui/lint/force-warn/allow-warnings.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: function is never used: `dead_function`
2-
--> $DIR/force-allowed-warning.rs:6:4
2+
--> $DIR/allow-warnings.rs:8:4
33
|
44
LL | fn dead_function() {}
55
| ^^^^^^^^^^^^^

src/test/ui/lint/force-warn/force-allowed-by-default-lint.rs renamed to src/test/ui/lint/force-warn/allowed-by-default-lint.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// --force-warn $LINT causes $LINT (which is allow-by-default) to warn
12
// compile-flags: --force-warn elided_lifetimes_in_paths -Zunstable-options
23
// check-pass
34

src/test/ui/lint/force-warn/force-allowed-by-default-lint.stderr renamed to src/test/ui/lint/force-warn/allowed-by-default-lint.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: hidden lifetime parameters in types are deprecated
2-
--> $DIR/force-allowed-by-default-lint.rs:8:12
2+
--> $DIR/allowed-by-default-lint.rs:9:12
33
|
44
LL | fn foo(x: &Foo) {}
55
| ^^^- help: indicate the anonymous lifetime: `<'_>`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// --force-warn $LINT causes $LINT (which is deny-by-default) to warn
2+
// despite $LINT being allowed on command line
3+
// compile-flags: -A const_err --force-warn const_err -Zunstable-options
4+
// check-pass
5+
6+
const C: i32 = 1 / 0;
7+
//~^ WARN any use of this value will cause an error
8+
//~| WARN this was previously accepted by the compiler
9+
10+
fn main() {}

src/test/ui/lint/force-warn/force-allowed-deny-by-default-lint.stderr renamed to src/test/ui/lint/force-warn/allowed-cli-deny-by-default-lint.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: any use of this value will cause an error
2-
--> $DIR/force-allowed-deny-by-default-lint.rs:5:16
2+
--> $DIR/allowed-cli-deny-by-default-lint.rs:6:16
33
|
44
LL | const C: i32 = 1 / 0;
55
| ---------------^^^^^-

src/test/ui/lint/force-warn/force-allowed-deny-by-default-lint.rs renamed to src/test/ui/lint/force-warn/allowed-deny-by-default-lint.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// --force-warn $LINT causes $LINT (which is deny-by-default) to warn
2+
// despite $LINT being allowed in module
13
// compile-flags: --force-warn const_err -Zunstable-options
24
// check-pass
35

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
warning: any use of this value will cause an error
2+
--> $DIR/allowed-deny-by-default-lint.rs:7:16
3+
|
4+
LL | const C: i32 = 1 / 0;
5+
| ---------------^^^^^-
6+
| |
7+
| attempt to divide `1_i32` by zero
8+
|
9+
= note: requested on the command line with `--force-warn const-err`
10+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
11+
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
12+
13+
warning: 1 warning emitted
14+

src/test/ui/lint/force-warn/force-lint-in-allowed-group.rs renamed to src/test/ui/lint/force-warn/allowed-group-warn-by-default-lint.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// --force-warn $LINT causes $LINT (which is warn-by-default) to warn
2+
// despite $LINT_GROUP (which contains $LINT) being allowed
13
// compile-flags: --force-warn bare_trait_objects -Zunstable-options
24
// check-pass
35

src/test/ui/lint/force-warn/force-lint-in-allowed-group.stderr renamed to src/test/ui/lint/force-warn/allowed-group-warn-by-default-lint.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: trait objects without an explicit `dyn` are deprecated
2-
--> $DIR/force-lint-in-allowed-group.rs:8:25
2+
--> $DIR/allowed-group-warn-by-default-lint.rs:10:25
33
|
44
LL | pub fn function(_x: Box<SomeTrait>) {}
55
| ^^^^^^^^^ help: use `dyn`: `dyn SomeTrait`

src/test/ui/lint/force-warn/force-allowed-warning.rs renamed to src/test/ui/lint/force-warn/allowed-warn-by-default-lint.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// --force-warn $LINT causes $LINT (which is warn-by-default) to warn
2+
// despite $LINT being allowed in module
13
// compile-flags: --force-warn dead_code -Zunstable-options
24
// check-pass
35

src/test/ui/lint/force-warn/force-lint-allow-all-warnings.stderr renamed to src/test/ui/lint/force-warn/allowed-warn-by-default-lint.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: function is never used: `dead_function`
2-
--> $DIR/force-lint-allow-all-warnings.rs:6:4
2+
--> $DIR/allowed-warn-by-default-lint.rs:8:4
33
|
44
LL | fn dead_function() {}
55
| ^^^^^^^^^^^^^

src/test/ui/lint/force-warn/force-warn-cap-lints-allow.rs renamed to src/test/ui/lint/force-warn/cap-lints-allow.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// --force-warn $LINT casuses $LINT to warn despite --cap-lints
2+
// set to allow
13
// compile-flags: --cap-lints allow --force-warn bare_trait_objects -Zunstable-options
24
// check-pass
35

src/test/ui/lint/force-warn/force-warn-cap-lints-allow.stderr renamed to src/test/ui/lint/force-warn/cap-lints-allow.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: trait objects without an explicit `dyn` are deprecated
2-
--> $DIR/force-warn-cap-lints-allow.rs:6:25
2+
--> $DIR/cap-lints-allow.rs:8:25
33
|
44
LL | pub fn function(_x: Box<SomeTrait>) {}
55
| ^^^^^^^^^ help: use `dyn`: `dyn SomeTrait`

src/test/ui/lint/force-warn/force-warn-cap-lints-warn.rs renamed to src/test/ui/lint/force-warn/cap-lints-warn-allowed-warn-by-default-lint.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// --force-warn $LINT_GROUP causes $LINT to warn despite $LINT being
2+
// allowed in module and cap-lints set to warn
13
// compile-flags: --cap-lints warn --force-warn rust-2021-compatibility -Zunstable-options
24
// check-pass
35
#![allow(ellipsis_inclusive_range_patterns)]

src/test/ui/lint/force-warn/force-warn-cap-lints-warn.stderr renamed to src/test/ui/lint/force-warn/cap-lints-warn-allowed-warn-by-default-lint.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: `...` range patterns are deprecated
2-
--> $DIR/force-warn-cap-lints-warn.rs:8:10
2+
--> $DIR/cap-lints-warn-allowed-warn-by-default-lint.rs:10:10
33
|
44
LL | 0...100 => true,
55
| ^^^ help: use `..=` for an inclusive range

src/test/ui/lint/force-warn/force-deny-by-default-lint.rs renamed to src/test/ui/lint/force-warn/deny-by-default-lint.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// --force-warn $LINT causes $LINT (which is deny-by-default) to warn
12
// compile-flags: --force-warn const_err -Zunstable-options
23
// check-pass
34

src/test/ui/lint/force-warn/force-deny-by-default-lint.stderr renamed to src/test/ui/lint/force-warn/deny-by-default-lint.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: any use of this value will cause an error
2-
--> $DIR/force-deny-by-default-lint.rs:4:16
2+
--> $DIR/deny-by-default-lint.rs:5:16
33
|
44
LL | const C: i32 = 1 / 0;
55
| ---------------^^^^^-

src/test/ui/lint/force-warn/force-lint-group-allow-all-warnings.rs renamed to src/test/ui/lint/force-warn/lint-group-allow-warnings.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// --force-warn $LINT_GROUP causes $LINT in $LINT_GROUP to warn
2+
// despite all warnings being allowed in module
3+
// warn-by-default lint to warn
14
// compile-flags: --force-warn nonstandard_style -Zunstable-options
25
// check-pass
36

src/test/ui/lint/force-warn/force-lint-group-allow-all-warnings.stderr renamed to src/test/ui/lint/force-warn/lint-group-allow-warnings.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: function `FUNCTION` should have a snake case name
2-
--> $DIR/force-lint-group-allow-all-warnings.rs:6:8
2+
--> $DIR/lint-group-allow-warnings.rs:9:8
33
|
44
LL | pub fn FUNCTION() {}
55
| ^^^^^^^^ help: convert the identifier to snake case: `function`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// --force-warn $LINT_GROUP causes $LINT (which is warn-by-default) to warn
2+
// despite $LINT being allowed on command line
3+
// compile-flags: -A bare-trait-objects --force-warn rust-2018-idioms -Zunstable-options
4+
// check-pass
5+
6+
pub trait SomeTrait {}
7+
8+
pub fn function(_x: Box<SomeTrait>) {}
9+
//~^ WARN trait objects without an explicit `dyn` are deprecated
10+
//~| WARN this is accepted in the current edition
11+
12+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
warning: trait objects without an explicit `dyn` are deprecated
2+
--> $DIR/lint-group-allowed-cli-warn-by-default-lint.rs:8:25
3+
|
4+
LL | pub fn function(_x: Box<SomeTrait>) {}
5+
| ^^^^^^^^^ help: use `dyn`: `dyn SomeTrait`
6+
|
7+
= note: `--force-warn bare-trait-objects` implied by `--force-warn rust-2018-idioms`
8+
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
9+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
10+
11+
warning: 1 warning emitted
12+

src/test/ui/lint/force-warn/force-warn-group.rs renamed to src/test/ui/lint/force-warn/lint-group-allowed-lint-group.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// --force-warn $LINT_GROUP causes $LINT to warn despite
2+
// $LINT_GROUP being allowed in module
13
// compile-flags: --force-warn rust_2018_idioms -Zunstable-options
24
// check-pass
35

src/test/ui/lint/force-warn/force-warn-group.stderr renamed to src/test/ui/lint/force-warn/lint-group-allowed-lint-group.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: trait objects without an explicit `dyn` are deprecated
2-
--> $DIR/force-warn-group.rs:8:25
2+
--> $DIR/lint-group-allowed-lint-group.rs:10:25
33
|
44
LL | pub fn function(_x: Box<SomeTrait>) {}
55
| ^^^^^^^^^ help: use `dyn`: `dyn SomeTrait`

src/test/ui/lint/force-warn/force-warn-group-allow-warning.rs renamed to src/test/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// --force-warn $LINT_GROUP causes $LINT (which is warn-by-default) to warn
2+
// despite $LINT being allowed in module
13
// compile-flags: --force-warn rust-2018-idioms -Zunstable-options
24
// check-pass
35

src/test/ui/lint/force-warn/force-warn-group-allow-warning.stderr renamed to src/test/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: trait objects without an explicit `dyn` are deprecated
2-
--> $DIR/force-warn-group-allow-warning.rs:8:25
2+
--> $DIR/lint-group-allowed-warn-by-default-lint.rs:10:25
33
|
44
LL | pub fn function(_x: Box<SomeTrait>) {}
55
| ^^^^^^^^^ help: use `dyn`: `dyn SomeTrait`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// --force-warn $LINT causes $LINT (which is warn-by-default) to warn
2+
// despite being allowed in one submodule (but not the other)
3+
// compile-flags: --force-warn dead_code -Zunstable-options
4+
// check-pass
5+
6+
mod one {
7+
#![allow(dead_code)]
8+
9+
fn dead_function() {}
10+
//~^ WARN function is never used
11+
}
12+
13+
mod two {
14+
fn dead_function() {}
15+
//~^ WARN function is never used
16+
}
17+
18+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
warning: function is never used: `dead_function`
2+
--> $DIR/warn-by-default-lint-two-modules.rs:9:8
3+
|
4+
LL | fn dead_function() {}
5+
| ^^^^^^^^^^^^^
6+
|
7+
= note: requested on the command line with `--force-warn dead-code`
8+
9+
warning: function is never used: `dead_function`
10+
--> $DIR/warn-by-default-lint-two-modules.rs:14:8
11+
|
12+
LL | fn dead_function() {}
13+
| ^^^^^^^^^^^^^
14+
15+
warning: 2 warnings emitted
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// --force-warn warnings is an error
2+
// compile-flags: --force-warn warnings -Zunstable-options
3+
// error-pattern: `warnings` lint group is not supported
4+
5+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0602]: `warnings` lint group is not supported with ´--force-warn´
2+
3+
error[E0602]: `warnings` lint group is not supported with ´--force-warn´
4+
5+
error[E0602]: `warnings` lint group is not supported with ´--force-warn´
6+
7+
error: aborting due to 3 previous errors
8+
9+
For more information about this error, try `rustc --explain E0602`.

0 commit comments

Comments
 (0)