From 64b5599352545e390ead3da4f14c3a1ffaba50d4 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 22 Oct 2018 11:20:17 -0400 Subject: [PATCH] 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. --- .../borrow_check/nll/region_infer/mod.rs | 1 + ...approximated-shorter-to-static-no-bound.rs | 1 - ...oximated-shorter-to-static-no-bound.stderr | 15 +---- ...roximated-shorter-to-static-wrong-bound.rs | 2 +- ...mated-shorter-to-static-wrong-bound.stderr | 19 ++----- .../ui/nll/user-annotations/closure-substs.rs | 6 +- .../user-annotations/closure-substs.stderr | 57 ++----------------- .../ui/regions/regions-static-bound.ll.stderr | 2 +- .../regions/regions-static-bound.nll.stderr | 25 +------- src/test/ui/regions/regions-static-bound.rs | 2 - 10 files changed, 17 insertions(+), 113 deletions(-) diff --git a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs index 5ed25406da4..50fd4afcd7e 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs @@ -1208,6 +1208,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { // to report the error. This gives better error messages // in some cases. self.report_error(mir, infcx, mir_def_id, longer_fr, shorter_fr, errors_buffer); + return; // continuing to iterate just reports more errors than necessary } } diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.rs b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.rs index 49b62581640..4bef6cf8cd1 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.rs +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.rs @@ -47,7 +47,6 @@ fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) { // Only works if 'x: 'y: demand_y(x, y, x.get()) - //~^ ERROR unsatisfied lifetime constraints }); } diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr index a5435cc65ca..f22dbdba934 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr @@ -7,7 +7,6 @@ LL | | //~^ ERROR borrowed data escapes outside of function LL | | LL | | // Only works if 'x: 'y: LL | | demand_y(x, y, x.get()) -LL | | //~^ ERROR unsatisfied lifetime constraints LL | | }); | |_____^ | @@ -44,21 +43,9 @@ LL | | //~^ ERROR borrowed data escapes outside of function LL | | LL | | // Only works if 'x: 'y: LL | | demand_y(x, y, x.get()) -LL | | //~^ ERROR unsatisfied lifetime constraints LL | | }); | |______^ `cell_a` escapes the function body here -error: unsatisfied lifetime constraints - --> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:49:9 - | -LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) { - | -- -- lifetime `'b` defined here - | | - | lifetime `'a` defined here -... -LL | demand_y(x, y, x.get()) - | ^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'a` must outlive `'b` - -error: aborting due to 2 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0521`. diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.rs b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.rs index 0181792cbdc..05e9818b91e 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.rs +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.rs @@ -47,9 +47,9 @@ fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u3 fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) { establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| { //~^ ERROR borrowed data escapes outside of function + // Only works if 'x: 'y: demand_y(x, y, x.get()) - //~^ ERROR unsatisfied lifetime constraints }); } diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr index 35692414081..2b1cb5a30ce 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr @@ -4,9 +4,9 @@ note: External requirements LL | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| { | _______________________________________________^ LL | | //~^ ERROR borrowed data escapes outside of function +LL | | LL | | // Only works if 'x: 'y: LL | | demand_y(x, y, x.get()) -LL | | //~^ ERROR unsatisfied lifetime constraints LL | | }); | |_____^ | @@ -25,7 +25,7 @@ note: No external requirements LL | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) { LL | | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| { LL | | //~^ ERROR borrowed data escapes outside of function -LL | | // Only works if 'x: 'y: +LL | | ... | LL | | }); LL | | } @@ -40,23 +40,12 @@ LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) { | ------ `cell_a` is a reference that is only valid in the function body LL | / establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| { LL | | //~^ ERROR borrowed data escapes outside of function +LL | | LL | | // Only works if 'x: 'y: LL | | demand_y(x, y, x.get()) -LL | | //~^ ERROR unsatisfied lifetime constraints LL | | }); | |______^ `cell_a` escapes the function body here -error: unsatisfied lifetime constraints - --> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:51:9 - | -LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) { - | -- -- lifetime `'b` defined here - | | - | lifetime `'a` defined here -... -LL | demand_y(x, y, x.get()) - | ^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'a` must outlive `'b` - -error: aborting due to 2 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0521`. diff --git a/src/test/ui/nll/user-annotations/closure-substs.rs b/src/test/ui/nll/user-annotations/closure-substs.rs index 7dd2d4113bb..77c7315fa66 100644 --- a/src/test/ui/nll/user-annotations/closure-substs.rs +++ b/src/test/ui/nll/user-annotations/closure-substs.rs @@ -23,8 +23,6 @@ fn foo1() { // Here `x` is bound in the closure sig: |x: &i32| -> &'static i32 { return x; //~ ERROR unsatisfied lifetime constraints - //~^ ERROR unsatisfied lifetime constraints - //~| ERROR unsatisfied lifetime constraints }; } @@ -38,9 +36,7 @@ fn bar<'a>() { fn bar1() { // Here `x` is bound in the closure sig: |x: &i32, b: fn(&'static i32)| { - b(x); //~ ERROR - //~^ ERROR borrowed data escapes outside of closure - //~| ERROR unsatisfied lifetime constraints + b(x); //~ ERROR borrowed data escapes outside of closure }; } diff --git a/src/test/ui/nll/user-annotations/closure-substs.stderr b/src/test/ui/nll/user-annotations/closure-substs.stderr index 126a66b8059..c69d514d9e6 100644 --- a/src/test/ui/nll/user-annotations/closure-substs.stderr +++ b/src/test/ui/nll/user-annotations/closure-substs.stderr @@ -16,30 +16,7 @@ LL | return x; //~ ERROR unsatisfied lifetime constraints | ^ returning this value requires that `'1` must outlive `'static` error: unsatisfied lifetime constraints - --> $DIR/closure-substs.rs:25:16 - | -LL | |x: &i32| -> &'static i32 { - | - - return type of closure is &'2 i32 - | | - | let's call the lifetime of this reference `'1` -LL | return x; //~ ERROR unsatisfied lifetime constraints - | ^ returning this value requires that `'1` must outlive `'2` - -error: unsatisfied lifetime constraints - --> $DIR/closure-substs.rs:25:16 - | -LL | |x: &i32| -> &'static i32 { - | ------------------------- - | | | - | | let's call the lifetime of this reference `'1` - | lifetime `'2` represents this closure's body -LL | return x; //~ ERROR unsatisfied lifetime constraints - | ^ closure was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` - | - = note: closure implements `Fn`, so references to captured variables can't escape the closure - -error: unsatisfied lifetime constraints - --> $DIR/closure-substs.rs:34:9 + --> $DIR/closure-substs.rs:32:9 | LL | fn bar<'a>() { | -- lifetime `'a` defined here @@ -47,36 +24,14 @@ LL | fn bar<'a>() { LL | b(x); //~ ERROR unsatisfied lifetime constraints | ^^^^ argument requires that `'a` must outlive `'static` -error: borrowed data escapes outside of closure - --> $DIR/closure-substs.rs:41:9 +error[E0521]: borrowed data escapes outside of closure + --> $DIR/closure-substs.rs:39:9 | LL | |x: &i32, b: fn(&'static i32)| { | - `x` is a reference that is only valid in the closure body -LL | b(x); //~ ERROR +LL | b(x); //~ ERROR borrowed data escapes outside of closure | ^^^^ `x` escapes the closure body here -error: borrowed data escapes outside of closure - --> $DIR/closure-substs.rs:41:9 - | -LL | |x: &i32, b: fn(&'static i32)| { - | - - `b` is declared here, outside of the closure body - | | - | `x` is a reference that is only valid in the closure body -LL | b(x); //~ ERROR - | ^^^^ `x` escapes the closure body here - -error: unsatisfied lifetime constraints - --> $DIR/closure-substs.rs:41:9 - | -LL | |x: &i32, b: fn(&'static i32)| { - | ------------------------------ - | | | - | | let's call the lifetime of this reference `'1` - | lifetime `'2` represents this closure's body -LL | b(x); //~ ERROR - | ^^^^ argument requires that `'1` must outlive `'2` - | - = note: closure implements `Fn`, so references to captured variables can't escape the closure - -error: aborting due to 8 previous errors +error: aborting due to 4 previous errors +For more information about this error, try `rustc --explain E0521`. diff --git a/src/test/ui/regions/regions-static-bound.ll.stderr b/src/test/ui/regions/regions-static-bound.ll.stderr index 16add00eb41..cf291279210 100644 --- a/src/test/ui/regions/regions-static-bound.ll.stderr +++ b/src/test/ui/regions/regions-static-bound.ll.stderr @@ -20,7 +20,7 @@ LL | static_id(&u); //[ll]~ ERROR explicit lifetime required in the type of | ^^^^^^^^^ lifetime `'static` required error[E0621]: explicit lifetime required in the type of `v` - --> $DIR/regions-static-bound.rs:27:5 + --> $DIR/regions-static-bound.rs:26:5 | LL | fn error(u: &(), v: &()) { | --- help: add explicit lifetime `'static` to the type of `v`: `&'static ()` diff --git a/src/test/ui/regions/regions-static-bound.nll.stderr b/src/test/ui/regions/regions-static-bound.nll.stderr index dc3a32cec6a..462fbe8ee19 100644 --- a/src/test/ui/regions/regions-static-bound.nll.stderr +++ b/src/test/ui/regions/regions-static-bound.nll.stderr @@ -15,7 +15,7 @@ LL | static_id(&u); //[ll]~ ERROR explicit lifetime required in the type of | ^^^^^^^^^^^^^ lifetime `'static` required error[E0621]: explicit lifetime required in the type of `v` - --> $DIR/regions-static-bound.rs:27:5 + --> $DIR/regions-static-bound.rs:26:5 | LL | fn error(u: &(), v: &()) { | --- help: add explicit lifetime `'static` to the type of `v`: `&'static ()` @@ -23,27 +23,6 @@ LL | fn error(u: &(), v: &()) { LL | static_id_indirect(&v); //[ll]~ ERROR explicit lifetime required in the type of `v` [E0621] | ^^^^^^^^^^^^^^^^^^^^^^ lifetime `'static` required -error: unsatisfied lifetime constraints - --> $DIR/regions-static-bound.rs:24:5 - | -LL | fn error(u: &(), v: &()) { - | - - let's call the lifetime of this reference `'2` - | | - | let's call the lifetime of this reference `'1` -LL | static_id(&u); //[ll]~ ERROR explicit lifetime required in the type of `u` [E0621] - | ^^^^^^^^^^^^^ argument requires that `'1` must outlive `'2` - -error: unsatisfied lifetime constraints - --> $DIR/regions-static-bound.rs:27:5 - | -LL | fn error(u: &(), v: &()) { - | - - let's call the lifetime of this reference `'1` - | | - | let's call the lifetime of this reference `'2` -... -LL | static_id_indirect(&v); //[ll]~ ERROR explicit lifetime required in the type of `v` [E0621] - | ^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'1` must outlive `'2` - -error: aborting due to 5 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0621`. diff --git a/src/test/ui/regions/regions-static-bound.rs b/src/test/ui/regions/regions-static-bound.rs index 34baf5ffff0..c5dc6000e83 100644 --- a/src/test/ui/regions/regions-static-bound.rs +++ b/src/test/ui/regions/regions-static-bound.rs @@ -23,10 +23,8 @@ fn static_id_wrong_way<'a>(t: &'a ()) -> &'static () where 'static: 'a { fn error(u: &(), v: &()) { static_id(&u); //[ll]~ ERROR explicit lifetime required in the type of `u` [E0621] //[nll]~^ ERROR explicit lifetime required in the type of `u` [E0621] - //[nll]~| ERROR unsatisfied lifetime constraints static_id_indirect(&v); //[ll]~ ERROR explicit lifetime required in the type of `v` [E0621] //[nll]~^ ERROR explicit lifetime required in the type of `v` [E0621] - //[nll]~| ERROR unsatisfied lifetime constraints } fn main() {}