about summary refs log tree commit diff
path: root/src/test/ui/pattern
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-10-12 20:54:15 +0000
committerbors <bors@rust-lang.org>2021-10-12 20:54:15 +0000
commitd7c97a02d1215e4ef26c31cb72dbaf16fd548b2c (patch)
tree97678e144716871aac7596ffe1f476db8ed62b83 /src/test/ui/pattern
parent044674337a180c494b7e6fdce4b20dca93324b2a (diff)
parent2a042d61055263e404d9588d39046ed51e96a560 (diff)
downloadrust-d7c97a02d1215e4ef26c31cb72dbaf16fd548b2c.tar.gz
rust-d7c97a02d1215e4ef26c31cb72dbaf16fd548b2c.zip
Auto merge of #89105 - DevinR528:reachable-fix, r=Nadrieril
Fix: non_exhaustive_omitted_patterns by filtering unstable and doc hidden variants

Fixes: #89042

Now that #86809 has been merged there are cases (std::io::ErrorKind) where unstable feature gated variants were included in warning/error messages when the feature was not turned on. This filters those variants out of the return of `SplitWildcard::new`.

Variants marked `doc(hidden)` are filtered out of the witnesses list in `Usefulness::apply_constructor`.

Probably worth a perf run :shrug: since this area can be sensitive.
Diffstat (limited to 'src/test/ui/pattern')
-rw-r--r--src/test/ui/pattern/usefulness/auxiliary/hidden.rs6
-rw-r--r--src/test/ui/pattern/usefulness/auxiliary/unstable.rs12
-rw-r--r--src/test/ui/pattern/usefulness/doc-hidden-non-exhaustive.rs30
-rw-r--r--src/test/ui/pattern/usefulness/doc-hidden-non-exhaustive.stderr54
-rw-r--r--src/test/ui/pattern/usefulness/stable-gated-patterns.rs18
-rw-r--r--src/test/ui/pattern/usefulness/stable-gated-patterns.stderr26
-rw-r--r--src/test/ui/pattern/usefulness/unstable-gated-patterns.rs22
-rw-r--r--src/test/ui/pattern/usefulness/unstable-gated-patterns.stderr17
8 files changed, 185 insertions, 0 deletions
diff --git a/src/test/ui/pattern/usefulness/auxiliary/hidden.rs b/src/test/ui/pattern/usefulness/auxiliary/hidden.rs
new file mode 100644
index 00000000000..742b7e82c16
--- /dev/null
+++ b/src/test/ui/pattern/usefulness/auxiliary/hidden.rs
@@ -0,0 +1,6 @@
+pub enum Foo {
+    A,
+    B,
+    #[doc(hidden)]
+    C,
+}
diff --git a/src/test/ui/pattern/usefulness/auxiliary/unstable.rs b/src/test/ui/pattern/usefulness/auxiliary/unstable.rs
new file mode 100644
index 00000000000..3142489c861
--- /dev/null
+++ b/src/test/ui/pattern/usefulness/auxiliary/unstable.rs
@@ -0,0 +1,12 @@
+#![feature(staged_api)]
+#![stable(feature = "stable_test_feature", since = "1.0.0")]
+
+#[stable(feature = "stable_test_feature", since = "1.0.0")]
+pub enum Foo {
+    #[stable(feature = "stable_test_feature", since = "1.0.0")]
+    Stable,
+    #[stable(feature = "stable_test_feature", since = "1.0.0")]
+    Stable2,
+    #[unstable(feature = "unstable_test_feature", issue = "none")]
+    Unstable,
+}
diff --git a/src/test/ui/pattern/usefulness/doc-hidden-non-exhaustive.rs b/src/test/ui/pattern/usefulness/doc-hidden-non-exhaustive.rs
new file mode 100644
index 00000000000..a1dcab09314
--- /dev/null
+++ b/src/test/ui/pattern/usefulness/doc-hidden-non-exhaustive.rs
@@ -0,0 +1,30 @@
+// aux-build:hidden.rs
+
+extern crate hidden;
+
+use hidden::Foo;
+
+fn main() {
+    match Foo::A {
+        Foo::A => {}
+        Foo::B => {}
+    }
+    //~^^^^ non-exhaustive patterns: `_` not covered
+
+    match Foo::A {
+        Foo::A => {}
+        Foo::C => {}
+    }
+    //~^^^^ non-exhaustive patterns: `B` not covered
+
+    match Foo::A {
+        Foo::A => {}
+    }
+    //~^^^ non-exhaustive patterns: `B` and `_` not covered
+
+    match None {
+        None => {}
+        Some(Foo::A) => {}
+    }
+    //~^^^^ non-exhaustive patterns: `Some(B)` and `Some(_)` not covered
+}
diff --git a/src/test/ui/pattern/usefulness/doc-hidden-non-exhaustive.stderr b/src/test/ui/pattern/usefulness/doc-hidden-non-exhaustive.stderr
new file mode 100644
index 00000000000..6c9539822b3
--- /dev/null
+++ b/src/test/ui/pattern/usefulness/doc-hidden-non-exhaustive.stderr
@@ -0,0 +1,54 @@
+error[E0004]: non-exhaustive patterns: `_` not covered
+  --> $DIR/doc-hidden-non-exhaustive.rs:8:11
+   |
+LL |     match Foo::A {
+   |           ^^^^^^ pattern `_` not covered
+   |
+   = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
+   = note: the matched value is of type `Foo`
+
+error[E0004]: non-exhaustive patterns: `B` not covered
+  --> $DIR/doc-hidden-non-exhaustive.rs:14:11
+   |
+LL |     match Foo::A {
+   |           ^^^^^^ pattern `B` not covered
+   |
+  ::: $DIR/auxiliary/hidden.rs:3:5
+   |
+LL |     B,
+   |     - not covered
+   |
+   = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
+   = note: the matched value is of type `Foo`
+
+error[E0004]: non-exhaustive patterns: `B` and `_` not covered
+  --> $DIR/doc-hidden-non-exhaustive.rs:20:11
+   |
+LL |     match Foo::A {
+   |           ^^^^^^ patterns `B` and `_` not covered
+   |
+  ::: $DIR/auxiliary/hidden.rs:3:5
+   |
+LL |     B,
+   |     - not covered
+   |
+   = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
+   = note: the matched value is of type `Foo`
+
+error[E0004]: non-exhaustive patterns: `Some(B)` and `Some(_)` not covered
+  --> $DIR/doc-hidden-non-exhaustive.rs:25:11
+   |
+LL |     match None {
+   |           ^^^^ patterns `Some(B)` and `Some(_)` not covered
+   |
+  ::: $SRC_DIR/core/src/option.rs:LL:COL
+   |
+LL |     Some(#[stable(feature = "rust1", since = "1.0.0")] T),
+   |     ---- not covered
+   |
+   = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
+   = note: the matched value is of type `Option<Foo>`
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0004`.
diff --git a/src/test/ui/pattern/usefulness/stable-gated-patterns.rs b/src/test/ui/pattern/usefulness/stable-gated-patterns.rs
new file mode 100644
index 00000000000..2e023a3be4a
--- /dev/null
+++ b/src/test/ui/pattern/usefulness/stable-gated-patterns.rs
@@ -0,0 +1,18 @@
+// aux-build:unstable.rs
+
+extern crate unstable;
+
+use unstable::Foo;
+
+fn main() {
+    match Foo::Stable {
+        Foo::Stable => {}
+    }
+    //~^^^ non-exhaustive patterns: `Stable2` and `_` not covered
+
+    match Foo::Stable {
+        Foo::Stable => {}
+        Foo::Stable2 => {}
+    }
+    //~^^^^ non-exhaustive patterns: `_` not covered
+}
diff --git a/src/test/ui/pattern/usefulness/stable-gated-patterns.stderr b/src/test/ui/pattern/usefulness/stable-gated-patterns.stderr
new file mode 100644
index 00000000000..9b42565ac73
--- /dev/null
+++ b/src/test/ui/pattern/usefulness/stable-gated-patterns.stderr
@@ -0,0 +1,26 @@
+error[E0004]: non-exhaustive patterns: `Stable2` and `_` not covered
+  --> $DIR/stable-gated-patterns.rs:8:11
+   |
+LL |     match Foo::Stable {
+   |           ^^^^^^^^^^^ patterns `Stable2` and `_` not covered
+   |
+  ::: $DIR/auxiliary/unstable.rs:9:5
+   |
+LL |     Stable2,
+   |     ------- not covered
+   |
+   = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
+   = note: the matched value is of type `Foo`
+
+error[E0004]: non-exhaustive patterns: `_` not covered
+  --> $DIR/stable-gated-patterns.rs:13:11
+   |
+LL |     match Foo::Stable {
+   |           ^^^^^^^^^^^ pattern `_` not covered
+   |
+   = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
+   = note: the matched value is of type `Foo`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0004`.
diff --git a/src/test/ui/pattern/usefulness/unstable-gated-patterns.rs b/src/test/ui/pattern/usefulness/unstable-gated-patterns.rs
new file mode 100644
index 00000000000..b9804b0ffe7
--- /dev/null
+++ b/src/test/ui/pattern/usefulness/unstable-gated-patterns.rs
@@ -0,0 +1,22 @@
+#![feature(unstable_test_feature)]
+
+// aux-build:unstable.rs
+
+extern crate unstable;
+
+use unstable::Foo;
+
+fn main() {
+    match Foo::Stable {
+        Foo::Stable => {}
+        Foo::Stable2 => {}
+    }
+    //~^^^^ non-exhaustive patterns: `Unstable` not covered
+
+    // Ok: all variants are explicitly matched
+    match Foo::Stable {
+        Foo::Stable => {}
+        Foo::Stable2 => {}
+        Foo::Unstable => {}
+    }
+}
diff --git a/src/test/ui/pattern/usefulness/unstable-gated-patterns.stderr b/src/test/ui/pattern/usefulness/unstable-gated-patterns.stderr
new file mode 100644
index 00000000000..f9c0196b765
--- /dev/null
+++ b/src/test/ui/pattern/usefulness/unstable-gated-patterns.stderr
@@ -0,0 +1,17 @@
+error[E0004]: non-exhaustive patterns: `Unstable` not covered
+  --> $DIR/unstable-gated-patterns.rs:10:11
+   |
+LL |     match Foo::Stable {
+   |           ^^^^^^^^^^^ pattern `Unstable` not covered
+   |
+  ::: $DIR/auxiliary/unstable.rs:11:5
+   |
+LL |     Unstable,
+   |     -------- not covered
+   |
+   = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
+   = note: the matched value is of type `Foo`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0004`.