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 // Test various cases where the old rules under lifetime elision
12 // yield slightly different results than the new rules.
20 struct SomeStruct<'a> {
24 fn deref<T>(ss: &T) -> T {
25 // produces the type of a deref without worrying about whether a
26 // move out would actually be legal
30 fn load0<'a>(ss: &'a Box<SomeTrait>) -> Box<SomeTrait> {
31 // Under old rules, the fully elaborated types of input/output were:
33 // for<'a,'b> fn(&'a Box<SomeTrait+'b>) -> Box<SomeTrait+'a>
35 // Under new rules the result is:
37 // for<'a> fn(&'a Box<SomeTrait+'static>) -> Box<SomeTrait+'static>
39 // Therefore, no type error.
44 fn load1(ss: &SomeTrait) -> &SomeTrait {
45 // Under old rules, the fully elaborated types of input/output were:
47 // for<'a,'b> fn(&'a (SomeTrait+'b)) -> &'a (SomeTrait+'a)
49 // Under new rules the result is:
51 // for<'a> fn(&'a (SomeTrait+'a)) -> &'a (SomeTrait+'a)
53 // In both cases, returning `ss` is legal.
58 fn load2<'a>(ss: &'a SomeTrait) -> &SomeTrait {
59 // Same as `load1` but with an explicit name thrown in for fun.
64 fn load3<'a,'b>(ss: &'a SomeTrait) -> &'b SomeTrait {
65 // Under old rules, the fully elaborated types of input/output were:
67 // for<'a,'b,'c>fn(&'a (SomeTrait+'c)) -> &'b (SomeTrait+'a)
69 // Based on the input/output types, the compiler could infer that
72 // must hold, and therefore it permitted `&'a (Sometrait+'c)` to be
73 // coerced to `&'b (SomeTrait+'a)`.
75 // Under the newer defaults, though, we get:
77 // for<'a,'b> fn(&'a (SomeTrait+'a)) -> &'b (SomeTrait+'b)
79 // which fails to type check.
82 //~^ ERROR cannot infer
83 //~| ERROR cannot infer