Skip to content

Commit b30c6dc

Browse files
committed
mem::discriminant trumps manual discriminant hashing
1 parent e400792 commit b30c6dc

File tree

1 file changed

+2
-78
lines changed

1 file changed

+2
-78
lines changed

clippy_lints/src/utils/hir_utils.rs

Lines changed: 2 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -406,51 +406,35 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
406406

407407
match e.node {
408408
ExprKind::AddrOf(m, ref e) => {
409-
let c: fn(_, _) -> _ = ExprKind::AddrOf;
410-
c.hash(&mut self.s);
411409
m.hash(&mut self.s);
412410
self.hash_expr(e);
413411
},
414412
ExprKind::Continue(i) => {
415-
let c: fn(_) -> _ = ExprKind::Continue;
416-
c.hash(&mut self.s);
417413
if let Some(i) = i.label {
418414
self.hash_name(i.ident.name);
419415
}
420416
},
421417
ExprKind::Yield(ref e) => {
422-
let c: fn(_) -> _ = ExprKind::Yield;
423-
c.hash(&mut self.s);
424418
self.hash_expr(e);
425419
},
426420
ExprKind::Assign(ref l, ref r) => {
427-
let c: fn(_, _) -> _ = ExprKind::Assign;
428-
c.hash(&mut self.s);
429421
self.hash_expr(l);
430422
self.hash_expr(r);
431423
},
432424
ExprKind::AssignOp(ref o, ref l, ref r) => {
433-
let c: fn(_, _, _) -> _ = ExprKind::AssignOp;
434-
c.hash(&mut self.s);
435425
o.hash(&mut self.s);
436426
self.hash_expr(l);
437427
self.hash_expr(r);
438428
},
439429
ExprKind::Block(ref b, _) => {
440-
let c: fn(_, _) -> _ = ExprKind::Block;
441-
c.hash(&mut self.s);
442430
self.hash_block(b);
443431
},
444432
ExprKind::Binary(op, ref l, ref r) => {
445-
let c: fn(_, _, _) -> _ = ExprKind::Binary;
446-
c.hash(&mut self.s);
447433
op.node.hash(&mut self.s);
448434
self.hash_expr(l);
449435
self.hash_expr(r);
450436
},
451437
ExprKind::Break(i, ref j) => {
452-
let c: fn(_, _) -> _ = ExprKind::Break;
453-
c.hash(&mut self.s);
454438
if let Some(i) = i.label {
455439
self.hash_name(i.ident.name);
456440
}
@@ -459,25 +443,17 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
459443
}
460444
},
461445
ExprKind::Box(ref e) => {
462-
let c: fn(_) -> _ = ExprKind::Box;
463-
c.hash(&mut self.s);
464446
self.hash_expr(e);
465447
},
466448
ExprKind::Call(ref fun, ref args) => {
467-
let c: fn(_, _) -> _ = ExprKind::Call;
468-
c.hash(&mut self.s);
469449
self.hash_expr(fun);
470450
self.hash_exprs(args);
471451
},
472452
ExprKind::Cast(ref e, ref _ty) => {
473-
let c: fn(_, _) -> _ = ExprKind::Cast;
474-
c.hash(&mut self.s);
475453
self.hash_expr(e);
476454
// TODO: _ty
477455
},
478456
ExprKind::Closure(cap, _, eid, _, _) => {
479-
let c: fn(_, _, _, _, _) -> _ = ExprKind::Closure;
480-
c.hash(&mut self.s);
481457
match cap {
482458
CaptureClause::CaptureByValue => 0,
483459
CaptureClause::CaptureByRef => 1,
@@ -486,46 +462,31 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
486462
self.hash_expr(&self.cx.tcx.hir().body(eid).value);
487463
},
488464
ExprKind::Field(ref e, ref f) => {
489-
let c: fn(_, _) -> _ = ExprKind::Field;
490-
c.hash(&mut self.s);
491465
self.hash_expr(e);
492466
self.hash_name(f.name);
493467
},
494468
ExprKind::Index(ref a, ref i) => {
495-
let c: fn(_, _) -> _ = ExprKind::Index;
496-
c.hash(&mut self.s);
497469
self.hash_expr(a);
498470
self.hash_expr(i);
499471
},
500-
ExprKind::InlineAsm(..) => {
501-
let c: fn(_, _, _) -> _ = ExprKind::InlineAsm;
502-
c.hash(&mut self.s);
503-
},
472+
ExprKind::InlineAsm(..) => {},
504473
ExprKind::If(ref cond, ref t, ref e) => {
505-
let c: fn(_, _, _) -> _ = ExprKind::If;
506-
c.hash(&mut self.s);
507474
self.hash_expr(cond);
508475
self.hash_expr(&**t);
509476
if let Some(ref e) = *e {
510477
self.hash_expr(e);
511478
}
512479
},
513480
ExprKind::Lit(ref l) => {
514-
let c: fn(_) -> _ = ExprKind::Lit;
515-
c.hash(&mut self.s);
516481
l.hash(&mut self.s);
517482
},
518483
ExprKind::Loop(ref b, ref i, _) => {
519-
let c: fn(_, _, _) -> _ = ExprKind::Loop;
520-
c.hash(&mut self.s);
521484
self.hash_block(b);
522485
if let Some(i) = *i {
523486
self.hash_name(i.ident.name);
524487
}
525488
},
526489
ExprKind::Match(ref e, ref arms, ref s) => {
527-
let c: fn(_, _, _) -> _ = ExprKind::Match;
528-
c.hash(&mut self.s);
529490
self.hash_expr(e);
530491

531492
for arm in arms {
@@ -539,36 +500,25 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
539500
s.hash(&mut self.s);
540501
},
541502
ExprKind::MethodCall(ref path, ref _tys, ref args) => {
542-
let c: fn(_, _, _) -> _ = ExprKind::MethodCall;
543-
c.hash(&mut self.s);
544503
self.hash_name(path.ident.name);
545504
self.hash_exprs(args);
546505
},
547506
ExprKind::Repeat(ref e, ref l_id) => {
548-
let c: fn(_, _) -> _ = ExprKind::Repeat;
549-
c.hash(&mut self.s);
550507
self.hash_expr(e);
551508
let full_table = self.tables;
552509
self.tables = self.cx.tcx.body_tables(l_id.body);
553510
self.hash_expr(&self.cx.tcx.hir().body(l_id.body).value);
554511
self.tables = full_table;
555512
},
556513
ExprKind::Ret(ref e) => {
557-
let c: fn(_) -> _ = ExprKind::Ret;
558-
c.hash(&mut self.s);
559514
if let Some(ref e) = *e {
560515
self.hash_expr(e);
561516
}
562517
},
563518
ExprKind::Path(ref qpath) => {
564-
let c: fn(_) -> _ = ExprKind::Path;
565-
c.hash(&mut self.s);
566519
self.hash_qpath(qpath);
567520
},
568521
ExprKind::Struct(ref path, ref fields, ref expr) => {
569-
let c: fn(_, _, _) -> _ = ExprKind::Struct;
570-
c.hash(&mut self.s);
571-
572522
self.hash_qpath(path);
573523

574524
for f in fields {
@@ -581,33 +531,20 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
581531
}
582532
},
583533
ExprKind::Tup(ref tup) => {
584-
let c: fn(_) -> _ = ExprKind::Tup;
585-
c.hash(&mut self.s);
586534
self.hash_exprs(tup);
587535
},
588536
ExprKind::Type(ref e, ref _ty) => {
589-
let c: fn(_, _) -> _ = ExprKind::Type;
590-
c.hash(&mut self.s);
591537
self.hash_expr(e);
592538
// TODO: _ty
593539
},
594540
ExprKind::Unary(lop, ref le) => {
595-
let c: fn(_, _) -> _ = ExprKind::Unary;
596-
c.hash(&mut self.s);
597-
598541
lop.hash(&mut self.s);
599542
self.hash_expr(le);
600543
},
601544
ExprKind::Array(ref v) => {
602-
let c: fn(_) -> _ = ExprKind::Array;
603-
c.hash(&mut self.s);
604-
605545
self.hash_exprs(v);
606546
},
607547
ExprKind::While(ref cond, ref b, l) => {
608-
let c: fn(_, _, _) -> _ = ExprKind::While;
609-
c.hash(&mut self.s);
610-
611548
self.hash_expr(cond);
612549
self.hash_block(b);
613550
if let Some(l) = l {
@@ -616,8 +553,6 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
616553
},
617554
ExprKind::Err => {},
618555
ExprKind::DropTemps(ref e) => {
619-
let c: fn(_) -> _ = ExprKind::DropTemps;
620-
c.hash(&mut self.s);
621556
self.hash_expr(e);
622557
},
623558
}
@@ -655,24 +590,15 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
655590
pub fn hash_stmt(&mut self, b: &Stmt) {
656591
match b.node {
657592
StmtKind::Local(ref local) => {
658-
let c: fn(_) -> _ = StmtKind::Local;
659-
c.hash(&mut self.s);
660593
if let Some(ref init) = local.init {
661594
self.hash_expr(init);
662595
}
663596
},
664-
StmtKind::Item(..) => {
665-
let c: fn(_) -> _ = StmtKind::Item;
666-
c.hash(&mut self.s);
667-
},
597+
StmtKind::Item(..) => {},
668598
StmtKind::Expr(ref expr) => {
669-
let c: fn(_) -> _ = StmtKind::Expr;
670-
c.hash(&mut self.s);
671599
self.hash_expr(expr);
672600
},
673601
StmtKind::Semi(ref expr) => {
674-
let c: fn(_) -> _ = StmtKind::Semi;
675-
c.hash(&mut self.s);
676602
self.hash_expr(expr);
677603
},
678604
}
@@ -681,8 +607,6 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
681607
pub fn hash_guard(&mut self, g: &Guard) {
682608
match g {
683609
Guard::If(ref expr) => {
684-
let c: fn(_) -> _ = Guard::If;
685-
c.hash(&mut self.s);
686610
self.hash_expr(expr);
687611
},
688612
}

0 commit comments

Comments
 (0)