]> git.proxmox.com Git - rustc.git/blob - src/test/ui/traits/trait-suggest-deferences-multiple-1.rs
New upstream version 1.51.0+dfsg1
[rustc.git] / src / test / ui / traits / trait-suggest-deferences-multiple-1.rs
1 use std::ops::{Deref, DerefMut};
2
3 trait Happy {}
4 struct LDM;
5 impl Happy for &mut LDM {}
6
7 struct Foo(LDM);
8 struct Bar(Foo);
9 struct Baz(Bar);
10 impl Deref for Foo {
11 type Target = LDM;
12 fn deref(&self) -> &Self::Target {
13 &self.0
14 }
15 }
16 impl Deref for Bar {
17 type Target = Foo;
18 fn deref(&self) -> &Self::Target {
19 &self.0
20 }
21 }
22 impl Deref for Baz {
23 type Target = Bar;
24 fn deref(&self) -> &Self::Target {
25 &self.0
26 }
27 }
28 impl DerefMut for Foo {
29 fn deref_mut(&mut self) -> &mut Self::Target {
30 &mut self.0
31 }
32 }
33 impl DerefMut for Bar {
34 fn deref_mut(&mut self) -> &mut Self::Target {
35 &mut self.0
36 }
37 }
38 impl DerefMut for Baz {
39 fn deref_mut(&mut self) -> &mut Self::Target {
40 &mut self.0
41 }
42 }
43
44
45 fn foo<T>(_: T) where T: Happy {}
46
47 fn main() {
48 // Currently the compiler doesn't try to suggest dereferences for situations
49 // where DerefMut involves. So this test is meant to ensure compiler doesn't
50 // generate incorrect help message.
51 let mut baz = Baz(Bar(Foo(LDM)));
52 foo(&mut baz);
53 //~^ ERROR the trait bound `&mut Baz: Happy` is not satisfied
54 }