]> git.proxmox.com Git - rustc.git/blame - src/test/ui/higher-lifetime-bounds.rs
New upstream version 1.37.0+dfsg1
[rustc.git] / src / test / ui / higher-lifetime-bounds.rs
CommitLineData
0531ce1d
XL
1#![allow(dead_code, non_camel_case_types)]
2
3// Test that bounds on higher-kinded lifetime binders are rejected.
4
5fn bar1<'a, 'b>(
6 x: &'a i32,
7 y: &'b i32,
8 f: for<'xa, 'xb: 'xa+'xa> fn(&'xa i32, &'xb i32) -> &'xa i32)
9 //~^ ERROR lifetime bounds cannot be used in this context
10{
11 // If the bound in f's type would matter, the call below would (have to)
12 // be rejected.
13 f(x, y);
14}
15
16fn bar2<'a, 'b, F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>(
17 //~^ ERROR lifetime bounds cannot be used in this context
18 x: &'a i32,
19 y: &'b i32,
20 f: F)
21{
22 // If the bound in f's type would matter, the call below would (have to)
23 // be rejected.
24 f(x, y);
25}
26
27fn bar3<'a, 'b, F>(
28 x: &'a i32,
29 y: &'b i32,
30 f: F)
31 where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32
32 //~^ ERROR lifetime bounds cannot be used in this context
33{
34 // If the bound in f's type would matter, the call below would (have to)
35 // be rejected.
36 f(x, y);
37}
38
39fn bar4<'a, 'b, F>(
40 x: &'a i32,
41 y: &'b i32,
42 f: F)
43 where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32
44 //~^ ERROR lifetime bounds cannot be used in this context
45{
46 // If the bound in f's type would matter, the call below would (have to)
47 // be rejected.
48 f(x, y);
49}
50
51struct S1<F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>(F);
52//~^ ERROR lifetime bounds cannot be used in this context
53struct S2<F>(F) where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32;
54//~^ ERROR lifetime bounds cannot be used in this context
55struct S3<F>(F) where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32;
56//~^ ERROR lifetime bounds cannot be used in this context
57
58struct S_fnty(for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32);
59//~^ ERROR lifetime bounds cannot be used in this context
60
dc9dc135 61type T1 = Box<dyn for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>;
0531ce1d
XL
62//~^ ERROR lifetime bounds cannot be used in this context
63
64fn main() {
65 let _ : Option<for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32> = None;
66 //~^ ERROR lifetime bounds cannot be used in this context
dc9dc135 67 let _ : Option<Box<dyn for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>> = None;
0531ce1d
XL
68 //~^ ERROR lifetime bounds cannot be used in this context
69}