diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index ec2c703ad49..a2fadb13a57 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -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 // ------------------------------------------------------------------------- diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 7a51e1e321a..a93d18950db 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -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! { diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 0e30e154ee5..9551120ca55 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -893,6 +893,7 @@ symbols! { nomem, non_ascii_idents, non_exhaustive, + non_exhaustive_omitted_patterns_lint, non_modrs_mods, none_error, nontemporal_store, diff --git a/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.rs b/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.rs new file mode 100644 index 00000000000..2a34ed4d4f6 --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.rs @@ -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 +} diff --git a/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.stderr b/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.stderr new file mode 100644 index 00000000000..691f64cf0ad --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.stderr @@ -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 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 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 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 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 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 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 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 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 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 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`. diff --git a/src/test/ui/rfc-2008-non-exhaustive/reachable-patterns.rs b/src/test/ui/rfc-2008-non-exhaustive/reachable-patterns.rs index c196ded404d..ce1b5c7c377 100644 --- a/src/test/ui/rfc-2008-non-exhaustive/reachable-patterns.rs +++ b/src/test/ui/rfc-2008-non-exhaustive/reachable-patterns.rs @@ -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; diff --git a/src/test/ui/rfc-2008-non-exhaustive/reachable-patterns.stderr b/src/test/ui/rfc-2008-non-exhaustive/reachable-patterns.stderr index e66fd8008a1..5b21e0402b1 100644 --- a/src/test/ui/rfc-2008-non-exhaustive/reachable-patterns.stderr +++ b/src/test/ui/rfc-2008-non-exhaustive/reachable-patterns.stderr @@ -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)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^