@@ -6,12 +6,10 @@ use syntax_pos::DUMMY_SP;
66
77use super :: { ConstKind , Item as ConstCx } ;
88
9- #[ derive( Clone , Copy ) ]
10- pub struct QualifSet ( u8 ) ;
11-
12- impl QualifSet {
13- fn contains < Q : ?Sized + Qualif > ( self ) -> bool {
14- self . 0 & ( 1 << Q :: IDX ) != 0
9+ pub fn in_any_value_of_ty ( cx : & ConstCx < ' _ , ' tcx > , ty : Ty < ' tcx > ) -> QualifSet {
10+ QualifSet {
11+ has_mut_interior : HasMutInterior :: in_any_value_of_ty ( cx, ty) ,
12+ needs_drop : NeedsDrop :: in_any_value_of_ty ( cx, ty) ,
1513 }
1614}
1715
@@ -22,14 +20,14 @@ impl QualifSet {
2220///
2321/// The default implementations proceed structurally.
2422pub trait Qualif {
25- const IDX : usize ;
26-
2723 /// The name of the file used to debug the dataflow analysis that computes this qualif.
2824 const ANALYSIS_NAME : & ' static str ;
2925
3026 /// Whether this `Qualif` is cleared when a local is moved from.
3127 const IS_CLEARED_ON_MOVE : bool = false ;
3228
29+ fn in_qualif_set ( set : & QualifSet ) -> bool ;
30+
3331 /// Return the qualification that is (conservatively) correct for any value
3432 /// of the type.
3533 fn in_any_value_of_ty ( _cx : & ConstCx < ' _ , ' tcx > , _ty : Ty < ' tcx > ) -> bool ;
@@ -122,9 +120,8 @@ pub trait Qualif {
122120 if cx. tcx . trait_of_item ( def_id) . is_some ( ) {
123121 Self :: in_any_value_of_ty ( cx, constant. literal . ty )
124122 } else {
125- let bits = cx. tcx . at ( constant. span ) . mir_const_qualif ( def_id) ;
126-
127- let qualif = QualifSet ( bits) . contains :: < Self > ( ) ;
123+ let qualifs = cx. tcx . at ( constant. span ) . mir_const_qualif ( def_id) ;
124+ let qualif = Self :: in_qualif_set ( & qualifs) ;
128125
129126 // Just in case the type is more specific than
130127 // the definition, e.g., impl associated const
@@ -210,9 +207,12 @@ pub trait Qualif {
210207pub struct HasMutInterior ;
211208
212209impl Qualif for HasMutInterior {
213- const IDX : usize = 0 ;
214210 const ANALYSIS_NAME : & ' static str = "flow_has_mut_interior" ;
215211
212+ fn in_qualif_set ( set : & QualifSet ) -> bool {
213+ set. has_mut_interior
214+ }
215+
216216 fn in_any_value_of_ty ( cx : & ConstCx < ' _ , ' tcx > , ty : Ty < ' tcx > ) -> bool {
217217 !ty. is_freeze ( cx. tcx , cx. param_env , DUMMY_SP )
218218 }
@@ -275,10 +275,13 @@ impl Qualif for HasMutInterior {
275275pub struct NeedsDrop ;
276276
277277impl Qualif for NeedsDrop {
278- const IDX : usize = 1 ;
279278 const ANALYSIS_NAME : & ' static str = "flow_needs_drop" ;
280279 const IS_CLEARED_ON_MOVE : bool = true ;
281280
281+ fn in_qualif_set ( set : & QualifSet ) -> bool {
282+ set. needs_drop
283+ }
284+
282285 fn in_any_value_of_ty ( cx : & ConstCx < ' _ , ' tcx > , ty : Ty < ' tcx > ) -> bool {
283286 ty. needs_drop ( cx. tcx , cx. param_env )
284287 }
0 commit comments