-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
false positive for if-let-rescope
where if let
statements without else
are also linted
#133167
Comments
cc @dingxiangfei2009 as you may know more about the intention. |
Marking this as |
FWIW I've just followed https://blog.rust-lang.org/2024/11/27/Rust-2024-public-testing.html to test out the Edition 2024 on the https://github.com/rust-lang/crates.io/ codebase and it looks like literally all of the suggested fixes were false positives. if I run |
FYI cc @traviscross |
We talked about this extensively in the edition call yesterday. Note that, while in simple cases like this it is a false positive, there are cases where the behavior does change for |
If the distinction between such cases is not tractable to get right, maybe add a note for no- |
IMHO false-negatives in this case seem better than this large number of false-positives. if there are false-negatives, wouldn't the compiler complain with a helpful message anyway? |
Not if the temporary is holding a lock that other code was assuming is being held, then it would be a runtime issue. Arguably such code would be best to not rely on temporary extensions, but we cannot know if that is the case. |
fwiw, if i run and also, the lint is only triggered if the so i think the best solution is to either lint every single |
Here's an example I got (minimized): fn foo(mut iter: impl Iterator<Item = i32>) {
if let Some(item) = iter.next() {
_ = item;
}
} It says that This is obviously wrong: But when I tried to verify, the warning went away when I inserted a |
Is there a way to opt out a type from having a significant |
Maybe there should be an option to explicitly exclude the |
A workaround is to run |
I ran this on a few more projects now and the false positive rate is 100% from what I can tell. I really think it would be good for projects to be able to opt out somehow from this migration lint. |
We're hopeful this will be improved by #133753 which is in the process of being merged. |
Code
remove the
else
from the example at https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/if_let_rescope/static.IF_LET_RESCOPE.htmlCurrent output
Desired output
Rationale and extra context
as far as i know, the new if-let-rescope is only relevant, when you have an
else
block, like in the actual example, because it cannot change to be dropped before theelse
, as there is no else, so (as far as i know) the place where it is dropped does not change.more info
if you change the code to print stuff
and then run it with both edition 2024 and edition 2021
they both do the same
Other cases
while testing i found out that if you modify the original code to include anything after the
if let
statement it doesn't lint it anymoreRust Version
Anything else?
No response
The text was updated successfully, but these errors were encountered: