]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/object-lifetime/object-lifetime-default-elision.rs
1 // Test various cases where the old rules under lifetime elision
2 // yield slightly different results than the new rules.
10 struct SomeStruct
<'a
> {
11 r
: Box
<dyn SomeTrait
+'a
>
14 fn deref
<T
>(ss
: &T
) -> T
{
15 // produces the type of a deref without worrying about whether a
16 // move out would actually be legal
20 fn load0
<'a
>(ss
: &'a Box
<dyn SomeTrait
>) -> Box
<dyn SomeTrait
> {
21 // Under old rules, the fully elaborated types of input/output were:
23 // for<'a,'b> fn(&'a Box<SomeTrait+'b>) -> Box<SomeTrait+'a>
25 // Under new rules the result is:
27 // for<'a> fn(&'a Box<SomeTrait+'static>) -> Box<SomeTrait+'static>
29 // Therefore, no type error.
34 fn load1(ss
: &dyn SomeTrait
) -> &dyn SomeTrait
{
35 // Under old rules, the fully elaborated types of input/output were:
37 // for<'a,'b> fn(&'a (SomeTrait+'b)) -> &'a (SomeTrait+'a)
39 // Under new rules the result is:
41 // for<'a> fn(&'a (SomeTrait+'a)) -> &'a (SomeTrait+'a)
43 // In both cases, returning `ss` is legal.
48 fn load2
<'a
>(ss
: &'a
dyn SomeTrait
) -> &dyn SomeTrait
{
49 // Same as `load1` but with an explicit name thrown in for fun.
54 fn load3
<'a
,'b
>(ss
: &'a
dyn SomeTrait
) -> &'b
dyn SomeTrait
{
55 // Under old rules, the fully elaborated types of input/output were:
57 // for<'a,'b,'c>fn(&'a (SomeTrait+'c)) -> &'b (SomeTrait+'a)
59 // Based on the input/output types, the compiler could infer that
62 // must hold, and therefore it permitted `&'a (Sometrait+'c)` to be
63 // coerced to `&'b (SomeTrait+'a)`.
65 // Under the newer defaults, though, we get:
67 // for<'a,'b> fn(&'a (SomeTrait+'a)) -> &'b (SomeTrait+'b)
69 // which fails to type check.
72 //~^ ERROR lifetime may not live long enough