Skip to content

Commit f724b99

Browse files
authored
Merge pull request #2181 from rust-lang-nursery/macro_check
Fix dogfood
2 parents b90523c + e76eac4 commit f724b99

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

clippy_lints/src/if_not_else.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use rustc::lint::*;
55
use syntax::ast::*;
66

7-
use utils::span_help_and_lint;
7+
use utils::{span_help_and_lint, in_external_macro};
88

99
/// **What it does:** Checks for usage of `!` or `!=` in an if condition with an
1010
/// else branch.
@@ -47,6 +47,9 @@ impl LintPass for IfNotElse {
4747

4848
impl EarlyLintPass for IfNotElse {
4949
fn check_expr(&mut self, cx: &EarlyContext, item: &Expr) {
50+
if in_external_macro(cx, item.span) {
51+
return;
52+
}
5053
if let ExprKind::If(ref cond, _, Some(ref els)) = item.node {
5154
if let ExprKind::Block(..) = els.node {
5255
match cond.node {

clippy_lints/src/non_expressive_names.rs

+3
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ const WHITELIST: &[&[&str]] = &[
7474
&["lhs", "rhs"],
7575
&["tx", "rx"],
7676
&["set", "get"],
77+
&["args", "arms"],
78+
&["qpath", "path"],
79+
&["lit", "lint"],
7780
];
7881

7982
struct SimilarNamesNameVisitor<'a: 'b, 'tcx: 'a, 'b>(&'b mut SimilarNamesLocalVisitor<'a, 'tcx>);

clippy_lints/src/transmute.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
214214
e.span,
215215
&format!("transmute from a type (`{}`) to a pointer to that type (`{}`)", from_ty, to_ty),
216216
),
217-
(&ty::TyRawPtr(from_pty), &ty::TyRef(_, to_rty)) => span_lint_and_then(
217+
(&ty::TyRawPtr(from_pty), &ty::TyRef(_, to_ref_ty)) => span_lint_and_then(
218218
cx,
219219
TRANSMUTE_PTR_TO_REF,
220220
e.span,
@@ -226,16 +226,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
226226
),
227227
|db| {
228228
let arg = sugg::Sugg::hir(cx, &args[0], "..");
229-
let (deref, cast) = if to_rty.mutbl == Mutability::MutMutable {
229+
let (deref, cast) = if to_ref_ty.mutbl == Mutability::MutMutable {
230230
("&mut *", "*mut")
231231
} else {
232232
("&*", "*const")
233233
};
234234

235-
let arg = if from_pty.ty == to_rty.ty {
235+
let arg = if from_pty.ty == to_ref_ty.ty {
236236
arg
237237
} else {
238-
arg.as_ty(&format!("{} {}", cast, get_type_snippet(cx, qpath, to_rty.ty)))
238+
arg.as_ty(&format!("{} {}", cast, get_type_snippet(cx, qpath, to_ref_ty.ty)))
239239
};
240240

241241
db.span_suggestion(e.span, "try", sugg::make_unop(deref, arg).to_string());
@@ -299,17 +299,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
299299
/// the type's `ToString` implementation. In weird cases it could lead to types
300300
/// with invalid `'_`
301301
/// lifetime, but it should be rare.
302-
fn get_type_snippet(cx: &LateContext, path: &QPath, to_rty: Ty) -> String {
302+
fn get_type_snippet(cx: &LateContext, path: &QPath, to_ref_ty: Ty) -> String {
303303
let seg = last_path_segment(path);
304304
if_chain! {
305305
if let Some(ref params) = seg.parameters;
306306
if !params.parenthesized;
307307
if let Some(to_ty) = params.types.get(1);
308308
if let TyRptr(_, ref to_ty) = to_ty.node;
309309
then {
310-
return snippet(cx, to_ty.ty.span, &to_rty.to_string()).to_string();
310+
return snippet(cx, to_ty.ty.span, &to_ref_ty.to_string()).to_string();
311311
}
312312
}
313313

314-
to_rty.to_string()
314+
to_ref_ty.to_string()
315315
}

0 commit comments

Comments
 (0)