]> git.lizzy.rs Git - rust.git/blob - src/test/ui/span/issue-24805-dropck-trait-has-items.rs
Various minor/cosmetic improvements to code
[rust.git] / src / test / ui / span / issue-24805-dropck-trait-has-items.rs
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);
48 }
49 //~^^ ERROR `d1` does not live long enough
50 fn f_mwsa() {
51     let (_d, d1);
52     d1 = D_HasMethodWithSelfArg(1);
53     _d = D_HasMethodWithSelfArg(&d1);
54 }
55 //~^^ ERROR `d1` does not live long enough
56 fn f_t() {
57     let (_d, d1);
58     d1 = D_HasType(1);
59     _d = D_HasType(&d1);
60 }
61 //~^^ ERROR `d1` does not live long enough
62
63 fn main() {
64     f_sm();
65     f_mwsa();
66     f_t();
67 }