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.
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.
11 // Check that traits with various kinds of associated items cause
12 // dropck to inject extra region constraints.
14 #![allow(non_camel_case_types)]
16 trait HasSelfMethod { fn m1(&self) { } }
17 trait HasMethodWithSelfArg { fn m2(x: &Self) { } }
18 trait HasType { type Something; }
20 impl HasSelfMethod for i32 { }
21 impl HasMethodWithSelfArg for i32 { }
22 impl HasType for i32 { type Something = (); }
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 = (); }
28 // e.g., `impl_drop!(Send, D_Send)` expands to:
30 // struct D_Send<T:Send>(T);
31 // impl<T:Send> Drop for D_Send<T> { fn drop(&mut self) { } }
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) { } }
40 impl_drop!{HasSelfMethod, D_HasSelfMethod}
41 impl_drop!{HasMethodWithSelfArg, D_HasMethodWithSelfArg}
42 impl_drop!{HasType, D_HasType}
46 d1 = D_HasSelfMethod(1);
47 _d = D_HasSelfMethod(&d1);
49 //~^^ ERROR `d1` does not live long enough
52 d1 = D_HasMethodWithSelfArg(1);
53 _d = D_HasMethodWithSelfArg(&d1);
55 //~^^ ERROR `d1` does not live long enough
61 //~^^ ERROR `d1` does not live long enough