Skip to content

manual_unwrap_or_else

Default: Enabled

Source Code

What it does

Finds patterns that reimplement Option::unwrap_or_else or Result::unwrap_or_else. Triggers when the value returned upon None or Err doesn't implement Drop.

Example

cairo
// This struct does not implement `Drop`, so it cannot be used in `manual_unwrap_or`.
struct Struct {
    x: felt252
}

let foo: Option<Struct> = None;
match foo {
    Some(v) => v,
    None => Struct { x: 0x0 },
};

Can be simplified to:

cairo
let foo: Option<i32> = None;
foo.unwrap_or_else(|| Struct { x: 0x0 });