summaryrefslogtreecommitdiffstats
path: root/tests/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs
blob: 255cab06070c650c774a3ca45b2f7386d7c325d9 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// FIXME: the following cases need to suggest more things to make users reach a working end state.

mod bav {
    trait OtherTrait<'a> {}
    impl<'a> OtherTrait<'a> for &'a () {}

    trait ObjectTrait {
        type Assoc: Bar;
    }
    trait MyTrait {
        fn use_self(&self) -> &() { panic!() }
    }
    trait Bar {}

    impl MyTrait for Box<dyn ObjectTrait<Assoc = i32>> {
        fn use_self(&self) -> &() { panic!() }
    }
    impl Bar for i32 {}

    fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = i32>>) -> impl OtherTrait<'a> {
        val.use_self() //~ ERROR cannot return value referencing function parameter
    }
}

mod bap {
    trait OtherTrait<'a> {}
    impl<'a> OtherTrait<'a> for &'a () {}

    trait ObjectTrait {
        type Assoc: Bar;
    }
    trait MyTrait {
        fn use_self(&self) -> &() { panic!() }
    }
    trait Bar {}

    impl MyTrait for Box<dyn ObjectTrait<Assoc = i32>> {
        fn use_self(&self) -> &() { panic!() }
    }
    impl Bar for i32 {}

    fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = i32>>) -> impl OtherTrait<'a> + 'a {
        val.use_self() //~ ERROR E0515
    }
}

// This case in particular requires the user to write all of the bounds we have in `mod bax`.
mod bay {
    trait OtherTrait<'a> {}
    impl<'a> OtherTrait<'a> for &'a () {}

    trait ObjectTrait {
        type Assoc: Bar;
    }
    trait MyTrait {
        fn use_self(&self) -> &() { panic!() }
    }
    trait Bar {}

    impl MyTrait for Box<dyn ObjectTrait<Assoc = i32>> {
        fn use_self(&self) -> &() { panic!() }
    }
    impl Bar for i32 {}

    fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = i32> + 'a>) -> &'a () {
        val.use_self()
    }
}

mod bax {
    trait OtherTrait<'a> {}
    impl<'a> OtherTrait<'a> for &'a () {}

    trait ObjectTrait {
        type Assoc: Bar;
    }
    trait MyTrait<'a> {
        fn use_self(&'a self) -> &'a () { panic!() }
    }
    trait Bar {}

    impl<'a> MyTrait<'a> for Box<dyn ObjectTrait<Assoc = i32> + 'a> {
        fn use_self(&'a self) -> &'a () { panic!() }
    }
    impl Bar for i32 {}

    fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = i32> + 'a>) -> &'a () {
        val.use_self()
    }
}

mod baw {
    trait OtherTrait<'a> {}
    impl<'a> OtherTrait<'a> for &'a () {}

    trait ObjectTrait {
        type Assoc: Bar;
    }
    trait MyTrait {
        fn use_self(&self) -> &() { panic!() }
    }
    trait Bar {}

    impl<'a> MyTrait for Box<dyn ObjectTrait<Assoc = Box<dyn Bar>>> {
        fn use_self(&self) -> &() { panic!() }
    }

    fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = Box<dyn Bar>>>) -> impl OtherTrait<'a> + 'a{
        val.use_self() //~ ERROR E0515
    }
}

fn main() {}