rust-lang / rust-lang/rust-clippy

`ignored-unit-patterns` ignores mutability

Open
#11,754 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-positive I-suggestion-causes-error
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

EDIT

Using the following flags

--force-warn clippy::ignored-unit-patterns

this code:

//@ edition:2021
//@ check-pass
#![feature(coroutines, stmt_expr_attributes)]

fn main() {
    let x = &mut ();
    || {
        let _c = #[coroutine]
        || yield *&mut *x;
        || _ = &mut *x;
    };
}

caused the following diagnostics:

    Checking _issue-110929-coroutine-conflict-error-ice v0.1.0 (/tmp/icemaker_global_tempdir.EuHmIYit9wj1/icemaker_clippyfix_tempdir.wfNVWxul8RLV/_issue-110929-coroutine-conflict-error-ice)
warning: matching over `()` is more explicit
  --> src/main.rs:10:12
   |
10 |         || _ = &mut *x;
   |            ^ help: use `()` instead of `_`: `()`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ignored_unit_patterns
   = note: requested on the command line with `--force-warn clippy::ignored-unit-patterns`

warning: `_issue-110929-coroutine-conflict-error-ice` (bin "_issue-110929-coroutine-conflict-error-ice") generated 1 warning (run `cargo clippy --fix --bin "_issue-110929-coroutine-conflict-error-ice"` to apply 1 suggestion)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s

However after applying these diagnostics, the resulting code:

//@ edition:2021
//@ check-pass
#![feature(coroutines, stmt_expr_attributes)]

fn main() {
    let x = &mut ();
    || {
        let _c = #[coroutine]
        || yield *&mut *x;
        || () = &mut *x;
    };
}

no longer compiled:

    Checking _issue-110929-coroutine-conflict-error-ice v0.1.0 (/tmp/icemaker_global_tempdir.EuHmIYit9wj1/icemaker_clippyfix_tempdir.wfNVWxul8RLV/_issue-110929-coroutine-conflict-error-ice)
error[E0308]: mismatched types
  --> src/main.rs:10:12
   |
10 |         || () = &mut *x;
   |            ^^   ------- this expression has type `&mut ()`
   |            |
   |            expected `&mut ()`, found `()`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `_issue-110929-coroutine-conflict-error-ice` (bin "_issue-110929-coroutine-conflict-error-ice") due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `_issue-110929-coroutine-conflict-error-ice` (bin "_issue-110929-coroutine-conflict-error-ice" test) due to 1 previous error

Version:

rustc 1.90.0-nightly (5e749eb66 2025-06-29)
binary: rustc
commit-hash: 5e749eb66f93ee998145399fbdde337e57cd72ef
commit-date: 2025-06-29
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.7

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the diagnostic with the provided Rust snippet and the ignored-unit-patterns lint, then inspect the lint's handling of mutable patterns. The fix is done when the suggested replacement preserves the required mutability and the resulting code compiles without the original warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.