Improve unnecessary_map_or
lint with negated expressions
#13995
Labels
C-enhancement
Category: Enhancement of lints, like adding more cases or adding help messages
C-question
Category: Questions
Description
The
unnecessary_map_or
lint just (almost) caused a bug in one of my projects, due to the way its suggestions work:alacritty/crossfont#72 (comment)
If you take a close look at the suggestion, it's clear that the leading
!
is not part of the suggestion:However my argument is that this mistake is far too easy to make, effectively making this suggestion have an unreasonably high chance to break something. It's possible this might apply to other clippy lints too, I'm not aware of all of them.
Humans are pretty bad at this whole reading thing, so my suggestion would be to explicitly include leading
!
into the expression if possible. I think this would reduce the chance of bugs like this happening. Replacing an entire line is always going to be easier for people than replacing just a part of it.I'm curious if this is something you'd be interested in. This would obviously only work in a best-effort heuristic manner, but I do think it could actually help people and prevent bugs. I have no doubt that sooner or later this would cause bugs otherwise (and maybe it already has).
Version
Additional Labels
@rustbot label +C-enhancement
@rustbot label +C-question
The text was updated successfully, but these errors were encountered: