Skip to content

question-mark usage suggested in const fn #9175

New issue

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

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

Already on GitHub? # to your account

Closed
urben1680 opened this issue Jul 14, 2022 · 1 comment · Fixed by #9487
Closed

question-mark usage suggested in const fn #9175

urben1680 opened this issue Jul 14, 2022 · 1 comment · Fixed by #9487
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing good first issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@urben1680
Copy link

urben1680 commented Jul 14, 2022

Summary

Clippy suggests to use the ? operator in a const fn where that operator is not allowed.

I hope I did this correctly, it is my first issue I fill in. Thanks for the great work on Clippy!

Lint Name

question_mark

Reproducer

I tried this code:

const fn clippy_false_positive(option: Option<()>) -> Option<()>{
    if option.is_none(){
        return None;
    }
    //stuff
    Some(())
}

I saw this happen:

warning: this block may be rewritten with the `?` operator
 --> src/main.rs:2:5
  |
2 | /     if option.is_none(){
3 | |         return None;
4 | |     }
  | |_____^ help: replace it with: `option?;`
  |
  = note: `#[warn(clippy::question_mark)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#question_mark

warning: `playground` (bin "playground") generated 1 warning

I expected to not see this to happen as the ? operator is not allowed in a const fn. Trying to do so results in:

error[[E0658]](https://doc.rust-lang.org/stable/error-index.html#E0658): `?` is not allowed in a `const fn`
 --> src/main.rs:2:5
  |
2 |     option?;
  |     ^^^^^^^
  |
  = note: [see issue #74935 <https://github.com/rust-lang/rust/issues/74935>](https://github.com/rust-lang/rust/issues/74935) for more information

For more information about this error, try `rustc --explain E0658`.

rust-lang/rust#74935

Version

rust: 1.62.0
clippy 0.1.64 (2022-07-13 87588a2)

Additional Labels

No response

@urben1680 urben1680 added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Jul 14, 2022
@Alexendoo Alexendoo added the good first issue These issues are a good way to get started with Clippy label Jul 14, 2022
@yerke
Copy link
Contributor

yerke commented Jul 17, 2022

@rustbot claim

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: Clippy is not doing the correct thing good first issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants