Skip to content

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

Closed
@nicholasbishop

Description

@nicholasbishop

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions