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

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

Closed
ubeing opened this issue Nov 19, 2024 · 2 comments
Closed

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

ubeing opened this issue Nov 19, 2024 · 2 comments
Labels
C-bug Category: bug

Comments

@ubeing
Copy link

ubeing commented Nov 19, 2024

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 'course_count', even if you prefix the variable with '_'

@ubeing ubeing added the C-bug Category: bug label Nov 19, 2024
@lnicola
Copy link
Member

lnicola commented Nov 19, 2024

Which crates are you using there?

@lnicola
Copy link
Member

lnicola commented Nov 19, 2024

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

Image

@lnicola lnicola closed this as not planned Won't fix, can't repro, duplicate, stale Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants