@@ -45,7 +45,7 @@ bitflags! {
45
45
// Borrows of temporaries can be promoted only if
46
46
// they have none of these qualifications.
47
47
struct Qualif : u8 {
48
- // Constant containing interior mutability (UnsafeCell).
48
+ // Constant containing interior mutability (` UnsafeCell` ).
49
49
const MUTABLE_INTERIOR = 1 << 0 ;
50
50
51
51
// Constant containing an ADT that implements Drop.
@@ -62,11 +62,12 @@ impl<'a, 'tcx> Qualif {
62
62
fn restrict ( & mut self , ty : Ty < ' tcx > ,
63
63
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
64
64
param_env : ty:: ParamEnv < ' tcx > ) {
65
+ self . insert ( Qualif :: MUTABLE_INTERIOR | Qualif :: NEEDS_DROP ) ;
65
66
if ty. is_freeze ( tcx, param_env, DUMMY_SP ) {
66
- * self = * self - Qualif :: MUTABLE_INTERIOR ;
67
+ self . remove ( Qualif :: MUTABLE_INTERIOR ) ;
67
68
}
68
69
if !ty. needs_drop ( tcx, param_env) {
69
- * self = * self - Qualif :: NEEDS_DROP ;
70
+ self . remove ( Qualif :: NEEDS_DROP ) ;
70
71
}
71
72
}
72
73
}
@@ -183,18 +184,17 @@ impl<'a, 'tcx> Qualifier<'a, 'tcx, 'tcx> {
183
184
}
184
185
}
185
186
186
- /// Add the given qualification to self.qualif.
187
+ /// Add the given qualification to ` self.qualif` .
187
188
fn add ( & mut self , qualif : Qualif ) {
188
189
self . qualif = self . qualif | qualif;
189
190
}
190
191
191
- /// Add the given type's qualification to self.qualif.
192
- fn add_type ( & mut self , ty : Ty < ' tcx > ) {
193
- self . add ( Qualif :: MUTABLE_INTERIOR | Qualif :: NEEDS_DROP ) ;
192
+ /// Restrict `self.qualif` by the given type's qualification.
193
+ fn restrict_to_type ( & mut self , ty : Ty < ' tcx > ) {
194
194
self . qualif . restrict ( ty, self . tcx , self . param_env ) ;
195
195
}
196
196
197
- /// Within the provided closure, self.qualif will start
197
+ /// Within the provided closure, ` self.qualif` will start
198
198
/// out empty, and its value after the closure returns will
199
199
/// be combined with the value before the call to nest.
200
200
fn nest < F : FnOnce ( & mut Self ) > ( & mut self , f : F ) {
@@ -501,7 +501,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
501
501
}
502
502
503
503
let ty = place. ty ( this. mir , this. tcx ) . to_ty ( this. tcx ) ;
504
- this. qualif . restrict ( ty, this . tcx , this . param_env ) ;
504
+ this. restrict_to_type ( ty) ;
505
505
}
506
506
507
507
ProjectionElem :: ConstantIndex { ..} |
@@ -534,7 +534,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
534
534
} = constant. literal {
535
535
// Don't peek inside trait associated constants.
536
536
if self . tcx . trait_of_item ( def_id) . is_some ( ) {
537
- self . add_type ( ty) ;
537
+ self . restrict_to_type ( ty) ;
538
538
} else {
539
539
let ( bits, _) = self . tcx . at ( constant. span ) . mir_const_qualif ( def_id) ;
540
540
@@ -936,16 +936,9 @@ This does not pose a problem by itself because they can't be accessed directly."
936
936
}
937
937
938
938
if let Some ( ( ref dest, _) ) = * destination {
939
- // Avoid propagating irrelevant callee/argument qualifications.
940
- if self . qualif . intersects ( Qualif :: NOT_CONST ) {
941
- self . qualif = Qualif :: NOT_CONST ;
942
- } else {
943
- // Be conservative about the returned value of a const fn.
944
- let tcx = self . tcx ;
945
- let ty = dest. ty ( self . mir , tcx) . to_ty ( tcx) ;
946
- self . qualif = Qualif :: empty ( ) ;
947
- self . add_type ( ty) ;
948
- }
939
+ // Be conservative about the returned value of a const fn.
940
+ let ty = dest. ty ( self . mir , self . tcx ) . to_ty ( self . tcx ) ;
941
+ self . restrict_to_type ( ty) ;
949
942
self . assign ( dest, location) ;
950
943
}
951
944
} else if let TerminatorKind :: Drop { location : ref place, .. } = * kind {
0 commit comments