rust-lang / rust-lang/rust-clippy

Warn about `Result`s only used in println!()

Open
#2,529 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

E-medium L-correctness T-middle
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

A few times now, I've come across tests where a result wasn't verified. Most often, this happens when the result is printed for debugging purposes. See sample code below or have a look at this this real-word example.

While I haven't seen it, I guess this could also be an issue outside of tests or with error!(), warn!(), etc.

I believe it would make since to emit a warning in such cases.

Sample:

some_fn() -> Result<…, …> {
    unimplemented!()
}

#[test]
fn a_test() {
    …
    let result = some_fn();
    println!("result: {:?}", result);   // This compiles with no warning because the `Result` is used by println!()
}

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 from the sample Rust code and investigate how Clippy currently handles unused Result values when they are passed to println!(). Determine the intended scope for println!, error!, warn!, tests, and non-test code; done means the relevant cases emit a warning without incorrectly flagging intentionally handled Results.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.