rust-lang / rust-lang/rust-clippy

needless_return doesn't trigger properly with tracing::instrument

Open
#13,577 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Summary

needless_return fails to trigger when the function has the macro attribute of #[tracing::instrument]. But it would trigger if the macro is expanded.

Lint Name

needless_return

Reproducer

Here is a link to the playground with the issue:

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=a6c39f2417be3c882ccff98c20f4ca5c

#[tracing::instrument]
fn foo() -> Result<Option<i32>, i32> {
    let res = Ok(42);
    match res {
        Ok(v) => Ok(Some(v)),
        Err(-1) => {
            return Err(-2);
        }
        Err(val) => return Err(val),
    }
}
Version

rustc 1.82.0 (f6e511eec 2024-10-15)
binary: rustc
commit-hash: f6e511eec7342f59a25f7c0534f1dbea00d01b14
commit-date: 2024-10-15
host: x86_64-unknown-linux-gnu
release: 1.82.0
LLVM version: 19.1.1

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 running the linked Rust Playground reproducer and inspecting the needless_return lint around its handling of functions with #[tracing::instrument]. Trace how the attribute affects linting, then add coverage for this case. Done means the lint triggers for the reproduced code without incorrectly flagging the other branches.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.