Skip to content

Commit 210e829

Browse files
add tests for metadata for unsized generics and opaques
1 parent 1d834cb commit 210e829

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// edition:2018
2+
3+
#![feature(ptr_metadata)]
4+
#![feature(type_alias_impl_trait)]
5+
6+
type Opaque = impl std::fmt::Debug + ?Sized;
7+
8+
fn opaque() -> &'static Opaque {
9+
&[1] as &[i32]
10+
}
11+
12+
fn a<T: ?Sized>() {
13+
is_thin::<T>();
14+
//~^ ERROR type mismatch resolving `<T as Pointee>::Metadata == ()`
15+
16+
is_thin::<Opaque>();
17+
//~^ ERROR type mismatch resolving `<impl Debug + ?Sized as Pointee>::Metadata == ()`
18+
}
19+
20+
fn is_thin<T: std::ptr::Pointee<Metadata = ()> + ?Sized>() {}
21+
22+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
error[E0271]: type mismatch resolving `<T as Pointee>::Metadata == ()`
2+
--> $DIR/pointee-tail-is-generic-errors.rs:13:5
3+
|
4+
LL | is_thin::<T>();
5+
| ^^^^^^^^^^^^ expected `()`, found associated type
6+
|
7+
= note: expected unit type `()`
8+
found associated type `<T as Pointee>::Metadata`
9+
= help: consider constraining the associated type `<T as Pointee>::Metadata` to `()`
10+
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
11+
note: required by a bound in `is_thin`
12+
--> $DIR/pointee-tail-is-generic-errors.rs:20:33
13+
|
14+
LL | fn is_thin<T: std::ptr::Pointee<Metadata = ()> + ?Sized>() {}
15+
| ^^^^^^^^^^^^^ required by this bound in `is_thin`
16+
17+
error[E0271]: type mismatch resolving `<impl Debug + ?Sized as Pointee>::Metadata == ()`
18+
--> $DIR/pointee-tail-is-generic-errors.rs:16:5
19+
|
20+
LL | type Opaque = impl std::fmt::Debug + ?Sized;
21+
| ----------------------------- the found opaque type
22+
...
23+
LL | is_thin::<Opaque>();
24+
| ^^^^^^^^^^^^^^^^^ expected `()`, found associated type
25+
|
26+
= note: expected unit type `()`
27+
found associated type `<impl Debug + ?Sized as Pointee>::Metadata`
28+
note: required by a bound in `is_thin`
29+
--> $DIR/pointee-tail-is-generic-errors.rs:20:33
30+
|
31+
LL | fn is_thin<T: std::ptr::Pointee<Metadata = ()> + ?Sized>() {}
32+
| ^^^^^^^^^^^^^ required by this bound in `is_thin`
33+
help: consider constraining the associated type `<impl Debug + ?Sized as Pointee>::Metadata` to `()`
34+
|
35+
LL | type Opaque = impl std::fmt::Debug<Metadata = ()> + ?Sized;
36+
| +++++++++++++++
37+
38+
error: aborting due to 2 previous errors
39+
40+
For more information about this error, try `rustc --explain E0271`.

0 commit comments

Comments
 (0)