@@ -713,10 +713,9 @@ use rustc_hash::FxHashSet;
713713use rustc_index:: bit_set:: BitSet ;
714714use smallvec:: { smallvec, SmallVec } ;
715715use std:: fmt;
716- use std:: ops:: Deref ;
717716
718717use crate :: constructor:: { Constructor , ConstructorSet , IntRange } ;
719- use crate :: pat:: { DeconstructedPat , PatOrWild , WitnessPat } ;
718+ use crate :: pat:: { DeconstructedPat , PatId , PatOrWild , WitnessPat } ;
720719use crate :: { Captures , MatchArm , TypeCx } ;
721720
722721use self :: ValidityConstraint :: * ;
@@ -728,36 +727,13 @@ pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R {
728727 f ( )
729728}
730729
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-
753730/// Context that provides information for usefulness checking.
754- struct UsefulnessCtxt < ' a , ' p , Cx : TypeCx > {
731+ struct UsefulnessCtxt < ' a , Cx : TypeCx > {
755732 /// The context for type information.
756733 tycx : & ' a Cx ,
757734 /// 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 > ,
761737}
762738
763739/// Context that provides information local to a place under investigation.
@@ -1378,7 +1354,7 @@ impl<Cx: TypeCx> WitnessMatrix<Cx> {
13781354/// We can however get false negatives because exhaustiveness does not explore all cases. See the
13791355/// section on relevancy at the top of the file.
13801356fn collect_overlapping_range_endpoints < ' p , Cx : TypeCx > (
1381- mcx : & mut UsefulnessCtxt < ' _ , ' p , Cx > ,
1357+ mcx : & mut UsefulnessCtxt < ' _ , Cx > ,
13821358 overlap_range : IntRange ,
13831359 matrix : & Matrix < ' p , Cx > ,
13841360 specialized_matrix : & Matrix < ' p , Cx > ,
@@ -1451,7 +1427,7 @@ fn collect_overlapping_range_endpoints<'p, Cx: TypeCx>(
14511427/// This is all explained at the top of the file.
14521428#[ instrument( level = "debug" , skip( mcx, is_top_level) , ret) ]
14531429fn compute_exhaustiveness_and_usefulness < ' a , ' p , Cx : TypeCx > (
1454- mcx : & mut UsefulnessCtxt < ' a , ' p , Cx > ,
1430+ mcx : & mut UsefulnessCtxt < ' a , Cx > ,
14551431 matrix : & mut Matrix < ' p , Cx > ,
14561432 is_top_level : bool ,
14571433) -> Result < WitnessMatrix < Cx > , Cx :: Error > {
@@ -1580,7 +1556,7 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
15801556 for row in matrix. rows ( ) {
15811557 if row. useful {
15821558 if let PatOrWild :: Pat ( pat) = row. head ( ) {
1583- mcx. useful_subpatterns . insert ( ByAddress ( pat) ) ;
1559+ mcx. useful_subpatterns . insert ( pat. uid ) ;
15841560 }
15851561 }
15861562 }
@@ -1602,14 +1578,14 @@ pub enum Usefulness<'p, Cx: TypeCx> {
16021578
16031579/// Report whether this pattern was found useful, and its subpatterns that were not useful if any.
16041580fn collect_pattern_usefulness < ' p , Cx : TypeCx > (
1605- useful_subpatterns : & FxHashSet < ByAddress < & ' p DeconstructedPat < Cx > > > ,
1581+ useful_subpatterns : & FxHashSet < PatId > ,
16061582 pat : & ' p DeconstructedPat < Cx > ,
16071583) -> Usefulness < ' p , Cx > {
16081584 fn pat_is_useful < ' p , Cx : TypeCx > (
1609- useful_subpatterns : & FxHashSet < ByAddress < & ' p DeconstructedPat < Cx > > > ,
1585+ useful_subpatterns : & FxHashSet < PatId > ,
16101586 pat : & ' p DeconstructedPat < Cx > ,
16111587 ) -> bool {
1612- if useful_subpatterns. contains ( & ByAddress ( pat) ) {
1588+ if useful_subpatterns. contains ( & pat. uid ) {
16131589 true
16141590 } else if pat. is_or_pat ( ) && pat. iter_fields ( ) . any ( |f| pat_is_useful ( useful_subpatterns, f) )
16151591 {
0 commit comments