Skip to content

ignored-unit-patterns suggestion is missing a reference #15187

@matthiaskrgr

Description

@matthiaskrgr

Using the following flags

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

this code:

type LifetimeBound<'r> = &'r dyn Fn(&'r ());

fn main() {
	let capture = String::new();
	let func = move |_| drop(&capture);
	let func_ref_bound: LifetimeBound = &func;
	drop(func_ref_bound);
}

caused the following diagnostics:

    Checking _snippet_1 v0.1.0 (/tmp/icemaker_global_tempdir.IbV1PR0WiGNQ/icemaker_clippyfix_tempdir.hkoPnYXFL2QE/_snippet_1)
warning: matching over `()` is more explicit
 --> src/main.rs:5:19
  |
5 |     let func = move |_| drop(&capture);
  |                      ^ 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: `_snippet_1` (bin "_snippet_1") generated 1 warning (run `cargo clippy --fix --bin "_snippet_1"` to apply 1 suggestion)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s

However after applying these diagnostics, the resulting code:

type LifetimeBound<'r> = &'r dyn Fn(&'r ());

fn main() {
	let capture = String::new();
	let func = move |()| drop(&capture);
	let func_ref_bound: LifetimeBound = &func;
	drop(func_ref_bound);
}

no longer compiled:

    Checking _snippet_1 v0.1.0 (/tmp/icemaker_global_tempdir.IbV1PR0WiGNQ/icemaker_clippyfix_tempdir.hkoPnYXFL2QE/_snippet_1)
error[E0631]: type mismatch in closure arguments
 --> src/main.rs:6:38
  |
5 |     let func = move |()| drop(&capture);
  |                --------- found signature defined here
6 |     let func_ref_bound: LifetimeBound = &func;
  |                                         ^^^^^ expected due to this
  |
  = note: expected closure signature `fn(&()) -> _`
             found closure signature `fn(()) -> _`
  = note: required for the cast from `&{closure@src/main.rs:5:13: 5:22}` to `&dyn std::ops::Fn(&())`
help: consider adjusting the signature so it borrows its argument
  |
5 |     let func = move |&()| drop(&capture);
  |                      +

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

Version:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions