Skip to content

Commit 02714b8

Browse files
committed
Regression tests and updates to existing tests.
The regression tests explore: (direct | indirect | doubly-indirect | unsafe) x (embedded | param): where: embedded: `struct Wrapper(... NoDerive ...);` param: `struct Wrapper<X>(... X ...);` direct: `const A: Wrapper<...> = Wrapper(NoDerive);` indirect: `const A: & & Wrapper<...> = Wrapper(NoDerive)` doubly-indirect: `const A: & & Wrapper<...> = & & Wrapper(& & NoDerive)` unsafe: `const A: UnsafeWrap<...> = UnsafeWrap(std::ptr::null())`
1 parent b560801 commit 02714b8

24 files changed

+448
-0
lines changed

src/test/ui/issues/issue-55511.rs

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ fn main() {
1414
//~^ ERROR `a` does not live long enough [E0597]
1515
match b {
1616
<() as Foo<'static>>::C => { }
17+
//~^ WARN must be annotated with `#[derive(PartialEq, Eq)]`
18+
//~| WARN will become a hard error in a future release
1719
_ => { }
1820
}
1921
}

src/test/ui/issues/issue-55511.stderr

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
warning: to use a constant of type `std::cell::Cell` in a pattern, `std::cell::Cell` must be annotated with `#[derive(PartialEq, Eq)]`
2+
--> $DIR/issue-55511.rs:16:9
3+
|
4+
LL | <() as Foo<'static>>::C => { }
5+
| ^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: #[warn(indirect_structural_match)] on by default
8+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9+
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
10+
111
error[E0597]: `a` does not live long enough
212
--> $DIR/issue-55511.rs:13:28
313
|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Test explores how `#[structral_match]` behaves in tandem with
2+
// `*const` and `*mut` pointers.
3+
4+
// run-pass
5+
6+
struct NoDerive(i32);
7+
8+
// This impl makes NoDerive irreflexive
9+
// (which doesn't matter here because `<*const T>::eq` won't recur on `T`).
10+
impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
11+
12+
impl Eq for NoDerive { }
13+
14+
#[derive(PartialEq, Eq)]
15+
struct WrapEmbedded(*const NoDerive);
16+
17+
const WRAP_UNSAFE_EMBEDDED: WrapEmbedded = WrapEmbedded(std::ptr::null());
18+
19+
fn main() {
20+
match WRAP_UNSAFE_EMBEDDED {
21+
WRAP_UNSAFE_EMBEDDED => { println!("WRAP_UNSAFE_EMBEDDED correctly matched itself"); }
22+
_ => { panic!("WRAP_UNSAFE_EMBEDDED did not match itself"); }
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Test explores how `#[structral_match]` behaves in tandem with
2+
// `*const` and `*mut` pointers.
3+
4+
// run-pass
5+
6+
struct NoDerive(i32);
7+
8+
// This impl makes NoDerive irreflexive
9+
// (which doesn't matter here because `<*const T>::eq` won't recur on `T`).
10+
impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
11+
12+
impl Eq for NoDerive { }
13+
14+
#[derive(PartialEq, Eq)]
15+
struct WrapParam<X>(*const X);
16+
17+
const WRAP_UNSAFE_PARAM: WrapParam<NoDerive> = WrapParam(std::ptr::null());
18+
19+
fn main() {
20+
match WRAP_UNSAFE_PARAM {
21+
WRAP_UNSAFE_PARAM => { println!("WRAP_UNSAFE_PARAM correctly matched itself"); }
22+
_ => { panic!("WRAP_UNSAFE_PARAM did not match itself"); }
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Test explores how `#[structral_match]` behaves in tandem with
2+
// `*const` and `*mut` pointers.
3+
4+
// run-pass
5+
6+
struct NoDerive(i32);
7+
8+
// This impl makes NoDerive irreflexive
9+
// (which doesn't matter here because `<*const T>::eq` won't recur on `T`).
10+
impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
11+
12+
impl Eq for NoDerive { }
13+
14+
#[derive(PartialEq, Eq)]
15+
struct WrapEmbedded(*const NoDerive);
16+
17+
const WRAP_UNSAFE_EMBEDDED: & &WrapEmbedded = & &WrapEmbedded(std::ptr::null());
18+
19+
fn main() {
20+
match WRAP_UNSAFE_EMBEDDED {
21+
WRAP_UNSAFE_EMBEDDED => { println!("WRAP_UNSAFE_EMBEDDED correctly matched itself"); }
22+
_ => { panic!("WRAP_UNSAFE_EMBEDDED did not match itself"); }
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Test explores how `#[structral_match]` behaves in tandem with
2+
// `*const` and `*mut` pointers.
3+
4+
// run-pass
5+
6+
struct NoDerive(i32);
7+
8+
// This impl makes NoDerive irreflexive
9+
// (which doesn't matter here because `<*const T>::eq` won't recur on `T`).
10+
impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
11+
12+
impl Eq for NoDerive { }
13+
14+
#[derive(PartialEq, Eq)]
15+
struct WrapParam<X>(*const X);
16+
17+
const WRAP_UNSAFE_PARAM: & &WrapParam<NoDerive> = & &WrapParam(std::ptr::null());
18+
19+
fn main() {
20+
match WRAP_UNSAFE_PARAM {
21+
WRAP_UNSAFE_PARAM => { println!("WRAP_UNSAFE_PARAM correctly matched itself"); }
22+
_ => { panic!("WRAP_UNSAFE_PARAM did not match itself"); }
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// This is part of a set of tests exploring the different ways a
2+
// `#[structural_match]` ADT might try to hold a
3+
// non-`#[structural_match]` in hidden manner that lets matches
4+
// through that we had intended to reject.
5+
//
6+
// See discussion on rust-lang/rust#62307 and rust-lang/rust#62339
7+
8+
struct NoDerive(i32);
9+
10+
// This impl makes NoDerive irreflexive.
11+
impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
12+
13+
impl Eq for NoDerive { }
14+
15+
#[derive(PartialEq, Eq)]
16+
struct WrapInline(NoDerive);
17+
18+
const WRAP_DIRECT_INLINE: WrapInline = WrapInline(NoDerive(0));
19+
20+
fn main() {
21+
match WRAP_DIRECT_INLINE {
22+
WRAP_DIRECT_INLINE => { panic!("WRAP_DIRECT_INLINE matched itself"); }
23+
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
24+
_ => { println!("WRAP_DIRECT_INLINE did not match itself"); }
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
2+
--> $DIR/cant-hide-behind-direct-struct-embedded.rs:22:9
3+
|
4+
LL | WRAP_DIRECT_INLINE => { panic!("WRAP_DIRECT_INLINE matched itself"); }
5+
| ^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// This is part of a set of tests exploring the different ways a
2+
// `#[structural_match]` ADT might try to hold a
3+
// non-`#[structural_match]` in hidden manner that lets matches
4+
// through that we had intended to reject.
5+
//
6+
// See discussion on rust-lang/rust#62307 and rust-lang/rust#62339
7+
8+
struct NoDerive(i32);
9+
10+
// This impl makes NoDerive irreflexive.
11+
impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
12+
13+
impl Eq for NoDerive { }
14+
15+
#[derive(PartialEq, Eq)]
16+
struct WrapParam<T>(T);
17+
18+
const WRAP_DIRECT_PARAM: WrapParam<NoDerive> = WrapParam(NoDerive(0));
19+
20+
fn main() {
21+
match WRAP_DIRECT_PARAM {
22+
WRAP_DIRECT_PARAM => { panic!("WRAP_DIRECT_PARAM matched itself"); }
23+
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
24+
_ => { println!("WRAP_DIRECT_PARAM did not match itself"); }
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
2+
--> $DIR/cant-hide-behind-direct-struct-param.rs:22:9
3+
|
4+
LL | WRAP_DIRECT_PARAM => { panic!("WRAP_DIRECT_PARAM matched itself"); }
5+
| ^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// This is part of a set of tests exploring the different ways a
2+
// `#[structural_match]` ADT might try to hold a
3+
// non-`#[structural_match]` in hidden manner that lets matches
4+
// through that we had intended to reject.
5+
//
6+
// See discussion on rust-lang/rust#62307 and rust-lang/rust#62339
7+
8+
// run-pass
9+
10+
struct NoDerive(i32);
11+
12+
// This impl makes NoDerive irreflexive.
13+
impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
14+
15+
impl Eq for NoDerive { }
16+
17+
#[derive(PartialEq, Eq)]
18+
struct WrapInline<'a>(&'a &'a NoDerive);
19+
20+
const WRAP_DOUBLY_INDIRECT_INLINE: & &WrapInline = & &WrapInline(& & NoDerive(0));
21+
22+
fn main() {
23+
match WRAP_DOUBLY_INDIRECT_INLINE {
24+
WRAP_DOUBLY_INDIRECT_INLINE => { panic!("WRAP_DOUBLY_INDIRECT_INLINE matched itself"); }
25+
//~^ WARN must be annotated with `#[derive(PartialEq, Eq)]`
26+
//~| WARN will become a hard error in a future release
27+
_ => { println!("WRAP_DOUBLY_INDIRECT_INLINE correctly did not match itself"); }
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
warning: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
2+
--> $DIR/cant-hide-behind-doubly-indirect-embedded.rs:24:9
3+
|
4+
LL | WRAP_DOUBLY_INDIRECT_INLINE => { panic!("WRAP_DOUBLY_INDIRECT_INLINE matched itself"); }
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: #[warn(indirect_structural_match)] on by default
8+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9+
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// This is part of a set of tests exploring the different ways a
2+
// `#[structural_match]` ADT might try to hold a
3+
// non-`#[structural_match]` in hidden manner that lets matches
4+
// through that we had intended to reject.
5+
//
6+
// See discussion on rust-lang/rust#62307 and rust-lang/rust#62339
7+
8+
// run-pass
9+
10+
struct NoDerive(i32);
11+
12+
// This impl makes NoDerive irreflexive.
13+
impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
14+
15+
impl Eq for NoDerive { }
16+
17+
#[derive(PartialEq, Eq)]
18+
struct WrapParam<'a, T>(&'a &'a T);
19+
20+
const WRAP_DOUBLY_INDIRECT_PARAM: & &WrapParam<NoDerive> = & &WrapParam(& & NoDerive(0));
21+
22+
fn main() {
23+
match WRAP_DOUBLY_INDIRECT_PARAM {
24+
WRAP_DOUBLY_INDIRECT_PARAM => { panic!("WRAP_DOUBLY_INDIRECT_PARAM matched itself"); }
25+
//~^ WARN must be annotated with `#[derive(PartialEq, Eq)]`
26+
//~| WARN will become a hard error in a future release
27+
_ => { println!("WRAP_DOUBLY_INDIRECT_PARAM correctly did not match itself"); }
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
warning: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
2+
--> $DIR/cant-hide-behind-doubly-indirect-param.rs:24:9
3+
|
4+
LL | WRAP_DOUBLY_INDIRECT_PARAM => { panic!("WRAP_DOUBLY_INDIRECT_PARAM matched itself"); }
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: #[warn(indirect_structural_match)] on by default
8+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9+
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// This is part of a set of tests exploring the different ways a
2+
// `#[structural_match]` ADT might try to hold a
3+
// non-`#[structural_match]` in hidden manner that lets matches
4+
// through that we had intended to reject.
5+
//
6+
// See discussion on rust-lang/rust#62307 and rust-lang/rust#62339
7+
8+
// run-pass
9+
10+
struct NoDerive(i32);
11+
12+
// This impl makes NoDerive irreflexive.
13+
impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
14+
15+
impl Eq for NoDerive { }
16+
17+
#[derive(PartialEq, Eq)]
18+
struct WrapInline(NoDerive);
19+
20+
const WRAP_INDIRECT_INLINE: & &WrapInline = & &WrapInline(NoDerive(0));
21+
22+
fn main() {
23+
match WRAP_INDIRECT_INLINE {
24+
WRAP_INDIRECT_INLINE => { panic!("WRAP_INDIRECT_INLINE matched itself"); }
25+
//~^ WARN must be annotated with `#[derive(PartialEq, Eq)]`
26+
//~| WARN will become a hard error in a future release
27+
_ => { println!("WRAP_INDIRECT_INLINE did not match itself"); }
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
warning: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
2+
--> $DIR/cant-hide-behind-indirect-struct-embedded.rs:24:9
3+
|
4+
LL | WRAP_INDIRECT_INLINE => { panic!("WRAP_INDIRECT_INLINE matched itself"); }
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: #[warn(indirect_structural_match)] on by default
8+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9+
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// This is part of a set of tests exploring the different ways a
2+
// `#[structural_match]` ADT might try to hold a
3+
// non-`#[structural_match]` in hidden manner that lets matches
4+
// through that we had intended to reject.
5+
//
6+
// See discussion on rust-lang/rust#62307 and rust-lang/rust#62339
7+
8+
// run-pass
9+
10+
struct NoDerive(i32);
11+
12+
// This impl makes NoDerive irreflexive.
13+
impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
14+
15+
impl Eq for NoDerive { }
16+
17+
#[derive(PartialEq, Eq)]
18+
struct WrapParam<T>(T);
19+
20+
const WRAP_INDIRECT_PARAM: & &WrapParam<NoDerive> = & &WrapParam(NoDerive(0));
21+
22+
fn main() {
23+
match WRAP_INDIRECT_PARAM {
24+
WRAP_INDIRECT_PARAM => { panic!("WRAP_INDIRECT_PARAM matched itself"); }
25+
//~^ WARN must be annotated with `#[derive(PartialEq, Eq)]`
26+
//~| WARN will become a hard error in a future release
27+
_ => { println!("WRAP_INDIRECT_PARAM correctly did not match itself"); }
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
warning: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
2+
--> $DIR/cant-hide-behind-indirect-struct-param.rs:24:9
3+
|
4+
LL | WRAP_INDIRECT_PARAM => { panic!("WRAP_INDIRECT_PARAM matched itself"); }
5+
| ^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: #[warn(indirect_structural_match)] on by default
8+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9+
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Issue 61118 pointed out a case where we hit an ICE during code gen:
2+
// the compiler assumed that `PartialEq` was always implemented on any
3+
// use of a `const` item in a pattern context, but the pre-existing
4+
// checking for the presence of `#[structural_match]` was too shallow
5+
// (see rust-lang/rust#62307), and so we hit cases where we were
6+
// trying to dispatch to `PartialEq` on types that did not implement
7+
// that trait.
8+
9+
struct B(i32);
10+
11+
const A: &[B] = &[];
12+
13+
pub fn main() {
14+
match &[][..] {
15+
A => (),
16+
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
17+
_ => (),
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: to use a constant of type `B` in a pattern, `B` must be annotated with `#[derive(PartialEq, Eq)]`
2+
--> $DIR/issue-61118-match-slice-forbidden-without-eq.rs:15:9
3+
|
4+
LL | A => (),
5+
| ^
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)