diff options
| author | Ralf Jung <post@ralfj.de> | 2023-12-24 11:09:58 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2023-12-24 11:10:38 +0100 |
| commit | 41020d1337cc9751c48cf1f33bc7a27c83ea8093 (patch) | |
| tree | 496774e8afc78d443e06a4bb62f22993a47c7d48 /tests | |
| parent | 3166bbef9248fce2695899e21203f42a21046551 (diff) | |
| download | rust-41020d1337cc9751c48cf1f33bc7a27c83ea8093.tar.gz rust-41020d1337cc9751c48cf1f33bc7a27c83ea8093.zip | |
fix ICE when using raw ptr in a pattern
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/consts/const_in_pattern/null-raw-ptr-issue-119270.rs | 19 | ||||
| -rw-r--r-- | tests/ui/consts/const_in_pattern/null-raw-ptr-issue-119270.stderr | 14 |
2 files changed, 33 insertions, 0 deletions
diff --git a/tests/ui/consts/const_in_pattern/null-raw-ptr-issue-119270.rs b/tests/ui/consts/const_in_pattern/null-raw-ptr-issue-119270.rs new file mode 100644 index 00000000000..03e91f2b3b1 --- /dev/null +++ b/tests/ui/consts/const_in_pattern/null-raw-ptr-issue-119270.rs @@ -0,0 +1,19 @@ +// run-pass +// Eventually this will be rejected (when the future-compat lints are turned into hard errors), and +// then this test can be removed. But meanwhile we should ensure that this works and does not ICE. +struct NoDerive(i32); + +#[derive(PartialEq)] +struct WrapEmbedded(*const NoDerive); + +const WRAP_UNSAFE_EMBEDDED: &&WrapEmbedded = &&WrapEmbedded(std::ptr::null()); + +fn main() { + let b = match WRAP_UNSAFE_EMBEDDED { + WRAP_UNSAFE_EMBEDDED => true, + //~^ WARN: must be annotated with `#[derive(PartialEq, Eq)]` + //~| previously accepted + _ => false, + }; + assert!(b); +} diff --git a/tests/ui/consts/const_in_pattern/null-raw-ptr-issue-119270.stderr b/tests/ui/consts/const_in_pattern/null-raw-ptr-issue-119270.stderr new file mode 100644 index 00000000000..c186d349e72 --- /dev/null +++ b/tests/ui/consts/const_in_pattern/null-raw-ptr-issue-119270.stderr @@ -0,0 +1,14 @@ +warning: to use a constant of type `WrapEmbedded` in a pattern, `WrapEmbedded` must be annotated with `#[derive(PartialEq, Eq)]` + --> $DIR/null-raw-ptr-issue-119270.rs:13:9 + | +LL | WRAP_UNSAFE_EMBEDDED => true, + | ^^^^^^^^^^^^^^^^^^^^ + | + = 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/62411> + = 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: `#[warn(indirect_structural_match)]` on by default + +warning: 1 warning emitted + |
