mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
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 rustc::lint::*;
|
||||||
use syntax::ast::*;
|
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
|
/// **What it does:** Checks for usage of `!` or `!=` in an if condition with an
|
||||||
/// else branch.
|
/// else branch.
|
||||||
@ -47,6 +47,9 @@ impl LintPass for IfNotElse {
|
|||||||
|
|
||||||
impl EarlyLintPass for IfNotElse {
|
impl EarlyLintPass for IfNotElse {
|
||||||
fn check_expr(&mut self, cx: &EarlyContext, item: &Expr) {
|
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::If(ref cond, _, Some(ref els)) = item.node {
|
||||||
if let ExprKind::Block(..) = els.node {
|
if let ExprKind::Block(..) = els.node {
|
||||||
match cond.node {
|
match cond.node {
|
||||||
|
@ -74,6 +74,9 @@ const WHITELIST: &[&[&str]] = &[
|
|||||||
&["lhs", "rhs"],
|
&["lhs", "rhs"],
|
||||||
&["tx", "rx"],
|
&["tx", "rx"],
|
||||||
&["set", "get"],
|
&["set", "get"],
|
||||||
|
&["args", "arms"],
|
||||||
|
&["qpath", "path"],
|
||||||
|
&["lit", "lint"],
|
||||||
];
|
];
|
||||||
|
|
||||||
struct SimilarNamesNameVisitor<'a: 'b, 'tcx: 'a, 'b>(&'b mut SimilarNamesLocalVisitor<'a, 'tcx>);
|
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,
|
e.span,
|
||||||
&format!("transmute from a type (`{}`) to a pointer to that type (`{}`)", from_ty, to_ty),
|
&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,
|
cx,
|
||||||
TRANSMUTE_PTR_TO_REF,
|
TRANSMUTE_PTR_TO_REF,
|
||||||
e.span,
|
e.span,
|
||||||
@ -226,16 +226,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
|||||||
),
|
),
|
||||||
|db| {
|
|db| {
|
||||||
let arg = sugg::Sugg::hir(cx, &args[0], "..");
|
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")
|
("&mut *", "*mut")
|
||||||
} else {
|
} else {
|
||||||
("&*", "*const")
|
("&*", "*const")
|
||||||
};
|
};
|
||||||
|
|
||||||
let arg = if from_pty.ty == to_rty.ty {
|
let arg = if from_pty.ty == to_ref_ty.ty {
|
||||||
arg
|
arg
|
||||||
} else {
|
} 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());
|
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
|
/// the type's `ToString` implementation. In weird cases it could lead to types
|
||||||
/// with invalid `'_`
|
/// with invalid `'_`
|
||||||
/// lifetime, but it should be rare.
|
/// 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);
|
let seg = last_path_segment(path);
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let Some(ref params) = seg.parameters;
|
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 Some(to_ty) = params.types.get(1);
|
||||||
if let TyRptr(_, ref to_ty) = to_ty.node;
|
if let TyRptr(_, ref to_ty) = to_ty.node;
|
||||||
then {
|
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…
Reference in New Issue
Block a user