We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
make_binop
1 parent 174065f commit 4418738Copy full SHA for 4418738
clippy_lints/src/loops.rs
@@ -875,7 +875,7 @@ impl std::ops::Sub for &MinifyingSugg<'static> {
875
fn sub(self, rhs: &MinifyingSugg<'static>) -> MinifyingSugg<'static> {
876
match (self.as_str(), rhs.as_str()) {
877
(_, "0") => self.clone(),
878
- ("0", _) => MinifyingSugg(sugg::make_unop("-", rhs.0.clone())),
+ ("0", _) => MinifyingSugg(-(rhs.0.clone())),
879
(x, y) if x == y => MinifyingSugg::non_paren("0"),
880
(_, _) => MinifyingSugg(&self.0 - &rhs.0),
881
}
@@ -898,7 +898,7 @@ impl std::ops::Sub<&MinifyingSugg<'static>> for MinifyingSugg<'static> {
898
899
900
(_, "0") => self,
901
902
903
(_, _) => MinifyingSugg(self.0 - &rhs.0),
904
clippy_lints/src/utils/sugg.rs
@@ -13,7 +13,7 @@ use rustc_span::{BytePos, Pos};
13
use std::borrow::Cow;
14
use std::convert::TryInto;
15
use std::fmt::Display;
16
-use std::ops::{Add, Not, Sub};
+use std::ops::{Add, Neg, Not, Sub};
17
18
/// A helper type to build suggestion correctly handling parenthesis.
19
pub enum Sugg<'a> {
@@ -354,6 +354,13 @@ impl Sub for &Sugg<'_> {
354
forward_binop_impls_to_ref!(impl Add, add for Sugg<'_>, type Output = Sugg<'static>);
355
forward_binop_impls_to_ref!(impl Sub, sub for Sugg<'_>, type Output = Sugg<'static>);
356
357
+impl Neg for Sugg<'_> {
358
+ type Output = Sugg<'static>;
359
+ fn neg(self) -> Sugg<'static> {
360
+ make_unop("-", self)
361
+ }
362
+}
363
+
364
impl Not for Sugg<'_> {
365
type Output = Sugg<'static>;
366
fn not(self) -> Sugg<'static> {
0 commit comments