Skip to content

Commit

Permalink
Rollup merge of rust-lang#89428 - DevinR528:reachable-featuregate, r=…
Browse files Browse the repository at this point in the history
…Nadrieril,camelid

Feature gate the non_exhaustive_omitted_patterns lint

Fixes rust-lang#89374

Add the machinery to gate the new `non_exhaustive_omitted_patterns` lint.

relates to rust-lang#89105 and rust-lang#89423
  • Loading branch information
matthiaskrgr authored Oct 10, 2021
2 parents a087958 + 1433878 commit 29fc7bd
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 20 deletions.
3 changes: 3 additions & 0 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
// -------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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! {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@ symbols! {
nomem,
non_ascii_idents,
non_exhaustive,
non_exhaustive_omitted_patterns_lint,
non_modrs_mods,
none_error,
nontemporal_store,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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`.
2 changes: 2 additions & 0 deletions src/test/ui/rfc-2008-non-exhaustive/reachable-patterns.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
40 changes: 20 additions & 20 deletions src/test/ui/rfc-2008-non-exhaustive/reachable-patterns.stderr
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
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)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: ensure that all fields are mentioned explicitly by adding the suggested fields
= 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)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: ensure that all fields are mentioned explicitly by adding the suggested fields
= 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)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: ensure that all fields are mentioned explicitly by adding the suggested fields
= 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
Expand All @@ -50,63 +50,63 @@ 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)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= 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

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)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= 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

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)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= 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

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)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= 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

error: some variants are not matched explicitly
--> $DIR/reachable-patterns.rs:90:9
--> $DIR/reachable-patterns.rs:92:9
|
LL | _ => {}
| ^ pattern `C` not covered
Expand All @@ -115,27 +115,27 @@ 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)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: ensure that all variants are matched explicitly by adding the suggested match arms
= 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)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down

0 comments on commit 29fc7bd

Please sign in to comment.