Skip to content

Commit 6e42521

Browse files
committed
Don't claim that locals in a function are declared outside of the
function body
1 parent fcd0cd0 commit 6e42521

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
391391

392392
let escapes_from = if infcx.tcx.is_closure(mir_def_id) { "closure" } else { "function" };
393393

394-
if fr_name_and_span.is_none() && outlived_fr_name_and_span.is_none() {
394+
// Revert to the normal error in these cases.
395+
// Assignments aren't "escapes" in function items.
396+
if (fr_name_and_span.is_none() && outlived_fr_name_and_span.is_none())
397+
|| (category == ConstraintCategory::Assignment && escapes_from == "function")
398+
{
395399
return self.report_general_error(mir, infcx, mir_def_id,
396400
fr, true, outlived_fr, false,
397401
category, span, errors_buffer);
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
error: borrowed data escapes outside of function
1+
error: unsatisfied lifetime constraints
22
--> $DIR/regions-infer-paramd-indirect.rs:33:9
33
|
4+
LL | impl<'a> set_f<'a> for c<'a> {
5+
| -- lifetime `'a` defined here
6+
...
47
LL | fn set_f_bad(&mut self, b: Box<b>) {
5-
| --------- - `b` is a reference that is only valid in the function body
6-
| |
7-
| `self` is declared here, outside of the function body
8+
| - has type `std::boxed::Box<std::boxed::Box<&'1 isize>>`
89
LL | self.f = b;
9-
| ^^^^^^ `b` escapes the function body here
10+
| ^^^^^^ assignment requires that `'1` must outlive `'a`
1011

1112
error: aborting due to previous error
1213

0 commit comments

Comments
 (0)