#[allow(clippy::needless_question_mark)] does not seems to prevent the lint from firing when it's applied on the last statement of a block, and is implicitly returned.
It's properly taken into account when using #![allow(clippy::needless_question_mark)] on the whole block, or when assigning let _ = Some(a?);.
Lint Name
needless_question_mark
Reproducer
I tried this code:
#![deny(clippy::all)]
fn some_function() -> Option<()> {
let a = Some(());
#[allow(clippy::needless_question_mark)]
Some(a?)
}
I saw this happen:
error: question mark operator is useless here
--> src/lib.rs:6:5
|
6 | Some(a?)
| ^^^^^^^^ help: try removing question mark and `Some()`: `a`
|
note: the lint level is defined here
--> src/lib.rs:1:9
|
1 | #![deny(clippy::all)]
| ^^^^^^^^^^^
= note: `#[deny(clippy::needless_question_mark)]` implied by `#[deny(clippy::all)]`
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_question_mark
I expected to see this happen:
No error since this lint is disabled.
In this case body seems to be checked when triggered, so it looks like that it will be difficult to fix this. It would be put #[allow(clippy::needless_question_mark)] on the block.
Summary
#[allow(clippy::needless_question_mark)]
does not seems to prevent the lint from firing when it's applied on the last statement of a block, and is implicitly returned. It's properly taken into account when using#![allow(clippy::needless_question_mark)]
on the whole block, or when assigninglet _ = Some(a?);
.Lint Name
needless_question_mark
Reproducer
I tried this code:
I saw this happen:
I expected to see this happen: No error since this lint is disabled.
Version
Additional Labels
No response