Skip to content

Possible false positive: unnecessary unwrap in assert! #5131

@CreepySkeleton

Description

@CreepySkeleton

I think the warning explains it all:

warning: You checked before that `unwrap_err()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
  --> tests/delimiters.rs:51:32
   |
51 |     assert!(m.is_ok(), "{:?}", m.unwrap_err());
   |             ---------          ^^^^^^^^^^^^^^
   |             |
   |             the check is happening here
   |

   = note: `#[warn(clippy::unnecessary_unwrap)]` on by default

   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_unwrap

I'm not sure if this is intended to act that way, but this is pretty common pattern in tests ("assert success or print the error otherwise).

$ cargo clippy -V
clippy 0.0.212 (69f99e74 2019-12-14)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingT-macrosType: Issues with macros and macro expansion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions