rust-lang / rust-lang/rust-clippy
semicolon_if_nothing_returned lint when future type inference fails with the semicolon
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
Using semicolon_if_nothing_returned can lead to clippy complaining that there ought to be a semicolon, in a location where placing one causes type inference to fail.
Lint Name
semicolon_if_nothing_returned
Reproducer
I tried this code:
#![warn(clippy::semicolon_if_nothing_returned)]
pub async fn something() {
if true {
eprintln!("hi");
} else {
futures::future::pending().await
}
}
I saw this happen:
7 | futures::future::pending().await
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `futures::future::pending().await;`
Adopting the suggestion causes:
7 | futures::future::pending().await;
| ^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T` declared on the function `pending`
I expected to see this happen:
No complaint.
Version
Rust 1.64.0 stable on the playground.
Additional Labels
@rustbot label +I-suggestion-causes-error
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the semicolon_if_nothing_returned lint implementation and its tests, then reproduce the reported Rust 1.64 example from the issue or the linked Playground. Check how the lint handles futures::future::pending().await when type inference depends on the expression value. Done means the lint no longer suggests a semicolon that makes this reproducer fail to compile, with regression coverage for the case.
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
- Clearly specified
- Newbie friendliness
- 55/100