From 0d2fd70dab06a833374f52db33332d4b2ad2566f Mon Sep 17 00:00:00 2001 From: Ryan Levick Date: Wed, 18 Aug 2021 11:05:59 +0200 Subject: [PATCH 1/2] Improve force-warn tests --- ...allow-all-warnings.rs => allow-warnings.rs} | 2 ++ ...ed-warning.stderr => allow-warnings.stderr} | 2 +- ...ault-lint.rs => allowed-by-default-lint.rs} | 1 + ...t.stderr => allowed-by-default-lint.stderr} | 2 +- .../allowed-cli-deny-by-default-lint.rs | 10 ++++++++++ ...=> allowed-cli-deny-by-default-lint.stderr} | 2 +- ...lint.rs => allowed-deny-by-default-lint.rs} | 2 ++ .../allowed-deny-by-default-lint.stderr | 14 ++++++++++++++ ...s => allowed-group-warn-by-default-lint.rs} | 2 ++ ... allowed-group-warn-by-default-lint.stderr} | 2 +- ...ning.rs => allowed-warn-by-default-lint.rs} | 2 ++ ...err => allowed-warn-by-default-lint.stderr} | 2 +- ...n-cap-lints-allow.rs => cap-lints-allow.rs} | 2 ++ ...nts-allow.stderr => cap-lints-allow.stderr} | 2 +- ...lints-warn-allowed-warn-by-default-lint.rs} | 2 ++ ...s-warn-allowed-warn-by-default-lint.stderr} | 2 +- ...default-lint.rs => deny-by-default-lint.rs} | 1 + ...lint.stderr => deny-by-default-lint.stderr} | 2 +- ...arnings.rs => lint-group-allow-warnings.rs} | 3 +++ ...stderr => lint-group-allow-warnings.stderr} | 2 +- ...t-group-allowed-cli-warn-by-default-lint.rs | 12 ++++++++++++ ...oup-allowed-cli-warn-by-default-lint.stderr | 12 ++++++++++++ ...oup.rs => lint-group-allowed-lint-group.rs} | 2 ++ ...rr => lint-group-allowed-lint-group.stderr} | 2 +- ...lint-group-allowed-warn-by-default-lint.rs} | 2 ++ ...-group-allowed-warn-by-default-lint.stderr} | 2 +- .../warn-by-default-lint-two-modules.rs | 18 ++++++++++++++++++ .../warn-by-default-lint-two-modules.stderr | 16 ++++++++++++++++ 28 files changed, 114 insertions(+), 11 deletions(-) rename src/test/ui/lint/force-warn/{force-lint-allow-all-warnings.rs => allow-warnings.rs} (59%) rename src/test/ui/lint/force-warn/{force-allowed-warning.stderr => allow-warnings.stderr} (83%) rename src/test/ui/lint/force-warn/{force-allowed-by-default-lint.rs => allowed-by-default-lint.rs} (75%) rename src/test/ui/lint/force-warn/{force-allowed-by-default-lint.stderr => allowed-by-default-lint.stderr} (84%) create mode 100644 src/test/ui/lint/force-warn/allowed-cli-deny-by-default-lint.rs rename src/test/ui/lint/force-warn/{force-allowed-deny-by-default-lint.stderr => allowed-cli-deny-by-default-lint.stderr} (90%) rename src/test/ui/lint/force-warn/{force-allowed-deny-by-default-lint.rs => allowed-deny-by-default-lint.rs} (68%) create mode 100644 src/test/ui/lint/force-warn/allowed-deny-by-default-lint.stderr rename src/test/ui/lint/force-warn/{force-lint-in-allowed-group.rs => allowed-group-warn-by-default-lint.rs} (70%) rename src/test/ui/lint/force-warn/{force-lint-in-allowed-group.stderr => allowed-group-warn-by-default-lint.stderr} (90%) rename src/test/ui/lint/force-warn/{force-allowed-warning.rs => allowed-warn-by-default-lint.rs} (59%) rename src/test/ui/lint/force-warn/{force-lint-allow-all-warnings.stderr => allowed-warn-by-default-lint.stderr} (81%) rename src/test/ui/lint/force-warn/{force-warn-cap-lints-allow.rs => cap-lints-allow.rs} (78%) rename src/test/ui/lint/force-warn/{force-warn-cap-lints-allow.stderr => cap-lints-allow.stderr} (91%) rename src/test/ui/lint/force-warn/{force-warn-cap-lints-warn.rs => cap-lints-warn-allowed-warn-by-default-lint.rs} (76%) rename src/test/ui/lint/force-warn/{force-warn-cap-lints-warn.stderr => cap-lints-warn-allowed-warn-by-default-lint.stderr} (88%) rename src/test/ui/lint/force-warn/{force-deny-by-default-lint.rs => deny-by-default-lint.rs} (75%) rename src/test/ui/lint/force-warn/{force-deny-by-default-lint.stderr => deny-by-default-lint.stderr} (91%) rename src/test/ui/lint/force-warn/{force-lint-group-allow-all-warnings.rs => lint-group-allow-warnings.rs} (58%) rename src/test/ui/lint/force-warn/{force-lint-group-allow-all-warnings.stderr => lint-group-allow-warnings.stderr} (84%) create mode 100644 src/test/ui/lint/force-warn/lint-group-allowed-cli-warn-by-default-lint.rs create mode 100644 src/test/ui/lint/force-warn/lint-group-allowed-cli-warn-by-default-lint.stderr rename src/test/ui/lint/force-warn/{force-warn-group.rs => lint-group-allowed-lint-group.rs} (75%) rename src/test/ui/lint/force-warn/{force-warn-group.stderr => lint-group-allowed-lint-group.stderr} (91%) rename src/test/ui/lint/force-warn/{force-warn-group-allow-warning.rs => lint-group-allowed-warn-by-default-lint.rs} (72%) rename src/test/ui/lint/force-warn/{force-warn-group-allow-warning.stderr => lint-group-allowed-warn-by-default-lint.stderr} (89%) create mode 100644 src/test/ui/lint/force-warn/warn-by-default-lint-two-modules.rs create mode 100644 src/test/ui/lint/force-warn/warn-by-default-lint-two-modules.stderr diff --git a/src/test/ui/lint/force-warn/force-lint-allow-all-warnings.rs b/src/test/ui/lint/force-warn/allow-warnings.rs similarity index 59% rename from src/test/ui/lint/force-warn/force-lint-allow-all-warnings.rs rename to src/test/ui/lint/force-warn/allow-warnings.rs index 0e8a65a41173d..6ee5ba6793280 100644 --- a/src/test/ui/lint/force-warn/force-lint-allow-all-warnings.rs +++ b/src/test/ui/lint/force-warn/allow-warnings.rs @@ -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 diff --git a/src/test/ui/lint/force-warn/force-allowed-warning.stderr b/src/test/ui/lint/force-warn/allow-warnings.stderr similarity index 83% rename from src/test/ui/lint/force-warn/force-allowed-warning.stderr rename to src/test/ui/lint/force-warn/allow-warnings.stderr index fced147254e82..cac2b4e918909 100644 --- a/src/test/ui/lint/force-warn/force-allowed-warning.stderr +++ b/src/test/ui/lint/force-warn/allow-warnings.stderr @@ -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() {} | ^^^^^^^^^^^^^ diff --git a/src/test/ui/lint/force-warn/force-allowed-by-default-lint.rs b/src/test/ui/lint/force-warn/allowed-by-default-lint.rs similarity index 75% rename from src/test/ui/lint/force-warn/force-allowed-by-default-lint.rs rename to src/test/ui/lint/force-warn/allowed-by-default-lint.rs index 4799429ea2c69..fd0b886d84dbe 100644 --- a/src/test/ui/lint/force-warn/force-allowed-by-default-lint.rs +++ b/src/test/ui/lint/force-warn/allowed-by-default-lint.rs @@ -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 diff --git a/src/test/ui/lint/force-warn/force-allowed-by-default-lint.stderr b/src/test/ui/lint/force-warn/allowed-by-default-lint.stderr similarity index 84% rename from src/test/ui/lint/force-warn/force-allowed-by-default-lint.stderr rename to src/test/ui/lint/force-warn/allowed-by-default-lint.stderr index 05513de81d1c8..baa47cbb10fd5 100644 --- a/src/test/ui/lint/force-warn/force-allowed-by-default-lint.stderr +++ b/src/test/ui/lint/force-warn/allowed-by-default-lint.stderr @@ -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: `<'_>` diff --git a/src/test/ui/lint/force-warn/allowed-cli-deny-by-default-lint.rs b/src/test/ui/lint/force-warn/allowed-cli-deny-by-default-lint.rs new file mode 100644 index 0000000000000..3fab9148392be --- /dev/null +++ b/src/test/ui/lint/force-warn/allowed-cli-deny-by-default-lint.rs @@ -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() {} diff --git a/src/test/ui/lint/force-warn/force-allowed-deny-by-default-lint.stderr b/src/test/ui/lint/force-warn/allowed-cli-deny-by-default-lint.stderr similarity index 90% rename from src/test/ui/lint/force-warn/force-allowed-deny-by-default-lint.stderr rename to src/test/ui/lint/force-warn/allowed-cli-deny-by-default-lint.stderr index dd4f88a3b533e..af6308f0d1b4f 100644 --- a/src/test/ui/lint/force-warn/force-allowed-deny-by-default-lint.stderr +++ b/src/test/ui/lint/force-warn/allowed-cli-deny-by-default-lint.stderr @@ -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; | ---------------^^^^^- diff --git a/src/test/ui/lint/force-warn/force-allowed-deny-by-default-lint.rs b/src/test/ui/lint/force-warn/allowed-deny-by-default-lint.rs similarity index 68% rename from src/test/ui/lint/force-warn/force-allowed-deny-by-default-lint.rs rename to src/test/ui/lint/force-warn/allowed-deny-by-default-lint.rs index d066feba86984..82a584ac97265 100644 --- a/src/test/ui/lint/force-warn/force-allowed-deny-by-default-lint.rs +++ b/src/test/ui/lint/force-warn/allowed-deny-by-default-lint.rs @@ -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 diff --git a/src/test/ui/lint/force-warn/allowed-deny-by-default-lint.stderr b/src/test/ui/lint/force-warn/allowed-deny-by-default-lint.stderr new file mode 100644 index 0000000000000..05656afd22d88 --- /dev/null +++ b/src/test/ui/lint/force-warn/allowed-deny-by-default-lint.stderr @@ -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 + +warning: 1 warning emitted + diff --git a/src/test/ui/lint/force-warn/force-lint-in-allowed-group.rs b/src/test/ui/lint/force-warn/allowed-group-warn-by-default-lint.rs similarity index 70% rename from src/test/ui/lint/force-warn/force-lint-in-allowed-group.rs rename to src/test/ui/lint/force-warn/allowed-group-warn-by-default-lint.rs index d8447bd238244..86ab12668a3e4 100644 --- a/src/test/ui/lint/force-warn/force-lint-in-allowed-group.rs +++ b/src/test/ui/lint/force-warn/allowed-group-warn-by-default-lint.rs @@ -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 diff --git a/src/test/ui/lint/force-warn/force-lint-in-allowed-group.stderr b/src/test/ui/lint/force-warn/allowed-group-warn-by-default-lint.stderr similarity index 90% rename from src/test/ui/lint/force-warn/force-lint-in-allowed-group.stderr rename to src/test/ui/lint/force-warn/allowed-group-warn-by-default-lint.stderr index c1ebdb9514bd4..d945cc3347aab 100644 --- a/src/test/ui/lint/force-warn/force-lint-in-allowed-group.stderr +++ b/src/test/ui/lint/force-warn/allowed-group-warn-by-default-lint.stderr @@ -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) {} | ^^^^^^^^^ help: use `dyn`: `dyn SomeTrait` diff --git a/src/test/ui/lint/force-warn/force-allowed-warning.rs b/src/test/ui/lint/force-warn/allowed-warn-by-default-lint.rs similarity index 59% rename from src/test/ui/lint/force-warn/force-allowed-warning.rs rename to src/test/ui/lint/force-warn/allowed-warn-by-default-lint.rs index 280de5064720a..7204782a324e3 100644 --- a/src/test/ui/lint/force-warn/force-allowed-warning.rs +++ b/src/test/ui/lint/force-warn/allowed-warn-by-default-lint.rs @@ -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 diff --git a/src/test/ui/lint/force-warn/force-lint-allow-all-warnings.stderr b/src/test/ui/lint/force-warn/allowed-warn-by-default-lint.stderr similarity index 81% rename from src/test/ui/lint/force-warn/force-lint-allow-all-warnings.stderr rename to src/test/ui/lint/force-warn/allowed-warn-by-default-lint.stderr index 3305f2c02834d..c46d7403fd023 100644 --- a/src/test/ui/lint/force-warn/force-lint-allow-all-warnings.stderr +++ b/src/test/ui/lint/force-warn/allowed-warn-by-default-lint.stderr @@ -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() {} | ^^^^^^^^^^^^^ diff --git a/src/test/ui/lint/force-warn/force-warn-cap-lints-allow.rs b/src/test/ui/lint/force-warn/cap-lints-allow.rs similarity index 78% rename from src/test/ui/lint/force-warn/force-warn-cap-lints-allow.rs rename to src/test/ui/lint/force-warn/cap-lints-allow.rs index e10d161e7c62b..de3a1bd8dd719 100644 --- a/src/test/ui/lint/force-warn/force-warn-cap-lints-allow.rs +++ b/src/test/ui/lint/force-warn/cap-lints-allow.rs @@ -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 diff --git a/src/test/ui/lint/force-warn/force-warn-cap-lints-allow.stderr b/src/test/ui/lint/force-warn/cap-lints-allow.stderr similarity index 91% rename from src/test/ui/lint/force-warn/force-warn-cap-lints-allow.stderr rename to src/test/ui/lint/force-warn/cap-lints-allow.stderr index 8514956af743e..f3ae16b5657f2 100644 --- a/src/test/ui/lint/force-warn/force-warn-cap-lints-allow.stderr +++ b/src/test/ui/lint/force-warn/cap-lints-allow.stderr @@ -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) {} | ^^^^^^^^^ help: use `dyn`: `dyn SomeTrait` diff --git a/src/test/ui/lint/force-warn/force-warn-cap-lints-warn.rs b/src/test/ui/lint/force-warn/cap-lints-warn-allowed-warn-by-default-lint.rs similarity index 76% rename from src/test/ui/lint/force-warn/force-warn-cap-lints-warn.rs rename to src/test/ui/lint/force-warn/cap-lints-warn-allowed-warn-by-default-lint.rs index 4afc0868608d3..70fb90dc1992b 100644 --- a/src/test/ui/lint/force-warn/force-warn-cap-lints-warn.rs +++ b/src/test/ui/lint/force-warn/cap-lints-warn-allowed-warn-by-default-lint.rs @@ -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)] diff --git a/src/test/ui/lint/force-warn/force-warn-cap-lints-warn.stderr b/src/test/ui/lint/force-warn/cap-lints-warn-allowed-warn-by-default-lint.stderr similarity index 88% rename from src/test/ui/lint/force-warn/force-warn-cap-lints-warn.stderr rename to src/test/ui/lint/force-warn/cap-lints-warn-allowed-warn-by-default-lint.stderr index 3a0227463e69a..3dafaf7055fd0 100644 --- a/src/test/ui/lint/force-warn/force-warn-cap-lints-warn.stderr +++ b/src/test/ui/lint/force-warn/cap-lints-warn-allowed-warn-by-default-lint.stderr @@ -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 diff --git a/src/test/ui/lint/force-warn/force-deny-by-default-lint.rs b/src/test/ui/lint/force-warn/deny-by-default-lint.rs similarity index 75% rename from src/test/ui/lint/force-warn/force-deny-by-default-lint.rs rename to src/test/ui/lint/force-warn/deny-by-default-lint.rs index 8331df02da763..b0a15cc2fba06 100644 --- a/src/test/ui/lint/force-warn/force-deny-by-default-lint.rs +++ b/src/test/ui/lint/force-warn/deny-by-default-lint.rs @@ -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 diff --git a/src/test/ui/lint/force-warn/force-deny-by-default-lint.stderr b/src/test/ui/lint/force-warn/deny-by-default-lint.stderr similarity index 91% rename from src/test/ui/lint/force-warn/force-deny-by-default-lint.stderr rename to src/test/ui/lint/force-warn/deny-by-default-lint.stderr index 68cd3a392f583..ef295f99e649c 100644 --- a/src/test/ui/lint/force-warn/force-deny-by-default-lint.stderr +++ b/src/test/ui/lint/force-warn/deny-by-default-lint.stderr @@ -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; | ---------------^^^^^- diff --git a/src/test/ui/lint/force-warn/force-lint-group-allow-all-warnings.rs b/src/test/ui/lint/force-warn/lint-group-allow-warnings.rs similarity index 58% rename from src/test/ui/lint/force-warn/force-lint-group-allow-all-warnings.rs rename to src/test/ui/lint/force-warn/lint-group-allow-warnings.rs index aaca59a2a2aab..e5dcd9a7ea16f 100644 --- a/src/test/ui/lint/force-warn/force-lint-group-allow-all-warnings.rs +++ b/src/test/ui/lint/force-warn/lint-group-allow-warnings.rs @@ -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 diff --git a/src/test/ui/lint/force-warn/force-lint-group-allow-all-warnings.stderr b/src/test/ui/lint/force-warn/lint-group-allow-warnings.stderr similarity index 84% rename from src/test/ui/lint/force-warn/force-lint-group-allow-all-warnings.stderr rename to src/test/ui/lint/force-warn/lint-group-allow-warnings.stderr index 065a8f6a556a0..dc7b1b7b98d0c 100644 --- a/src/test/ui/lint/force-warn/force-lint-group-allow-all-warnings.stderr +++ b/src/test/ui/lint/force-warn/lint-group-allow-warnings.stderr @@ -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` diff --git a/src/test/ui/lint/force-warn/lint-group-allowed-cli-warn-by-default-lint.rs b/src/test/ui/lint/force-warn/lint-group-allowed-cli-warn-by-default-lint.rs new file mode 100644 index 0000000000000..4eb05b538b0ba --- /dev/null +++ b/src/test/ui/lint/force-warn/lint-group-allowed-cli-warn-by-default-lint.rs @@ -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) {} +//~^ WARN trait objects without an explicit `dyn` are deprecated +//~| WARN this is accepted in the current edition + +fn main() {} diff --git a/src/test/ui/lint/force-warn/lint-group-allowed-cli-warn-by-default-lint.stderr b/src/test/ui/lint/force-warn/lint-group-allowed-cli-warn-by-default-lint.stderr new file mode 100644 index 0000000000000..dc62521bf898b --- /dev/null +++ b/src/test/ui/lint/force-warn/lint-group-allowed-cli-warn-by-default-lint.stderr @@ -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) {} + | ^^^^^^^^^ 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 + +warning: 1 warning emitted + diff --git a/src/test/ui/lint/force-warn/force-warn-group.rs b/src/test/ui/lint/force-warn/lint-group-allowed-lint-group.rs similarity index 75% rename from src/test/ui/lint/force-warn/force-warn-group.rs rename to src/test/ui/lint/force-warn/lint-group-allowed-lint-group.rs index 0198610b78e10..dc13b2b24748c 100644 --- a/src/test/ui/lint/force-warn/force-warn-group.rs +++ b/src/test/ui/lint/force-warn/lint-group-allowed-lint-group.rs @@ -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 diff --git a/src/test/ui/lint/force-warn/force-warn-group.stderr b/src/test/ui/lint/force-warn/lint-group-allowed-lint-group.stderr similarity index 91% rename from src/test/ui/lint/force-warn/force-warn-group.stderr rename to src/test/ui/lint/force-warn/lint-group-allowed-lint-group.stderr index 54bee452cddad..fcbae024eb60f 100644 --- a/src/test/ui/lint/force-warn/force-warn-group.stderr +++ b/src/test/ui/lint/force-warn/lint-group-allowed-lint-group.stderr @@ -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) {} | ^^^^^^^^^ help: use `dyn`: `dyn SomeTrait` diff --git a/src/test/ui/lint/force-warn/force-warn-group-allow-warning.rs b/src/test/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.rs similarity index 72% rename from src/test/ui/lint/force-warn/force-warn-group-allow-warning.rs rename to src/test/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.rs index 193ba2b6f0da5..b7f79b3d4aa3b 100644 --- a/src/test/ui/lint/force-warn/force-warn-group-allow-warning.rs +++ b/src/test/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.rs @@ -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 diff --git a/src/test/ui/lint/force-warn/force-warn-group-allow-warning.stderr b/src/test/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.stderr similarity index 89% rename from src/test/ui/lint/force-warn/force-warn-group-allow-warning.stderr rename to src/test/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.stderr index 29eba6d635f93..1212ae083c23b 100644 --- a/src/test/ui/lint/force-warn/force-warn-group-allow-warning.stderr +++ b/src/test/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.stderr @@ -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) {} | ^^^^^^^^^ help: use `dyn`: `dyn SomeTrait` diff --git a/src/test/ui/lint/force-warn/warn-by-default-lint-two-modules.rs b/src/test/ui/lint/force-warn/warn-by-default-lint-two-modules.rs new file mode 100644 index 0000000000000..d2cb3417be68a --- /dev/null +++ b/src/test/ui/lint/force-warn/warn-by-default-lint-two-modules.rs @@ -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() {} diff --git a/src/test/ui/lint/force-warn/warn-by-default-lint-two-modules.stderr b/src/test/ui/lint/force-warn/warn-by-default-lint-two-modules.stderr new file mode 100644 index 0000000000000..2a3cf85a1e331 --- /dev/null +++ b/src/test/ui/lint/force-warn/warn-by-default-lint-two-modules.stderr @@ -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 + From d70056e30c9253f42eb12f1030b4977a2a6bc688 Mon Sep 17 00:00:00 2001 From: Ryan Levick Date: Wed, 18 Aug 2021 11:53:59 +0200 Subject: [PATCH 2/2] Error when warnings lint group is used with force-warn --- compiler/rustc_error_codes/src/error_codes/E0602.md | 2 +- compiler/rustc_lint/src/context.rs | 11 ++++++++++- src/test/ui/lint/force-warn/warnings-lint-group.rs | 5 +++++ .../ui/lint/force-warn/warnings-lint-group.stderr | 9 +++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/lint/force-warn/warnings-lint-group.rs create mode 100644 src/test/ui/lint/force-warn/warnings-lint-group.stderr diff --git a/compiler/rustc_error_codes/src/error_codes/E0602.md b/compiler/rustc_error_codes/src/error_codes/E0602.md index dcaf251a96b5b..7980b704cae6d 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0602.md +++ b/compiler/rustc_error_codes/src/error_codes/E0602.md @@ -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: diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 47c6e904cd7e5..c2a46e997df47 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -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)), diff --git a/src/test/ui/lint/force-warn/warnings-lint-group.rs b/src/test/ui/lint/force-warn/warnings-lint-group.rs new file mode 100644 index 0000000000000..fa25a1f8a842a --- /dev/null +++ b/src/test/ui/lint/force-warn/warnings-lint-group.rs @@ -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() {} diff --git a/src/test/ui/lint/force-warn/warnings-lint-group.stderr b/src/test/ui/lint/force-warn/warnings-lint-group.stderr new file mode 100644 index 0000000000000..03f5788b527d3 --- /dev/null +++ b/src/test/ui/lint/force-warn/warnings-lint-group.stderr @@ -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`.