Skip to content

Commit f11b236

Browse files
oli-obkflip1995
authored andcommitted
mem::discriminant trumps manual discriminant hashing
1 parent bc031d4 commit f11b236

File tree

1 file changed

+2
-76
lines changed

1 file changed

+2
-76
lines changed

clippy_lints/src/utils/hir_utils.rs

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

404404
match e.node {
405405
ExprKind::AddrOf(m, ref e) => {
406-
let c: fn(_, _) -> _ = ExprKind::AddrOf;
407-
c.hash(&mut self.s);
408406
m.hash(&mut self.s);
409407
self.hash_expr(e);
410408
},
411409
ExprKind::Continue(i) => {
412-
let c: fn(_) -> _ = ExprKind::Continue;
413-
c.hash(&mut self.s);
414410
if let Some(i) = i.label {
415411
self.hash_name(i.ident.name);
416412
}
417413
},
418414
ExprKind::Yield(ref e) => {
419-
let c: fn(_) -> _ = ExprKind::Yield;
420-
c.hash(&mut self.s);
421415
self.hash_expr(e);
422416
},
423417
ExprKind::Assign(ref l, ref r) => {
424-
let c: fn(_, _) -> _ = ExprKind::Assign;
425-
c.hash(&mut self.s);
426418
self.hash_expr(l);
427419
self.hash_expr(r);
428420
},
429421
ExprKind::AssignOp(ref o, ref l, ref r) => {
430-
let c: fn(_, _, _) -> _ = ExprKind::AssignOp;
431-
c.hash(&mut self.s);
432422
o.hash(&mut self.s);
433423
self.hash_expr(l);
434424
self.hash_expr(r);
435425
},
436426
ExprKind::Block(ref b, _) => {
437-
let c: fn(_, _) -> _ = ExprKind::Block;
438-
c.hash(&mut self.s);
439427
self.hash_block(b);
440428
},
441429
ExprKind::Binary(op, ref l, ref r) => {
442-
let c: fn(_, _, _) -> _ = ExprKind::Binary;
443-
c.hash(&mut self.s);
444430
op.node.hash(&mut self.s);
445431
self.hash_expr(l);
446432
self.hash_expr(r);
447433
},
448434
ExprKind::Break(i, ref j) => {
449-
let c: fn(_, _) -> _ = ExprKind::Break;
450-
c.hash(&mut self.s);
451435
if let Some(i) = i.label {
452436
self.hash_name(i.ident.name);
453437
}
@@ -456,25 +440,17 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
456440
}
457441
},
458442
ExprKind::Box(ref e) => {
459-
let c: fn(_) -> _ = ExprKind::Box;
460-
c.hash(&mut self.s);
461443
self.hash_expr(e);
462444
},
463445
ExprKind::Call(ref fun, ref args) => {
464-
let c: fn(_, _) -> _ = ExprKind::Call;
465-
c.hash(&mut self.s);
466446
self.hash_expr(fun);
467447
self.hash_exprs(args);
468448
},
469449
ExprKind::Cast(ref e, ref _ty) => {
470-
let c: fn(_, _) -> _ = ExprKind::Cast;
471-
c.hash(&mut self.s);
472450
self.hash_expr(e);
473451
// TODO: _ty
474452
},
475453
ExprKind::Closure(cap, _, eid, _, _) => {
476-
let c: fn(_, _, _, _, _) -> _ = ExprKind::Closure;
477-
c.hash(&mut self.s);
478454
match cap {
479455
CaptureClause::CaptureByValue => 0,
480456
CaptureClause::CaptureByRef => 1,
@@ -483,37 +459,24 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
483459
self.hash_expr(&self.cx.tcx.hir().body(eid).value);
484460
},
485461
ExprKind::Field(ref e, ref f) => {
486-
let c: fn(_, _) -> _ = ExprKind::Field;
487-
c.hash(&mut self.s);
488462
self.hash_expr(e);
489463
self.hash_name(f.name);
490464
},
491465
ExprKind::Index(ref a, ref i) => {
492-
let c: fn(_, _) -> _ = ExprKind::Index;
493-
c.hash(&mut self.s);
494466
self.hash_expr(a);
495467
self.hash_expr(i);
496468
},
497-
ExprKind::InlineAsm(..) => {
498-
let c: fn(_, _, _) -> _ = ExprKind::InlineAsm;
499-
c.hash(&mut self.s);
500-
},
469+
ExprKind::InlineAsm(..) => {},
501470
ExprKind::Lit(ref l) => {
502-
let c: fn(_) -> _ = ExprKind::Lit;
503-
c.hash(&mut self.s);
504471
l.hash(&mut self.s);
505472
},
506473
ExprKind::Loop(ref b, ref i, _) => {
507-
let c: fn(_, _, _) -> _ = ExprKind::Loop;
508-
c.hash(&mut self.s);
509474
self.hash_block(b);
510475
if let Some(i) = *i {
511476
self.hash_name(i.ident.name);
512477
}
513478
},
514479
ExprKind::Match(ref e, ref arms, ref s) => {
515-
let c: fn(_, _, _) -> _ = ExprKind::Match;
516-
c.hash(&mut self.s);
517480
self.hash_expr(e);
518481

519482
for arm in arms {
@@ -527,36 +490,25 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
527490
s.hash(&mut self.s);
528491
},
529492
ExprKind::MethodCall(ref path, ref _tys, ref args) => {
530-
let c: fn(_, _, _) -> _ = ExprKind::MethodCall;
531-
c.hash(&mut self.s);
532493
self.hash_name(path.ident.name);
533494
self.hash_exprs(args);
534495
},
535496
ExprKind::Repeat(ref e, ref l_id) => {
536-
let c: fn(_, _) -> _ = ExprKind::Repeat;
537-
c.hash(&mut self.s);
538497
self.hash_expr(e);
539498
let full_table = self.tables;
540499
self.tables = self.cx.tcx.body_tables(l_id.body);
541500
self.hash_expr(&self.cx.tcx.hir().body(l_id.body).value);
542501
self.tables = full_table;
543502
},
544503
ExprKind::Ret(ref e) => {
545-
let c: fn(_) -> _ = ExprKind::Ret;
546-
c.hash(&mut self.s);
547504
if let Some(ref e) = *e {
548505
self.hash_expr(e);
549506
}
550507
},
551508
ExprKind::Path(ref qpath) => {
552-
let c: fn(_) -> _ = ExprKind::Path;
553-
c.hash(&mut self.s);
554509
self.hash_qpath(qpath);
555510
},
556511
ExprKind::Struct(ref path, ref fields, ref expr) => {
557-
let c: fn(_, _, _) -> _ = ExprKind::Struct;
558-
c.hash(&mut self.s);
559-
560512
self.hash_qpath(path);
561513

562514
for f in fields {
@@ -569,33 +521,20 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
569521
}
570522
},
571523
ExprKind::Tup(ref tup) => {
572-
let c: fn(_) -> _ = ExprKind::Tup;
573-
c.hash(&mut self.s);
574524
self.hash_exprs(tup);
575525
},
576526
ExprKind::Type(ref e, ref _ty) => {
577-
let c: fn(_, _) -> _ = ExprKind::Type;
578-
c.hash(&mut self.s);
579527
self.hash_expr(e);
580528
// TODO: _ty
581529
},
582530
ExprKind::Unary(lop, ref le) => {
583-
let c: fn(_, _) -> _ = ExprKind::Unary;
584-
c.hash(&mut self.s);
585-
586531
lop.hash(&mut self.s);
587532
self.hash_expr(le);
588533
},
589534
ExprKind::Array(ref v) => {
590-
let c: fn(_) -> _ = ExprKind::Array;
591-
c.hash(&mut self.s);
592-
593535
self.hash_exprs(v);
594536
},
595537
ExprKind::While(ref cond, ref b, l) => {
596-
let c: fn(_, _, _) -> _ = ExprKind::While;
597-
c.hash(&mut self.s);
598-
599538
self.hash_expr(cond);
600539
self.hash_block(b);
601540
if let Some(l) = l {
@@ -604,8 +543,6 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
604543
},
605544
ExprKind::Err => {},
606545
ExprKind::DropTemps(ref e) => {
607-
let c: fn(_) -> _ = ExprKind::DropTemps;
608-
c.hash(&mut self.s);
609546
self.hash_expr(e);
610547
},
611548
}
@@ -643,24 +580,15 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
643580
pub fn hash_stmt(&mut self, b: &Stmt) {
644581
match b.node {
645582
StmtKind::Local(ref local) => {
646-
let c: fn(_) -> _ = StmtKind::Local;
647-
c.hash(&mut self.s);
648583
if let Some(ref init) = local.init {
649584
self.hash_expr(init);
650585
}
651586
},
652-
StmtKind::Item(..) => {
653-
let c: fn(_) -> _ = StmtKind::Item;
654-
c.hash(&mut self.s);
655-
},
587+
StmtKind::Item(..) => {},
656588
StmtKind::Expr(ref expr) => {
657-
let c: fn(_) -> _ = StmtKind::Expr;
658-
c.hash(&mut self.s);
659589
self.hash_expr(expr);
660590
},
661591
StmtKind::Semi(ref expr) => {
662-
let c: fn(_) -> _ = StmtKind::Semi;
663-
c.hash(&mut self.s);
664592
self.hash_expr(expr);
665593
},
666594
}
@@ -669,8 +597,6 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
669597
pub fn hash_guard(&mut self, g: &Guard) {
670598
match g {
671599
Guard::If(ref expr) => {
672-
let c: fn(_) -> _ = Guard::If;
673-
c.hash(&mut self.s);
674600
self.hash_expr(expr);
675601
},
676602
}

0 commit comments

Comments
 (0)