]> git.lizzy.rs Git - rust.git/blob - tests/ui/impl-trait/object-unsafe-trait-in-return-position-dyn-trait.rs
Rollup merge of #106427 - mejrs:translation_errors, r=davidtwco
[rust.git] / tests / ui / impl-trait / object-unsafe-trait-in-return-position-dyn-trait.rs
1 #![allow(bare_trait_objects)]
2 trait NotObjectSafe {
3     fn foo() -> Self;
4 }
5
6 struct A;
7 struct B;
8
9 impl NotObjectSafe for A {
10     fn foo() -> Self {
11         A
12     }
13 }
14
15 impl NotObjectSafe for B {
16     fn foo() -> Self {
17         B
18     }
19 }
20
21 fn car() -> dyn NotObjectSafe { //~ ERROR the trait `NotObjectSafe` cannot be made into an object
22     if true {
23         return A;
24     }
25     B
26 }
27
28 fn cat() -> Box<dyn NotObjectSafe> { //~ ERROR the trait `NotObjectSafe` cannot be made into an
29     if true {
30         return Box::new(A);
31     }
32     Box::new(B)
33 }
34
35 fn main() {}