1 // Check that traits with various kinds of associated items cause
2 // dropck to inject extra region constraints.
4 #![allow(non_camel_case_types)]
6 trait HasSelfMethod { fn m1(&self) { } }
7 trait HasMethodWithSelfArg { fn m2(x: &Self) { } }
8 trait HasType { type Something; }
10 impl HasSelfMethod for i32 { }
11 impl HasMethodWithSelfArg for i32 { }
12 impl HasType for i32 { type Something = (); }
14 impl<'a,T> HasSelfMethod for &'a T { }
15 impl<'a,T> HasMethodWithSelfArg for &'a T { }
16 impl<'a,T> HasType for &'a T { type Something = (); }
18 // e.g., `impl_drop!(Send, D_Send)` expands to:
20 // struct D_Send<T:Send>(T);
21 // impl<T:Send> Drop for D_Send<T> { fn drop(&mut self) { } }
23 macro_rules! impl_drop {
24 ($Bound:ident, $Id:ident) => {
25 struct $Id<T:$Bound>(T);
26 impl <T:$Bound> Drop for $Id<T> { fn drop(&mut self) { } }
30 impl_drop!{HasSelfMethod, D_HasSelfMethod}
31 impl_drop!{HasMethodWithSelfArg, D_HasMethodWithSelfArg}
32 impl_drop!{HasType, D_HasType}
36 d1 = D_HasSelfMethod(1);
37 _d = D_HasSelfMethod(&d1);
39 //~^^ ERROR `d1` does not live long enough
42 d1 = D_HasMethodWithSelfArg(1);
43 _d = D_HasMethodWithSelfArg(&d1);
45 //~^^ ERROR `d1` does not live long enough
51 //~^^ ERROR `d1` does not live long enough