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

Possible false positive: unnecessary unwrap in assert! #5131

Closed
CreepySkeleton opened this issue Feb 3, 2020 · 0 comments · Fixed by #5132
Closed

Possible false positive: unnecessary unwrap in assert! #5131

CreepySkeleton opened this issue Feb 3, 2020 · 0 comments · Fixed by #5132
Labels
C-bug Category: Clippy is not doing the correct thing T-macros Type: Issues with macros and macro expansion

Comments

@CreepySkeleton
Copy link

CreepySkeleton commented Feb 3, 2020

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)
@flip1995 flip1995 added C-bug Category: Clippy is not doing the correct thing T-macros Type: Issues with macros and macro expansion labels Feb 3, 2020
bors added a commit that referenced this issue Feb 6, 2020
Do not lint `unnecessary_unwrap` in external macros

Fixes #5131

I think we shouldn't lint `{panicking, unnecessary}_unwrap` in macros, not just `assert!`.

changelog: Fix false positive in `unnecessary_unwrap`
@bors bors closed this as completed in a3135ba Feb 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing T-macros Type: Issues with macros and macro expansion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants