Stream: t-compiler/help

Topic: borrowed data escapes outside of function


Santiago Pastorino (Jun 26 2019 at 21:49, on Zulip):

I'm getting this error on a change I'm trying to do

Santiago Pastorino (Jun 26 2019 at 21:49, on Zulip):
error[E0521]: borrowed data escapes outside of function
   --> src/librustc_codegen_ssa/mir/analyze.rs:228:9
    |
218 |     fn visit_place(&mut self,
    |                    --------- `self` is declared here, outside of the function body
219 |                    place: &mir::Place<'tcx>,
    |                    ----- `place` is a reference that is only valid in the function body
...
228 |         self.process_place(place_ref, context, location);
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `place` escapes the function body here

error: aborting due to previous error
Santiago Pastorino (Jun 26 2019 at 21:50, on Zulip):

place is a reference to Place that has base and projection fields

Santiago Pastorino (Jun 26 2019 at 21:51, on Zulip):

then I'm building a PlaceRef struct which is a different data structure that holds references to base and projection from Place

Santiago Pastorino (Jun 26 2019 at 21:51, on Zulip):

I guess I should state that the references that PlaceRef hold do not outlive the reference to Place

Santiago Pastorino (Jun 26 2019 at 21:52, on Zulip):

but unsure how to do it exactly

Santiago Pastorino (Jun 26 2019 at 21:53, on Zulip):

but also, I'm not understanding properly the error message

Santiago Pastorino (Jun 26 2019 at 21:53, on Zulip):

/cc @oli

Santiago Pastorino (Jun 26 2019 at 21:55, on Zulip):

just in case, this is the code ... https://github.com/rust-lang/rust/pull/60913/commits/2cf35e58d7eee9891784ca530e8639051d2c70ef

Santiago Pastorino (Jun 26 2019 at 22:04, on Zulip):

ok, was doing a silly thing, fixed

Santiago Pastorino (Jun 26 2019 at 22:04, on Zulip):

still the error message I think is not great

Santiago Pastorino (Jun 26 2019 at 22:05, on Zulip):

/cc @nikomatsakis @oli @Esteban Küber opinions?

Esteban Küber (Jun 26 2019 at 23:38, on Zulip):

At the very least the "outside of the function body" needs to be fixed in https://github.com/rust-lang/rust/blob/9606f6fa64926a84d82e3c62dbdc57f5c10f756d/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs#L498-L575

Esteban Küber (Jun 26 2019 at 23:39, on Zulip):

but the error itself is not nice at all in this context

nikomatsakis (Jul 08 2019 at 20:42, on Zulip):

yeah the error is pretty wildly inappropriate. not quite sure why that is happening.

nikomatsakis (Jul 08 2019 at 20:42, on Zulip):

@Santiago Pastorino do you think you can file an issue with a minimal reproduction?

nikomatsakis (Jul 08 2019 at 20:42, on Zulip):

maybe cc me and I'll try to add some notes at some point

Santiago Pastorino (Jul 08 2019 at 22:24, on Zulip):

@nikomatsakis going to open an issue, yeah :)

Last update: Nov 11 2019 at 22:30UTC