]> git.lizzy.rs Git - rust.git/blob - src/test/ui/object-lifetime/object-lifetime-default-ambiguous.rs
Auto merge of #54581 - petrochenkov:cfgattr, r=alexcrichton
[rust.git] / src / test / ui / object-lifetime / object-lifetime-default-ambiguous.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 that if a struct declares multiple region bounds for a given
12 // type parameter, an explicit lifetime bound is required on object
13 // lifetimes within.
14
15 #![allow(dead_code)]
16
17 trait Test {
18     fn foo(&self) { }
19 }
20
21 struct Ref0<T:?Sized> {
22     r: *mut T
23 }
24
25 struct Ref1<'a,T:'a+?Sized> {
26     r: &'a T
27 }
28
29 struct Ref2<'a,'b:'a,T:'a+'b+?Sized> {
30     r: &'a &'b T
31 }
32
33 fn a<'a,'b>(t: Ref2<'a,'b,Test>) {
34     //~^ ERROR lifetime bound for this object type cannot be deduced from context
35 }
36
37 fn b(t: Ref2<Test>) {
38     //~^ ERROR lifetime bound for this object type cannot be deduced from context
39 }
40
41 fn c(t: Ref2<&Test>) {
42     // In this case, the &'a overrides.
43 }
44
45 fn d(t: Ref2<Ref1<Test>>) {
46     // In this case, the lifetime parameter from the Ref1 overrides.
47 }
48
49 fn e(t: Ref2<Ref0<Test>>) {
50     // In this case, Ref2 is ambiguous, but Ref0 overrides with 'static.
51 }
52
53 fn f(t: &Ref2<Test>) {
54     //~^ ERROR lifetime bound for this object type cannot be deduced from context
55 }
56
57 fn main() {
58 }