]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/object-lifetime-default-mybox.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / test / compile-fail / object-lifetime-default-mybox.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 // Test a "pass-through" object-lifetime-default that produces errors.
12
13 #![allow(dead_code)]
14
15 trait SomeTrait {
16 fn dummy(&self) { }
17 }
18
19 struct MyBox<T:?Sized> {
20 r: Box<T>
21 }
22
23 fn deref<T>(ss: &T) -> T {
24 // produces the type of a deref without worrying about whether a
25 // move out would actually be legal
26 loop { }
27 }
28
29 fn load0(ss: &MyBox<SomeTrait>) -> MyBox<SomeTrait> {
30 deref(ss)
31 }
32
33 fn load1<'a,'b>(a: &'a MyBox<SomeTrait>,
34 b: &'b MyBox<SomeTrait>)
35 -> &'b MyBox<SomeTrait>
36 {
37 a //~ ERROR E0312
38 }
39
40 fn load2<'a>(ss: &MyBox<SomeTrait+'a>) -> MyBox<SomeTrait+'a> {
41 load0(ss) //~ ERROR mismatched types
42 }
43
44 fn main() {
45 }