Fix copy lints

This commit is contained in:
mcarton 2016-12-02 22:23:24 +01:00
parent fe15880beb
commit 65ff2df7e7
No known key found for this signature in database
GPG Key ID: 5E427C794CBA45E8
2 changed files with 38 additions and 22 deletions

View File

@ -3,7 +3,7 @@ use rustc::lint::*;
use rustc::hir::*; use rustc::hir::*;
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
use std::collections::hash_map::DefaultHasher; use std::collections::hash_map::DefaultHasher;
use syntax::ast::{Name, NodeId}; use syntax::ast::Name;
use syntax::ptr::P; use syntax::ptr::P;
use utils::differing_macro_contexts; use utils::differing_macro_contexts;
@ -100,13 +100,14 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
self.eq_expr(lc, rc) && self.eq_block(lt, rt) && both(le, re, |l, r| self.eq_expr(l, r)) self.eq_expr(lc, rc) && self.eq_block(lt, rt) && both(le, re, |l, r| self.eq_expr(l, r))
} }
(&ExprLit(ref l), &ExprLit(ref r)) => l.node == r.node, (&ExprLit(ref l), &ExprLit(ref r)) => l.node == r.node,
(&ExprLoop(ref lb, ref ll, _), &ExprLoop(ref rb, ref rl, _)) => { (&ExprLoop(ref lb, ref ll, ref lls), &ExprLoop(ref rb, ref rl, ref rls)) => {
self.eq_block(lb, rb) && both(ll, rl, |l, r| l.node.as_str() == r.node.as_str()) lls == rls && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.node.as_str() == r.node.as_str())
} }
(&ExprMatch(ref le, ref la, ref ls), &ExprMatch(ref re, ref ra, ref rs)) => { (&ExprMatch(ref le, ref la, ref ls), &ExprMatch(ref re, ref ra, ref rs)) => {
ls == rs && self.eq_expr(le, re) && ls == rs && self.eq_expr(le, re) &&
over(la, ra, |l, r| { over(la, ra, |l, r| {
self.eq_expr(&l.body, &r.body) && both(&l.guard, &r.guard, |l, r| self.eq_expr(l, r)) && self.eq_expr(&l.body, &r.body) &&
both(&l.guard, &r.guard, |l, r| self.eq_expr(l, r)) &&
over(&l.pats, &r.pats, |l, r| self.eq_pat(l, r)) over(&l.pats, &r.pats, |l, r| self.eq_pat(l, r))
}) })
} }
@ -153,8 +154,8 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
(&PatKind::TupleStruct(ref lp, ref la, ls), &PatKind::TupleStruct(ref rp, ref ra, rs)) => { (&PatKind::TupleStruct(ref lp, ref la, ls), &PatKind::TupleStruct(ref rp, ref ra, rs)) => {
self.eq_qpath(lp, rp) && over(la, ra, |l, r| self.eq_pat(l, r)) && ls == rs self.eq_qpath(lp, rp) && over(la, ra, |l, r| self.eq_pat(l, r)) && ls == rs
} }
(&PatKind::Binding(ref lb, ref ld, ref li, ref lp), &PatKind::Binding(ref rb, ref rd, ref ri, ref rp)) => { (&PatKind::Binding(ref lb, _, ref li, ref lp), &PatKind::Binding(ref rb, _, ref ri, ref rp)) => {
lb == rb && ld == rd && li.node.as_str() == ri.node.as_str() && both(lp, rp, |l, r| self.eq_pat(l, r)) lb == rb && li.node.as_str() == ri.node.as_str() && both(lp, rp, |l, r| self.eq_pat(l, r))
} }
(&PatKind::Path(ref l), &PatKind::Path(ref r)) => self.eq_qpath(l, r), (&PatKind::Path(ref l), &PatKind::Path(ref r)) => self.eq_qpath(l, r),
(&PatKind::Lit(ref l), &PatKind::Lit(ref r)) => self.eq_expr(l, r), (&PatKind::Lit(ref l), &PatKind::Lit(ref r)) => self.eq_expr(l, r),
@ -456,13 +457,13 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
ExprPath(ref qpath) => { ExprPath(ref qpath) => {
let c: fn(_) -> _ = ExprPath; let c: fn(_) -> _ = ExprPath;
c.hash(&mut self.s); c.hash(&mut self.s);
self.hash_qpath(qpath, e.id); self.hash_qpath(qpath);
} }
ExprStruct(ref path, ref fields, ref expr) => { ExprStruct(ref path, ref fields, ref expr) => {
let c: fn(_, _, _) -> _ = ExprStruct; let c: fn(_, _, _) -> _ = ExprStruct;
c.hash(&mut self.s); c.hash(&mut self.s);
self.hash_qpath(path, e.id); self.hash_qpath(path);
for f in fields { for f in fields {
self.hash_name(&f.name.node); self.hash_name(&f.name.node);
@ -527,8 +528,16 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
n.as_str().hash(&mut self.s); n.as_str().hash(&mut self.s);
} }
pub fn hash_qpath(&mut self, p: &QPath, id: NodeId) { pub fn hash_qpath(&mut self, p: &QPath) {
self.cx.tcx.tables().qpath_def(p, id).hash(&mut self.s); match *p {
QPath::Resolved(_, ref path) => {
self.hash_path(path);
}
QPath::TypeRelative(_, ref path) => {
self.hash_name(&path.name);
}
}
//self.cx.tcx.tables().qpath_def(p, id).hash(&mut self.s);
} }
pub fn hash_path(&mut self, p: &Path) { pub fn hash_path(&mut self, p: &Path) {

View File

@ -122,22 +122,22 @@ fn if_same_then_else() -> Result<&'static str, ()> {
if true { if true {
//~^NOTE same as this //~^NOTE same as this
for _ in &[42] { for _ in &[42] {
let foo: &Option<_> = &Some::<u8>(42); // let foo: &Option<_> = &Some::<u8>(42);
if true { // if true {
break; // break;
} else { // } else {
continue; // continue;
} // }
} }
} }
else { //~ERROR this `if` has identical blocks else { //~ERROR this `if` has identical blocks
for _ in &[42] { for _ in &[42] {
let foo: &Option<_> = &Some::<u8>(42); // let foo: &Option<_> = &Some::<u8>(42);
if true { // if true {
break; // break;
} else { // } else {
continue; // continue;
} // }
} }
} }
@ -237,6 +237,13 @@ fn if_same_then_else() -> Result<&'static str, ()> {
if let Some(42) = None {} if let Some(42) = None {}
} }
if true {
if let Some(42) = None::<u8> {}
}
else {
if let Some(42) = None::<u32> {}
}
if true { if true {
if let Some(a) = Some(42) {} if let Some(a) = Some(42) {}
} }