Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upimmutable loop condition lint gives up on mutated upvars #2916
Comments
This comment has been minimized.
This comment has been minimized.
|
Notes on my failed noobish attempt to fix this:
If you try this, you'll find that it does fix the above examples... but it is still easily defeated by the following simple example, which becomes a false positive: (very ungood for a deny-by-default lint, so I won't be submitting a PR
I find it really hard to believe that there's no way to figure out the local that an Upvar ultimately corresponds to. There's gotta be a way... right? |
This comment has been minimized.
This comment has been minimized.
|
I think I did the "fix" of bailing out on
If I remember correctly this was the point where I failed fixing it and decided to bail out... Edit: Yep #2572 |
This comment has been minimized.
This comment has been minimized.
|
I think I am losing my mind here
|
This comment has been minimized.
This comment has been minimized.
|
I am beginning to believe that the compiler does not have this functionality implemented anywhere because it does not need it. Everything the compiler cares about is integrated directly into borrowck or similar, probably so that it can be computed efficiently. Consider some of the specific error messages the compiler gives: || {
let x = vec![()];
|| {
|| {
x.sort();
};
};
};
Pay close attention and you'll notice that the spans in the error suggest local reasoning on just the statements/expressions that lie immediately in the body of the first closure (treating the nested closures as opaque). It is not the In another example, the compiler does evidently see through the layers of closures: move || {
let x = vec![()];
move || {
move || {
vec![0,1,2].into_iter().map(|_| drop(x));
}
}
};
The "captured outer variable" comes from the I do still hope this is just me being a noob and not seeing the solution right under my nose. Because otherwise it does not bode well for |
ExpHP
referenced this issue
Jul 14, 2018
Open
A 'close' annotation to restrict the bindings accessible by a block #2914
This comment has been minimized.
This comment has been minimized.
|
Your investigations go way beyond what I tried back then. Anyway, maybe this could help: There is a method for getting the Maybe this also helps, in case you haven't found it yet: rustc-guide: Identifiers in the HIR Big Thanks for taking your time and looking into this! |
ExpHP commentedJul 13, 2018
Currently the immutable loop condition lint gives up on code like the following, where the variable being mutated is an upvar:
This is a known problem with a
FIXMEin the source, but I think that fixing it (or at least, discovering how to fix it) will be a useful step towards implementing #2914, which requires much more reliable ways of discovering whether a given variable is used.