rust/tests/ui/impl-trait/object-unsafe-trait-in-return-position-impl-trait.rs
2023-01-11 09:32:08 +00:00

47 lines
567 B
Rust

trait NotObjectSafe {
fn foo() -> Self;
}
trait ObjectSafe {
fn bar(&self);
}
struct A;
struct B;
impl NotObjectSafe for A {
fn foo() -> Self {
A
}
}
impl NotObjectSafe for B {
fn foo() -> Self {
B
}
}
impl ObjectSafe for A {
fn bar(&self) {}
}
impl ObjectSafe for B {
fn bar(&self) {}
}
fn can() -> impl NotObjectSafe {
if true {
return A;
}
B //~ ERROR mismatched types
}
fn cat() -> impl ObjectSafe {
if true {
return A;
}
B //~ ERROR mismatched types
}
fn main() {}