summaryrefslogtreecommitdiffstats
path: root/tests/ui/consts/const_in_pattern
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
commitef24de24a82fe681581cc130f342363c47c0969a (patch)
tree0d494f7e1a38b95c92426f58fe6eaa877303a86c /tests/ui/consts/const_in_pattern
parentReleasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz
rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/consts/const_in_pattern')
-rw-r--r--tests/ui/consts/const_in_pattern/issue-34784-match-on-non-int-raw-ptr.rs32
-rw-r--r--tests/ui/consts/const_in_pattern/issue-34784-match-on-non-int-raw-ptr.stderr34
-rw-r--r--tests/ui/consts/const_in_pattern/issue-44333.rs4
-rw-r--r--tests/ui/consts/const_in_pattern/issue-44333.stderr4
-rw-r--r--tests/ui/consts/const_in_pattern/issue-78057.rs1
-rw-r--r--tests/ui/consts/const_in_pattern/issue-78057.stderr17
-rw-r--r--tests/ui/consts/const_in_pattern/reject_non_structural.rs5
-rw-r--r--tests/ui/consts/const_in_pattern/reject_non_structural.stderr33
8 files changed, 85 insertions, 45 deletions
diff --git a/tests/ui/consts/const_in_pattern/issue-34784-match-on-non-int-raw-ptr.rs b/tests/ui/consts/const_in_pattern/issue-34784-match-on-non-int-raw-ptr.rs
new file mode 100644
index 000000000..2491071d1
--- /dev/null
+++ b/tests/ui/consts/const_in_pattern/issue-34784-match-on-non-int-raw-ptr.rs
@@ -0,0 +1,32 @@
+#![deny(pointer_structural_match)]
+#![allow(dead_code)]
+
+const C: *const u8 = &0;
+// Make sure we also find pointers nested in other types.
+const C_INNER: (*const u8, u8) = (C, 0);
+
+fn foo(x: *const u8) {
+ match x {
+ C => {} //~ERROR: behave unpredictably
+ //~| previously accepted
+ _ => {}
+ }
+}
+
+fn foo2(x: *const u8) {
+ match (x, 1) {
+ C_INNER => {} //~ERROR: behave unpredictably
+ //~| previously accepted
+ _ => {}
+ }
+}
+
+const D: *const [u8; 4] = b"abcd";
+
+fn main() {
+ match D {
+ D => {} //~ERROR: behave unpredictably
+ //~| previously accepted
+ _ => {}
+ }
+}
diff --git a/tests/ui/consts/const_in_pattern/issue-34784-match-on-non-int-raw-ptr.stderr b/tests/ui/consts/const_in_pattern/issue-34784-match-on-non-int-raw-ptr.stderr
new file mode 100644
index 000000000..ab53346b5
--- /dev/null
+++ b/tests/ui/consts/const_in_pattern/issue-34784-match-on-non-int-raw-ptr.stderr
@@ -0,0 +1,34 @@
+error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
+ --> $DIR/issue-34784-match-on-non-int-raw-ptr.rs:10:9
+ |
+LL | C => {}
+ | ^
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/70861>
+note: the lint level is defined here
+ --> $DIR/issue-34784-match-on-non-int-raw-ptr.rs:1:9
+ |
+LL | #![deny(pointer_structural_match)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
+ --> $DIR/issue-34784-match-on-non-int-raw-ptr.rs:18:9
+ |
+LL | C_INNER => {}
+ | ^^^^^^^
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/70861>
+
+error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
+ --> $DIR/issue-34784-match-on-non-int-raw-ptr.rs:28:9
+ |
+LL | D => {}
+ | ^
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/70861>
+
+error: aborting due to 3 previous errors
+
diff --git a/tests/ui/consts/const_in_pattern/issue-44333.rs b/tests/ui/consts/const_in_pattern/issue-44333.rs
index 96e8795e5..aaf1edb6f 100644
--- a/tests/ui/consts/const_in_pattern/issue-44333.rs
+++ b/tests/ui/consts/const_in_pattern/issue-44333.rs
@@ -16,9 +16,9 @@ const BAR: Func = bar;
fn main() {
match test(std::env::consts::ARCH.len()) {
- FOO => println!("foo"), //~ WARN pointers in patterns behave unpredictably
+ FOO => println!("foo"), //~ WARN behave unpredictably
//~^ WARN will become a hard error
- BAR => println!("bar"), //~ WARN pointers in patterns behave unpredictably
+ BAR => println!("bar"), //~ WARN behave unpredictably
//~^ WARN will become a hard error
_ => unreachable!(),
}
diff --git a/tests/ui/consts/const_in_pattern/issue-44333.stderr b/tests/ui/consts/const_in_pattern/issue-44333.stderr
index 731ef509c..441aeecbc 100644
--- a/tests/ui/consts/const_in_pattern/issue-44333.stderr
+++ b/tests/ui/consts/const_in_pattern/issue-44333.stderr
@@ -1,4 +1,4 @@
-warning: function pointers and unsized pointers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
+warning: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
--> $DIR/issue-44333.rs:19:9
|
LL | FOO => println!("foo"),
@@ -12,7 +12,7 @@ note: the lint level is defined here
LL | #![warn(pointer_structural_match)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
-warning: function pointers and unsized pointers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
+warning: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
--> $DIR/issue-44333.rs:21:9
|
LL | BAR => println!("bar"),
diff --git a/tests/ui/consts/const_in_pattern/issue-78057.rs b/tests/ui/consts/const_in_pattern/issue-78057.rs
index 69cf8404d..88b5d68cb 100644
--- a/tests/ui/consts/const_in_pattern/issue-78057.rs
+++ b/tests/ui/consts/const_in_pattern/issue-78057.rs
@@ -12,6 +12,5 @@ fn main() {
FOO => {},
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
_ => {}
- //~^ ERROR unreachable pattern
}
}
diff --git a/tests/ui/consts/const_in_pattern/issue-78057.stderr b/tests/ui/consts/const_in_pattern/issue-78057.stderr
index df155bdb6..5ec68719a 100644
--- a/tests/ui/consts/const_in_pattern/issue-78057.stderr
+++ b/tests/ui/consts/const_in_pattern/issue-78057.stderr
@@ -7,20 +7,5 @@ LL | FOO => {},
= note: the traits must be derived, manual `impl`s are not sufficient
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
-error: unreachable pattern
- --> $DIR/issue-78057.rs:14:9
- |
-LL | FOO => {},
- | --- matches any value
-LL |
-LL | _ => {}
- | ^ unreachable pattern
- |
-note: the lint level is defined here
- --> $DIR/issue-78057.rs:1:9
- |
-LL | #![deny(unreachable_patterns)]
- | ^^^^^^^^^^^^^^^^^^^^
-
-error: aborting due to 2 previous errors
+error: aborting due to previous error
diff --git a/tests/ui/consts/const_in_pattern/reject_non_structural.rs b/tests/ui/consts/const_in_pattern/reject_non_structural.rs
index dc6b9a331..df772740a 100644
--- a/tests/ui/consts/const_in_pattern/reject_non_structural.rs
+++ b/tests/ui/consts/const_in_pattern/reject_non_structural.rs
@@ -1,3 +1,5 @@
+// compile-flags: -Zdeduplicate-diagnostics=yes
+
// This test of structural match checking enumerates the different kinds of
// const definitions, collecting cases where the const pattern is rejected.
//
@@ -78,9 +80,6 @@ fn main() {
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
//~| NOTE the traits must be derived
//~| NOTE StructuralEq.html for details
- //~| ERROR must be annotated with `#[derive(PartialEq, Eq)]`
- //~| NOTE the traits must be derived
- //~| NOTE StructuralEq.html for details
trait Trait: Sized { const ASSOC: Option<Self>; }
impl Trait for NoDerive { const ASSOC: Option<NoDerive> = Some(NoDerive); }
diff --git a/tests/ui/consts/const_in_pattern/reject_non_structural.stderr b/tests/ui/consts/const_in_pattern/reject_non_structural.stderr
index b6e439f21..72bb0aeaf 100644
--- a/tests/ui/consts/const_in_pattern/reject_non_structural.stderr
+++ b/tests/ui/consts/const_in_pattern/reject_non_structural.stderr
@@ -1,5 +1,5 @@
error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:40:36
+ --> $DIR/reject_non_structural.rs:42:36
|
LL | match Derive::Some(NoDerive) { ENUM => dbg!(ENUM), _ => panic!("whoops"), };
| ^^^^
@@ -8,7 +8,7 @@ LL | match Derive::Some(NoDerive) { ENUM => dbg!(ENUM), _ => panic!("whoops"
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:46:28
+ --> $DIR/reject_non_structural.rs:48:28
|
LL | match Some(NoDerive) { FIELD => dbg!(FIELD), _ => panic!("whoops"), };
| ^^^^^
@@ -17,7 +17,7 @@ LL | match Some(NoDerive) { FIELD => dbg!(FIELD), _ => panic!("whoops"), };
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:53:27
+ --> $DIR/reject_non_structural.rs:55:27
|
LL | match Some(NoDerive) {INDIRECT => dbg!(INDIRECT), _ => panic!("whoops"), };
| ^^^^^^^^
@@ -26,7 +26,7 @@ LL | match Some(NoDerive) {INDIRECT => dbg!(INDIRECT), _ => panic!("whoops")
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:59:36
+ --> $DIR/reject_non_structural.rs:61:36
|
LL | match (None, Some(NoDerive)) { TUPLE => dbg!(TUPLE), _ => panic!("whoops"), };
| ^^^^^
@@ -35,7 +35,7 @@ LL | match (None, Some(NoDerive)) { TUPLE => dbg!(TUPLE), _ => panic!("whoop
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:65:28
+ --> $DIR/reject_non_structural.rs:67:28
|
LL | match Some(NoDerive) { TYPE_ASCRIPTION => dbg!(TYPE_ASCRIPTION), _ => panic!("whoops"), };
| ^^^^^^^^^^^^^^^
@@ -44,7 +44,7 @@ LL | match Some(NoDerive) { TYPE_ASCRIPTION => dbg!(TYPE_ASCRIPTION), _ => p
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:71:36
+ --> $DIR/reject_non_structural.rs:73:36
|
LL | match [None, Some(NoDerive)] { ARRAY => dbg!(ARRAY), _ => panic!("whoops"), };
| ^^^^^
@@ -53,7 +53,7 @@ LL | match [None, Some(NoDerive)] { ARRAY => dbg!(ARRAY), _ => panic!("whoop
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:77:33
+ --> $DIR/reject_non_structural.rs:79:33
|
LL | match [Some(NoDerive); 2] { REPEAT => dbg!(REPEAT), _ => panic!("whoops"), };
| ^^^^^^
@@ -62,16 +62,7 @@ LL | match [Some(NoDerive); 2] { REPEAT => dbg!(REPEAT), _ => panic!("whoops
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:77:33
- |
-LL | match [Some(NoDerive); 2] { REPEAT => dbg!(REPEAT), _ => panic!("whoops"), };
- | ^^^^^^
- |
- = note: the traits must be derived, manual `impl`s are not sufficient
- = note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
-
-error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:87:28
+ --> $DIR/reject_non_structural.rs:86:28
|
LL | match Some(NoDerive) { NoDerive::ASSOC => dbg!(NoDerive::ASSOC), _ => panic!("whoops"), };
| ^^^^^^^^^^^^^^^
@@ -80,7 +71,7 @@ LL | match Some(NoDerive) { NoDerive::ASSOC => dbg!(NoDerive::ASSOC), _ => p
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:93:28
+ --> $DIR/reject_non_structural.rs:92:28
|
LL | match Some(NoDerive) { BLOCK => dbg!(BLOCK), _ => panic!("whoops"), };
| ^^^^^
@@ -89,7 +80,7 @@ LL | match Some(NoDerive) { BLOCK => dbg!(BLOCK), _ => panic!("whoops"), };
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
warning: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:99:29
+ --> $DIR/reject_non_structural.rs:98:29
|
LL | match &Some(NoDerive) { ADDR_OF => dbg!(ADDR_OF), _ => panic!("whoops"), };
| ^^^^^^^
@@ -99,10 +90,10 @@ LL | match &Some(NoDerive) { ADDR_OF => dbg!(ADDR_OF), _ => panic!("whoops")
= note: the traits must be derived, manual `impl`s are not sufficient
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
note: the lint level is defined here
- --> $DIR/reject_non_structural.rs:12:9
+ --> $DIR/reject_non_structural.rs:14:9
|
LL | #![warn(indirect_structural_match)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
-error: aborting due to 10 previous errors; 1 warning emitted
+error: aborting due to 9 previous errors; 1 warning emitted