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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 10 additions & 1 deletion
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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: `<'_>`
Lines changed: 10 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 14 additions & 0 deletions
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+

0 commit comments

Comments
 (0)