Add feature gate to non_exhaustive_omitted_patterns lint

Actually add the feature to the lints ui test
Add tracking issue to the feature declaration
Rename feature gate to non_exhaustive_omitted_patterns_lint
Add more omitted_patterns lint feature gate
This commit is contained in:
Devin Ragotzy 2021-10-01 10:21:56 -04:00 committed by Devin Ragotzy
parent 44995f7afb
commit 14338786fd
7 changed files with 154 additions and 20 deletions

View File

@ -678,6 +678,9 @@ declare_features! (
/// Allows `#[doc(cfg_hide(...))]`.
(active, doc_cfg_hide, "1.57.0", Some(43781), None),
/// Allows using the `non_exhaustive_omitted_patterns` lint.
(active, non_exhaustive_omitted_patterns_lint, "1.57.0", Some(89554), None),
// -------------------------------------------------------------------------
// feature-group-end: actual feature gates
// -------------------------------------------------------------------------

View File

@ -6,6 +6,7 @@
use crate::{declare_lint, declare_lint_pass, FutureIncompatibilityReason};
use rustc_span::edition::Edition;
use rustc_span::symbol::sym;
declare_lint! {
/// The `forbidden_lint_groups` lint detects violations of
@ -3476,6 +3477,8 @@ declare_lint! {
/// }
///
/// // in crate B
/// #![feature(non_exhaustive_omitted_patterns_lint)]
///
/// match Bar::A {
/// Bar::A => {},
/// #[warn(non_exhaustive_omitted_patterns)]
@ -3512,6 +3515,7 @@ declare_lint! {
pub NON_EXHAUSTIVE_OMITTED_PATTERNS,
Allow,
"detect when patterns of types marked `non_exhaustive` are missed",
@feature_gate = sym::non_exhaustive_omitted_patterns_lint;
}
declare_lint! {

View File

@ -893,6 +893,7 @@ symbols! {
nomem,
non_ascii_idents,
non_exhaustive,
non_exhaustive_omitted_patterns_lint,
non_modrs_mods,
none_error,
nontemporal_store,

View File

@ -0,0 +1,31 @@
#![deny(non_exhaustive_omitted_patterns)]
//~^ ERROR the `non_exhaustive_omitted_patterns` lint is unstable
//~| ERROR the `non_exhaustive_omitted_patterns` lint is unstable
#![allow(non_exhaustive_omitted_patterns)]
//~^ ERROR the `non_exhaustive_omitted_patterns` lint is unstable
//~| ERROR the `non_exhaustive_omitted_patterns` lint is unstable
fn main() {
enum Foo {
A, B, C,
}
#[allow(non_exhaustive_omitted_patterns)]
match Foo::A {
Foo::A => {}
Foo::B => {}
}
//~^^^^^ ERROR the `non_exhaustive_omitted_patterns` lint is unstable
//~| ERROR the `non_exhaustive_omitted_patterns` lint is unstable
//~| ERROR the `non_exhaustive_omitted_patterns` lint is unstable
//~| ERROR the `non_exhaustive_omitted_patterns` lint is unstable
match Foo::A {
Foo::A => {}
Foo::B => {}
#[warn(non_exhaustive_omitted_patterns)]
_ => {}
}
//~^^^ ERROR the `non_exhaustive_omitted_patterns` lint is unstable
//~| ERROR the `non_exhaustive_omitted_patterns` lint is unstable
}

View File

@ -0,0 +1,93 @@
error[E0658]: the `non_exhaustive_omitted_patterns` lint is unstable
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:1:1
|
LL | #![deny(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
error[E0658]: the `non_exhaustive_omitted_patterns` lint is unstable
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:4:1
|
LL | #![allow(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
error[E0658]: the `non_exhaustive_omitted_patterns` lint is unstable
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:13:5
|
LL | #[allow(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
error[E0658]: the `non_exhaustive_omitted_patterns` lint is unstable
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:13:5
|
LL | #[allow(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
error[E0658]: the `non_exhaustive_omitted_patterns` lint is unstable
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:26:9
|
LL | #[warn(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
error[E0658]: the `non_exhaustive_omitted_patterns` lint is unstable
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:1:1
|
LL | #![deny(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
error[E0658]: the `non_exhaustive_omitted_patterns` lint is unstable
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:4:1
|
LL | #![allow(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
error[E0658]: the `non_exhaustive_omitted_patterns` lint is unstable
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:13:5
|
LL | #[allow(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
error[E0658]: the `non_exhaustive_omitted_patterns` lint is unstable
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:13:5
|
LL | #[allow(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
error[E0658]: the `non_exhaustive_omitted_patterns` lint is unstable
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:26:9
|
LL | #[warn(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
error: aborting due to 10 previous errors
For more information about this error, try `rustc --explain E0658`.

View File

@ -1,5 +1,7 @@
// Test that the `non_exhaustive_omitted_patterns` lint is triggered correctly.
#![feature(non_exhaustive_omitted_patterns_lint)]
// aux-build:enums.rs
extern crate enums;

View File

@ -1,11 +1,11 @@
warning: some fields are not explicitly listed
--> $DIR/reachable-patterns.rs:127:9
--> $DIR/reachable-patterns.rs:129:9
|
LL | VariantNonExhaustive::Bar { x, .. } => {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ field `y` not listed
|
note: the lint level is defined here
--> $DIR/reachable-patterns.rs:124:12
--> $DIR/reachable-patterns.rs:126:12
|
LL | #[warn(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -13,13 +13,13 @@ LL | #[warn(non_exhaustive_omitted_patterns)]
= note: the pattern is of type `VariantNonExhaustive` and the `non_exhaustive_omitted_patterns` attribute was found
warning: some fields are not explicitly listed
--> $DIR/reachable-patterns.rs:132:9
--> $DIR/reachable-patterns.rs:134:9
|
LL | let FunctionalRecord { first_field, second_field, .. } = FunctionalRecord::default();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ field `third_field` not listed
|
note: the lint level is defined here
--> $DIR/reachable-patterns.rs:131:12
--> $DIR/reachable-patterns.rs:133:12
|
LL | #[warn(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -27,13 +27,13 @@ LL | #[warn(non_exhaustive_omitted_patterns)]
= note: the pattern is of type `FunctionalRecord` and the `non_exhaustive_omitted_patterns` attribute was found
warning: some fields are not explicitly listed
--> $DIR/reachable-patterns.rs:140:29
--> $DIR/reachable-patterns.rs:142:29
|
LL | let NestedStruct { bar: NormalStruct { first_field, .. }, .. } = NestedStruct::default();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ field `second_field` not listed
|
note: the lint level is defined here
--> $DIR/reachable-patterns.rs:139:12
--> $DIR/reachable-patterns.rs:141:12
|
LL | #[warn(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -41,7 +41,7 @@ LL | #[warn(non_exhaustive_omitted_patterns)]
= note: the pattern is of type `NormalStruct` and the `non_exhaustive_omitted_patterns` attribute was found
warning: some fields are not explicitly listed
--> $DIR/reachable-patterns.rs:140:9
--> $DIR/reachable-patterns.rs:142:9
|
LL | let NestedStruct { bar: NormalStruct { first_field, .. }, .. } = NestedStruct::default();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ field `foo` not listed
@ -50,13 +50,13 @@ LL | let NestedStruct { bar: NormalStruct { first_field, .. }, .. } = Nested
= note: the pattern is of type `NestedStruct` and the `non_exhaustive_omitted_patterns` attribute was found
error: some variants are not matched explicitly
--> $DIR/reachable-patterns.rs:54:9
--> $DIR/reachable-patterns.rs:56:9
|
LL | _ => {}
| ^ pattern `Struct { .. }` not covered
|
note: the lint level is defined here
--> $DIR/reachable-patterns.rs:53:16
--> $DIR/reachable-patterns.rs:55:16
|
LL | #[deny(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -64,13 +64,13 @@ LL | #[deny(non_exhaustive_omitted_patterns)]
= note: the matched value is of type `NonExhaustiveEnum` and the `non_exhaustive_omitted_patterns` attribute was found
error: some variants are not matched explicitly
--> $DIR/reachable-patterns.rs:61:9
--> $DIR/reachable-patterns.rs:63:9
|
LL | _ => {}
| ^ pattern `Tuple(_)` not covered
|
note: the lint level is defined here
--> $DIR/reachable-patterns.rs:60:16
--> $DIR/reachable-patterns.rs:62:16
|
LL | #[deny(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -78,13 +78,13 @@ LL | #[deny(non_exhaustive_omitted_patterns)]
= note: the matched value is of type `NonExhaustiveEnum` and the `non_exhaustive_omitted_patterns` attribute was found
error: some variants are not matched explicitly
--> $DIR/reachable-patterns.rs:71:9
--> $DIR/reachable-patterns.rs:73:9
|
LL | _ => {}
| ^ pattern `Unit` not covered
|
note: the lint level is defined here
--> $DIR/reachable-patterns.rs:70:16
--> $DIR/reachable-patterns.rs:72:16
|
LL | #[deny(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -92,13 +92,13 @@ LL | #[deny(non_exhaustive_omitted_patterns)]
= note: the matched value is of type `NonExhaustiveEnum` and the `non_exhaustive_omitted_patterns` attribute was found
error: some variants are not matched explicitly
--> $DIR/reachable-patterns.rs:88:32
--> $DIR/reachable-patterns.rs:90:32
|
LL | NestedNonExhaustive::A(_) => {}
| ^ patterns `Tuple(_)` and `Struct { .. }` not covered
|
note: the lint level is defined here
--> $DIR/reachable-patterns.rs:85:12
--> $DIR/reachable-patterns.rs:87:12
|
LL | #[deny(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -106,7 +106,7 @@ LL | #[deny(non_exhaustive_omitted_patterns)]
= note: the matched value is of type `NonExhaustiveEnum` and the `non_exhaustive_omitted_patterns` attribute was found
error: some variants are not matched explicitly
--> $DIR/reachable-patterns.rs:90:9
--> $DIR/reachable-patterns.rs:92:9
|
LL | _ => {}
| ^ pattern `C` not covered
@ -115,13 +115,13 @@ LL | _ => {}
= note: the matched value is of type `NestedNonExhaustive` and the `non_exhaustive_omitted_patterns` attribute was found
error: some variants are not matched explicitly
--> $DIR/reachable-patterns.rs:120:9
--> $DIR/reachable-patterns.rs:122:9
|
LL | _ => {}
| ^ patterns `HostUnreachable`, `NetworkUnreachable`, `NetworkDown` and 18 more not covered
|
note: the lint level is defined here
--> $DIR/reachable-patterns.rs:97:12
--> $DIR/reachable-patterns.rs:99:12
|
LL | #[deny(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -129,13 +129,13 @@ LL | #[deny(non_exhaustive_omitted_patterns)]
= note: the matched value is of type `ErrorKind` and the `non_exhaustive_omitted_patterns` attribute was found
error: some variants are not matched explicitly
--> $DIR/reachable-patterns.rs:157:9
--> $DIR/reachable-patterns.rs:159:9
|
LL | _ => {}
| ^ pattern `A(_)` not covered
|
note: the lint level is defined here
--> $DIR/reachable-patterns.rs:155:12
--> $DIR/reachable-patterns.rs:157:12
|
LL | #[deny(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^