mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-06 04:08:40 +00:00
Add tests
This commit is contained in:
parent
4dcb70b8cf
commit
cbadf786bc
26
tests/ui/impl-trait/trait_upcasting.rs
Normal file
26
tests/ui/impl-trait/trait_upcasting.rs
Normal 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() {}
|
29
tests/ui/impl-trait/trait_upcasting.stderr
Normal file
29
tests/ui/impl-trait/trait_upcasting.stderr
Normal 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`.
|
Loading…
Reference in New Issue
Block a user