Skip to content

Commit 64b5599

Browse files
committed
stop reporting "unsatisfied lifetime bounds" errors after the first
In particular, after the first for a given region variable. This suppresses a lot of duplicate errors.
1 parent 2921fba commit 64b5599

10 files changed

+17
-113
lines changed

src/librustc_mir/borrow_check/nll/region_infer/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
12081208
// to report the error. This gives better error messages
12091209
// in some cases.
12101210
self.report_error(mir, infcx, mir_def_id, longer_fr, shorter_fr, errors_buffer);
1211+
return; // continuing to iterate just reports more errors than necessary
12111212
}
12121213
}
12131214

src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.rs

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
4747

4848
// Only works if 'x: 'y:
4949
demand_y(x, y, x.get())
50-
//~^ ERROR unsatisfied lifetime constraints
5150
});
5251
}
5352

src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr

+1-14
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ LL | | //~^ ERROR borrowed data escapes outside of function
77
LL | |
88
LL | | // Only works if 'x: 'y:
99
LL | | demand_y(x, y, x.get())
10-
LL | | //~^ ERROR unsatisfied lifetime constraints
1110
LL | | });
1211
| |_____^
1312
|
@@ -44,21 +43,9 @@ LL | | //~^ ERROR borrowed data escapes outside of function
4443
LL | |
4544
LL | | // Only works if 'x: 'y:
4645
LL | | demand_y(x, y, x.get())
47-
LL | | //~^ ERROR unsatisfied lifetime constraints
4846
LL | | });
4947
| |______^ `cell_a` escapes the function body here
5048

