1
Fork 0

Dogfood match_ref_pats for if let

This commit is contained in:
Seo Sanghyeon 2015-11-25 02:44:40 +09:00
parent b40e80f039
commit a3e8091e87
11 changed files with 21 additions and 21 deletions

View file

@ -44,7 +44,7 @@ impl LintPass for ApproxConstant {
impl LateLintPass for ApproxConstant { impl LateLintPass for ApproxConstant {
fn check_expr(&mut self, cx: &LateContext, e: &Expr) { fn check_expr(&mut self, cx: &LateContext, e: &Expr) {
if let &ExprLit(ref lit) = &e.node { if let ExprLit(ref lit) = e.node {
check_lit(cx, lit, e); check_lit(cx, lit, e);
} }
} }

View file

@ -42,7 +42,7 @@ impl LateLintPass for AttrPass {
} }
fn is_relevant_item(item: &Item) -> bool { fn is_relevant_item(item: &Item) -> bool {
if let &ItemFn(_, _, _, _, _, ref block) = &item.node { if let ItemFn(_, _, _, _, _, ref block) = item.node {
is_relevant_block(block) is_relevant_block(block)
} else { false } } else { false }
} }

View file

@ -182,7 +182,7 @@ fn check_ineffective_gt(cx: &LateContext, span: Span, m: u64, c: u64, op: &str)
fn fetch_int_literal(cx: &LateContext, lit : &Expr) -> Option<u64> { fn fetch_int_literal(cx: &LateContext, lit : &Expr) -> Option<u64> {
match lit.node { match lit.node {
ExprLit(ref lit_ptr) => { ExprLit(ref lit_ptr) => {
if let &LitInt(value, _) = &lit_ptr.node { if let LitInt(value, _) = lit_ptr.node {
Option::Some(value) //TODO: Handle sign Option::Some(value) //TODO: Handle sign
} else { Option::None } } else { Option::None }
} }

View file

@ -125,7 +125,7 @@ fn check_len_zero(cx: &LateContext, span: Span, name: &Name,
fn has_is_empty(cx: &LateContext, expr: &Expr) -> bool { fn has_is_empty(cx: &LateContext, expr: &Expr) -> bool {
/// get a ImplOrTraitItem and return true if it matches is_empty(self) /// get a ImplOrTraitItem and return true if it matches is_empty(self)
fn is_is_empty(cx: &LateContext, id: &ImplOrTraitItemId) -> bool { fn is_is_empty(cx: &LateContext, id: &ImplOrTraitItemId) -> bool {
if let &MethodTraitItemId(def_id) = id { if let MethodTraitItemId(def_id) = *id {
if let ty::MethodTraitItem(ref method) = if let ty::MethodTraitItem(ref method) =
cx.tcx.impl_or_trait_item(def_id) { cx.tcx.impl_or_trait_item(def_id) {
method.name.as_str() == "is_empty" method.name.as_str() == "is_empty"

View file

@ -168,7 +168,7 @@ impl <'v, 't> RefVisitor<'v, 't> {
} }
fn record(&mut self, lifetime: &Option<Lifetime>) { fn record(&mut self, lifetime: &Option<Lifetime>) {
if let &Some(ref lt) = lifetime { if let Some(ref lt) = *lifetime {
if lt.name.as_str() == "'static" { if lt.name.as_str() == "'static" {
self.lts.push(Static); self.lts.push(Static);
} else { } else {

View file

@ -84,10 +84,10 @@ impl LateLintPass for CmpNan {
fn check_expr(&mut self, cx: &LateContext, expr: &Expr) { fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
if let ExprBinary(ref cmp, ref left, ref right) = expr.node { if let ExprBinary(ref cmp, ref left, ref right) = expr.node {
if is_comparison_binop(cmp.node) { if is_comparison_binop(cmp.node) {
if let &ExprPath(_, ref path) = &left.node { if let ExprPath(_, ref path) = left.node {
check_nan(cx, path, expr.span); check_nan(cx, path, expr.span);
} }
if let &ExprPath(_, ref path) = &right.node { if let ExprPath(_, ref path) = right.node {
check_nan(cx, path, expr.span); check_nan(cx, path, expr.span);
} }
} }
@ -189,7 +189,7 @@ fn check_to_owned(cx: &LateContext, expr: &Expr, other_span: Span, left: bool, o
} }
} }
ExprCall(ref path, ref v) if v.len() == 1 => { ExprCall(ref path, ref v) if v.len() == 1 => {
if let &ExprPath(None, ref path) = &path.node { if let ExprPath(None, ref path) = path.node {
if match_path(path, &["String", "from_str"]) || if match_path(path, &["String", "from_str"]) ||
match_path(path, &["String", "from"]) { match_path(path, &["String", "from"]) {
snippet(cx, v[0].span, "..") snippet(cx, v[0].span, "..")
@ -235,7 +235,7 @@ impl LintPass for ModuloOne {
impl LateLintPass for ModuloOne { impl LateLintPass for ModuloOne {
fn check_expr(&mut self, cx: &LateContext, expr: &Expr) { fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
if let ExprBinary(ref cmp, _, ref right) = expr.node { if let ExprBinary(ref cmp, _, ref right) = expr.node {
if let &Spanned {node: BinOp_::BiRem, ..} = cmp { if let Spanned {node: BinOp_::BiRem, ..} = *cmp {
if is_integer_literal(right, 1) { if is_integer_literal(right, 1) {
cx.span_lint(MODULO_ONE, expr.span, "any number modulo 1 will be 0"); cx.span_lint(MODULO_ONE, expr.span, "any number modulo 1 will be 0");
} }

View file

@ -34,7 +34,7 @@ pub struct MutexAtomic;
impl LateLintPass for MutexAtomic { impl LateLintPass for MutexAtomic {
fn check_expr(&mut self, cx: &LateContext, expr: &Expr) { fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
let ty = cx.tcx.expr_ty(expr); let ty = cx.tcx.expr_ty(expr);
if let &ty::TyStruct(_, subst) = &ty.sty { if let ty::TyStruct(_, subst) = ty.sty {
if match_type(cx, ty, &MUTEX_PATH) { if match_type(cx, ty, &MUTEX_PATH) {
let mutex_param = &subst.types.get(ParamSpace::TypeSpace, 0).sty; let mutex_param = &subst.types.get(ParamSpace::TypeSpace, 0).sty;
if let Some(atomic_name) = get_atomic_name(mutex_param) { if let Some(atomic_name) = get_atomic_name(mutex_param) {

View file

@ -28,13 +28,13 @@ impl LintPass for PtrArg {
impl LateLintPass for PtrArg { impl LateLintPass for PtrArg {
fn check_item(&mut self, cx: &LateContext, item: &Item) { fn check_item(&mut self, cx: &LateContext, item: &Item) {
if let &ItemFn(ref decl, _, _, _, _, _) = &item.node { if let ItemFn(ref decl, _, _, _, _, _) = item.node {
check_fn(cx, decl); check_fn(cx, decl);
} }
} }
fn check_impl_item(&mut self, cx: &LateContext, item: &ImplItem) { fn check_impl_item(&mut self, cx: &LateContext, item: &ImplItem) {
if let &ImplItemKind::Method(ref sig, _) = &item.node { if let ImplItemKind::Method(ref sig, _) = item.node {
if let Some(Node::NodeItem(it)) = cx.tcx.map.find(cx.tcx.map.get_parent(item.id)) { if let Some(Node::NodeItem(it)) = cx.tcx.map.find(cx.tcx.map.get_parent(item.id)) {
if let ItemImpl(_, _, _, Some(_), _, _) = it.node { if let ItemImpl(_, _, _, Some(_), _, _) = it.node {
return; // ignore trait impls return; // ignore trait impls
@ -45,7 +45,7 @@ impl LateLintPass for PtrArg {
} }
fn check_trait_item(&mut self, cx: &LateContext, item: &TraitItem) { fn check_trait_item(&mut self, cx: &LateContext, item: &TraitItem) {
if let &MethodTraitItem(ref sig, _) = &item.node { if let MethodTraitItem(ref sig, _) = item.node {
check_fn(cx, &sig.decl); check_fn(cx, &sig.decl);
} }
} }

View file

@ -40,10 +40,10 @@ impl LateLintPass for StepByZero {
if_let_chain! { if_let_chain! {
[ [
// .iter() call // .iter() call
let &ExprMethodCall( Spanned { node: ref iter_name, .. }, _, ref iter_args ) = iter, let ExprMethodCall( Spanned { node: ref iter_name, .. }, _, ref iter_args ) = *iter,
iter_name.as_str() == "iter", iter_name.as_str() == "iter",
// range expression in .zip() call: 0..x.len() // range expression in .zip() call: 0..x.len()
let &ExprRange(Some(ref from), Some(ref to)) = zip_arg, let ExprRange(Some(ref from), Some(ref to)) = *zip_arg,
is_integer_literal(from, 0), is_integer_literal(from, 0),
// .len() call // .len() call
let ExprMethodCall(Spanned { node: ref len_name, .. }, _, ref len_args) = to.node, let ExprMethodCall(Spanned { node: ref len_name, .. }, _, ref len_args) = to.node,

View file

@ -63,8 +63,8 @@ fn check_decl(cx: &LateContext, decl: &Decl, bindings: &mut Vec<(Name, Span)>) {
if is_from_for_desugar(decl) { return; } if is_from_for_desugar(decl) { return; }
if let DeclLocal(ref local) = decl.node { if let DeclLocal(ref local) = decl.node {
let Local{ ref pat, ref ty, ref init, id: _, span } = **local; let Local{ ref pat, ref ty, ref init, id: _, span } = **local;
if let &Some(ref t) = ty { check_ty(cx, t, bindings) } if let Some(ref t) = *ty { check_ty(cx, t, bindings) }
if let &Some(ref o) = init { if let Some(ref o) = *init {
check_expr(cx, o, bindings); check_expr(cx, o, bindings);
check_pat(cx, pat, &Some(o), span, bindings); check_pat(cx, pat, &Some(o), span, bindings);
} else { } else {
@ -210,7 +210,7 @@ fn check_expr(cx: &LateContext, expr: &Expr, bindings: &mut Vec<(Name, Span)>) {
ExprIf(ref cond, ref then, ref otherwise) => { ExprIf(ref cond, ref then, ref otherwise) => {
check_expr(cx, cond, bindings); check_expr(cx, cond, bindings);
check_block(cx, then, bindings); check_block(cx, then, bindings);
if let &Some(ref o) = otherwise { check_expr(cx, o, bindings); } if let Some(ref o) = *otherwise { check_expr(cx, o, bindings); }
} }
ExprWhile(ref cond, ref block, _) => { ExprWhile(ref cond, ref block, _) => {
check_expr(cx, cond, bindings); check_expr(cx, cond, bindings);

View file

@ -34,14 +34,14 @@ impl LintPass for StringAdd {
impl LateLintPass for StringAdd { impl LateLintPass for StringAdd {
fn check_expr(&mut self, cx: &LateContext, e: &Expr) { fn check_expr(&mut self, cx: &LateContext, e: &Expr) {
if let &ExprBinary(Spanned{ node: BiAdd, .. }, ref left, _) = &e.node { if let ExprBinary(Spanned{ node: BiAdd, .. }, ref left, _) = e.node {
if is_string(cx, left) { if is_string(cx, left) {
if let Allow = cx.current_level(STRING_ADD_ASSIGN) { if let Allow = cx.current_level(STRING_ADD_ASSIGN) {
// the string_add_assign is allow, so no duplicates // the string_add_assign is allow, so no duplicates
} else { } else {
let parent = get_parent_expr(cx, e); let parent = get_parent_expr(cx, e);
if let Some(ref p) = parent { if let Some(ref p) = parent {
if let &ExprAssign(ref target, _) = &p.node { if let ExprAssign(ref target, _) = p.node {
// avoid duplicate matches // avoid duplicate matches
if is_exp_equal(cx, target, left) { return; } if is_exp_equal(cx, target, left) { return; }
} }
@ -51,7 +51,7 @@ impl LateLintPass for StringAdd {
"you added something to a string. \ "you added something to a string. \
Consider using `String::push_str()` instead") Consider using `String::push_str()` instead")
} }
} else if let &ExprAssign(ref target, ref src) = &e.node { } else if let ExprAssign(ref target, ref src) = e.node {
if is_string(cx, target) && is_add(cx, src, target) { if is_string(cx, target) && is_add(cx, src, target) {
span_lint(cx, STRING_ADD_ASSIGN, e.span, span_lint(cx, STRING_ADD_ASSIGN, e.span,
"you assigned the result of adding something to this string. \ "you assigned the result of adding something to this string. \