Don't claim that locals in a function are declared outside of the
function body
This commit is contained in:
parent
fcd0cd0ade
commit
6e425219f1
@ -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);
|
||||
|
@ -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>) {
|
||||
| --------- - `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<std::boxed::Box<&'1 isize>>`
|
||||
LL | self.f = b;
|
||||
| ^^^^^^ `b` escapes the function body here
|
||||
| ^^^^^^ assignment requires that `'1` must outlive `'a`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user