51-
error: unsatisfied lifetime constraints
52-
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:49:9
53-
|
54-
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
55-
| -- -- lifetime `'b` defined here
56-
| |
57-
| lifetime `'a` defined here
58-
...
59-
LL | demand_y(x, y, x.get())
60-
| ^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'a` must outlive `'b`
61-
62-
error: aborting due to 2 previous errors
49+
error: aborting due to previous error
6350

6451
For more information about this error, try `rustc --explain E0521`.

src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u3
4747
fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
4848
establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
4949
//~^ ERROR borrowed data escapes outside of function
50+
5051
// Only works if 'x: 'y:
5152
demand_y(x, y, x.get())
52-
//~^ ERROR unsatisfied lifetime constraints
5353
});
5454
}
5555

src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr

+4-15
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ note: External requirements
44
LL | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
55
| _______________________________________________^
66
LL | | //~^ ERROR borrowed data escapes outside of function
7+
LL | |
78
LL | | // Only works if 'x: 'y:
89
LL | | demand_y(x, y, x.get())
9-
LL | | //~^ ERROR unsatisfied lifetime constraints
1010
LL | | });
1111
| |_____^
1212
|
@@ -25,7 +25,7 @@ note: No external requirements
2525
LL | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
2626
LL | | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
2727
LL | | //~^ ERROR borrowed data escapes outside of function
28-
LL | | // Only works if 'x: 'y:
28+
LL | |
2929
... |
3030
LL | | });
3131
LL | | }
@@ -40,23 +40,12 @@ LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
4040
| ------ `cell_a` is a reference that is only valid in the function body
4141
LL | / establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
4242
LL | | //~^ ERROR borrowed data escapes outside of function
43+
LL | |
4344
LL | | // Only works if 'x: 'y:
4445
LL | | demand_y(x, y, x.get())
45-
LL | | //~^ ERROR unsatisfied lifetime constraints
4646
LL | | });
4747
| |______^ `cell_a` escapes the function body here
4848

49-
error: unsatisfied lifetime constraints
50-
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:51:9
51-
|
52-
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
53-
| -- -- lifetime `'b` defined here
54-
| |
55-
| lifetime `'a` defined here
56-
...
57-
LL | demand_y(x, y, x.get())
58-
| ^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'a` must outlive `'b`
59-
60-
error: aborting due to 2 previous errors
49+
error: aborting due to previous error
6150

6251
For more information about this error, try `rustc --explain E0521`.

src/test/ui/nll/user-annotations/closure-substs.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ fn foo1() {
2323
// Here `x` is bound in the closure sig:
2424
|x: &i32| -> &'static i32 {
2525
return x; //~ ERROR unsatisfied lifetime constraints
26-
//~^ ERROR unsatisfied lifetime constraints
27-
//~| ERROR unsatisfied lifetime constraints
2826
};
2927
}
3028

@@ -38,9 +36,7 @@ fn bar<'a>() {
3836
fn bar1() {
3937
// Here `x` is bound in the closure sig:
4038
|x: &i32, b: fn(&'static i32)| {
41-
b(x); //~ ERROR
42-
//~^ ERROR borrowed data escapes outside of closure
43-
//~| ERROR unsatisfied lifetime constraints
39+
b(x); //~ ERROR borrowed data escapes outside of closure
4440
};
4541
}
4642

src/test/ui/nll/user-annotations/closure-substs.stderr

+6-51
Original file line numberDiff line numberDiff line change
@@ -16,67 +16,22 @@ LL | return x; //~ ERROR unsatisfied lifetime constraints
1616
| ^ returning this value requires that `'1` must outlive `'static`
1717

1818
error: unsatisfied lifetime constraints
19-
--> $DIR/closure-substs.rs:25:16
20-
|
21-
LL | |x: &i32| -> &'static i32 {
22-
| - - return type of closure is &'2 i32
23-
| |
24-
| let's call the lifetime of this reference `'1`
25-
LL | return x; //~ ERROR unsatisfied lifetime constraints
26-
| ^ returning this value requires that `'1` must outlive `'2`
27-
28-
error: unsatisfied lifetime constraints
29-
--> $DIR/closure-substs.rs:25:16
30-
|
31-
LL | |x: &i32| -> &'static i32 {
32-
| -------------------------
33-
| | |
34-
| | let's call the lifetime of this reference `'1`
35-
| lifetime `'2` represents this closure's body
36-
LL | return x; //~ ERROR unsatisfied lifetime constraints
37-
| ^ closure was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
38-
|
39-
= note: closure implements `Fn`, so references to captured variables can't escape the closure
40-
41-
error: unsatisfied lifetime constraints
42-
--> $DIR/closure-substs.rs:34:9
19+
--> $DIR/closure-substs.rs:32:9
4320
|
4421
LL | fn bar<'a>() {
4522
| -- lifetime `'a` defined here
4623
...
4724
LL | b(x); //~ ERROR unsatisfied lifetime constraints
4825
| ^^^^ argument requires that `'a` must outlive `'static`
4926

