Skip to content

Commit 65ff2df

Browse files
committed
Fix copy lints
1 parent fe15880 commit 65ff2df

File tree

2 files changed

+38
-22
lines changed

2 files changed

+38
-22
lines changed

clippy_lints/src/utils/hir.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc::lint::*;
33
use rustc::hir::*;
44
use std::hash::{Hash, Hasher};
55
use std::collections::hash_map::DefaultHasher;
6-
use syntax::ast::{Name, NodeId};
6+
use syntax::ast::Name;
77
use syntax::ptr::P;
88
use utils::differing_macro_contexts;
99

@@ -100,13 +100,14 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
100100
self.eq_expr(lc, rc) && self.eq_block(lt, rt) && both(le, re, |l, r| self.eq_expr(l, r))
101101
}
102102
(&ExprLit(ref l), &ExprLit(ref r)) => l.node == r.node,
103-
(&ExprLoop(ref lb, ref ll, _), &ExprLoop(ref rb, ref rl, _)) => {
104-
self.eq_block(lb, rb) && both(ll, rl, |l, r| l.node.as_str() == r.node.as_str())
103+
(&ExprLoop(ref lb, ref ll, ref lls), &ExprLoop(ref rb, ref rl, ref rls)) => {
104+
lls == rls && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.node.as_str() == r.node.as_str())
105105
}
106106
(&ExprMatch(ref le, ref la, ref ls), &ExprMatch(ref re, ref ra, ref rs)) => {
107107
ls == rs && self.eq_expr(le, re) &&
108108
over(la, ra, |l, r| {
109-
self.eq_expr(&l.body, &r.body) && both(&l.guard, &r.guard, |l, r| self.eq_expr(l, r)) &&
109+
self.eq_expr(&l.body, &r.body) &&
110+
both(&l.guard, &r.guard, |l, r| self.eq_expr(l, r)) &&
110111
over(&l.pats, &r.pats, |l, r| self.eq_pat(l, r))
111112
})
112113
}
@@ -153,8 +154,8 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
153154
(&PatKind::TupleStruct(ref lp, ref la, ls), &PatKind::TupleStruct(ref rp, ref ra, rs)) => {
154155
self.eq_qpath(lp, rp) && over(la, ra, |l, r| self.eq_pat(l, r)) && ls == rs
155156
}
156-
(&PatKind::Binding(ref lb, ref ld, ref li, ref lp), &PatKind::Binding(ref rb, ref rd, ref ri, ref rp)) => {
157-
lb == rb && ld == rd && li.node.as_str() == ri.node.as_str() && both(lp, rp, |l, r| self.eq_pat(l, r))
157+
(&PatKind::Binding(ref lb, _, ref li, ref lp), &PatKind::Binding(ref rb, _, ref ri, ref rp)) => {
158+
lb == rb && li.node.as_str() == ri.node.as_str() && both(lp, rp, |l, r| self.eq_pat(l, r))
158159
}
159160
(&PatKind::Path(ref l), &PatKind::Path(ref r)) => self.eq_qpath(l, r),
160161
(&PatKind::Lit(ref l), &PatKind::Lit(ref r)) => self.eq_expr(l, r),
@@ -456,13 +457,13 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
456457
ExprPath(ref qpath) => {
457458
let c: fn(_) -> _ = ExprPath;
458459
c.hash(&mut self.s);
459-
self.hash_qpath(qpath, e.id);
460+
self.hash_qpath(qpath);
460461
}
461462
ExprStruct(ref path, ref fields, ref expr) => {
462463
let c: fn(_, _, _) -> _ = ExprStruct;
463464
c.hash(&mut self.s);
464465

465-
self.hash_qpath(path, e.id);
466+
self.hash_qpath(path);
466467

467468
for f in fields {
468469
self.hash_name(&f.name.node);
@@ -527,8 +528,16 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
527528
n.as_str().hash(&mut self.s);
528529
}
529530

530-
pub fn hash_qpath(&mut self, p: &QPath, id: NodeId) {
531-
self.cx.tcx.tables().qpath_def(p, id).hash(&mut self.s);
531+
pub fn hash_qpath(&mut self, p: &QPath) {
532+
match *p {
533+
QPath::Resolved(_, ref path) => {
534+
self.hash_path(path);
535+
}
536+
QPath::TypeRelative(_, ref path) => {
537+
self.hash_name(&path.name);
538+
}
539+
}
540+
//self.cx.tcx.tables().qpath_def(p, id).hash(&mut self.s);
532541
}
533542

534543
pub fn hash_path(&mut self, p: &Path) {

tests/compile-fail/copies.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,22 +122,22 @@ fn if_same_then_else() -> Result<&'static str, ()> {
122122
if true {
123123
//~^NOTE same as this
124124
for _ in &[42] {
125-
let foo: &Option<_> = &Some::<u8>(42);
126-
if true {
127-
break;
128-
} else {
129-
continue;
130-
}
125+
// let foo: &Option<_> = &Some::<u8>(42);
126+
// if true {
127+
// break;
128+
// } else {
129+
// continue;
130+
// }
131131
}
132132
}
133133
else { //~ERROR this `if` has identical blocks
134134
for _ in &[42] {
135-
let foo: &Option<_> = &Some::<u8>(42);
136-
if true {
137-
break;
138-
} else {
139-
continue;
140-
}
135+
// let foo: &Option<_> = &Some::<u8>(42);
136+
// if true {
137+
// break;
138+
// } else {
139+
// continue;
140+
// }
141141
}
142142
}
143143

@@ -237,6 +237,13 @@ fn if_same_then_else() -> Result<&'static str, ()> {
237237
if let Some(42) = None {}
238238
}
239239

240+
if true {
241+
if let Some(42) = None::<u8> {}
242+
}
243+
else {
244+
if let Some(42) = None::<u32> {}
245+
}
246+
240247
if true {
241248
if let Some(a) = Some(42) {}
242249
}

0 commit comments

Comments
 (0)