about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Wright <mikerite@lavabit.com>2019-09-25 06:20:40 +0200
committerMichael Wright <mikerite@lavabit.com>2019-09-25 06:40:04 +0200
commit89cdd26e71ecc7778f05b06c8878d641a258519a (patch)
tree96457361bf8a92178a725da3f377e10e032254f2
parent0cc48ad9f9bddf8fda492a2ab2485dfee69b8cf9 (diff)
downloadrust-89cdd26e71ecc7778f05b06c8878d641a258519a.tar.gz
rust-89cdd26e71ecc7778f05b06c8878d641a258519a.zip
Refactor `booleans`
Inline `snip (..)` function
-rw-r--r--clippy_lints/src/booleans.rs19
1 files changed, 11 insertions, 8 deletions
diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs
index a85b77475e5..dafa34dec1d 100644
--- a/clippy_lints/src/booleans.rs
+++ b/clippy_lints/src/booleans.rs
@@ -183,7 +183,7 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
                         self.output.push_str(&str)
                     } else {
                         self.output.push('!');
-                        let snip = snip(self.cx, terminal)?;
+                        let snip = snippet_opt(self.cx, terminal.span)?;
                         self.output.push_str(&snip);
                     }
                 },
@@ -215,7 +215,7 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
                 }
             },
             &Term(n) => {
-                let snip = snip(self.cx, self.terminals[n as usize])?;
+                let snip = snippet_opt(self.cx, self.terminals[n as usize].span)?;
                 self.output.push_str(&snip);
             },
         }
@@ -223,10 +223,6 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
     }
 }
 
-fn snip(cx: &LateContext<'_, '_>, e: &Expr) -> Option<String> {
-    snippet_opt(cx, e.span)
-}
-
 fn simplify_not(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<String> {
     match &expr.node {
         ExprKind::Binary(binop, lhs, rhs) => {
@@ -243,7 +239,14 @@ fn simplify_not(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<String> {
                 BinOpKind::Ge => Some(" < "),
                 _ => None,
             }
-            .and_then(|op| Some(format!("{}{}{}", snip(cx, lhs)?, op, snip(cx, rhs)?)))
+            .and_then(|op| {
+                Some(format!(
+                    "{}{}{}",
+                    snippet_opt(cx, lhs.span)?,
+                    op,
+                    snippet_opt(cx, rhs.span)?
+                ))
+            })
         },
         ExprKind::MethodCall(path, _, args) if args.len() == 1 => {
             let type_of_receiver = cx.tables.expr_ty(&args[0]);
@@ -255,7 +258,7 @@ fn simplify_not(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<String> {
                 .cloned()
                 .flat_map(|(a, b)| vec![(a, b), (b, a)])
                 .find(|&(a, _)| a == path.ident.name.as_str())
-                .and_then(|(_, neg_method)| Some(format!("{}.{}()", snip(cx, &args[0])?, neg_method)))
+                .and_then(|(_, neg_method)| Some(format!("{}.{}()", snippet_opt(cx, args[0].span)?, neg_method)))
         },
         _ => None,
     }