Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

needless_question_mark lint not applied to async fn #8277

Closed
Swatinem opened this issue Jan 14, 2022 · 2 comments · Fixed by #8311
Closed

needless_question_mark lint not applied to async fn #8277

Swatinem opened this issue Jan 14, 2022 · 2 comments · Fixed by #8311
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@Swatinem
Copy link
Contributor

Swatinem commented Jan 14, 2022

Summary

It seems like the needless_question_mark is not correctly applied to async fn, while it is applied to normal functions (obviously), and also async blocks correctly. See the reproduction below.

Lint Name

needless_question_mark

Reproducer

I tried this code:

pub fn normal_fn() -> Result<(), ()> {
    let res = Err(());
    Ok(res?) // warns
}
pub async fn async_fn() -> Result<(), ()> {
    let res = Err(());
    Ok(res?) // does not warn
}
pub fn async_block() -> impl std::future::Future<Output = Result<(), ()>> {
    async move {
        let res = Err(());
        Ok(res?) // warns
    }
}

I expected to see this happen:

All three variants should trigger a needless_question_mark lint.

Instead, this happened:

Only the normal_fn and async_block variants are triggering the lint.

warning: question mark operator is useless here
  --> src/main.rs:47:5
   |
47 |     Ok(res?) // warns
   |     ^^^^^^^^ help: try: `res`
   |
   = note: `#[warn(clippy::needless_question_mark)]` implied by `#[warn(clippy::all)]`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_question_mark

warning: question mark operator is useless here
  --> src/main.rs:56:9
   |
56 |         Ok(res?) // warns
   |         ^^^^^^^^ help: try: `res`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_question_mark

Version

rustc 1.58.0 (02072b482 2022-01-11)
binary: rustc
commit-hash: 02072b482a8b5357f7fb5e5637444ae30e423c40
commit-date: 2022-01-11
host: x86_64-apple-darwin
release: 1.58.0
LLVM version: 13.0.0

and

rustc 1.60.0-nightly (22e491ac7 2022-01-13)
binary: rustc
commit-hash: 22e491ac7ed454d34669151a8b6464cb643c9b41
commit-date: 2022-01-13
host: x86_64-apple-darwin
release: 1.60.0-nightly
LLVM version: 13.0.0
@Swatinem Swatinem added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Jan 14, 2022
@loyd
Copy link

loyd commented Jan 14, 2022

It seems that question_mark also works incorrectly.

@dswij
Copy link
Member

dswij commented Jan 18, 2022

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants