Skip to content

unused_unit triggers when the type annotation is needed to compile #14577

@kristoff3r

Description

@kristoff3r

Summary

When running the code snippet from the 2024 edition guide it triggers the unused_unit lint, even though removing the type annotation will make the code stop compiling.

Encountered in bevyengine/bevy#18778

Lint Name

unused_unit

Reproducer

trait Unit {} impl Unit for () {} fn run<R: Unit>(f: impl FnOnce() -> R) { f(); } fn main() { run(|| -> () { todo!() }); }

Output

warning: unneeded unit return type --> src/main.rs:12:11 | 12 | run(|| -> () { 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 

Version

 

Additional Labels

No response

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveI-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