Add tests

This commit is contained in:
Oli Scherer 2024-05-24 14:17:54 +00:00
parent 4dcb70b8cf
commit cbadf786bc
2 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,26 @@
//! Test that we allow unsizing `Trait<Concrete>` to `Trait<Opaque>` and vice versa
trait Trait<T> {}
impl<T, U> Trait<T> for U {}
fn hello() -> &'static (dyn Trait<impl Sized> + Send) {
if false {
let x = hello();
let _: &'static dyn Trait<()> = x;
//~^ ERROR: mismatched types
}
todo!()
}
fn bye() -> &'static dyn Trait<impl Sized> {
if false {
let mut x = bye();
let y: &'static (dyn Trait<()> + Send) = &();
x = y;
//~^ ERROR: mismatched types
}
todo!()
}
fn main() {}

View File

@ -0,0 +1,29 @@
error[E0308]: mismatched types
--> $DIR/trait_upcasting.rs:10:41
|
LL | fn hello() -> &'static (dyn Trait<impl Sized> + Send) {
| ---------- the found opaque type
...
LL | let _: &'static dyn Trait<()> = x;
| ---------------------- ^ expected trait `Trait<()>`, found trait `Trait<impl Sized> + Send`
| |
| expected due to this
|
= note: expected reference `&'static (dyn Trait<()> + 'static)`
found reference `&dyn Trait<impl Sized> + Send`
error[E0308]: mismatched types
--> $DIR/trait_upcasting.rs:20:13
|
LL | fn bye() -> &'static dyn Trait<impl Sized> {
| ---------- the expected opaque type
...
LL | x = y;
| ^ expected trait `Trait<impl Sized>`, found trait `Trait<()> + Send`
|
= note: expected reference `&dyn Trait<impl Sized>`
found reference `&'static (dyn Trait<()> + Send + 'static)`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0308`.