-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied
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
DianaNites
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied