Stream: t-compiler/wg-nll

Topic: function args vs. target


Russell Cohen (Apr 07 2020 at 16:58, on Zulip):

Someone posted this example on twitter: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=a4232dffd9300e6febeabf2208ea589d which I thought was interesting -- The argument borrow _could_ end before we borrow self, but obviously it doesn't. I was curious what would be needed to fix this. (Obviously in this example you could just do self.a, but the user says IRL they needed a mut ref)

Russell Cohen (Apr 07 2020 at 17:00, on Zulip):

for clarity:

struct Foo {
    a: usize,
}

impl Foo {
    fn bad(&mut self) {
        let ref mut b = self.a;
        self.doit(*b);
    }
   fn doit(&mut self, _b: usize) {}
}
pnkfelix (Apr 09 2020 at 13:25, on Zulip):

Is this similar to two-phase borrows?

pnkfelix (Apr 09 2020 at 13:26, on Zulip):

I think it may be two phase borrows

pnkfelix (Apr 09 2020 at 13:26, on Zulip):

(or "generalized two-phase borrows", rather)

Russell Cohen (Apr 09 2020 at 15:46, on Zulip):

oh, maybe. But because it's explicitly ref mut it isn't?

pnkfelix (Apr 09 2020 at 18:05, on Zulip):

I don't know yet

pnkfelix (Apr 09 2020 at 18:05, on Zulip):

It just struck me as quite similar

nikomatsakis (Apr 18 2020 at 11:32, on Zulip):

@Russell Cohen I think @pnkfelix is correct that this is related to two-phase borrows, but there are two complications:

Russell Cohen (Apr 23 2020 at 18:07, on Zulip):

Got it. So theoretically it could be handled in exactly this form, but the generalized form causes issues.

Last update: Jun 05 2020 at 22:40UTC