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 dfed41cb1de..b7000b254a7 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 @@ -391,7 +391,11 @@ impl<'tcx> RegionInferenceContext<'tcx> { 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() { + // Revert to the normal error in these cases. + // Assignments aren't "escapes" in function items. + if (fr_name_and_span.is_none() && outlived_fr_name_and_span.is_none()) + || (category == ConstraintCategory::Assignment && escapes_from == "function") + { return self.report_general_error(mir, infcx, mir_def_id, fr, true, outlived_fr, false, category, span, errors_buffer); diff --git a/src/test/ui/regions/regions-infer-paramd-indirect.nll.stderr b/src/test/ui/regions/regions-infer-paramd-indirect.nll.stderr index 8e29e77713b..7558c5caa0e 100644 --- a/src/test/ui/regions/regions-infer-paramd-indirect.nll.stderr +++ b/src/test/ui/regions/regions-infer-paramd-indirect.nll.stderr @@ -1,12 +1,13 @@ -error: borrowed data escapes outside of function +error: unsatisfied lifetime constraints --> $DIR/regions-infer-paramd-indirect.rs:33:9 | +LL | impl<'a> set_f<'a> for c<'a> { + | -- lifetime `'a` defined here +... LL | fn set_f_bad(&mut self, b: Box) { - | --------- - `b` is a reference that is only valid in the function body - | | - | `self` is declared here, outside of the function body + | - has type `std::boxed::Box>` LL | self.f = b; - | ^^^^^^ `b` escapes the function body here + | ^^^^^^ assignment requires that `'1` must outlive `'a` error: aborting due to previous error