From e76eac4b18fde208f1df7d1ad653354cf35a6724 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Fri, 27 Oct 2017 10:51:43 +0200 Subject: [PATCH] Fix dogfood --- clippy_lints/src/if_not_else.rs | 5 ++++- clippy_lints/src/non_expressive_names.rs | 3 +++ clippy_lints/src/transmute.rs | 14 +++++++------- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/if_not_else.rs b/clippy_lints/src/if_not_else.rs index 66f2778f2159..3cdffbf82ae4 100644 --- a/clippy_lints/src/if_not_else.rs +++ b/clippy_lints/src/if_not_else.rs @@ -4,7 +4,7 @@ use rustc::lint::*; use syntax::ast::*; -use utils::span_help_and_lint; +use utils::{span_help_and_lint, in_external_macro}; /// **What it does:** Checks for usage of `!` or `!=` in an if condition with an /// else branch. @@ -47,6 +47,9 @@ impl LintPass for IfNotElse { impl EarlyLintPass for IfNotElse { fn check_expr(&mut self, cx: &EarlyContext, item: &Expr) { + if in_external_macro(cx, item.span) { + return; + } if let ExprKind::If(ref cond, _, Some(ref els)) = item.node { if let ExprKind::Block(..) = els.node { match cond.node { diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index 478b4c3e0eb6..6cbeea8214d0 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -74,6 +74,9 @@ const WHITELIST: &[&[&str]] = &[ &["lhs", "rhs"], &["tx", "rx"], &["set", "get"], + &["args", "arms"], + &["qpath", "path"], + &["lit", "lint"], ]; struct SimilarNamesNameVisitor<'a: 'b, 'tcx: 'a, 'b>(&'b mut SimilarNamesLocalVisitor<'a, 'tcx>); diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index f816ddc464f5..fde6abe48af0 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -214,7 +214,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { e.span, &format!("transmute from a type (`{}`) to a pointer to that type (`{}`)", from_ty, to_ty), ), - (&ty::TyRawPtr(from_pty), &ty::TyRef(_, to_rty)) => span_lint_and_then( + (&ty::TyRawPtr(from_pty), &ty::TyRef(_, to_ref_ty)) => span_lint_and_then( cx, TRANSMUTE_PTR_TO_REF, e.span, @@ -226,16 +226,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { ), |db| { let arg = sugg::Sugg::hir(cx, &args[0], ".."); - let (deref, cast) = if to_rty.mutbl == Mutability::MutMutable { + let (deref, cast) = if to_ref_ty.mutbl == Mutability::MutMutable { ("&mut *", "*mut") } else { ("&*", "*const") }; - let arg = if from_pty.ty == to_rty.ty { + let arg = if from_pty.ty == to_ref_ty.ty { arg } else { - arg.as_ty(&format!("{} {}", cast, get_type_snippet(cx, qpath, to_rty.ty))) + arg.as_ty(&format!("{} {}", cast, get_type_snippet(cx, qpath, to_ref_ty.ty))) }; db.span_suggestion(e.span, "try", sugg::make_unop(deref, arg).to_string()); @@ -299,7 +299,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute { /// the type's `ToString` implementation. In weird cases it could lead to types /// with invalid `'_` /// lifetime, but it should be rare. -fn get_type_snippet(cx: &LateContext, path: &QPath, to_rty: Ty) -> String { +fn get_type_snippet(cx: &LateContext, path: &QPath, to_ref_ty: Ty) -> String { let seg = last_path_segment(path); if_chain! { if let Some(ref params) = seg.parameters; @@ -307,9 +307,9 @@ fn get_type_snippet(cx: &LateContext, path: &QPath, to_rty: Ty) -> String { if let Some(to_ty) = params.types.get(1); if let TyRptr(_, ref to_ty) = to_ty.node; then { - return snippet(cx, to_ty.ty.span, &to_rty.to_string()).to_string(); + return snippet(cx, to_ty.ty.span, &to_ref_ty.to_string()).to_string(); } } - to_rty.to_string() + to_ref_ty.to_string() }