From b377e7bbfbf584de4c1a775fd41b957cbd2e057b Mon Sep 17 00:00:00 2001 From: David Wood Date: Tue, 24 Jul 2018 16:22:41 +0200 Subject: [PATCH] Change label from closure to function where appropriate. --- .../nll/region_infer/error_reporting/mod.rs | 32 ++++++++++--------- .../static-return-lifetime-infered.nll.stderr | 12 +++---- .../impl/dyn-trait.nll.stderr | 6 ++-- src/test/ui/issue-16683.nll.stderr | 6 ++-- src/test/ui/issue-17758.nll.stderr | 6 ++-- src/test/ui/issue-52213.nll.stderr | 6 ++-- ...oximated-shorter-to-static-no-bound.stderr | 6 ++-- ...mated-shorter-to-static-wrong-bound.stderr | 6 ++-- src/test/ui/nll/issue-50716.stderr | 6 ++-- src/test/ui/nll/mir_check_cast_reify.stderr | 6 ++-- .../ui/nll/mir_check_cast_unsafe_fn.stderr | 6 ++-- 11 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs index cef6ab311a3..c88259d5e8f 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs @@ -324,8 +324,8 @@ impl<'tcx> RegionInferenceContext<'tcx> { match (category, fr_is_local, outlived_fr_is_local) { (ConstraintCategory::Assignment, true, false) | (ConstraintCategory::CallArgument, true, false) => - self.report_escapes_closure_error(mir, infcx, mir_def_id, fr, outlived_fr, - category, span, errors_buffer), + self.report_escaping_data_error(mir, infcx, mir_def_id, fr, outlived_fr, + category, span, errors_buffer), _ => self.report_general_error(mir, infcx, mir_def_id, fr, fr_is_local, outlived_fr, outlived_fr_is_local, @@ -333,7 +333,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { }; } - fn report_escapes_closure_error( + fn report_escaping_data_error( &self, mir: &Mir<'tcx>, infcx: &InferCtxt<'_, '_, 'tcx>, @@ -348,22 +348,23 @@ impl<'tcx> RegionInferenceContext<'tcx> { let outlived_fr_name_and_span = self.get_var_name_and_span_for_region(infcx.tcx, mir, outlived_fr); + let escapes_from = if infcx.tcx.is_closure(mir_def_id) { "closure" } else { "function" }; + if fr_name_and_span.is_none() && outlived_fr_name_and_span.is_none() { return self.report_general_error(mir, infcx, mir_def_id, fr, true, outlived_fr, false, category, span, errors_buffer); } - let mut diag = infcx - .tcx - .sess - .struct_span_err(span, &format!("borrowed data escapes outside of closure")); + let mut diag = infcx.tcx.sess.struct_span_err( + span, &format!("borrowed data escapes outside of {}", escapes_from), + ); if let Some((outlived_fr_name, outlived_fr_span)) = outlived_fr_name_and_span { if let Some(name) = outlived_fr_name { diag.span_label( outlived_fr_span, - format!("`{}` is declared here, outside of the closure body", name), + format!("`{}` is declared here, outside of the {} body", name, escapes_from), ); } } @@ -372,13 +373,12 @@ impl<'tcx> RegionInferenceContext<'tcx> { if let Some(name) = fr_name { diag.span_label( fr_span, - format!( - "`{}` is a reference that is only valid in the closure body", - name - ), + format!("`{}` is a reference that is only valid in the {} body", + name, escapes_from), ); - diag.span_label(span, format!("`{}` escapes the closure body here", name)); + diag.span_label(span, format!("`{}` escapes the {} body here", + name, escapes_from)); } } @@ -409,12 +409,14 @@ impl<'tcx> RegionInferenceContext<'tcx> { let outlived_fr_name = self.give_region_a_name( infcx, mir, mir_def_id, outlived_fr, counter, &mut diag); + let mir_def_name = if infcx.tcx.is_closure(mir_def_id) { "closure" } else { "function" }; + match (category, outlived_fr_is_local, fr_is_local) { (ConstraintCategory::Return, true, _) => { diag.span_label(span, format!( - "closure was supposed to return data with lifetime `{}` but it is returning \ + "{} was supposed to return data with lifetime `{}` but it is returning \ data with lifetime `{}`", - fr_name, outlived_fr_name, + mir_def_name, fr_name, outlived_fr_name, )); }, _ => { diff --git a/src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr b/src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr index c6f8d2e519c..123a93636d2 100644 --- a/src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr +++ b/src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr @@ -10,21 +10,19 @@ warning: not reporting region error due to nll LL | self.x.iter().map(|a| a.0) | ^^^^ -error: borrowed data escapes outside of closure +error: unsatisfied lifetime constraints --> $DIR/static-return-lifetime-infered.rs:17:9 | LL | fn iter_values_anon(&self) -> impl Iterator { - | ----- `self` is a reference that is only valid in the closure body + | - let's call the lifetime of this reference `'1` LL | self.x.iter().map(|a| a.0) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ `self` escapes the closure body here + | ^^^^^^^^^^^^^ free region requires that `'1` must outlive `'static` -error: borrowed data escapes outside of closure +error: unsatisfied lifetime constraints --> $DIR/static-return-lifetime-infered.rs:21:9 | -LL | fn iter_values<'a>(&'a self) -> impl Iterator { - | -------- `self` is a reference that is only valid in the closure body LL | self.x.iter().map(|a| a.0) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ `self` escapes the closure body here + | ^^^^^^^^^^^^^ free region requires that `'a` must outlive `'static` error: aborting due to 2 previous errors diff --git a/src/test/ui/in-band-lifetimes/impl/dyn-trait.nll.stderr b/src/test/ui/in-band-lifetimes/impl/dyn-trait.nll.stderr index e26b1956d5e..f5d98e04ad8 100644 --- a/src/test/ui/in-band-lifetimes/impl/dyn-trait.nll.stderr +++ b/src/test/ui/in-band-lifetimes/impl/dyn-trait.nll.stderr @@ -4,13 +4,13 @@ warning: not reporting region error due to nll LL | static_val(x); //~ ERROR cannot infer | ^ -error: borrowed data escapes outside of closure +error: borrowed data escapes outside of function --> $DIR/dyn-trait.rs:32:5 | LL | fn with_dyn_debug_static<'a>(x: Box) { - | - `x` is a reference that is only valid in the closure body + | - `x` is a reference that is only valid in the function body LL | static_val(x); //~ ERROR cannot infer - | ^^^^^^^^^^^^^ `x` escapes the closure body here + | ^^^^^^^^^^^^^ `x` escapes the function body here error: aborting due to previous error diff --git a/src/test/ui/issue-16683.nll.stderr b/src/test/ui/issue-16683.nll.stderr index f9dda27da09..890bb426441 100644 --- a/src/test/ui/issue-16683.nll.stderr +++ b/src/test/ui/issue-16683.nll.stderr @@ -10,13 +10,13 @@ warning: not reporting region error due to nll LL | self.a(); //~ ERROR cannot infer | ^ -error: borrowed data escapes outside of closure +error: borrowed data escapes outside of function --> $DIR/issue-16683.rs:14:9 | LL | fn b(&self) { - | ----- `self` is a reference that is only valid in the closure body + | ----- `self` is a reference that is only valid in the function body LL | self.a(); //~ ERROR cannot infer - | ^^^^^^^^ `self` escapes the closure body here + | ^^^^^^^^ `self` escapes the function body here error: aborting due to previous error diff --git a/src/test/ui/issue-17758.nll.stderr b/src/test/ui/issue-17758.nll.stderr index 5775135aefc..c51a72f885d 100644 --- a/src/test/ui/issue-17758.nll.stderr +++ b/src/test/ui/issue-17758.nll.stderr @@ -10,13 +10,13 @@ warning: not reporting region error due to nll LL | self.foo(); | ^^^ -error: borrowed data escapes outside of closure +error: borrowed data escapes outside of function --> $DIR/issue-17758.rs:17:9 | LL | fn bar(&self) { - | ----- `self` is a reference that is only valid in the closure body + | ----- `self` is a reference that is only valid in the function body LL | self.foo(); - | ^^^^^^^^^^ `self` escapes the closure body here + | ^^^^^^^^^^ `self` escapes the function body here error: aborting due to previous error diff --git a/src/test/ui/issue-52213.nll.stderr b/src/test/ui/issue-52213.nll.stderr index fb5da7d7a19..c288cf9ed82 100644 --- a/src/test/ui/issue-52213.nll.stderr +++ b/src/test/ui/issue-52213.nll.stderr @@ -5,10 +5,10 @@ LL | match (&t,) { //~ ERROR cannot infer an appropriate lifetime | ^^^^^ error: unsatisfied lifetime constraints - --> $DIR/issue-52213.rs:12:11 + --> $DIR/issue-52213.rs:13:11 | -LL | match (&t,) { //~ ERROR cannot infer an appropriate lifetime - | ^^^^^ free region requires that `'a` must outlive `'b` +LL | ((u,),) => u, + | ^ free region requires that `'a` must outlive `'b` error: aborting due to previous error 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 3177cd7c28f..33e4240736f 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 @@ -23,18 +23,18 @@ LL | | }); = note: number of external vids: 2 = note: where '_#1r: '_#0r -error: borrowed data escapes outside of closure +error: borrowed data escapes outside of function --> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:45:5 | 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 closure body + | ------ `cell_a` is a reference that is only valid in the function body LL | / establish_relationships(&cell_a, &cell_b, |_outlives, x, y| { LL | | //~^ ERROR LL | | LL | | // Only works if 'x: 'y: LL | | demand_y(x, y, x.get()) //~ WARNING not reporting region error due to nll LL | | }); - | |______^ `cell_a` escapes the closure body here + | |______^ `cell_a` escapes the function body here note: No external requirements --> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:44:1 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 089c88abcdd..5f98a0fd36d 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 @@ -23,18 +23,18 @@ LL | | }); = note: number of external vids: 3 = note: where '_#1r: '_#0r -error: borrowed data escapes outside of closure +error: borrowed data escapes outside of function --> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:48:5 | 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 closure body + | ------ `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 LL | | // Only works if 'x: 'y: LL | | demand_y(x, y, x.get()) LL | | //~^ WARNING not reporting region error due to nll LL | | }); - | |______^ `cell_a` escapes the closure body here + | |______^ `cell_a` escapes the function body here note: No external requirements --> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:47:1 diff --git a/src/test/ui/nll/issue-50716.stderr b/src/test/ui/nll/issue-50716.stderr index 8acf2ef51ec..f12ab9b4f96 100644 --- a/src/test/ui/nll/issue-50716.stderr +++ b/src/test/ui/nll/issue-50716.stderr @@ -1,11 +1,11 @@ -error: borrowed data escapes outside of closure +error: borrowed data escapes outside of function --> $DIR/issue-50716.rs:25:14 | LL | fn foo<'a, T: 'static>(s: Box<<&'a T as A>::X>) - | - `s` is a reference that is only valid in the closure body + | - `s` is a reference that is only valid in the function body ... LL | let _x = *s; //~ ERROR - | ^^ `s` escapes the closure body here + | ^^ `s` escapes the function body here error: aborting due to previous error diff --git a/src/test/ui/nll/mir_check_cast_reify.stderr b/src/test/ui/nll/mir_check_cast_reify.stderr index 13f90e1f159..d8f186a2232 100644 --- a/src/test/ui/nll/mir_check_cast_reify.stderr +++ b/src/test/ui/nll/mir_check_cast_reify.stderr @@ -4,14 +4,14 @@ warning: not reporting region error due to nll LL | let f: fn(_) -> _ = foo; | ^^^ -error: borrowed data escapes outside of closure +error: borrowed data escapes outside of function --> $DIR/mir_check_cast_reify.rs:48:5 | LL | fn bar<'a>(x: &'a u32) -> &'static u32 { - | - `x` is a reference that is only valid in the closure body + | - `x` is a reference that is only valid in the function body ... LL | f(x) - | ^^^^ `x` escapes the closure body here + | ^^^^ `x` escapes the function body here error: aborting due to previous error diff --git a/src/test/ui/nll/mir_check_cast_unsafe_fn.stderr b/src/test/ui/nll/mir_check_cast_unsafe_fn.stderr index b08c6f32e6b..98c03e37814 100644 --- a/src/test/ui/nll/mir_check_cast_unsafe_fn.stderr +++ b/src/test/ui/nll/mir_check_cast_unsafe_fn.stderr @@ -4,14 +4,14 @@ warning: not reporting region error due to nll LL | let g: unsafe fn(_) -> _ = f; | ^ -error: borrowed data escapes outside of closure +error: borrowed data escapes outside of function --> $DIR/mir_check_cast_unsafe_fn.rs:20:14 | LL | fn bar<'a>(input: &'a u32, f: fn(&'a u32) -> &'a u32) -> &'static u32 { - | ----- `input` is a reference that is only valid in the closure body + | ----- `input` is a reference that is only valid in the function body ... LL | unsafe { g(input) } - | ^^^^^^^^ `input` escapes the closure body here + | ^^^^^^^^ `input` escapes the function body here error: aborting due to previous error