1 // Test that if a struct declares multiple region bounds for a given
2 // type parameter, an explicit lifetime bound is required on object
3 // lifetimes within.
4 
5 #![allow(dead_code)]
6 
7 trait Test {
foo(&self)8     fn foo(&self) { }
9 }
10 
11 struct Ref0<T:?Sized> {
12     r: *mut T
13 }
14 
15 struct Ref1<'a,T:'a+?Sized> {
16     r: &'a T
17 }
18 
19 struct Ref2<'a,'b:'a,T:'a+'b+?Sized> {
20     r: &'a &'b T
21 }
22 
a<'a,'b>(t: Ref2<'a,'b, dyn Test>)23 fn a<'a,'b>(t: Ref2<'a,'b, dyn Test>) {
24     //~^ ERROR lifetime bound for this object type cannot be deduced from context
25 }
26 
b(t: Ref2<dyn Test>)27 fn b(t: Ref2<dyn Test>) {
28     //~^ ERROR lifetime bound for this object type cannot be deduced from context
29 }
30 
c(t: Ref2<&dyn Test>)31 fn c(t: Ref2<&dyn Test>) {
32     // In this case, the &'a overrides.
33 }
34 
d(t: Ref2<Ref1<dyn Test>>)35 fn d(t: Ref2<Ref1<dyn Test>>) {
36     // In this case, the lifetime parameter from the Ref1 overrides.
37 }
38 
e(t: Ref2<Ref0<dyn Test>>)39 fn e(t: Ref2<Ref0<dyn Test>>) {
40     // In this case, Ref2 is ambiguous, but Ref0 overrides with 'static.
41 }
42 
f(t: &Ref2<dyn Test>)43 fn f(t: &Ref2<dyn Test>) {
44     //~^ ERROR lifetime bound for this object type cannot be deduced from context
45 }
46 
main()47 fn main() {
48 }
49