Skip to content

Commit 60d9df2

Browse files
committed
Add tests for opaque types
1 parent 516798e commit 60d9df2

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![feature(const_fn, type_alias_impl_trait)]
2+
3+
type Bar = impl Send;
4+
5+
// While i32 is structural-match, we do not want to leak this information.
6+
// (See https://github.com/rust-lang/rust/issues/72156)
7+
const fn leak_free() -> Bar {
8+
7i32
9+
}
10+
const LEAK_FREE: Bar = leak_free();
11+
12+
fn leak_free_test() {
13+
match todo!() {
14+
LEAK_FREE => (),
15+
//~^ opaque types cannot be used in patterns
16+
_ => (),
17+
}
18+
}
19+
20+
fn main() { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: opaque types cannot be used in patterns
2+
--> $DIR/structural-match-no-leak.rs:14:9
3+
|
4+
LL | LEAK_FREE => (),
5+
| ^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#![feature(const_fn, type_alias_impl_trait)]
2+
3+
type Foo = impl Send;
4+
5+
// This is not structural-match
6+
struct A;
7+
8+
const fn value() -> Foo {
9+
A
10+
}
11+
const VALUE: Foo = value();
12+
13+
fn test() {
14+
match todo!() {
15+
VALUE => (),
16+
//~^ opaque types cannot be used in patterns
17+
_ => (),
18+
}
19+
}
20+
21+
fn main() { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: opaque types cannot be used in patterns
2+
--> $DIR/structural-match.rs:15:9
3+
|
4+
LL | VALUE => (),
5+
| ^^^^^
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)