We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
make_binop
1 parent e0a77a0 commit 0fbcd7aCopy full SHA for 0fbcd7a
clippy_lints/src/loops.rs
@@ -844,7 +844,7 @@ impl std::ops::Sub for &MinifyingSugg<'static> {
844
fn sub(self, rhs: &MinifyingSugg<'static>) -> MinifyingSugg<'static> {
845
match (self.as_str(), rhs.as_str()) {
846
(_, "0") => self.clone(),
847
- ("0", _) => MinifyingSugg(sugg::make_unop("-", rhs.0.clone())),
+ ("0", _) => MinifyingSugg(-(rhs.0.clone())),
848
(x, y) if x == y => MinifyingSugg::non_paren("0"),
849
(_, _) => MinifyingSugg(&self.0 - &rhs.0),
850
}
@@ -867,7 +867,7 @@ impl std::ops::Sub<&MinifyingSugg<'static>> for MinifyingSugg<'static> {
867
868
869
(_, "0") => self,
870
871
872
(_, _) => MinifyingSugg(self.0 - &rhs.0),
873
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> {
@@ -350,6 +350,13 @@ impl Sub for &Sugg<'_> {
350
forward_binop_impls_to_ref!(impl Add, add for Sugg<'_>, type Output = Sugg<'static>);
351
forward_binop_impls_to_ref!(impl Sub, sub for Sugg<'_>, type Output = Sugg<'static>);
352
353
+impl Neg for Sugg<'_> {
354
+ type Output = Sugg<'static>;
355
+ fn neg(self) -> Sugg<'static> {
356
+ make_unop("-", self)
357
+ }
358
+}
359
+
360
impl Not for Sugg<'_> {
361
type Output = Sugg<'static>;
362
fn not(self) -> Sugg<'static> {
0 commit comments