@@ -6,12 +6,10 @@ use syntax_pos::DUMMY_SP;
6
6
7
7
use super :: { ConstKind , Item as ConstCx } ;
8
8
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) ,
15
13
}
16
14
}
17
15
@@ -22,14 +20,14 @@ impl QualifSet {
22
20
///
23
21
/// The default implementations proceed structurally.
24
22
pub trait Qualif {
25
- const IDX : usize ;
26
-
27
23
/// The name of the file used to debug the dataflow analysis that computes this qualif.
28
24
const ANALYSIS_NAME : & ' static str ;
29
25
30
26
/// Whether this `Qualif` is cleared when a local is moved from.
31
27
const IS_CLEARED_ON_MOVE : bool = false ;
32
28
29
+ fn in_qualif_set ( set : & QualifSet ) -> bool ;
30
+
33
31
/// Return the qualification that is (conservatively) correct for any value
34
32
/// of the type.
35
33
fn in_any_value_of_ty ( _cx : & ConstCx < ' _ , ' tcx > , _ty : Ty < ' tcx > ) -> bool ;
@@ -122,9 +120,8 @@ pub trait Qualif {
122
120
if cx. tcx . trait_of_item ( def_id) . is_some ( ) {
123
121
Self :: in_any_value_of_ty ( cx, constant. literal . ty )
124
122
} 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) ;
128
125
129
126
// Just in case the type is more specific than
130
127
// the definition, e.g., impl associated const
@@ -210,9 +207,12 @@ pub trait Qualif {
210
207
pub struct HasMutInterior ;
211
208
212
209
impl Qualif for HasMutInterior {
213
- const IDX : usize = 0 ;
214
210
const ANALYSIS_NAME : & ' static str = "flow_has_mut_interior" ;
215
211
212
+ fn in_qualif_set ( set : & QualifSet ) -> bool {
213
+ set. has_mut_interior
214
+ }
215
+
216
216
fn in_any_value_of_ty ( cx : & ConstCx < ' _ , ' tcx > , ty : Ty < ' tcx > ) -> bool {
217
217
!ty. is_freeze ( cx. tcx , cx. param_env , DUMMY_SP )
218
218
}
@@ -275,10 +275,13 @@ impl Qualif for HasMutInterior {
275
275
pub struct NeedsDrop ;
276
276
277
277
impl Qualif for NeedsDrop {
278
- const IDX : usize = 1 ;
279
278
const ANALYSIS_NAME : & ' static str = "flow_needs_drop" ;
280
279
const IS_CLEARED_ON_MOVE : bool = true ;
281
280
281
+ fn in_qualif_set ( set : & QualifSet ) -> bool {
282
+ set. needs_drop
283
+ }
284
+
282
285
fn in_any_value_of_ty ( cx : & ConstCx < ' _ , ' tcx > , ty : Ty < ' tcx > ) -> bool {
283
286
ty. needs_drop ( cx. tcx , cx. param_env )
284
287
}
0 commit comments