Skip to content

Commit

Permalink
Auto merge of rust-lang#88134 - rylev:force-warn-improvements, r=niko…
Browse files Browse the repository at this point in the history
…matsakis

Force warn improvements

As part of stablization of the `--force-warn` option (rust-lang#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`
  • Loading branch information
bors committed Aug 21, 2021
2 parents b6e334d + d70056e commit 99b73e8
Show file tree
Hide file tree
Showing 32 changed files with 139 additions and 13 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/error_codes/E0602.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
An unknown lint was used on the command line.
An unknown or invalid lint was used on the command line.

Erroneous code example:

Expand Down
11 changes: 10 additions & 1 deletion compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,16 @@ impl LintStore {
crate_attrs: &[ast::Attribute],
) {
let (tool_name, lint_name_only) = parse_lint_and_tool_name(lint_name);

if lint_name_only == crate::WARNINGS.name_lower() && level == Level::ForceWarn {
return struct_span_err!(
sess,
DUMMY_SP,
E0602,
"`{}` lint group is not supported with ´--force-warn´",
crate::WARNINGS.name_lower()
)
.emit();
}
let db = match self.check_lint_name(sess, lint_name_only, tool_name, crate_attrs) {
CheckLintNameResult::Ok(_) => None,
CheckLintNameResult::Warning(ref msg, _) => Some(sess.struct_warn(msg)),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// --force-warn $LINT causes $LINT (which is warn-by-default) to warn
// despite allowing all warnings in module
// compile-flags: --force-warn dead_code -Zunstable-options
// check-pass

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: function is never used: `dead_function`
--> $DIR/force-allowed-warning.rs:6:4
--> $DIR/allow-warnings.rs:8:4
|
LL | fn dead_function() {}
| ^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// --force-warn $LINT causes $LINT (which is allow-by-default) to warn
// compile-flags: --force-warn elided_lifetimes_in_paths -Zunstable-options
// check-pass

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: hidden lifetime parameters in types are deprecated
--> $DIR/force-allowed-by-default-lint.rs:8:12
--> $DIR/allowed-by-default-lint.rs:9:12
|
LL | fn foo(x: &Foo) {}
| ^^^- help: indicate the anonymous lifetime: `<'_>`
Expand Down
10 changes: 10 additions & 0 deletions src/test/ui/lint/force-warn/allowed-cli-deny-by-default-lint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// --force-warn $LINT causes $LINT (which is deny-by-default) to warn
// despite $LINT being allowed on command line
// compile-flags: -A const_err --force-warn const_err -Zunstable-options
// check-pass

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() {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: any use of this value will cause an error
--> $DIR/force-allowed-deny-by-default-lint.rs:5:16
--> $DIR/allowed-cli-deny-by-default-lint.rs:6:16
|
LL | const C: i32 = 1 / 0;
| ---------------^^^^^-
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// --force-warn $LINT causes $LINT (which is deny-by-default) to warn
// despite $LINT being allowed in module
// compile-flags: --force-warn const_err -Zunstable-options
// check-pass

Expand Down
14 changes: 14 additions & 0 deletions src/test/ui/lint/force-warn/allowed-deny-by-default-lint.stderr
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/allowed-deny-by-default-lint.rs:7:16
|
LL | const C: i32 = 1 / 0;
| ---------------^^^^^-
| |
| attempt to divide `1_i32` by zero
|
= note: requested on the command line with `--force-warn const-err`
= 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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: trait objects without an explicit `dyn` are deprecated
--> $DIR/force-lint-in-allowed-group.rs:8:25
--> $DIR/allowed-group-warn-by-default-lint.rs:10:25
|
LL | pub fn function(_x: Box<SomeTrait>) {}
| ^^^^^^^^^ help: use `dyn`: `dyn SomeTrait`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// --force-warn $LINT causes $LINT (which is warn-by-default) to warn
// despite $LINT being allowed in module
// compile-flags: --force-warn dead_code -Zunstable-options
// check-pass

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: function is never used: `dead_function`
--> $DIR/force-lint-allow-all-warnings.rs:6:4
--> $DIR/allowed-warn-by-default-lint.rs:8:4
|
LL | fn dead_function() {}
| ^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// --force-warn $LINT casuses $LINT to warn despite --cap-lints
// set to allow
// compile-flags: --cap-lints allow --force-warn bare_trait_objects -Zunstable-options
// check-pass

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: trait objects without an explicit `dyn` are deprecated
--> $DIR/force-warn-cap-lints-allow.rs:6:25
--> $DIR/cap-lints-allow.rs:8:25
|
LL | pub fn function(_x: Box<SomeTrait>) {}
| ^^^^^^^^^ help: use `dyn`: `dyn SomeTrait`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// --force-warn $LINT_GROUP causes $LINT to warn despite $LINT being
// allowed in module and cap-lints set to warn
// compile-flags: --cap-lints warn --force-warn rust-2021-compatibility -Zunstable-options
// check-pass
#![allow(ellipsis_inclusive_range_patterns)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: `...` range patterns are deprecated
--> $DIR/force-warn-cap-lints-warn.rs:8:10
--> $DIR/cap-lints-warn-allowed-warn-by-default-lint.rs:10:10
|
LL | 0...100 => true,
| ^^^ help: use `..=` for an inclusive range
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// --force-warn $LINT causes $LINT (which is deny-by-default) to warn
// compile-flags: --force-warn const_err -Zunstable-options
// check-pass

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: any use of this value will cause an error
--> $DIR/force-deny-by-default-lint.rs:4:16
--> $DIR/deny-by-default-lint.rs:5:16
|
LL | const C: i32 = 1 / 0;
| ---------------^^^^^-
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// --force-warn $LINT_GROUP causes $LINT in $LINT_GROUP to warn
// despite all warnings being allowed in module
// warn-by-default lint to warn
// compile-flags: --force-warn nonstandard_style -Zunstable-options
// check-pass

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: function `FUNCTION` should have a snake case name
--> $DIR/force-lint-group-allow-all-warnings.rs:6:8
--> $DIR/lint-group-allow-warnings.rs:9:8
|
LL | pub fn FUNCTION() {}
| ^^^^^^^^ help: convert the identifier to snake case: `function`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// --force-warn $LINT_GROUP causes $LINT (which is warn-by-default) to warn
// despite $LINT being allowed on command line
// compile-flags: -A bare-trait-objects --force-warn rust-2018-idioms -Zunstable-options
// check-pass

pub trait SomeTrait {}

pub fn function(_x: Box<SomeTrait>) {}
//~^ WARN trait objects without an explicit `dyn` are deprecated
//~| WARN this is accepted in the current edition

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
warning: trait objects without an explicit `dyn` are deprecated
--> $DIR/lint-group-allowed-cli-warn-by-default-lint.rs:8:25
|
LL | pub fn function(_x: Box<SomeTrait>) {}
| ^^^^^^^^^ help: use `dyn`: `dyn SomeTrait`
|
= note: `--force-warn bare-trait-objects` implied by `--force-warn rust-2018-idioms`
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>

warning: 1 warning emitted

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: trait objects without an explicit `dyn` are deprecated
--> $DIR/force-warn-group.rs:8:25
--> $DIR/lint-group-allowed-lint-group.rs:10:25
|
LL | pub fn function(_x: Box<SomeTrait>) {}
| ^^^^^^^^^ help: use `dyn`: `dyn SomeTrait`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// --force-warn $LINT_GROUP causes $LINT (which is warn-by-default) to warn
// despite $LINT being allowed in module
// compile-flags: --force-warn rust-2018-idioms -Zunstable-options
// check-pass

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: trait objects without an explicit `dyn` are deprecated
--> $DIR/force-warn-group-allow-warning.rs:8:25
--> $DIR/lint-group-allowed-warn-by-default-lint.rs:10:25
|
LL | pub fn function(_x: Box<SomeTrait>) {}
| ^^^^^^^^^ help: use `dyn`: `dyn SomeTrait`
Expand Down
18 changes: 18 additions & 0 deletions src/test/ui/lint/force-warn/warn-by-default-lint-two-modules.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// --force-warn $LINT causes $LINT (which is warn-by-default) to warn
// despite being allowed in one submodule (but not the other)
// compile-flags: --force-warn dead_code -Zunstable-options
// check-pass

mod one {
#![allow(dead_code)]

fn dead_function() {}
//~^ WARN function is never used
}

mod two {
fn dead_function() {}
//~^ WARN function is never used
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
warning: function is never used: `dead_function`
--> $DIR/warn-by-default-lint-two-modules.rs:9:8
|
LL | fn dead_function() {}
| ^^^^^^^^^^^^^
|
= note: requested on the command line with `--force-warn dead-code`

warning: function is never used: `dead_function`
--> $DIR/warn-by-default-lint-two-modules.rs:14:8
|
LL | fn dead_function() {}
| ^^^^^^^^^^^^^

warning: 2 warnings emitted

5 changes: 5 additions & 0 deletions src/test/ui/lint/force-warn/warnings-lint-group.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// --force-warn warnings is an error
// compile-flags: --force-warn warnings -Zunstable-options
// error-pattern: `warnings` lint group is not supported

fn main() {}
9 changes: 9 additions & 0 deletions src/test/ui/lint/force-warn/warnings-lint-group.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0602]: `warnings` lint group is not supported with ´--force-warn´

error[E0602]: `warnings` lint group is not supported with ´--force-warn´

error[E0602]: `warnings` lint group is not supported with ´--force-warn´

error: aborting due to 3 previous errors

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

0 comments on commit 99b73e8

Please sign in to comment.