summaryrefslogtreecommitdiffstats
path: root/src/test/ui/associated-types/issue-65774-2.rs
blob: 171e0893b4719a570837dd78c84e672595a04154 (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
#![feature(associated_type_defaults)]

trait MyDisplay { fn method(&self) { } }

impl<'a, T: MyDisplay> MyDisplay for &'a mut T { }

struct T;

trait MPU {
    type MpuConfig: MyDisplay = T;
    //~^ ERROR the trait bound `T: MyDisplay` is not satisfied
}

struct S;

impl MPU for S { }

trait MyWrite {
    fn my_write(&self, _: &dyn MyDisplay) { }
}

trait ProcessType {
    fn process_detail_fmt(&self, _: &mut dyn MyWrite);
}

struct Process;

impl ProcessType for Process {
    fn process_detail_fmt(&self, writer: &mut dyn MyWrite)
    {

        let mut val: Option<<S as MPU>::MpuConfig> = None;
        let valref: &mut <S as MPU>::MpuConfig = val.as_mut().unwrap();

        // // This causes a different ICE (but its similar if you squint right):
        // //
        // // `Unimplemented` selecting `Binder(<T as MyDisplay>)` during codegen
        //
        writer.my_write(valref)
        //~^ ERROR the trait bound `T: MyDisplay` is not satisfied

        // This one causes the ICE:
        // FulfillmentError(Obligation(predicate=Binder(TraitPredicate(<T as MyDisplay>)),
        // depth=1),Unimplemented)
        /*let closure = |config: &mut <S as MPU>::MpuConfig| writer.my_write(&config);
        closure(valref);*/
    }
}

fn create() -> &'static dyn ProcessType {
    let input: Option<&mut Process> = None;
    let process: &mut Process = input.unwrap();
    process
}

pub fn main() {
    create();
}