rust-lang / rust-lang/rust-clippy
needless_return doesn't trigger properly with tracing::instrument
Nobody has claimed this yet.
- 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:
#[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
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 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