Stream: t-compiler/wg-nll

Topic: issue-45696-dangly-paths


nikomatsakis (Jul 25 2018 at 15:27, on Zulip):

Just to spite @Jake Goulding, I'm going to use the "dangly paths" jargon here -- but this thread is devoted to figuring out how to resolve #45696. There is some background discussion on the general problem in https://github.com/nikomatsakis/nll-rfc/issues/40 as well.

In any case, I think @pnkfelix that we probably just want to hardcode a rule around Box for the time-being...

nikomatsakis (Jul 25 2018 at 15:27, on Zulip):

specifically, some kind of rule saying that when a Box is dropped, it's ok to have borrows of its referent

nikomatsakis (Jul 25 2018 at 15:29, on Zulip):

the example from #45696:

#![feature(nll)]

fn foo(x: Box<&mut i32>) -> &mut i32 {
    *x
}

fn main() {}

the problem here is that we drop x on exit from the fn -- even though **x is still borrowed (note that the return is actually implicitly equal to &mut **x, even though it looks like a move)

Matthew Jasper (Jul 25 2018 at 21:49, on Zulip):

I had a look at special casing Box recently.

Matthew Jasper (Jul 25 2018 at 21:52, on Zulip):

Some notes: we currently drop individual fields of !Drop structs/tuples/closures/generators and only access the fields that need drop (so &mut T fields don't have an access allowing their referent to be borrowed.

Matthew Jasper (Jul 25 2018 at 21:53, on Zulip):

Storage dead stops the actual reference being borrowed)

Matthew Jasper (Jul 25 2018 at 21:56, on Zulip):

However, this can't be naively extended to Box, by making Drop do a deep access of the field of *x that implement Drop, followed by a shallow access of *x, since this causes dropping struct A(Box<A>) to give an infinite loop.

Matthew Jasper (Jul 25 2018 at 21:58, on Zulip):

So it seems like the special casing would have to be when/after checking for conflicts, which probably saves some time checking whether types implement Drop when it doesn't matter.

pnkfelix (Jul 26 2018 at 10:43, on Zulip):

specifically, some kind of rule saying that when a Box is dropped, it's ok to have borrows of its referent

yeah okay, I'll try to do this

Last update: Nov 21 2019 at 13:40UTC