]> git.lizzy.rs Git - rust.git/blob - src/test/ui/higher-lifetime-bounds.rs
Auto merge of #54720 - davidtwco:issue-51191, r=nikomatsakis
[rust.git] / src / test / ui / higher-lifetime-bounds.rs
1 // Copyright 2014 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 #![allow(dead_code, non_camel_case_types)]
12
13 // Test that bounds on higher-kinded lifetime binders are rejected.
14
15 fn bar1<'a, 'b>(
16     x: &'a i32,
17     y: &'b i32,
18     f: for<'xa, 'xb: 'xa+'xa> fn(&'xa i32, &'xb i32) -> &'xa i32)
19     //~^ ERROR lifetime bounds cannot be used in this context
20 {
21     // If the bound in f's type would matter, the call below would (have to)
22     // be rejected.
23     f(x, y);
24 }
25
26 fn bar2<'a, 'b, F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>(
27     //~^ ERROR lifetime bounds cannot be used in this context
28     x: &'a i32,
29     y: &'b i32,
30     f: F)
31 {
32     // If the bound in f's type would matter, the call below would (have to)
33     // be rejected.
34     f(x, y);
35 }
36
37 fn bar3<'a, 'b, F>(
38     x: &'a i32,
39     y: &'b i32,
40     f: F)
41     where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32
42     //~^ ERROR lifetime bounds cannot be used in this context
43 {
44     // If the bound in f's type would matter, the call below would (have to)
45     // be rejected.
46     f(x, y);
47 }
48
49 fn bar4<'a, 'b, F>(
50     x: &'a i32,
51     y: &'b i32,
52     f: F)
53     where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32
54     //~^ ERROR lifetime bounds cannot be used in this context
55 {
56     // If the bound in f's type would matter, the call below would (have to)
57     // be rejected.
58     f(x, y);
59 }
60
61 struct S1<F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>(F);
62 //~^ ERROR lifetime bounds cannot be used in this context
63 struct S2<F>(F) where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32;
64 //~^ ERROR lifetime bounds cannot be used in this context
65 struct S3<F>(F) where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32;
66 //~^ ERROR lifetime bounds cannot be used in this context
67
68 struct S_fnty(for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32);
69 //~^ ERROR lifetime bounds cannot be used in this context
70
71 type T1 = Box<for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>;
72 //~^ ERROR lifetime bounds cannot be used in this context
73
74 fn main() {
75     let _ : Option<for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32> = None;
76     //~^ ERROR lifetime bounds cannot be used in this context
77     let _ : Option<Box<for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>> = None;
78     //~^ ERROR lifetime bounds cannot be used in this context
79 }