-
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=<try>
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
7 changed files
with
197 additions
and
24 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
69 changes: 69 additions & 0 deletions
69
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,69 @@ | ||
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))] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: the `non_exhaustive_omitted_pattern` lint level must be set on the whole match | ||
--> $DIR/omitted-patterns-dont-lint-on-arm.rs:34:9 | ||
| | ||
LL | _ => {} | ||
| ^ | ||
| | ||
= help: it used to make sense to set the lint level on an individual match arm, but that is no longer the case | ||
note: the lint level is defined here | ||
--> $DIR/omitted-patterns-dont-lint-on-arm.rs:33:16 | ||
| | ||
LL | #[deny(non_exhaustive_omitted_patterns)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: the `non_exhaustive_omitted_pattern` lint level must be set on the whole match | ||
--> $DIR/omitted-patterns-dont-lint-on-arm.rs:41:9 | ||
| | ||
LL | _ => {} | ||
| ^ | ||
| | ||
= help: it used to make sense to set the lint level on an individual match arm, but that is no longer the case | ||
note: the lint level is defined here | ||
--> $DIR/omitted-patterns-dont-lint-on-arm.rs:40:31 | ||
| | ||
LL | #[cfg_attr(lint, deny(non_exhaustive_omitted_patterns))] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: the `non_exhaustive_omitted_pattern` lint level must be set on the whole match | ||
--> $DIR/omitted-patterns-dont-lint-on-arm.rs:48:9 | ||
| | ||
LL | _ => {} | ||
| ^ | ||
| | ||
= help: it used to make sense to set the lint level on an individual match arm, but that is no longer the case | ||
note: the lint level is defined here | ||
--> $DIR/omitted-patterns-dont-lint-on-arm.rs:47:31 | ||
| | ||
LL | #[cfg_attr(lint, warn(non_exhaustive_omitted_patterns))] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 4 previous errors; 1 warning emitted | ||
|
29 changes: 29 additions & 0 deletions
29
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,29 @@ | ||
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: the `non_exhaustive_omitted_pattern` lint level must be set on the whole match | ||
--> $DIR/omitted-patterns-dont-lint-on-arm.rs:34:9 | ||
| | ||
LL | _ => {} | ||
| ^ | ||
| | ||
= help: it used to make sense to set the lint level on an individual match arm, but that is no longer the case | ||
note: the lint level is defined here | ||
--> $DIR/omitted-patterns-dont-lint-on-arm.rs:33:16 | ||
| | ||
LL | #[deny(non_exhaustive_omitted_patterns)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
50 changes: 50 additions & 0 deletions
50
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,50 @@ | ||
// 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)] | ||
_ => {} //~ ERROR lint level must be set on the whole match | ||
} | ||
|
||
match val { | ||
NonExhaustiveEnum::Unit => {} | ||
NonExhaustiveEnum::Tuple(_) => {} | ||
#[cfg_attr(lint, deny(non_exhaustive_omitted_patterns))] | ||
_ => {} //[lint]~ ERROR 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 | ||
} | ||
} |