@@ -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.
@@ -1398,7 +1374,7 @@ impl<Cx: TypeCx> WitnessMatrix<Cx> {
1398
1374
/// We can however get false negatives because exhaustiveness does not explore all cases. See the
1399
1375
/// section on relevancy at the top of the file.
1400
1376
fn collect_overlapping_range_endpoints < ' p , Cx : TypeCx > (
1401
- mcx : & mut UsefulnessCtxt < ' _ , ' p , Cx > ,
1377
+ mcx : & mut UsefulnessCtxt < ' _ , Cx > ,
1402
1378
overlap_range : IntRange ,
1403
1379
matrix : & Matrix < ' p , Cx > ,
1404
1380
specialized_matrix : & Matrix < ' p , Cx > ,
@@ -1471,7 +1447,7 @@ fn collect_overlapping_range_endpoints<'p, Cx: TypeCx>(
1471
1447
/// This is all explained at the top of the file.
1472
1448
#[ instrument( level = "debug" , skip( mcx) , ret) ]
1473
1449
fn compute_exhaustiveness_and_usefulness < ' a , ' p , Cx : TypeCx > (
1474
- mcx : & mut UsefulnessCtxt < ' a , ' p , Cx > ,
1450
+ mcx : & mut UsefulnessCtxt < ' a , Cx > ,
1475
1451
matrix : & mut Matrix < ' p , Cx > ,
1476
1452
) -> Result < WitnessMatrix < Cx > , Cx :: Error > {
1477
1453
debug_assert ! ( matrix. rows( ) . all( |r| r. len( ) == matrix. column_count( ) ) ) ;
@@ -1598,7 +1574,7 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
1598
1574
for row in matrix. rows ( ) {
1599
1575
if row. useful {
1600
1576
if let PatOrWild :: Pat ( pat) = row. head ( ) {
1601
- mcx. useful_subpatterns . insert ( ByAddress ( pat) ) ;
1577
+ mcx. useful_subpatterns . insert ( pat. uid ) ;
1602
1578
}
1603
1579
}
1604
1580
}
@@ -1620,14 +1596,14 @@ pub enum Usefulness<'p, Cx: TypeCx> {
1620
1596
1621
1597
/// Report whether this pattern was found useful, and its subpatterns that were not useful if any.
1622
1598
fn collect_pattern_usefulness < ' p , Cx : TypeCx > (
1623
- useful_subpatterns : & FxHashSet < ByAddress < & ' p DeconstructedPat < Cx > > > ,
1599
+ useful_subpatterns : & FxHashSet < PatId > ,
1624
1600
pat : & ' p DeconstructedPat < Cx > ,
1625
1601
) -> Usefulness < ' p , Cx > {
1626
1602
fn pat_is_useful < ' p , Cx : TypeCx > (
1627
- useful_subpatterns : & FxHashSet < ByAddress < & ' p DeconstructedPat < Cx > > > ,
1603
+ useful_subpatterns : & FxHashSet < PatId > ,
1628
1604
pat : & ' p DeconstructedPat < Cx > ,
1629
1605
) -> bool {
1630
- if useful_subpatterns. contains ( & ByAddress ( pat) ) {
1606
+ if useful_subpatterns. contains ( & pat. uid ) {
1631
1607
true
1632
1608
} else if pat. is_or_pat ( ) && pat. iter_fields ( ) . any ( |f| pat_is_useful ( useful_subpatterns, f) )
1633
1609
{
0 commit comments