]> git.lizzy.rs Git - rust.git/commitdiff
Merge pull request #727 from oli-obk/similar_names
authorManish Goregaokar <manishsmail@gmail.com>
Mon, 21 Mar 2016 05:05:36 +0000 (10:35 +0530)
committerManish Goregaokar <manishsmail@gmail.com>
Mon, 21 Mar 2016 05:05:36 +0000 (10:35 +0530)
lint on binding-names that are too similar

1  2 
src/consts.rs
src/utils/hir.rs
src/utils/mod.rs

diff --combined src/consts.rs
index e6bda7df8de9295175a3bd7dcf894cad39cf2353,f04ad1d214ae3c9a9be30bdc5bb110845df7539b..67da1216c42f24190599acd8ca75655d40291f52
@@@ -82,7 -82,7 +82,7 @@@ impl Constant 
  impl PartialEq for Constant {
      fn eq(&self, other: &Constant) -> bool {
          match (self, other) {
-             (&Constant::Str(ref ls, ref lsty), &Constant::Str(ref rs, ref rsty)) => ls == rs && lsty == rsty,
+             (&Constant::Str(ref ls, ref l_sty), &Constant::Str(ref rs, ref r_sty)) => ls == rs && l_sty == r_sty,
              (&Constant::Binary(ref l), &Constant::Binary(ref r)) => l == r,
              (&Constant::Char(l), &Constant::Char(r)) => l == r,
              (&Constant::Int(l), &Constant::Int(r)) => l.is_negative() == r.is_negative() && l.to_u64_unchecked() == r.to_u64_unchecked(),
@@@ -145,8 -145,8 +145,8 @@@ impl Hash for Constant 
  impl PartialOrd for Constant {
      fn partial_cmp(&self, other: &Constant) -> Option<Ordering> {
          match (self, other) {
-             (&Constant::Str(ref ls, ref lsty), &Constant::Str(ref rs, ref rsty)) => {
-                 if lsty == rsty {
+             (&Constant::Str(ref ls, ref l_sty), &Constant::Str(ref rs, ref r_sty)) => {
+                 if l_sty == r_sty {
                      Some(ls.cmp(rs))
                  } else {
                      None
@@@ -290,7 -290,7 +290,7 @@@ impl<'c, 'cc> ConstEvalLateContext<'c, 
              }
              // separate if lets to avoid double borrowing the def_map
              if let Some(id) = maybe_id {
 -                if let Some((const_expr, _ty)) = lookup_const_by_id(lcx.tcx, id, None, None) {
 +                if let Some((const_expr, _ty)) = lookup_const_by_id(lcx.tcx, id, None) {
                      let ret = self.expr(const_expr);
                      if ret.is_some() {
                          self.needed_resolution = true;
          }
      }
  
      fn binop_apply<F>(&mut self, left: &Expr, right: &Expr, op: F) -> Option<Constant>
          where F: Fn(Constant, Constant) -> Option<Constant>
      {
diff --combined src/utils/hir.rs
index fd8dc046eb52b2f7ed3d73a5de4202b1b824e041,bc7bc358a9c0159a730ca08b9f953085518c5a01..ed2a49b3caa4c189ce9b81c5182ae4b2a39fe0fe
@@@ -67,24 -67,24 +67,24 @@@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx
          }
  
          match (&left.node, &right.node) {
-             (&ExprAddrOf(lmut, ref le), &ExprAddrOf(rmut, ref re)) => lmut == rmut && self.eq_expr(le, re),
+             (&ExprAddrOf(l_mut, ref le), &ExprAddrOf(r_mut, ref re)) => l_mut == r_mut && self.eq_expr(le, re),
              (&ExprAgain(li), &ExprAgain(ri)) => both(&li, &ri, |l, r| l.node.name.as_str() == r.node.name.as_str()),
              (&ExprAssign(ref ll, ref lr), &ExprAssign(ref rl, ref rr)) => self.eq_expr(ll, rl) && self.eq_expr(lr, rr),
              (&ExprAssignOp(ref lo, ref ll, ref lr), &ExprAssignOp(ref ro, ref rl, ref rr)) => {
                  lo.node == ro.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
              }
              (&ExprBlock(ref l), &ExprBlock(ref r)) => self.eq_block(l, r),
-             (&ExprBinary(lop, ref ll, ref lr), &ExprBinary(rop, ref rl, ref rr)) => {
-                 lop.node == rop.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
+             (&ExprBinary(l_op, ref ll, ref lr), &ExprBinary(r_op, ref rl, ref rr)) => {
+                 l_op.node == r_op.node && self.eq_expr(ll, rl) && self.eq_expr(lr, rr)
              }
              (&ExprBreak(li), &ExprBreak(ri)) => both(&li, &ri, |l, r| l.node.name.as_str() == r.node.name.as_str()),
              (&ExprBox(ref l), &ExprBox(ref r)) => self.eq_expr(l, r),
-             (&ExprCall(ref lfun, ref largs), &ExprCall(ref rfun, ref rargs)) => {
-                 !self.ignore_fn && self.eq_expr(lfun, rfun) && self.eq_exprs(largs, rargs)
+             (&ExprCall(ref l_fun, ref l_args), &ExprCall(ref r_fun, ref r_args)) => {
+                 !self.ignore_fn && self.eq_expr(l_fun, r_fun) && self.eq_exprs(l_args, r_args)
              }
              (&ExprCast(ref lx, ref lt), &ExprCast(ref rx, ref rt)) => self.eq_expr(lx, rx) && self.eq_ty(lt, rt),
-             (&ExprField(ref lfexp, ref lfident), &ExprField(ref rfexp, ref rfident)) => {
-                 lfident.node == rfident.node && self.eq_expr(lfexp, rfexp)
+             (&ExprField(ref l_f_exp, ref l_f_ident), &ExprField(ref r_f_exp, ref r_f_ident)) => {
+                 l_f_ident.node == r_f_ident.node && self.eq_expr(l_f_exp, r_f_exp)
              }
              (&ExprIndex(ref la, ref li), &ExprIndex(ref ra, ref ri)) => self.eq_expr(la, ra) && self.eq_expr(li, ri),
              (&ExprIf(ref lc, ref lt, ref le), &ExprIf(ref rc, ref rt, ref re)) => {
                      over(&l.pats, &r.pats, |l, r| self.eq_pat(l, r))
                  })
              }
-             (&ExprMethodCall(ref lname, ref ltys, ref largs),
-              &ExprMethodCall(ref rname, ref rtys, ref rargs)) => {
+             (&ExprMethodCall(ref l_name, ref l_tys, ref l_args),
+              &ExprMethodCall(ref r_name, ref r_tys, ref r_args)) => {
                  // TODO: tys
-                 !self.ignore_fn && lname.node == rname.node && ltys.is_empty() && rtys.is_empty() &&
-                 self.eq_exprs(largs, rargs)
+                 !self.ignore_fn && l_name.node == r_name.node && l_tys.is_empty() && r_tys.is_empty() &&
+                 self.eq_exprs(l_args, r_args)
              }
              (&ExprRepeat(ref le, ref ll), &ExprRepeat(ref re, ref rl)) => self.eq_expr(le, re) && self.eq_expr(ll, rl),
              (&ExprRet(ref l), &ExprRet(ref r)) => both(l, r, |l, r| self.eq_expr(l, r)),
-             (&ExprPath(ref lqself, ref lsubpath), &ExprPath(ref rqself, ref rsubpath)) => {
-                 both(lqself, rqself, |l, r| self.eq_qself(l, r)) && self.eq_path(lsubpath, rsubpath)
+             (&ExprPath(ref l_qself, ref l_subpath), &ExprPath(ref r_qself, ref r_subpath)) => {
+                 both(l_qself, r_qself, |l, r| self.eq_qself(l, r)) && self.eq_path(l_subpath, r_subpath)
              }
-             (&ExprStruct(ref lpath, ref lf, ref lo), &ExprStruct(ref rpath, ref rf, ref ro)) => {
-                 self.eq_path(lpath, rpath) &&
+             (&ExprStruct(ref l_path, ref lf, ref lo), &ExprStruct(ref r_path, ref rf, ref ro)) => {
+                 self.eq_path(l_path, r_path) &&
                      both(lo, ro, |l, r| self.eq_expr(l, r)) &&
                      over(lf, rf, |l, r| self.eq_field(l, r))
              }
-             (&ExprTup(ref ltup), &ExprTup(ref rtup)) => self.eq_exprs(ltup, rtup),
+             (&ExprTup(ref l_tup), &ExprTup(ref r_tup)) => self.eq_exprs(l_tup, r_tup),
              (&ExprTupField(ref le, li), &ExprTupField(ref re, ri)) => li.node == ri.node && self.eq_expr(le, re),
-             (&ExprUnary(lop, ref le), &ExprUnary(rop, ref re)) => lop == rop && self.eq_expr(le, re),
+             (&ExprUnary(l_op, ref le), &ExprUnary(r_op, ref re)) => l_op == r_op && self.eq_expr(le, re),
              (&ExprVec(ref l), &ExprVec(ref r)) => self.eq_exprs(l, r),
              (&ExprWhile(ref lc, ref lb, ref ll), &ExprWhile(ref rc, ref rb, ref rl)) => {
                  self.eq_expr(lc, rc) && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.name.as_str() == r.name.as_str())
  
      fn eq_ty(&self, left: &Ty, right: &Ty) -> bool {
          match (&left.node, &right.node) {
-             (&TyVec(ref lvec), &TyVec(ref rvec)) => self.eq_ty(lvec, rvec),
+             (&TyVec(ref l_vec), &TyVec(ref r_vec)) => self.eq_ty(l_vec, r_vec),
              (&TyFixedLengthVec(ref lt, ref ll), &TyFixedLengthVec(ref rt, ref rl)) => {
                  self.eq_ty(lt, rt) && self.eq_expr(ll, rl)
              }
-             (&TyPtr(ref lmut), &TyPtr(ref rmut)) => lmut.mutbl == rmut.mutbl && self.eq_ty(&*lmut.ty, &*rmut.ty),
-             (&TyRptr(_, ref lrmut), &TyRptr(_, ref rrmut)) => {
-                 lrmut.mutbl == rrmut.mutbl && self.eq_ty(&*lrmut.ty, &*rrmut.ty)
+             (&TyPtr(ref l_mut), &TyPtr(ref r_mut)) => l_mut.mutbl == r_mut.mutbl && self.eq_ty(&*l_mut.ty, &*r_mut.ty),
+             (&TyRptr(_, ref l_rmut), &TyRptr(_, ref r_rmut)) => {
+                 l_rmut.mutbl == r_rmut.mutbl && self.eq_ty(&*l_rmut.ty, &*r_rmut.ty)
              }
-             (&TyPath(ref lq, ref lpath), &TyPath(ref rq, ref rpath)) => {
-                 both(lq, rq, |l, r| self.eq_qself(l, r)) && self.eq_path(lpath, rpath)
+             (&TyPath(ref lq, ref l_path), &TyPath(ref rq, ref r_path)) => {
+                 both(lq, rq, |l, r| self.eq_qself(l, r)) && self.eq_path(l_path, r_path)
              }
              (&TyTup(ref l), &TyTup(ref r)) => over(l, r, |l, r| self.eq_ty(l, r)),
              (&TyInfer, &TyInfer) => true,
@@@ -332,8 -332,8 +332,8 @@@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tc
                  self.hash_expr(a);
                  self.hash_expr(i);
              }
 -            ExprInlineAsm(_) => {
 -                let c: fn(_) -> _ = ExprInlineAsm;
 +            ExprInlineAsm(..) => {
 +                let c: fn(_, _, _) -> _ = ExprInlineAsm;
                  c.hash(&mut self.s);
              }
              ExprIf(ref cond, ref t, ref e) => {
diff --combined src/utils/mod.rs
index 16174e434d4a84402a0f6e62e66a5b511580aeeb,de303a35f17304199c9aaaba42d075121fd4ef59..050aec0e43041824864086a02b6108dd26b14c77
@@@ -102,8 -102,8 +102,8 @@@ macro_rules! if_let_chain 
  
  /// Returns true if the two spans come from differing expansions (i.e. one is from a macro and one
  /// isn't).
- pub fn differing_macro_contexts(sp1: Span, sp2: Span) -> bool {
-     sp1.expn_id != sp2.expn_id
+ pub fn differing_macro_contexts(lhs: Span, rhs: Span) -> bool {
+     rhs.expn_id != lhs.expn_id
  }
  /// Returns true if this `expn_info` was expanded by any macro.
  pub fn in_macro<T: LintContext>(cx: &T, span: Span) -> bool {
@@@ -270,7 -270,6 +270,7 @@@ pub fn implements_trait<'a, 'tcx>(cx: &
                                    -> bool {
      cx.tcx.populate_implementations_for_trait_if_necessary(trait_id);
  
 +    let ty = cx.tcx.erase_regions(&ty);
      let infcx = infer::new_infer_ctxt(cx.tcx, &cx.tcx.tables, None, ProjectionMode::Any);
      let obligation = traits::predicate_for_trait_def(cx.tcx,
                                                       traits::ObligationCause::dummy(),