Stream: general

Topic: Is this a bug?


Paul Faria (Jan 01 2020 at 22:24, on Zulip):

I'm seeing an error that doesn't make any sense to me. I'm curious if I should file this as a bug or if there's a legitimate problem with my code. Link to playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=3060a65b2bfa0996dcd655d6289324c4

Paul Faria (Jan 01 2020 at 22:25, on Zulip):

I could understand if the problem was on line 28, where I'm getting a reference that locks self to immutable, and then I can't pass self as a mutable reference, but the error pointing to line 20 makes no sense, especially since line 21 immediately returns that value!

Paul Faria (Jan 01 2020 at 22:26, on Zulip):

My thought to fix the (or what I thought was the original) error was to add a call to clone (see modified example here: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=f773d4d25f46467f1fc0b415324a3ccb) on line 28, but I still run into the same issue.

Paul Faria (Jan 01 2020 at 23:45, on Zulip):

Here's another variation further simplified without any async: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=425f9be6798d37b7291582629ac184cb

Paul Faria (Jan 01 2020 at 23:48, on Zulip):

I was able to solve it with this version: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=ecdc7880c62b9071abd4971a07c0b012 I find it pretty unexpected to be honest though. Is this an edge case fixed by polonius?

Jake Goulding (Jan 02 2020 at 02:09, on Zulip):

Yes. Pretty sure this is another form of Returning a reference from a HashMap or Vec causes a borrow to last beyond the scope it's in?.

Jake Goulding (Jan 02 2020 at 02:09, on Zulip):

And yes, Polonius should address it; this is NLL case #3.

Paul Faria (Jan 02 2020 at 04:05, on Zulip):

Ok, that's helpful to know. Thank you!

Last update: May 26 2020 at 11:10UTC