]> git.lizzy.rs Git - rust.git/blob - src/test/ui/regions/regions-free-region-ordering-callee.rs
Auto merge of #54624 - arielb1:evaluate-outlives, r=nikomatsakis
[rust.git] / src / test / ui / regions / regions-free-region-ordering-callee.rs
1 // Copyright 2012 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 // Tests that callees correctly infer an ordering between free regions
12 // that appear in their parameter list.  See also
13 // regions-free-region-ordering-caller.rs
14
15 fn ordering1<'a, 'b>(x: &'a &'b usize) -> &'a usize {
16     // It is safe to assume that 'a <= 'b due to the type of x
17     let y: &'b usize = &**x;
18     return y;
19 }
20
21 fn ordering2<'a, 'b>(x: &'a &'b usize, y: &'a usize) -> &'b usize {
22     // However, it is not safe to assume that 'b <= 'a
23     &*y //~ ERROR 23:5: 23:8: lifetime mismatch [E0623]
24 }
25
26 fn ordering3<'a, 'b>(x: &'a usize, y: &'b usize) -> &'a &'b usize {
27     // Do not infer an ordering from the return value.
28     let z: &'b usize = &*x;
29     //~^ ERROR 28:24: 28:27: lifetime mismatch [E0623]
30     panic!();
31 }
32
33 // see regions-free-region-ordering-callee-4.rs
34
35 fn ordering5<'a, 'b>(a: &'a usize, b: &'b usize, x: Option<&'a &'b usize>) {
36     let z: Option<&'a &'b usize> = None;
37 }
38
39 fn main() {}