summaryrefslogtreecommitdiffstats
path: root/src/test/ui/impl-trait/object-unsafe-trait-in-return-position-dyn-trait.rs
blob: ab3086c78b3a1a9139a5960b01510b2f5bee0ef4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#![allow(bare_trait_objects)]
trait NotObjectSafe {
    fn foo() -> Self;
}

struct A;
struct B;

impl NotObjectSafe for A {
    fn foo() -> Self {
        A
    }
}

impl NotObjectSafe for B {
    fn foo() -> Self {
        B
    }
}

fn car() -> dyn NotObjectSafe { //~ ERROR the trait `NotObjectSafe` cannot be made into an object
    if true {
        return A;
    }
    B
}

fn cat() -> Box<dyn NotObjectSafe> { //~ ERROR the trait `NotObjectSafe` cannot be made into an
    if true {
        return Box::new(A);
    }
    Box::new(B)
}

fn main() {}