-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 #117094 - Nadrieril:warn-lint-on-arm, r=cjgillot
Warn users who set `non_exhaustive_omitted_patterns` lint level on a match arm Before #116734, the recommended usage of the [`non_exhaustive_omitted_patterns` lint](#89554) was: ```rust match Bar::A { Bar::A => {}, #[warn(non_exhaustive_omitted_patterns)] _ => {}, } ``` After #116734 this no longer makes sense, and recommended usage is now: ```rust #[warn(non_exhaustive_omitted_patterns)] match Bar::A { Bar::A => {}, _ => {}, } ``` As you can guess, this silently breaks all uses of the lint that used the previous form. This is a problem in particular because `syn` recommends usage of this lint to its users in the old way. This PR emits a warning when the previous form is used so users can update. r? `@cjgillot`
- Loading branch information
Showing
8 changed files
with
233 additions
and
25 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
75 changes: 75 additions & 0 deletions
75
tests/ui/rfcs/rfc-2008-non-exhaustive/omitted-patterns-dont-lint-on-arm.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,75 @@ | ||
error: some variants are not matched explicitly | ||
--> $DIR/omitted-patterns-dont-lint-on-arm.rs:15:11 | ||
| | ||
LL | match val { | ||
| ^^^ pattern `NonExhaustiveEnum::Struct { .. }` not covered | ||
| | ||
= help: ensure that all variants are matched explicitly by adding the suggested match arms | ||
= note: the matched value is of type `NonExhaustiveEnum` and the `non_exhaustive_omitted_patterns` attribute was found | ||
note: the lint level is defined here | ||
--> $DIR/omitted-patterns-dont-lint-on-arm.rs:14:12 | ||
| | ||
LL | #[deny(non_exhaustive_omitted_patterns)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: some variants are not matched explicitly | ||
--> $DIR/omitted-patterns-dont-lint-on-arm.rs:23:11 | ||
| | ||
LL | match val { | ||
| ^^^ pattern `NonExhaustiveEnum::Struct { .. }` not covered | ||
| | ||
= help: ensure that all variants are matched explicitly by adding the suggested match arms | ||
= note: the matched value is of type `NonExhaustiveEnum` and the `non_exhaustive_omitted_patterns` attribute was found | ||
note: the lint level is defined here | ||
--> $DIR/omitted-patterns-dont-lint-on-arm.rs:22:27 | ||
| | ||
LL | #[cfg_attr(lint, deny(non_exhaustive_omitted_patterns))] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: the lint level must be set on the whole match | ||
--> $DIR/omitted-patterns-dont-lint-on-arm.rs:34:9 | ||
| | ||
LL | #[deny(non_exhaustive_omitted_patterns)] | ||
| ------------------------------- remove this attribute | ||
LL | _ => {} | ||
| ^ | ||
| | ||
= help: it no longer has any effect to set the lint level on an individual match arm | ||
help: set the lint level on the whole match | ||
| | ||
LL + #[deny(non_exhaustive_omitted_patterns)] | ||
LL | match val { | ||
| | ||
|
||
warning: the lint level must be set on the whole match | ||
--> $DIR/omitted-patterns-dont-lint-on-arm.rs:42:9 | ||
| | ||
LL | #[cfg_attr(lint, deny(non_exhaustive_omitted_patterns))] | ||
| ------------------------------- remove this attribute | ||
LL | _ => {} | ||
| ^ | ||
| | ||
= help: it no longer has any effect to set the lint level on an individual match arm | ||
help: set the lint level on the whole match | ||
| | ||
LL + #[deny(non_exhaustive_omitted_patterns)] | ||
LL | match val { | ||
| | ||
|
||
warning: the lint level must be set on the whole match | ||
--> $DIR/omitted-patterns-dont-lint-on-arm.rs:50:9 | ||
| | ||
LL | #[cfg_attr(lint, warn(non_exhaustive_omitted_patterns))] | ||
| ------------------------------- remove this attribute | ||
LL | _ => {} | ||
| ^ | ||
| | ||
= help: it no longer has any effect to set the lint level on an individual match arm | ||
help: set the lint level on the whole match | ||
| | ||
LL + #[warn(non_exhaustive_omitted_patterns)] | ||
LL | match val { | ||
| | ||
|
||
error: aborting due to 2 previous errors; 3 warnings emitted | ||
|
31 changes: 31 additions & 0 deletions
31
tests/ui/rfcs/rfc-2008-non-exhaustive/omitted-patterns-dont-lint-on-arm.normal.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,31 @@ | ||
error: some variants are not matched explicitly | ||
--> $DIR/omitted-patterns-dont-lint-on-arm.rs:15:11 | ||
| | ||
LL | match val { | ||
| ^^^ pattern `NonExhaustiveEnum::Struct { .. }` not covered | ||
| | ||
= help: ensure that all variants are matched explicitly by adding the suggested match arms | ||
= note: the matched value is of type `NonExhaustiveEnum` and the `non_exhaustive_omitted_patterns` attribute was found | ||
note: the lint level is defined here | ||
--> $DIR/omitted-patterns-dont-lint-on-arm.rs:14:12 | ||
| | ||
LL | #[deny(non_exhaustive_omitted_patterns)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: the lint level must be set on the whole match | ||
--> $DIR/omitted-patterns-dont-lint-on-arm.rs:34:9 | ||
| | ||
LL | #[deny(non_exhaustive_omitted_patterns)] | ||
| ------------------------------- remove this attribute | ||
LL | _ => {} | ||
| ^ | ||
| | ||
= help: it no longer has any effect to set the lint level on an individual match arm | ||
help: set the lint level on the whole match | ||
| | ||
LL + #[deny(non_exhaustive_omitted_patterns)] | ||
LL | match val { | ||
| | ||
|
||
error: aborting due to previous error; 1 warning emitted | ||
|
53 changes: 53 additions & 0 deletions
53
tests/ui/rfcs/rfc-2008-non-exhaustive/omitted-patterns-dont-lint-on-arm.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,53 @@ | ||
// revisions: normal lint | ||
// Test that putting the lint level on a match arm emits a warning, as this was previously | ||
// meaningful and is no longer. | ||
#![feature(non_exhaustive_omitted_patterns_lint)] | ||
|
||
// aux-build:enums.rs | ||
extern crate enums; | ||
|
||
use enums::NonExhaustiveEnum; | ||
|
||
fn main() { | ||
let val = NonExhaustiveEnum::Unit; | ||
|
||
#[deny(non_exhaustive_omitted_patterns)] | ||
match val { | ||
//~^ ERROR some variants are not matched explicitly | ||
NonExhaustiveEnum::Unit => {} | ||
NonExhaustiveEnum::Tuple(_) => {} | ||
_ => {} | ||
} | ||
|
||
#[cfg_attr(lint, deny(non_exhaustive_omitted_patterns))] | ||
match val { | ||
//[lint]~^ ERROR some variants are not matched explicitly | ||
NonExhaustiveEnum::Unit => {} | ||
NonExhaustiveEnum::Tuple(_) => {} | ||
_ => {} | ||
} | ||
|
||
match val { | ||
NonExhaustiveEnum::Unit => {} | ||
NonExhaustiveEnum::Tuple(_) => {} | ||
#[deny(non_exhaustive_omitted_patterns)] | ||
_ => {} | ||
} | ||
//~^^ WARN lint level must be set on the whole match | ||
|
||
match val { | ||
NonExhaustiveEnum::Unit => {} | ||
NonExhaustiveEnum::Tuple(_) => {} | ||
#[cfg_attr(lint, deny(non_exhaustive_omitted_patterns))] | ||
_ => {} | ||
} | ||
//[lint]~^^ WARN lint level must be set on the whole match | ||
|
||
match val { | ||
NonExhaustiveEnum::Unit => {} | ||
NonExhaustiveEnum::Tuple(_) => {} | ||
#[cfg_attr(lint, warn(non_exhaustive_omitted_patterns))] | ||
_ => {} | ||
} | ||
//[lint]~^^ WARN lint level must be set on the whole match | ||
} |