summaryrefslogtreecommitdiffstats
path: root/src/test/ui/suggestions/constrain-trait.rs
blob: 99ccf7a7f3bdf712cf43b19f7c3576ed493318ad (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
// run-rustfix
// check-only

#[derive(Debug)]
struct Demo {
    a: String
}

trait GetString {
    fn get_a(&self) -> &String;
}

trait UseString: std::fmt::Debug {
    fn use_string(&self) {
        println!("{:?}", self.get_a()); //~ ERROR no method named `get_a` found
    }
}

trait UseString2 {
    fn use_string(&self) {
        println!("{:?}", self.get_a()); //~ ERROR no method named `get_a` found
    }
}

impl GetString for Demo {
    fn get_a(&self) -> &String {
        &self.a
    }
}

impl UseString for Demo {}
impl UseString2 for Demo {}


#[cfg(test)]
mod tests {
    use crate::{Demo, UseString};

    #[test]
    fn it_works() {
        let d = Demo { a: "test".to_string() };
        d.use_string();
    }
}


fn main() {}