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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 10 additions & 0 deletions
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
|
Lines changed: 24 additions & 0 deletions
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+
}
Lines changed: 24 additions & 0 deletions
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+
}
Lines changed: 24 additions & 0 deletions
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+
}
Lines changed: 24 additions & 0 deletions
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+
}
Lines changed: 26 additions & 0 deletions
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+
}
Lines changed: 8 additions & 0 deletions
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+
Lines changed: 26 additions & 0 deletions
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+
}
Lines changed: 8 additions & 0 deletions
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+

0 commit comments

Comments
 (0)