Skip to content

unused_unit reports confusing suggestion for trait objects with unnecessary parenthesisin the type #15176

@sdroege

Description

@sdroege

Summary

See https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=6e4227dddcac03952423666db31f2780

Lint Name

unused_unit

Reproducer

I tried this code:

fn main() {
    let _x: Box<&dyn (FnMut(i32))> = todo!();
}

I saw this happen:

warning: unneeded unit return type
 --> src/main.rs:2:23
  |
2 |     let _x: Box<&dyn (FnMut(i32))> = todo!();
  |                       ^^^^^^^^^^ help: remove the `-> ()`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit
  = note: `#[warn(clippy::unused_unit)]` on by default

I expected to see this happen: A suggestion to remove the unnecessary parenthesis

Version

rustc 1.88.0 (6b00bc388 2025-06-23)
binary: rustc
commit-hash: 6b00bc3880198600130e1cf62b8f8a93494488cc
commit-date: 2025-06-23
host: x86_64-unknown-linux-gnu
release: 1.88.0
LLVM version: 20.1.5

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions