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

clippy incorrectly suggests rewriting an if-let-else #303

Closed
nicholasbishop opened this issue Oct 25, 2021 · 1 comment · Fixed by #312
Closed

clippy incorrectly suggests rewriting an if-let-else #303

nicholasbishop opened this issue Oct 25, 2021 · 1 comment · Fixed by #312

Comments

@nicholasbishop
Copy link
Member

nicholasbishop commented Oct 25, 2021

CI is currently failing with a clippy error:

error: this if-let-else may be rewritten with the `?` operator
Error:   --> src/alloc.rs:64:23
   |
64 |               let ptr = if let Ok(ptr) = boot_services()
   |  _______________________^
65 | |                 .as_ref()
66 | |                 .allocate_pool(mem_ty, size + align)
67 | |                 .warning_as_error()
...  |
71 | |                 return ptr::null_mut();
72 | |             };
   | |_____________^
   |
note: the lint level is defined here
  --> src/lib.rs:35:9
   |
35 | #![deny(clippy::all)]
   |         ^^^^^^^^^^^
   = note: `#[deny(clippy::question_mark)]` implied by `#[deny(clippy::all)]`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#question_mark
help: replace it with
   |
64 ~             let ptr = boot_services()
65 +                 .as_ref()
66 +                 .allocate_pool(mem_ty, size + align)
67 ~                 .warning_as_error()?;
   |

Initially I thought, "neat, I didn't know ? works with pointer types". Turns out it doesn't, clippy is just wrong. I'm assuming this is the same issue as reported in rust-lang/rust-clippy#7859, which currently has a PR up for review. I think for now we can disable clippy on the block of code, and leave this issue open to revert the change once clippy is fixed. And if that PR doesn't fix it, we should open a new clippy issue.

nicholasbishop added a commit to nicholasbishop/uefi-rs that referenced this issue Oct 25, 2021
Clippy says this code can be rewritten with a `?`, but the suggested
change is not valid.

Tracked in rust-osdev#303 to revert
this change once clippy is fixed.
nicholasbishop added a commit to nicholasbishop/uefi-rs that referenced this issue Oct 25, 2021
Clippy says this code can be rewritten with a `?`, but the suggested
change is not valid.

Tracked in rust-osdev#303 to revert
this change once clippy is fixed.
nicholasbishop added a commit that referenced this issue Oct 25, 2021
Clippy says this code can be rewritten with a `?`, but the suggested
change is not valid.

Tracked in #303 to revert
this change once clippy is fixed.
@nicholasbishop
Copy link
Member Author

Latest nightly is still failing the same way, so filed a new issue for it: rust-lang/rust-clippy#7910

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant