@pnkfelix I was planning to experiment with this diagnostic improvement.
As far as I can gather, there's no existing code that might help with determining if we're in the "used in future iteration" case - closest I can find is this code but that doesn't seem useful here.
Do you think a reasonable approach to take is to try follow the MIR statements from where the borrow is used through the basic blocks until I can find the borrow use location again (perhaps require that I pass over the borrow being made)? That seems a little contrived but I'm not sure how else I'd determine if the statements are in a loop.
I was wondering if we could get away with just comparing the spans?
How do you mean?
i.e. if the span of the use occurs earlier in the source than that of the borrow, then assume that this can only happen due to loop's iterating
and adjust the message accordingly
Its a hack, I know
I thought about that, but wasn't sure if there were cases I wasn't considering that might trip it up.
so the main case I can think of that might trip that up
I guess I could try it and find out.
would be (maybe) something with
if let PAT = EXPR;
but I dont think you can have a use in the PAT there...
function_call(..., &something_borrowed, ...)
that might break it
you might have to double check that the end of the use's span occurs before the beginning of the borrow's span
rather than just comparing the starts of the two spans
(but maybe try the simpler way first, and just see if you can break it with an example like that.)
oh of course
you dont' even need
if let; just a move does it. Sigh.
what a pain
@pnkfelix Submitted #52948 for this with my initial suggested approach. I think it caught more cases than the span comparison.
wait, you've all gotten used to this, right?
I hit that OTP button all the time by accident. Usually I catch it quickly enough to delete it (just to keep noise out of the channel), but this time I failed.