Skip to content

Regression (?) in unused_assignments lint when Drop is implemented #148418

@iliakonnov

Description

@iliakonnov

I've only tried two versions available on rust playground.

I'm not quite sure what behaviour is better or worse, but a change between stable and beta is at least worth mentioning in changelogs. I have not found any relevant issues about unused_assignments lint change, so I believe this may be in fact unintended.

I've noticed that when my cargo check have failed in CI (running stable), but succeeded locally (running nightly).

Code

I tried this code:

struct Foo;

impl Drop for Foo {
    fn drop(&mut self) {}
}

fn main() {
    let mut foo = Foo;
    foo = Foo;
}

I expected to see this happen:

warning: variable `foo` is assigned to, but never used
 --> src/main.rs:8:13
  |
8 |     let mut foo = Foo;
  |             ^^^
  |
  = note: consider using `_foo` instead
  = note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default
help: you might have meant to pattern match on the similarly named struct `Foo` (notice the capitalization)
  |
8 -     let mut foo = Foo;
8 +     let mut Foo = Foo;
  |

warning: value assigned to `foo` is never read
 --> src/main.rs:9:5
  |
9 |     foo = Foo;
  |     ^^^
  |
  = help: maybe it is overwritten before being read?
  = note: `#[warn(unused_assignments)]` (part of `#[warn(unused)]`) on by default

Instead, this happened: (no warnings)

   Compiling playground v0.0.1 (/playground)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.46s
     Running `target/debug/playground`

Version it worked on

It most recently worked on: 1.91.0

Version with regression

1.92.0-beta.2 (2025-10-31 0a411606e9cc00588c83)

@rustbot modify labels: +regression-from-stable-to-beta -regression-untriaged

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-prioritizeIssue: Indicates that prioritization has been requested for this issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions