Skip to content

Regression unused_assignments for variable with underscore prefix captured by closure #149889

Closed

Description

@SamRodri

Code

I tried this code:

fn lock() -> impl Drop {
    struct Handle;
    impl Drop for Handle {
        fn drop(&mut self) {
            
        }
    }
    Handle
}
fn bar(_f: impl FnMut(bool)) { }
pub fn foo() {
    let mut _handle = None;
    bar(move |l| {
        if l {
            _handle = Some(lock());
        } else {
            _handle = None;
        }
    })
}

I expected to see this happen: no lints

Instead, this happened: a warning unused_assignments for each assign of _handle

Version it worked on

It most recently worked on: 1.91.1

Version with regression

rustc --version --verbose:

rustc 1.92.0 (ded5c06cf 2025-12-08)
binary: rustc
commit-hash: ded5c06cf21d2b93bffd5d884aa6e96934ee4234
commit-date: 2025-12-08
host: x86_64-pc-windows-msvc
release: 1.92.0
LLVM version: 21.1.3

Activity

  1. added
    C-bugCategory: This is a bug.
    regression-untriagedUntriaged performance or correctness regression.
    on Dec 11, 2025
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Dec 11, 2025
  3. dalance commented on Dec 12, 2025

    @dalance
    Contributor

    rust-lang/rust-clippy#16223 may be the same cause.

  4. apiraino commented on Dec 12, 2025

    @apiraino
    Contributor

    The bisection points to #149072
    cc: @chenyukang

    But in reality this is another occurrence of the beta regression originated in #142390
    cc: @cjgillot

    @rustbot label +L-unused_assignments

  5. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Dec 12, 2025
  6. self-assigned this
    on Dec 12, 2025
  7. added 2 commits that reference this issue on Jan 18, 2026
    d0745c8
    0331284
  8. added a commit that references this issue on Jan 18, 2026
    a4ae3dd
  9. removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jan 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.L-unused_assignmentsLint: unused_assignmentsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-untriagedUntriaged performance or correctness regression.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions