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
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!
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.
Here's another variation further simplified without any async: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=425f9be6798d37b7291582629ac184cb
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?
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?.
And yes, Polonius should address it; this is NLL case #3.
Ok, that's helpful to know. Thank you!