Skip to content

Commit 89a184a

Browse files
committed
add test for complex suggestions
1 parent 3a1847b commit 89a184a

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Test the more elaborate outlives suggestions.
2+
3+
#![feature(nll)]
4+
5+
// Should suggest: 'a: 'c, 'b: 'd
6+
fn foo1<'a, 'b, 'c, 'd>(x: &'a usize, y: &'b usize) -> (&'c usize, &'d usize) {
7+
(x, y) //~ERROR lifetime may not live long enough
8+
//~^ERROR lifetime may not live long enough
9+
}
10+
11+
// Should suggest: 'a: 'c and use 'static instead of 'b
12+
fn foo2<'a, 'b, 'c>(x: &'a usize, y: &'b usize) -> (&'c usize, &'static usize) {
13+
(x, y) //~ERROR lifetime may not live long enough
14+
//~^ERROR lifetime may not live long enough
15+
}
16+
17+
// Should suggest: 'a and 'b are the same and use 'static instead of 'c
18+
fn foo3<'a, 'b, 'c, 'd, 'e>(
19+
x: &'a usize,
20+
y: &'b usize,
21+
z: &'c usize,
22+
) -> (&'b usize, &'a usize, &'static usize) {
23+
(x, y, z) //~ERROR lifetime may not live long enough
24+
//~^ERROR lifetime may not live long enough
25+
//~^^ERROR lifetime may not live long enough
26+
}
27+
28+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
error: lifetime may not live long enough
2+
--> $DIR/outlives-suggestion-more.rs:7:5
3+
|
4+
LL | fn foo1<'a, 'b, 'c, 'd>(x: &'a usize, y: &'b usize) -> (&'c usize, &'d usize) {
5+
| -- -- lifetime `'c` defined here
6+
| |
7+
| lifetime `'a` defined here
8+
LL | (x, y)
9+
| ^^^^^^ returning this value requires that `'a` must outlive `'c`
10+
|
11+
= help: consider adding the following bound: `'a: 'c`
12+
13+
error: lifetime may not live long enough
14+
--> $DIR/outlives-suggestion-more.rs:7:5
15+
|
16+
LL | fn foo1<'a, 'b, 'c, 'd>(x: &'a usize, y: &'b usize) -> (&'c usize, &'d usize) {
17+
| -- -- lifetime `'d` defined here
18+
| |
19+
| lifetime `'b` defined here
20+
LL | (x, y)
21+
| ^^^^^^ returning this value requires that `'b` must outlive `'d`
22+
|
23+
= help: consider adding the following bound: `'b: 'd`
24+
25+
help: the following changes may resolve your lifetime errors
26+
|
27+
= help: add bound `'a: 'c`
28+
= help: add bound `'b: 'd`
29+
30+
error: lifetime may not live long enough
31+
--> $DIR/outlives-suggestion-more.rs:13:5
32+
|
33+
LL | fn foo2<'a, 'b, 'c>(x: &'a usize, y: &'b usize) -> (&'c usize, &'static usize) {
34+
| -- -- lifetime `'c` defined here
35+
| |
36+
| lifetime `'a` defined here
37+
LL | (x, y)
38+
| ^^^^^^ returning this value requires that `'a` must outlive `'c`
39+
|
40+
= help: consider adding the following bound: `'a: 'c`
41+
42+
error: lifetime may not live long enough
43+
--> $DIR/outlives-suggestion-more.rs:13:5
44+
|
45+
LL | fn foo2<'a, 'b, 'c>(x: &'a usize, y: &'b usize) -> (&'c usize, &'static usize) {
46+
| -- lifetime `'b` defined here
47+
LL | (x, y)
48+
| ^^^^^^ returning this value requires that `'b` must outlive `'static`
49+
|
50+
= help: consider replacing `'b` with `'static`
51+
52+
help: the following changes may resolve your lifetime errors
53+
|
54+
= help: add bound `'a: 'c`
55+
= help: replace `'b` with `'static`
56+
57+
error: lifetime may not live long enough
58+
--> $DIR/outlives-suggestion-more.rs:23:5
59+
|
60+
LL | fn foo3<'a, 'b, 'c, 'd, 'e>(
61+
| -- -- lifetime `'b` defined here
62+
| |
63+
| lifetime `'a` defined here
64+
...
65+
LL | (x, y, z)
66+
| ^^^^^^^^^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a`
67+
|
68+
= help: consider adding the following bound: `'a: 'b`
69+
70+
error: lifetime may not live long enough
71+
--> $DIR/outlives-suggestion-more.rs:23:5
72+
|
73+
LL | fn foo3<'a, 'b, 'c, 'd, 'e>(
74+
| -- -- lifetime `'b` defined here
75+
| |
76+
| lifetime `'a` defined here
77+
...
78+
LL | (x, y, z)
79+
| ^^^^^^^^^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b`
80+
|
81+
= help: consider adding the following bound: `'b: 'a`
82+
83+
error: lifetime may not live long enough
84+
--> $DIR/outlives-suggestion-more.rs:23:5
85+
|
86+
LL | fn foo3<'a, 'b, 'c, 'd, 'e>(
87+
| -- lifetime `'c` defined here
88+
...
89+
LL | (x, y, z)
90+
| ^^^^^^^^^ returning this value requires that `'c` must outlive `'static`
91+
|
92+
= help: consider replacing `'c` with `'static`
93+
94+
help: the following changes may resolve your lifetime errors
95+
|
96+
= help: `'a` and `'b` must be the same: replace one with the other
97+
= help: replace `'c` with `'static`
98+
99+
error: aborting due to 7 previous errors
100+

0 commit comments

Comments
 (0)