2020-01-15 15:49:54 -08:00
|
|
|
#![allow(bare_trait_objects)]
|
2024-10-09 23:31:01 +02:00
|
|
|
|
|
|
|
trait DynIncompatible {
|
2020-01-15 15:49:54 -08:00
|
|
|
fn foo() -> Self;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct A;
|
|
|
|
struct B;
|
|
|
|
|
2024-10-09 23:31:01 +02:00
|
|
|
impl DynIncompatible for A {
|
2020-01-15 15:49:54 -08:00
|
|
|
fn foo() -> Self {
|
|
|
|
A
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-09 23:31:01 +02:00
|
|
|
impl DynIncompatible for B {
|
2020-01-15 15:49:54 -08:00
|
|
|
fn foo() -> Self {
|
|
|
|
B
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-20 14:19:36 -08:00
|
|
|
fn car() -> dyn DynIncompatible { //~ ERROR the trait `DynIncompatible` is not dyn compatible
|
2025-02-02 14:58:12 +00:00
|
|
|
//~^ ERROR return type cannot be a trait object without pointer indirection
|
2020-01-15 15:49:54 -08:00
|
|
|
if true {
|
|
|
|
return A;
|
|
|
|
}
|
|
|
|
B
|
|
|
|
}
|
|
|
|
|
2024-11-20 14:19:36 -08:00
|
|
|
fn cat() -> Box<dyn DynIncompatible> { //~ ERROR the trait `DynIncompatible` is not dyn compatible
|
2020-01-15 15:49:54 -08:00
|
|
|
if true {
|
2024-11-20 14:19:36 -08:00
|
|
|
return Box::new(A); //~ ERROR is not dyn compatible
|
2020-01-15 15:49:54 -08:00
|
|
|
}
|
2024-11-20 14:19:36 -08:00
|
|
|
Box::new(B) //~ ERROR is not dyn compatible
|
2020-01-15 15:49:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|