about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThibsG <Thibs@debian.com>2020-11-02 18:03:16 +0100
committerThibsG <Thibs@debian.com>2020-11-05 09:14:20 +0100
commitf83762b79cf23bfa91d77d6f04ec2b87b2159b07 (patch)
treeb93a61daa838876ef247850a129a100693ece132
parentce98468158318a47f6bab3707d348e116451ad39 (diff)
downloadrust-f83762b79cf23bfa91d77d6f04ec2b87b2159b07.tar.gz
rust-f83762b79cf23bfa91d77d6f04ec2b87b2159b07.zip
Skip rustfmt as it is wanted for this test
-rw-r--r--clippy_lints/src/reference.rs23
-rw-r--r--clippy_lints/src/try_err.rs6
-rw-r--r--tests/ui/deref_addrof.fixed1
-rw-r--r--tests/ui/deref_addrof.rs1
-rw-r--r--tests/ui/deref_addrof.stderr4
5 files changed, 14 insertions, 21 deletions
diff --git a/clippy_lints/src/reference.rs b/clippy_lints/src/reference.rs
index 8646d616735..35a1310d68b 100644
--- a/clippy_lints/src/reference.rs
+++ b/clippy_lints/src/reference.rs
@@ -1,11 +1,10 @@
 use crate::utils::{in_macro, snippet_opt, snippet_with_applicability, span_lint_and_sugg};
 use if_chain::if_chain;
-use rustc_ast::ast::{Expr, ExprKind, UnOp, Mutability};
+use rustc_ast::ast::{Expr, ExprKind, Mutability, UnOp};
 use rustc_errors::Applicability;
 use rustc_lint::{EarlyContext, EarlyLintPass};
 use rustc_session::{declare_lint_pass, declare_tool_lint};
 use rustc_span::BytePos;
-// use rustc_span::source_map::{BytePos, Span};
 
 declare_clippy_lint! {
     /// **What it does:** Checks for usage of `*&` and `*&mut` in expressions.
@@ -53,31 +52,29 @@ impl EarlyLintPass for DerefAddrOf {
                         // Remove leading whitespace from the given span
                         // e.g: ` $visitor` turns into `$visitor`
                         let trim_leading_whitespaces = |span| {
-                            if let Some(start_no_whitespace) = snippet_opt(cx, span).and_then(|snip| {
+                            snippet_opt(cx, span).and_then(|snip| {
+                                #[allow(clippy::cast_possible_truncation)]
                                 snip.find(|c: char| !c.is_whitespace()).map(|pos| {
                                     span.lo() + BytePos(pos as u32)
                                 })
-                            }) {
-                                e.span.with_lo(start_no_whitespace)
-                            } else {
-                                span
-                            }
+                            }).map_or(span, |start_no_whitespace| e.span.with_lo(start_no_whitespace))
                         };
 
                         let rpos = if *mutability == Mutability::Mut {
                             macro_source.rfind("mut").expect("already checked this is a mutable reference") + "mut".len()
                         } else {
-                            macro_source.rfind("&").expect("already checked this is a reference") + "&".len()
+                            macro_source.rfind('&').expect("already checked this is a reference") + "&".len()
                         };
+                        #[allow(clippy::cast_possible_truncation)]
                         let span_after_ref = e.span.with_lo(BytePos(e.span.lo().0 + rpos as u32));
                         let span = trim_leading_whitespaces(span_after_ref);
-                        snippet_with_applicability(cx, span, "_", &mut applicability).to_string()
+                        snippet_with_applicability(cx, span, "_", &mut applicability)
                     } else {
-                        snippet_with_applicability(cx, e.span, "_", &mut applicability).to_string()
+                        snippet_with_applicability(cx, e.span, "_", &mut applicability)
                     }
                 } else {
-                    snippet_with_applicability(cx, addrof_target.span, "_", &mut applicability).to_string()
-                };
+                    snippet_with_applicability(cx, addrof_target.span, "_", &mut applicability)
+                }.to_string();
                 span_lint_and_sugg(
                     cx,
                     DEREF_ADDROF,
diff --git a/clippy_lints/src/try_err.rs b/clippy_lints/src/try_err.rs
index e6d8e7521a8..9c1185d30f2 100644
--- a/clippy_lints/src/try_err.rs
+++ b/clippy_lints/src/try_err.rs
@@ -92,13 +92,9 @@ impl<'tcx> LateLintPass<'tcx> for TryErr {
 
                 let expr_err_ty = cx.typeck_results().expr_ty(err_arg);
 
-                // println!("\n\n{:?}", in_macro(expr.span));
-                // println!("{:#?}", snippet(cx, err_arg.span, "_"));
                 let origin_snippet = if err_arg.span.from_expansion() && !in_macro(expr.span) {
-                    // println!("from expansion");
                     snippet_with_macro_callsite(cx, err_arg.span, "_")
                 } else {
-                    // println!("just a snippet");
                     snippet(cx, err_arg.span, "_")
                 };
                 let suggestion = if err_ty == expr_err_ty {
@@ -106,8 +102,6 @@ impl<'tcx> LateLintPass<'tcx> for TryErr {
                 } else {
                     format!("return {}{}.into(){}", prefix, origin_snippet, suffix)
                 };
-                // println!("origin_snippet: {:#?}", origin_snippet);
-                // println!("suggestion: {:#?}", suggestion);
 
                 span_lint_and_sugg(
                     cx,
diff --git a/tests/ui/deref_addrof.fixed b/tests/ui/deref_addrof.fixed
index 689e9d55223..0795900558b 100644
--- a/tests/ui/deref_addrof.fixed
+++ b/tests/ui/deref_addrof.fixed
@@ -38,6 +38,7 @@ fn main() {
     let b = *aref;
 }
 
+#[rustfmt::skip]
 macro_rules! m {
     ($visitor: expr) => {
         $visitor
diff --git a/tests/ui/deref_addrof.rs b/tests/ui/deref_addrof.rs
index 57effce5d12..60c4318601b 100644
--- a/tests/ui/deref_addrof.rs
+++ b/tests/ui/deref_addrof.rs
@@ -38,6 +38,7 @@ fn main() {
     let b = **&aref;
 }
 
+#[rustfmt::skip]
 macro_rules! m {
     ($visitor: expr) => {
         *& $visitor
diff --git a/tests/ui/deref_addrof.stderr b/tests/ui/deref_addrof.stderr
index 52c1f7d1da8..e85b30fa56e 100644
--- a/tests/ui/deref_addrof.stderr
+++ b/tests/ui/deref_addrof.stderr
@@ -49,7 +49,7 @@ LL |     let b = **&aref;
    |              ^^^^^^ help: try this: `aref`
 
 error: immediately dereferencing a reference
-  --> $DIR/deref_addrof.rs:43:9
+  --> $DIR/deref_addrof.rs:44:9
    |
 LL |         *& $visitor
    |         ^^^^^^^^^^^ help: try this: `$visitor`
@@ -60,7 +60,7 @@ LL |         m!(self)
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: immediately dereferencing a reference
-  --> $DIR/deref_addrof.rs:50:9
+  --> $DIR/deref_addrof.rs:51:9
    |
 LL |         *& mut $visitor
    |         ^^^^^^^^^^^^^^^ help: try this: `$visitor`