]>
Commit | Line | Data |
---|---|---|
d9579d0f AL |
1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT |
2 | // file at the top-level directory of this distribution and at | |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
11 | // Check that traits with various kinds of associated items cause | |
12 | // dropck to inject extra region constraints. | |
13 | ||
14 | #![allow(non_camel_case_types)] | |
15 | ||
16 | trait HasSelfMethod { fn m1(&self) { } } | |
17 | trait HasMethodWithSelfArg { fn m2(x: &Self) { } } | |
18 | trait HasType { type Something; } | |
19 | ||
20 | impl HasSelfMethod for i32 { } | |
21 | impl HasMethodWithSelfArg for i32 { } | |
22 | impl HasType for i32 { type Something = (); } | |
23 | ||
24 | impl<'a,T> HasSelfMethod for &'a T { } | |
25 | impl<'a,T> HasMethodWithSelfArg for &'a T { } | |
26 | impl<'a,T> HasType for &'a T { type Something = (); } | |
27 | ||
28 | // e.g. `impl_drop!(Send, D_Send)` expands to: | |
29 | // ```rust | |
30 | // struct D_Send<T:Send>(T); | |
31 | // impl<T:Send> Drop for D_Send<T> { fn drop(&mut self) { } } | |
32 | // ``` | |
33 | macro_rules! impl_drop { | |
34 | ($Bound:ident, $Id:ident) => { | |
35 | struct $Id<T:$Bound>(T); | |
36 | impl <T:$Bound> Drop for $Id<T> { fn drop(&mut self) { } } | |
37 | } | |
38 | } | |
39 | ||
40 | impl_drop!{HasSelfMethod, D_HasSelfMethod} | |
41 | impl_drop!{HasMethodWithSelfArg, D_HasMethodWithSelfArg} | |
42 | impl_drop!{HasType, D_HasType} | |
43 | ||
44 | fn f_sm() { | |
45 | let (_d, d1); | |
46 | d1 = D_HasSelfMethod(1); | |
47 | _d = D_HasSelfMethod(&d1); //~ ERROR `d1` does not live long enough | |
48 | } | |
49 | fn f_mwsa() { | |
50 | let (_d, d1); | |
51 | d1 = D_HasMethodWithSelfArg(1); | |
52 | _d = D_HasMethodWithSelfArg(&d1); //~ ERROR `d1` does not live long enough | |
53 | } | |
54 | fn f_t() { | |
55 | let (_d, d1); | |
56 | d1 = D_HasType(1); | |
57 | _d = D_HasType(&d1); //~ ERROR `d1` does not live long enough | |
58 | } | |
59 | ||
60 | fn main() { | |
61 | f_sm(); | |
62 | f_mwsa(); | |
63 | f_t(); | |
64 | } |