Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kristoff3r opened this issue Apr 9, 2025 · 1 comment · Fixed by #14609
Closed

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

kristoff3r opened this issue Apr 9, 2025 · 1 comment · Fixed by #14609
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@kristoff3r
Copy link

kristoff3r commented Apr 9, 2025

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

@kristoff3r kristoff3r added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Apr 9, 2025
@profetia
Copy link
Contributor

@rustbot claim

@samueltardieu samueltardieu added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Apr 11, 2025
github-merge-queue bot pushed a commit that referenced this issue Apr 27, 2025
…4609)

Closes #14577.

Migrate this lint to late pass and avoids `unit_never_type_fallback`
since it is no longer permitted in Rust 2024.

changelog: [`unused_unit`] fix wrong suggestions when unit never type
fallback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants