]> git.lizzy.rs Git - rust.git/blob - src/test/ui/span/issue-24805-dropck-trait-has-items.rs
Rollup merge of #87922 - Manishearth:c-enum-target-spec, r=nagisa,eddyb
[rust.git] / src / test / ui / span / issue-24805-dropck-trait-has-items.rs
1 // Check that traits with various kinds of associated items cause
2 // dropck to inject extra region constraints.
3
4 #![allow(non_camel_case_types)]
5
6 trait HasSelfMethod { fn m1(&self) { } }
7 trait HasMethodWithSelfArg { fn m2(x: &Self) { } }
8 trait HasType { type Something; }
9
10 impl HasSelfMethod for i32 { }
11 impl HasMethodWithSelfArg for i32 { }
12 impl HasType for i32 { type Something = (); }
13
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 = (); }
17
18 // e.g., `impl_drop!(Send, D_Send)` expands to:
19 //   ```rust
20 //   struct D_Send<T:Send>(T);
21 //   impl<T:Send> Drop for D_Send<T> { fn drop(&mut self) { } }
22 //   ```
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) { } }
27     }
28 }
29
30 impl_drop!{HasSelfMethod,        D_HasSelfMethod}
31 impl_drop!{HasMethodWithSelfArg, D_HasMethodWithSelfArg}
32 impl_drop!{HasType,              D_HasType}
33
34 fn f_sm() {
35     let (_d, d1);
36     d1 = D_HasSelfMethod(1);
37     _d = D_HasSelfMethod(&d1);
38 }
39 //~^^ ERROR `d1` does not live long enough
40 fn f_mwsa() {
41     let (_d, d1);
42     d1 = D_HasMethodWithSelfArg(1);
43     _d = D_HasMethodWithSelfArg(&d1);
44 }
45 //~^^ ERROR `d1` does not live long enough
46 fn f_t() {
47     let (_d, d1);
48     d1 = D_HasType(1);
49     _d = D_HasType(&d1);
50 }
51 //~^^ ERROR `d1` does not live long enough
52
53 fn main() {
54     f_sm();
55     f_mwsa();
56     f_t();
57 }