]> git.proxmox.com Git - rustc.git/blame - src/test/compile-fail/issue-24805-dropck-trait-has-items.rs
New upstream version 1.13.0+dfsg1
[rustc.git] / src / test / compile-fail / issue-24805-dropck-trait-has-items.rs
CommitLineData
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
16trait HasSelfMethod { fn m1(&self) { } }
17trait HasMethodWithSelfArg { fn m2(x: &Self) { } }
18trait HasType { type Something; }
19
20impl HasSelfMethod for i32 { }
21impl HasMethodWithSelfArg for i32 { }
22impl HasType for i32 { type Something = (); }
23
24impl<'a,T> HasSelfMethod for &'a T { }
25impl<'a,T> HasMethodWithSelfArg for &'a T { }
26impl<'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// ```
33macro_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
40impl_drop!{HasSelfMethod, D_HasSelfMethod}
41impl_drop!{HasMethodWithSelfArg, D_HasMethodWithSelfArg}
42impl_drop!{HasType, D_HasType}
43
44fn f_sm() {
45 let (_d, d1);
46 d1 = D_HasSelfMethod(1);
47 _d = D_HasSelfMethod(&d1); //~ ERROR `d1` does not live long enough
48}
49fn f_mwsa() {
50 let (_d, d1);
51 d1 = D_HasMethodWithSelfArg(1);
52 _d = D_HasMethodWithSelfArg(&d1); //~ ERROR `d1` does not live long enough
53}
54fn 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
60fn main() {
61 f_sm();
62 f_mwsa();
63 f_t();
64}