Merge pull request #2181 from rust-lang-nursery/macro_check
Fix dogfood
This commit is contained in:
commit
f724b9951a
@ -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 {
|
||||
|
@ -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>);
|
||||
|
@ -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()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user