rust-lang / rust-lang/rust-clippy

Diverging subexpression lint should not fire on `todo!()`

Open
#10,243 7 comments 8 reactions 1 assignee View on GitHub

@alex-semenyuk is already working on this.

Since Jan 29, 2023.

C-bug I-false-positive
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

For incomplete code, it is not that helpful to point out that a subexpression diverges. I suggest suppressing the lint warning when the diverging subexpression is an application of the todo!() macro.

Lint Name

diverging_sub_expression

Reproducer

I tried this code:

#![allow(unused)]

fn main() {
  let x: u32 = todo!();
  println!("{x}");
}

I saw this happen:

warning: sub-expression diverges
 --> src/main.rs:4:16
  |
4 |   let x: u32 = todo!();
  |                ^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#diverging_sub_expression
  = note: `#[warn(clippy::diverging_sub_expression)]` on by default
  = note: this warning originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info)

I expected to see this happen: No warning

Version
rustc 1.68.0-nightly (3020239de 2023-01-09)
binary: rustc
commit-hash: 3020239de947ec52677e9b4e853a6a9fc073d1f9
commit-date: 2023-01-09
host: x86_64-unknown-linux-gnu
release: 1.68.0-nightly
LLVM version: 15.0.6
Additional Labels

No response

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.