rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.31k stars 1.62k forks source link

Incorrect warning:#[warn(unused_variables)] #18534

Open ubeing opened 3 days ago

ubeing commented 3 days ago

rust-analyzer version: V0.3.2188

rustc version: 1.81.9

editor or extension: VSCode on macOS

code snippet to reproduce:

pub async fn new_course(
    new_course: web::Json<Course>,
    app_state: web::Data<AppState>,
) -> HttpResponse {
        let course_count = app_state
        .courses
        .lock()
        .unwrap()
        .clone()
        .into_iter()
        .filter(|course| course.teacher_id == new_course.teacher_id)
        .collect::<Vec<Course>>()
        .len();
    let new_course = Course {
        teacher_id: new_course.teacher_id,
        id: Some(course_count + 1),
        name: new_course.name.clone(),
        time: Some(Utc::now().naive_utc()),
    };
    app_state.courses.lock().unwrap().push(new_course);
    HttpResponse::Ok().json("Course added")
}

The IDE always issues an unused variable warning for the variable 'coursecount', even if you prefix the variable with ''

lnicola commented 3 days ago

Which crates are you using there?

lnicola commented 3 days ago

FWIW, I don't get any warning. And you're unnecessarily cloning courses there.

Image