]> git.lizzy.rs Git - rust.git/blob - src/test/ui/suggestions/constrain-trait.rs
Merge branch 'master' into rusty-hermit
[rust.git] / src / test / ui / suggestions / constrain-trait.rs
1 // run-rustfix
2 // check-only
3
4 #[derive(Debug)]
5 struct Demo {
6     a: String
7 }
8
9 trait GetString {
10     fn get_a(&self) -> &String;
11 }
12
13 trait UseString: std::fmt::Debug {
14     fn use_string(&self) {
15         println!("{:?}", self.get_a()); //~ ERROR no method named `get_a` found for type `&Self`
16     }
17 }
18
19 trait UseString2 {
20     fn use_string(&self) {
21         println!("{:?}", self.get_a()); //~ ERROR no method named `get_a` found for type `&Self`
22     }
23 }
24
25 impl GetString for Demo {
26     fn get_a(&self) -> &String {
27         &self.a
28     }
29 }
30
31 impl UseString for Demo {}
32 impl UseString2 for Demo {}
33
34
35 #[cfg(test)]
36 mod tests {
37     use crate::{Demo, UseString};
38
39     #[test]
40     fn it_works() {
41         let d = Demo { a: "test".to_string() };
42         d.use_string();
43     }
44 }
45
46
47 fn main() {}