rust-lang / rust-lang/rust-clippy

semicolon_if_nothing_returned lint when future type inference fails with the semicolon

Open
#9,729 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-positive I-suggestion-causes-error
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.

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=805cabba28a97e36a701643678ad26fb

Version
Rust 1.64.0 stable on the playground.
Additional Labels

@rustbot label +I-suggestion-causes-error

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.