-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
skip(..).next() lint incorrectly suggest using nth() in some cases #8128
Comments
Thank you for the report. I think a good solution would be to add a note that the iterator has to be set to mutable and use |
Hi. I'm interested in this issue. |
Hi, I have a problem, could you help me? for example: fn main() {
let test_string = "1|1 2";
let sp = test_string.split('|').map(|s| s.trim()); // 1
let out: Vec<&str> = sp.skip(1).next().unwrap().split('').collect(); // 2
} The way I can think of is to find stmt 1, then according to stmt -> local -> pat->binding to see if it is mut. |
Hey @surechen, you can get the parent block by using |
Thank you very much. |
Fix 8128 Fixes #8128 changelog: Fix error suggestion of `skip(..).next()` for immutable variable.
Summary
Clippy incorrectly reports that I should switch to using
nth(..)
instead of theskip(..).next()
but does not account for the fact that my variable is not mutable, and thus cannot usenth(..)
. I found this while attempting acargo clippy --fix
and it applied this fix and caused compile error and prevented any further clippy fixes from being applied.Reproducer
I tried this code:
I expected to see this happen:
Either for clippy to realize I cannot use
nth()
as suggested because the variable is not mutable, or for it to change that variable to mutable as part of the fix (I could see how this could be complicated/bad).I suppose changing the help to mention that nth() would be available if the variable was mutable and that the the user should consider changing it.
Instead, this happened:
Clippy reports that I should be using
nth()
instead ofskip(1).next()
but without other changes in my code this is not an allowable fix.Version
Additional Labels
l-suggestion-causes-error
The text was updated successfully, but these errors were encountered: