Stream: t-compiler/wg-nll

Topic: issue-52663-future-loop-iteration


davidtwco (Aug 01 2018 at 13:19, on Zulip):

@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.

pnkfelix (Aug 01 2018 at 13:23, on Zulip):

I was wondering if we could get away with just comparing the spans?

davidtwco (Aug 01 2018 at 13:24, on Zulip):

How do you mean?

pnkfelix (Aug 01 2018 at 13:24, on Zulip):

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

pnkfelix (Aug 01 2018 at 13:24, on Zulip):

and adjust the message accordingly

davidtwco (Aug 01 2018 at 13:24, on Zulip):

Ah.

pnkfelix (Aug 01 2018 at 13:24, on Zulip):

Its a hack, I know

davidtwco (Aug 01 2018 at 13:24, on Zulip):

I thought about that, but wasn't sure if there were cases I wasn't considering that might trip it up.

pnkfelix (Aug 01 2018 at 13:25, on Zulip):

so the main case I can think of that might trip that up

davidtwco (Aug 01 2018 at 13:25, on Zulip):

I guess I could try it and find out.

pnkfelix (Aug 01 2018 at 13:25, on Zulip):

would be (maybe) something with if let PAT = EXPR;

pnkfelix (Aug 01 2018 at 13:25, on Zulip):

but I dont think you can have a use in the PAT there...

pnkfelix (Aug 01 2018 at 13:26, on Zulip):

oh

pnkfelix (Aug 01 2018 at 13:26, on Zulip):

function_call(..., &something_borrowed, ...)

pnkfelix (Aug 01 2018 at 13:26, on Zulip):

that might break it

pnkfelix (Aug 01 2018 at 13:26, on Zulip):

you might have to double check that the end of the use's span occurs before the beginning of the borrow's span

pnkfelix (Aug 01 2018 at 13:27, on Zulip):

rather than just comparing the starts of the two spans

pnkfelix (Aug 01 2018 at 13:27, on Zulip):

(but maybe try the simpler way first, and just see if you can break it with an example like that.)

davidtwco (Aug 01 2018 at 13:42, on Zulip):

@pnkfelix that approach results in this test with no loops changing from this result to this result. It also affects this test.

pnkfelix (Aug 01 2018 at 13:46, on Zulip):

oh of course

pnkfelix (Aug 01 2018 at 13:46, on Zulip):

you dont' even need if let; just a move does it. Sigh.

pnkfelix (Aug 01 2018 at 13:48, on Zulip):

what a pain

davidtwco (Aug 01 2018 at 15:43, on Zulip):

@pnkfelix Submitted #52948 for this with my initial suggested approach. I think it caught more cases than the span comparison.

pnkfelix (Aug 01 2018 at 15:51, on Zulip):

oh cool!

pnkfelix (Aug 01 2018 at 15:52, on Zulip):

219326

pnkfelix (Aug 01 2018 at 20:21, on Zulip):

219326

wait, you've all gotten used to this, right?

pnkfelix (Aug 01 2018 at 20:22, on Zulip):

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.

Last update: Nov 21 2019 at 23:30UTC