Open
Description
Summary
The needless_return
lint does not recognize cfg
'd out code located after the return, which makes the return
actually required, and where removing it is invalid and will fail to compile.
Lint Name
needless_return
Reproducer
I tried this code:
fn _bar() -> u64 {
return 456;
#[cfg(no)]
123
}
I saw this happen:
warning: unneeded `return` statement
--> src/lib.rs:17:5
|
17 | return 456;
| ^^^^^^^^^^
I expected to see this happen:
No warning. Following the suggestion will fail to compile, and give further incorrect advice.
error: expected `;`, found `#`
--> src/lib.rs:17:8
|
17 | 456
| ^ help: add `;` here
18 |
19 | #[cfg(no)]
| - unexpected token
Version
rustc 1.87.0-nightly (1aeb99d24 2025-03-19)
binary: rustc
commit-hash: 1aeb99d248e1b0069110cb03c6f1dcc7b36fd7f3
commit-date: 2025-03-19
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity