@@ -713,10 +713,9 @@ use rustc_hash::FxHashSet;
713
713
use rustc_index:: bit_set:: BitSet ;
714
714
use smallvec:: { smallvec, SmallVec } ;
715
715
use std:: fmt;
716
- use std:: ops:: Deref ;
717
716
718
717
use crate :: constructor:: { Constructor , ConstructorSet , IntRange } ;
719
- use crate :: pat:: { DeconstructedPat , PatOrWild , WitnessPat } ;
718
+ use crate :: pat:: { DeconstructedPat , PatId , PatOrWild , WitnessPat } ;
720
719
use crate :: { Captures , MatchArm , TypeCx } ;
721
720
722
721
use self :: ValidityConstraint :: * ;
@@ -728,36 +727,13 @@ pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R {
728
727
f ( )
729
728
}
730
729
731
- /// Wrapper type for by-address hashing. Comparison and hashing of the wrapped pointer type will be
732
- /// based on the address of its contents, rather than their value.
733
- struct ByAddress < T > ( T ) ;
734
-
735
- impl < T : Deref > ByAddress < T > {
736
- fn addr ( & self ) -> * const T :: Target {
737
- ( & * self . 0 ) as * const _
738
- }
739
- }
740
- /// Raw pointer hashing and comparison.
741
- impl < T : Deref > std:: hash:: Hash for ByAddress < T > {
742
- fn hash < H : std:: hash:: Hasher > ( & self , state : & mut H ) {
743
- self . addr ( ) . hash ( state)
744
- }
745
- }
746
- impl < T : Deref > PartialEq for ByAddress < T > {
747
- fn eq ( & self , other : & Self ) -> bool {
748
- std:: ptr:: eq ( self . addr ( ) , other. addr ( ) )
749
- }
750
- }
751
- impl < T : Deref > Eq for ByAddress < T > { }
752
-
753
730
/// Context that provides information for usefulness checking.
754
- struct UsefulnessCtxt < ' a , ' p , Cx : TypeCx > {
731
+ struct UsefulnessCtxt < ' a , Cx : TypeCx > {
755
732
/// The context for type information.
756
733
tycx : & ' a Cx ,
757
734
/// Collect the patterns found useful during usefulness checking. This is used to lint
758
- /// unreachable (sub)patterns. We distinguish patterns by their address to avoid needing to
759
- /// inspect the contents. They'll all be distinct anyway since they carry a `Span`.
760
- useful_subpatterns : FxHashSet < ByAddress < & ' p DeconstructedPat < Cx > > > ,
735
+ /// unreachable (sub)patterns.
736
+ useful_subpatterns : FxHashSet < PatId > ,
761
737
}
762
738
763
739
/// Context that provides information local to a place under investigation.
@@ -1378,7 +1354,7 @@ impl<Cx: TypeCx> WitnessMatrix<Cx> {
1378
1354
/// We can however get false negatives because exhaustiveness does not explore all cases. See the
1379
1355
/// section on relevancy at the top of the file.
1380
1356
fn collect_overlapping_range_endpoints < ' p , Cx : TypeCx > (
1381
- mcx : & mut UsefulnessCtxt < ' _ , ' p , Cx > ,
1357
+ mcx : & mut UsefulnessCtxt < ' _ , Cx > ,
1382
1358
overlap_range : IntRange ,
1383
1359
matrix : & Matrix < ' p , Cx > ,
1384
1360
specialized_matrix : & Matrix < ' p , Cx > ,
@@ -1451,7 +1427,7 @@ fn collect_overlapping_range_endpoints<'p, Cx: TypeCx>(
1451
1427
/// This is all explained at the top of the file.
1452
1428
#[ instrument( level = "debug" , skip( mcx, is_top_level) , ret) ]
1453
1429
fn compute_exhaustiveness_and_usefulness < ' a , ' p , Cx : TypeCx > (
1454
- mcx : & mut UsefulnessCtxt < ' a , ' p , Cx > ,
1430
+ mcx : & mut UsefulnessCtxt < ' a , Cx > ,
1455
1431
matrix : & mut Matrix < ' p , Cx > ,
1456
1432
is_top_level : bool ,
1457
1433
) -> Result < WitnessMatrix < Cx > , Cx :: Error > {
@@ -1580,7 +1556,7 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
1580
1556
for row in matrix. rows ( ) {
1581
1557
if row. useful {
1582
1558
if let PatOrWild :: Pat ( pat) = row. head ( ) {
1583
- mcx. useful_subpatterns . insert ( ByAddress ( pat) ) ;
1559
+ mcx. useful_subpatterns . insert ( pat. uid ) ;
1584
1560
}
1585
1561
}
1586
1562
}
@@ -1602,14 +1578,14 @@ pub enum Usefulness<'p, Cx: TypeCx> {
1602
1578
1603
1579
/// Report whether this pattern was found useful, and its subpatterns that were not useful if any.
1604
1580
fn collect_pattern_usefulness < ' p , Cx : TypeCx > (
1605
- useful_subpatterns : & FxHashSet < ByAddress < & ' p DeconstructedPat < Cx > > > ,
1581
+ useful_subpatterns : & FxHashSet < PatId > ,
1606
1582
pat : & ' p DeconstructedPat < Cx > ,
1607
1583
) -> Usefulness < ' p , Cx > {
1608
1584
fn pat_is_useful < ' p , Cx : TypeCx > (
1609
- useful_subpatterns : & FxHashSet < ByAddress < & ' p DeconstructedPat < Cx > > > ,
1585
+ useful_subpatterns : & FxHashSet < PatId > ,
1610
1586
pat : & ' p DeconstructedPat < Cx > ,
1611
1587
) -> bool {
1612
- if useful_subpatterns. contains ( & ByAddress ( pat) ) {
1588
+ if useful_subpatterns. contains ( & pat. uid ) {
1613
1589
true
1614
1590
} else if pat. is_or_pat ( ) && pat. iter_fields ( ) . any ( |f| pat_is_useful ( useful_subpatterns, f) )
1615
1591
{
0 commit comments