Skip to content

Commit b377e7b

Browse files
committed
Change label from closure to function where appropriate.
1 parent 055aaaf commit b377e7b

11 files changed

+49
-49
lines changed

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

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -324,16 +324,16 @@ impl<'tcx> RegionInferenceContext<'tcx> {
324324
match (category, fr_is_local, outlived_fr_is_local) {
325325
(ConstraintCategory::Assignment, true, false) |
326326
(ConstraintCategory::CallArgument, true, false) =>
327-
self.report_escapes_closure_error(mir, infcx, mir_def_id, fr, outlived_fr,
328-
category, span, errors_buffer),
327+
self.report_escaping_data_error(mir, infcx, mir_def_id, fr, outlived_fr,
328+
category, span, errors_buffer),
329329
_ =>
330330
self.report_general_error(mir, infcx, mir_def_id, fr, fr_is_local,
331331
outlived_fr, outlived_fr_is_local,
332332
category, span, errors_buffer),
333333
};
334334
}
335335

336-
fn report_escapes_closure_error(
336+
fn report_escaping_data_error(
337337
&self,
338338
mir: &Mir<'tcx>,
339339
infcx: &InferCtxt<'_, '_, 'tcx>,
@@ -348,22 +348,23 @@ impl<'tcx> RegionInferenceContext<'tcx> {
348348
let outlived_fr_name_and_span =
349349
self.get_var_name_and_span_for_region(infcx.tcx, mir, outlived_fr);
350350

351+
let escapes_from = if infcx.tcx.is_closure(mir_def_id) { "closure" } else { "function" };
352+
351353
if fr_name_and_span.is_none() && outlived_fr_name_and_span.is_none() {
352354
return self.report_general_error(mir, infcx, mir_def_id,
353355
fr, true, outlived_fr, false,
354356
category, span, errors_buffer);
355357
}
356358

357-
let mut diag = infcx
358-
.tcx
359-
.sess
360-
.struct_span_err(span, &format!("borrowed data escapes outside of closure"));
359+
let mut diag = infcx.tcx.sess.struct_span_err(
360+
span, &format!("borrowed data escapes outside of {}", escapes_from),
361+
);
361362

362363
if let Some((outlived_fr_name, outlived_fr_span)) = outlived_fr_name_and_span {
363364
if let Some(name) = outlived_fr_name {
364365
diag.span_label(
365366
outlived_fr_span,
366-
format!("`{}` is declared here, outside of the closure body", name),
367+
format!("`{}` is declared here, outside of the {} body", name, escapes_from),
367368
);
368369
}
369370
}
@@ -372,13 +373,12 @@ impl<'tcx> RegionInferenceContext<'tcx> {
372373
if let Some(name) = fr_name {
373374
diag.span_label(
374375
fr_span,
375-
format!(
376-
"`{}` is a reference that is only valid in the closure body",
377-
name
378-
),
376+
format!("`{}` is a reference that is only valid in the {} body",
377+
name, escapes_from),
379378
);
380379

381-
diag.span_label(span, format!("`{}` escapes the closure body here", name));
380+
diag.span_label(span, format!("`{}` escapes the {} body here",
381+
name, escapes_from));
382382
}
383383
}
384384

@@ -409,12 +409,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
409409
let outlived_fr_name = self.give_region_a_name(
410410
infcx, mir, mir_def_id, outlived_fr, counter, &mut diag);
411411

412+
let mir_def_name = if infcx.tcx.is_closure(mir_def_id) { "closure" } else { "function" };
413+
412414
match (category, outlived_fr_is_local, fr_is_local) {
413415
(ConstraintCategory::Return, true, _) => {
414416
diag.span_label(span, format!(
415-
"closure was supposed to return data with lifetime `{}` but it is returning \
417+
"{} was supposed to return data with lifetime `{}` but it is returning \
416418
data with lifetime `{}`",
417-
fr_name, outlived_fr_name,
419+
mir_def_name, fr_name, outlived_fr_name,
418420
));
419421
},
420422
_ => {

src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,19 @@ warning: not reporting region error due to nll
1010
LL | self.x.iter().map(|a| a.0)
1111
| ^^^^
1212

13-
error: borrowed data escapes outside of closure
13+
error: unsatisfied lifetime constraints
1414
--> $DIR/static-return-lifetime-infered.rs:17:9
1515
|
1616
LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> {
17-
| ----- `self` is a reference that is only valid in the closure body
17+
| - let's call the lifetime of this reference `'1`
1818
LL | self.x.iter().map(|a| a.0)
19-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ `self` escapes the closure body here
19+
| ^^^^^^^^^^^^^ free region requires that `'1` must outlive `'static`
2020

21-
error: borrowed data escapes outside of closure
21+
error: unsatisfied lifetime constraints
2222
--> $DIR/static-return-lifetime-infered.rs:21:9
2323
|
24-
LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> {
25-
| -------- `self` is a reference that is only valid in the closure body
2624
LL | self.x.iter().map(|a| a.0)
27-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ `self` escapes the closure body here
25+
| ^^^^^^^^^^^^^ free region requires that `'a` must outlive `'static`
2826

2927
error: aborting due to 2 previous errors
3028

src/test/ui/in-band-lifetimes/impl/dyn-trait.nll.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ warning: not reporting region error due to nll
44
LL | static_val(x); //~ ERROR cannot infer
55
| ^
66

7-
error: borrowed data escapes outside of closure
7+
error: borrowed data escapes outside of function
88
--> $DIR/dyn-trait.rs:32:5
99
|
1010
LL | fn with_dyn_debug_static<'a>(x: Box<dyn Debug + 'a>) {
11-
| - `x` is a reference that is only valid in the closure body
11+
| - `x` is a reference that is only valid in the function body
1212
LL | static_val(x); //~ ERROR cannot infer
13-
| ^^^^^^^^^^^^^ `x` escapes the closure body here
13+
| ^^^^^^^^^^^^^ `x` escapes the function body here
1414

1515
error: aborting due to previous error
1616

src/test/ui/issue-16683.nll.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ warning: not reporting region error due to nll
1010
LL | self.a(); //~ ERROR cannot infer
1111
| ^
1212

13-
error: borrowed data escapes outside of closure
13+
error: borrowed data escapes outside of function
1414
--> $DIR/issue-16683.rs:14:9
1515
|
1616
LL | fn b(&self) {
17-
| ----- `self` is a reference that is only valid in the closure body
17+
| ----- `self` is a reference that is only valid in the function body
1818
LL | self.a(); //~ ERROR cannot infer
19-
| ^^^^^^^^ `self` escapes the closure body here
19+
| ^^^^^^^^ `self` escapes the function body here
2020

2121
error: aborting due to previous error
2222

src/test/ui/issue-17758.nll.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ warning: not reporting region error due to nll
1010
LL | self.foo();
1111
| ^^^
1212

13-
error: borrowed data escapes outside of closure
13+
error: borrowed data escapes outside of function
1414
--> $DIR/issue-17758.rs:17:9
1515
|
1616
LL | fn bar(&self) {
17-
| ----- `self` is a reference that is only valid in the closure body
17+
| ----- `self` is a reference that is only valid in the function body
1818
LL | self.foo();
19-
| ^^^^^^^^^^ `self` escapes the closure body here
19+
| ^^^^^^^^^^ `self` escapes the function body here
2020

2121
error: aborting due to previous error
2222

src/test/ui/issue-52213.nll.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ LL | match (&t,) { //~ ERROR cannot infer an appropriate lifetime
55
| ^^^^^
66

77
error: unsatisfied lifetime constraints
8-
--> $DIR/issue-52213.rs:12:11
8+
--> $DIR/issue-52213.rs:13:11
99
|
10-
LL | match (&t,) { //~ ERROR cannot infer an appropriate lifetime
11-
| ^^^^^ free region requires that `'a` must outlive `'b`
10+
LL | ((u,),) => u,
11+
| ^ free region requires that `'a` must outlive `'b`
1212

1313
error: aborting due to previous error
1414

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ LL | | });
2323
= note: number of external vids: 2
2424
= note: where '_#1r: '_#0r
2525

26-
error: borrowed data escapes outside of closure
26+
error: borrowed data escapes outside of function
2727
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:45:5
2828
|
2929
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
30-
| ------ `cell_a` is a reference that is only valid in the closure body
30+
| ------ `cell_a` is a reference that is only valid in the function body
3131
LL | / establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
3232
LL | | //~^ ERROR
3333
LL | |
3434
LL | | // Only works if 'x: 'y:
3535
LL | | demand_y(x, y, x.get()) //~ WARNING not reporting region error due to nll
3636
LL | | });
37-
| |______^ `cell_a` escapes the closure body here
37+
| |______^ `cell_a` escapes the function body here
3838

3939
note: No external requirements
4040
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:44:1

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ LL | | });
2323
= note: number of external vids: 3
2424
= note: where '_#1r: '_#0r
2525

26-
error: borrowed data escapes outside of closure
26+
error: borrowed data escapes outside of function
2727
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:48:5
2828
|
2929
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
30-
| ------ `cell_a` is a reference that is only valid in the closure body
30+
| ------ `cell_a` is a reference that is only valid in the function body
3131
LL | / establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
3232
LL | | //~^ ERROR
3333
LL | | // Only works if 'x: 'y:
3434
LL | | demand_y(x, y, x.get())
3535
LL | | //~^ WARNING not reporting region error due to nll
3636
LL | | });
37-
| |______^ `cell_a` escapes the closure body here
37+
| |______^ `cell_a` escapes the function body here
3838

3939
note: No external requirements
4040
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:47:1

src/test/ui/nll/issue-50716.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
error: borrowed data escapes outside of closure
1+
error: borrowed data escapes outside of function
22
--> $DIR/issue-50716.rs:25:14
33
|
44
LL | fn foo<'a, T: 'static>(s: Box<<&'a T as A>::X>)
5-
| - `s` is a reference that is only valid in the closure body
5+
| - `s` is a reference that is only valid in the function body
66
...
77
LL | let _x = *s; //~ ERROR
8-
| ^^ `s` escapes the closure body here
8+
| ^^ `s` escapes the function body here
99

1010
error: aborting due to previous error
1111

src/test/ui/nll/mir_check_cast_reify.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ warning: not reporting region error due to nll
44
LL | let f: fn(_) -> _ = foo;
55
| ^^^
66

7-
error: borrowed data escapes outside of closure
7+
error: borrowed data escapes outside of function
88
--> $DIR/mir_check_cast_reify.rs:48:5
99
|
1010
LL | fn bar<'a>(x: &'a u32) -> &'static u32 {
11-
| - `x` is a reference that is only valid in the closure body
11+
| - `x` is a reference that is only valid in the function body
1212
...
1313
LL | f(x)
14-
| ^^^^ `x` escapes the closure body here
14+
| ^^^^ `x` escapes the function body here
1515

1616
error: aborting due to previous error
1717

src/test/ui/nll/mir_check_cast_unsafe_fn.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ warning: not reporting region error due to nll
44
LL | let g: unsafe fn(_) -> _ = f;
55
| ^
66

7-
error: borrowed data escapes outside of closure
7+
error: borrowed data escapes outside of function
88
--> $DIR/mir_check_cast_unsafe_fn.rs:20:14
99
|
1010
LL | fn bar<'a>(input: &'a u32, f: fn(&'a u32) -> &'a u32) -> &'static u32 {
11-
| ----- `input` is a reference that is only valid in the closure body
11+
| ----- `input` is a reference that is only valid in the function body
1212
...
1313
LL | unsafe { g(input) }
14-
| ^^^^^^^^ `input` escapes the closure body here
14+
| ^^^^^^^^ `input` escapes the function body here
1515

1616
error: aborting due to previous error
1717

0 commit comments

Comments
 (0)