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