50-
error: borrowed data escapes outside of closure
51-
--> $DIR/closure-substs.rs:41:9
27+
error[E0521]: borrowed data escapes outside of closure
28+
--> $DIR/closure-substs.rs:39:9
5229
|
5330
LL | |x: &i32, b: fn(&'static i32)| {
5431
| - `x` is a reference that is only valid in the closure body
55-
LL | b(x); //~ ERROR
56-
| ^^^^ `x` escapes the closure body here
57-
58-
error: borrowed data escapes outside of closure
59-
--> $DIR/closure-substs.rs:41:9
60-
|
61-
LL | |x: &i32, b: fn(&'static i32)| {
62-
| - - `b` is declared here, outside of the closure body
63-
| |
64-
| `x` is a reference that is only valid in the closure body
65-
LL | b(x); //~ ERROR
32+
LL | b(x); //~ ERROR borrowed data escapes outside of closure
6633
| ^^^^ `x` escapes the closure body here
6734

68-
error: unsatisfied lifetime constraints
69-
--> $DIR/closure-substs.rs:41:9
70-
|
71-
LL | |x: &i32, b: fn(&'static i32)| {
72-
| ------------------------------
73-
| | |
74-
| | let's call the lifetime of this reference `'1`
75-
| lifetime `'2` represents this closure's body
76-
LL | b(x); //~ ERROR
77-
| ^^^^ argument requires that `'1` must outlive `'2`
78-
|
79-
= note: closure implements `Fn`, so references to captured variables can't escape the closure
80-
81-
error: aborting due to 8 previous errors
35+
error: aborting due to 4 previous errors
8236

37+
For more information about this error, try `rustc --explain E0521`.

src/test/ui/regions/regions-static-bound.ll.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ LL | static_id(&u); //[ll]~ ERROR explicit lifetime required in the type of
2020
| ^^^^^^^^^ lifetime `'static` required
2121

2222
error[E0621]: explicit lifetime required in the type of `v`
23-
--> $DIR/regions-static-bound.rs:27:5
23+
--> $DIR/regions-static-bound.rs:26:5
2424
|
2525
LL | fn error(u: &(), v: &()) {
2626
| --- help: add explicit lifetime `'static` to the type of `v`: `&'static ()`

src/test/ui/regions/regions-static-bound.nll.stderr

+2-23
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,14 @@ LL | static_id(&u); //[ll]~ ERROR explicit lifetime required in the type of
1515
| ^^^^^^^^^^^^^ lifetime `'static` required
1616

1717
error[E0621]: explicit lifetime required in the type of `v`
18-
--> $DIR/regions-static-bound.rs:27:5
18+
--> $DIR/regions-static-bound.rs:26:5
1919
|
2020
LL | fn error(u: &(), v: &()) {
2121
| --- help: add explicit lifetime `'static` to the type of `v`: `&'static ()`
2222
...
2323
LL | static_id_indirect(&v); //[ll]~ ERROR explicit lifetime required in the type of `v` [E0621]
2424
| ^^^^^^^^^^^^^^^^^^^^^^ lifetime `'static` required
2525

26-
error: unsatisfied lifetime constraints
27-
--> $DIR/regions-static-bound.rs:24:5
28-
|
29-
LL | fn error(u: &(), v: &()) {
30-
| - - let's call the lifetime of this reference `'2`
31-
| |
32-
| let's call the lifetime of this reference `'1`
33-
LL | static_id(&u); //[ll]~ ERROR explicit lifetime required in the type of `u` [E0621]
34-
| ^^^^^^^^^^^^^ argument requires that `'1` must outlive `'2`
35-
36-
error: unsatisfied lifetime constraints
37-
--> $DIR/regions-static-bound.rs:27:5
38-
|
39-
LL | fn error(u: &(), v: &()) {
40-
| - - let's call the lifetime of this reference `'1`
41-
| |
42-
| let's call the lifetime of this reference `'2`
43-
...
44-
LL | static_id_indirect(&v); //[ll]~ ERROR explicit lifetime required in the type of `v` [E0621]
45-
| ^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'1` must outlive `'2`
46-
47-
error: aborting due to 5 previous errors
26+
error: aborting due to 3 previous errors
4827

4928
For more information about this error, try `rustc --explain E0621`.

src/test/ui/regions/regions-static-bound.rs

-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ fn static_id_wrong_way<'a>(t: &'a ()) -> &'static () where 'static: 'a {
2323
fn error(u: &(), v: &()) {
2424
static_id(&u); //[ll]~ ERROR explicit lifetime required in the type of `u` [E0621]
2525
//[nll]~^ ERROR explicit lifetime required in the type of `u` [E0621]
26-
//[nll]~| ERROR unsatisfied lifetime constraints
2726
static_id_indirect(&v); //[ll]~ ERROR explicit lifetime required in the type of `v` [E0621]
2827
//[nll]~^ ERROR explicit lifetime required in the type of `v` [E0621]
29-
//[nll]~| ERROR unsatisfied lifetime constraints
3028
}
3129

3230
fn main() {}

0 commit comments

Comments
 (0)