Skip to content
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

Autofix explicit_counter_loop (MaybeIncorrect) produces invalid rust code. #13572

Open
iago-lito opened this issue Oct 20, 2024 · 1 comment
Open
Labels
I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@iago-lito
Copy link

iago-lito commented Oct 20, 2024

Description

Applying fix on this situation:

fn f(v: Vec<u64>) {
    let mut i = 0;
    for e in &v {  // consider using: `for (i, e) in v.iter().enumerate()`
        println!("{i}: {e}");
        i += 1;
    }
}

Produces the following:

fn f(v: Vec<u64>) {
    let mut i = 0;
    for (i, e) in v.iter().enumerate() {
        println!("{i}: {e}");
        i += 1; // /!\ cannot assign twice to immutable variable `i`
    }
}

I'm not sure whether this contradicts with the "should result in valid Rust code" part of the MaybeIncorrect marker for this lint (?), but possibly the orginal i variable should be removed by this autofix?

Version

rustc 1.84.0-nightly (da935398d 2024-10-19)
binary: rustc
commit-hash: da935398d582344c5b7689bd6632d8ec01b0c988
commit-date: 2024-10-19
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.1

Additional Labels

No response

@alex-semenyuk
Copy link
Member

@rustbot label +I-suggestion-causes-error

@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

No branches or pull requests

3 participants