Change label from closure to function where appropriate.
This commit is contained in:
parent
055aaaf765
commit
b377e7bbfb
@ -324,7 +324,7 @@ 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,
|
||||
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,
|
||||
@ -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,
|
||||
));
|
||||
},
|
||||
_ => {
|
||||
|
@ -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<Item=u32> {
|
||||
| ----- `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<Item=u32> {
|
||||
| -------- `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
|
||||
|
||||
|
@ -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<dyn Debug + 'a>) {
|
||||
| - `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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user