@@ -392,57 +392,49 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
392
392
393
393
#[ allow( clippy:: many_single_char_names, clippy:: too_many_lines) ]
394
394
pub fn hash_expr ( & mut self , e : & Expr ) {
395
- if let Some ( e) = constant_simple ( self . cx , self . tables , e) {
395
+ let simple_const = constant_simple ( self . cx , self . tables , e) ;
396
+
397
+ // const hashing may result in the same hash as some unrelated node, so add a sort of
398
+ // discriminant depending on which path we're choosing next
399
+ simple_const. is_some ( ) . hash ( & mut self . s ) ;
400
+
401
+ if let Some ( e) = simple_const {
396
402
return e. hash ( & mut self . s ) ;
397
403
}
398
404
405
+ std:: mem:: discriminant ( & e. node ) . hash ( & mut self . s ) ;
406
+
399
407
match e. node {
400
408
ExprKind :: AddrOf ( m, ref e) => {
401
- let c: fn ( _, _) -> _ = ExprKind :: AddrOf ;
402
- c. hash ( & mut self . s ) ;
403
409
m. hash ( & mut self . s ) ;
404
410
self . hash_expr ( e) ;
405
411
} ,
406
412
ExprKind :: Continue ( i) => {
407
- let c: fn ( _) -> _ = ExprKind :: Continue ;
408
- c. hash ( & mut self . s ) ;
409
413
if let Some ( i) = i. label {
410
414
self . hash_name ( i. ident . name ) ;
411
415
}
412
416
} ,
413
417
ExprKind :: Yield ( ref e) => {
414
- let c: fn ( _) -> _ = ExprKind :: Yield ;
415
- c. hash ( & mut self . s ) ;
416
418
self . hash_expr ( e) ;
417
419
} ,
418
420
ExprKind :: Assign ( ref l, ref r) => {
419
- let c: fn ( _, _) -> _ = ExprKind :: Assign ;
420
- c. hash ( & mut self . s ) ;
421
421
self . hash_expr ( l) ;
422
422
self . hash_expr ( r) ;
423
423
} ,
424
424
ExprKind :: AssignOp ( ref o, ref l, ref r) => {
425
- let c: fn ( _, _, _) -> _ = ExprKind :: AssignOp ;
426
- c. hash ( & mut self . s ) ;
427
425
o. hash ( & mut self . s ) ;
428
426
self . hash_expr ( l) ;
429
427
self . hash_expr ( r) ;
430
428
} ,
431
429
ExprKind :: Block ( ref b, _) => {
432
- let c: fn ( _, _) -> _ = ExprKind :: Block ;
433
- c. hash ( & mut self . s ) ;
434
430
self . hash_block ( b) ;
435
431
} ,
436
432
ExprKind :: Binary ( op, ref l, ref r) => {
437
- let c: fn ( _, _, _) -> _ = ExprKind :: Binary ;
438
- c. hash ( & mut self . s ) ;
439
433
op. node . hash ( & mut self . s ) ;
440
434
self . hash_expr ( l) ;
441
435
self . hash_expr ( r) ;
442
436
} ,
443
437
ExprKind :: Break ( i, ref j) => {
444
- let c: fn ( _, _) -> _ = ExprKind :: Break ;
445
- c. hash ( & mut self . s ) ;
446
438
if let Some ( i) = i. label {
447
439
self . hash_name ( i. ident . name ) ;
448
440
}
@@ -451,25 +443,17 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
451
443
}
452
444
} ,
453
445
ExprKind :: Box ( ref e) => {
454
- let c: fn ( _) -> _ = ExprKind :: Box ;
455
- c. hash ( & mut self . s ) ;
456
446
self . hash_expr ( e) ;
457
447
} ,
458
448
ExprKind :: Call ( ref fun, ref args) => {
459
- let c: fn ( _, _) -> _ = ExprKind :: Call ;
460
- c. hash ( & mut self . s ) ;
461
449
self . hash_expr ( fun) ;
462
450
self . hash_exprs ( args) ;
463
451
} ,
464
452
ExprKind :: Cast ( ref e, ref _ty) => {
465
- let c: fn ( _, _) -> _ = ExprKind :: Cast ;
466
- c. hash ( & mut self . s ) ;
467
453
self . hash_expr ( e) ;
468
454
// TODO: _ty
469
455
} ,
470
456
ExprKind :: Closure ( cap, _, eid, _, _) => {
471
- let c: fn ( _, _, _, _, _) -> _ = ExprKind :: Closure ;
472
- c. hash ( & mut self . s ) ;
473
457
match cap {
474
458
CaptureClause :: CaptureByValue => 0 ,
475
459
CaptureClause :: CaptureByRef => 1 ,
@@ -478,46 +462,31 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
478
462
self . hash_expr ( & self . cx . tcx . hir ( ) . body ( eid) . value ) ;
479
463
} ,
480
464
ExprKind :: Field ( ref e, ref f) => {
481
- let c: fn ( _, _) -> _ = ExprKind :: Field ;
482
- c. hash ( & mut self . s ) ;
483
465
self . hash_expr ( e) ;
484
466
self . hash_name ( f. name ) ;
485
467
} ,
486
468
ExprKind :: Index ( ref a, ref i) => {
487
- let c: fn ( _, _) -> _ = ExprKind :: Index ;
488
- c. hash ( & mut self . s ) ;
489
469
self . hash_expr ( a) ;
490
470
self . hash_expr ( i) ;
491
471
} ,
492
- ExprKind :: InlineAsm ( ..) => {
493
- let c: fn ( _, _, _) -> _ = ExprKind :: InlineAsm ;
494
- c. hash ( & mut self . s ) ;
495
- } ,
472
+ ExprKind :: InlineAsm ( ..) => { } ,
496
473
ExprKind :: If ( ref cond, ref t, ref e) => {
497
- let c: fn ( _, _, _) -> _ = ExprKind :: If ;
498
- c. hash ( & mut self . s ) ;
499
474
self . hash_expr ( cond) ;
500
475
self . hash_expr ( & * * t) ;
501
476
if let Some ( ref e) = * e {
502
477
self . hash_expr ( e) ;
503
478
}
504
479
} ,
505
480
ExprKind :: Lit ( ref l) => {
506
- let c: fn ( _) -> _ = ExprKind :: Lit ;
507
- c. hash ( & mut self . s ) ;
508
481
l. hash ( & mut self . s ) ;
509
482
} ,
510
483
ExprKind :: Loop ( ref b, ref i, _) => {
511
- let c: fn ( _, _, _) -> _ = ExprKind :: Loop ;
512
- c. hash ( & mut self . s ) ;
513
484
self . hash_block ( b) ;
514
485
if let Some ( i) = * i {
515
486
self . hash_name ( i. ident . name ) ;
516
487
}
517
488
} ,
518
489
ExprKind :: Match ( ref e, ref arms, ref s) => {
519
- let c: fn ( _, _, _) -> _ = ExprKind :: Match ;
520
- c. hash ( & mut self . s ) ;
521
490
self . hash_expr ( e) ;
522
491
523
492
for arm in arms {
@@ -531,36 +500,25 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
531
500
s. hash ( & mut self . s ) ;
532
501
} ,
533
502
ExprKind :: MethodCall ( ref path, ref _tys, ref args) => {
534
- let c: fn ( _, _, _) -> _ = ExprKind :: MethodCall ;
535
- c. hash ( & mut self . s ) ;
536
503
self . hash_name ( path. ident . name ) ;
537
504
self . hash_exprs ( args) ;
538
505
} ,
539
506
ExprKind :: Repeat ( ref e, ref l_id) => {
540
- let c: fn ( _, _) -> _ = ExprKind :: Repeat ;
541
- c. hash ( & mut self . s ) ;
542
507
self . hash_expr ( e) ;
543
508
let full_table = self . tables ;
544
509
self . tables = self . cx . tcx . body_tables ( l_id. body ) ;
545
510
self . hash_expr ( & self . cx . tcx . hir ( ) . body ( l_id. body ) . value ) ;
546
511
self . tables = full_table;
547
512
} ,
548
513
ExprKind :: Ret ( ref e) => {
549
- let c: fn ( _) -> _ = ExprKind :: Ret ;
550
- c. hash ( & mut self . s ) ;
551
514
if let Some ( ref e) = * e {
552
515
self . hash_expr ( e) ;
553
516
}
554
517
} ,
555
518
ExprKind :: Path ( ref qpath) => {
556
- let c: fn ( _) -> _ = ExprKind :: Path ;
557
- c. hash ( & mut self . s ) ;
558
519
self . hash_qpath ( qpath) ;
559
520
} ,
560
521
ExprKind :: Struct ( ref path, ref fields, ref expr) => {
561
- let c: fn ( _, _, _) -> _ = ExprKind :: Struct ;
562
- c. hash ( & mut self . s ) ;
563
-
564
522
self . hash_qpath ( path) ;
565
523
566
524
for f in fields {
@@ -573,33 +531,20 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
573
531
}
574
532
} ,
575
533
ExprKind :: Tup ( ref tup) => {
576
- let c: fn ( _) -> _ = ExprKind :: Tup ;
577
- c. hash ( & mut self . s ) ;
578
534
self . hash_exprs ( tup) ;
579
535
} ,
580
536
ExprKind :: Type ( ref e, ref _ty) => {
581
- let c: fn ( _, _) -> _ = ExprKind :: Type ;
582
- c. hash ( & mut self . s ) ;
583
537
self . hash_expr ( e) ;
584
538
// TODO: _ty
585
539
} ,
586
540
ExprKind :: Unary ( lop, ref le) => {
587
- let c: fn ( _, _) -> _ = ExprKind :: Unary ;
588
- c. hash ( & mut self . s ) ;
589
-
590
541
lop. hash ( & mut self . s ) ;
591
542
self . hash_expr ( le) ;
592
543
} ,
593
544
ExprKind :: Array ( ref v) => {
594
- let c: fn ( _) -> _ = ExprKind :: Array ;
595
- c. hash ( & mut self . s ) ;
596
-
597
545
self . hash_exprs ( v) ;
598
546
} ,
599
547
ExprKind :: While ( ref cond, ref b, l) => {
600
- let c: fn ( _, _, _) -> _ = ExprKind :: While ;
601
- c. hash ( & mut self . s ) ;
602
-
603
548
self . hash_expr ( cond) ;
604
549
self . hash_block ( b) ;
605
550
if let Some ( l) = l {
@@ -608,8 +553,6 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
608
553
} ,
609
554
ExprKind :: Err => { } ,
610
555
ExprKind :: DropTemps ( ref e) => {
611
- let c: fn ( _) -> _ = ExprKind :: DropTemps ;
612
- c. hash ( & mut self . s ) ;
613
556
self . hash_expr ( e) ;
614
557
} ,
615
558
}
@@ -647,24 +590,15 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
647
590
pub fn hash_stmt ( & mut self , b : & Stmt ) {
648
591
match b. node {
649
592
StmtKind :: Local ( ref local) => {
650
- let c: fn ( _) -> _ = StmtKind :: Local ;
651
- c. hash ( & mut self . s ) ;
652
593
if let Some ( ref init) = local. init {
653
594
self . hash_expr ( init) ;
654
595
}
655
596
} ,
656
- StmtKind :: Item ( ..) => {
657
- let c: fn ( _) -> _ = StmtKind :: Item ;
658
- c. hash ( & mut self . s ) ;
659
- } ,
597
+ StmtKind :: Item ( ..) => { } ,
660
598
StmtKind :: Expr ( ref expr) => {
661
- let c: fn ( _) -> _ = StmtKind :: Expr ;
662
- c. hash ( & mut self . s ) ;
663
599
self . hash_expr ( expr) ;
664
600
} ,
665
601
StmtKind :: Semi ( ref expr) => {
666
- let c: fn ( _) -> _ = StmtKind :: Semi ;
667
- c. hash ( & mut self . s ) ;
668
602
self . hash_expr ( expr) ;
669
603
} ,
670
604
}
@@ -673,8 +607,6 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
673
607
pub fn hash_guard ( & mut self , g : & Guard ) {
674
608
match g {
675
609
Guard :: If ( ref expr) => {
676
- let c: fn ( _) -> _ = Guard :: If ;
677
- c. hash ( & mut self . s ) ;
678
610
self . hash_expr ( expr) ;
679
611
} ,
680
612
}
0 commit comments