22//!
33//! See the `Qualif` trait for more info.
44
5+ use crate :: dataflow:: { fmt:: DebugWithContext , JoinSemiLattice } ;
56use rustc_errors:: ErrorReported ;
7+ use rustc_index:: bit_set:: BitSet ;
8+ use rustc_index:: vec:: IndexVec ;
69use rustc_middle:: mir:: * ;
710use rustc_middle:: ty:: { self , subst:: SubstsRef , AdtDef , Ty } ;
811use rustc_span:: DUMMY_SP ;
912use rustc_trait_selection:: traits;
10- use rustc_index:: vec:: IndexVec ;
11- use rustc_index:: bit_set:: BitSet ;
12- use crate :: dataflow:: { JoinSemiLattice , fmt:: DebugWithContext } ;
1313
1414use super :: ConstCx ;
1515
@@ -64,7 +64,11 @@ pub(crate) trait Qualif {
6464
6565 /// Sometimes const fn calls cannot possibly contain the qualif, so we can treat function
6666 /// calls special here.
67- fn in_any_function_call ( cx : & ConstCx < ' _ , ' tcx > , ty : Ty < ' tcx > , _args : Option < Self :: Result > ) -> Option < Self :: Result > {
67+ fn in_any_function_call (
68+ cx : & ConstCx < ' _ , ' tcx > ,
69+ ty : Ty < ' tcx > ,
70+ _args : Option < Self :: Result > ,
71+ ) -> Option < Self :: Result > {
6872 Self :: in_any_value_of_ty ( cx, ty)
6973 }
7074
@@ -159,7 +163,11 @@ impl Qualif for HasMutInterior {
159163 ( !ty. is_freeze ( cx. tcx . at ( DUMMY_SP ) , cx. param_env ) ) . then_some ( ( ) )
160164 }
161165
162- fn in_adt_inherently ( cx : & ConstCx < ' _ , ' tcx > , adt : & ' tcx AdtDef , _: SubstsRef < ' tcx > ) -> Option < ( ) > {
166+ fn in_adt_inherently (
167+ cx : & ConstCx < ' _ , ' tcx > ,
168+ adt : & ' tcx AdtDef ,
169+ _: SubstsRef < ' tcx > ,
170+ ) -> Option < ( ) > {
163171 // Exactly one type, `UnsafeCell`, has the `HasMutInterior` qualif inherently.
164172 // It arises structurally for all other types.
165173 ( Some ( adt. did ) == cx. tcx . lang_items ( ) . unsafe_cell_type ( ) ) . then_some ( ( ) )
@@ -190,7 +198,7 @@ impl JoinSemiLattice for HasMutInteriorBehindRefState {
190198 ( Self :: OnlyHasMutInterior , Self :: Yes ) => {
191199 * self = Self :: Yes ;
192200 true
193- } ,
201+ }
194202 ( Self :: OnlyHasMutInterior , Self :: OnlyHasMutInterior ) => false ,
195203 }
196204 }
@@ -201,27 +209,47 @@ impl Qualif for HasMutInteriorBehindRef {
201209 type Result = HasMutInteriorBehindRefState ;
202210
203211 fn in_qualifs ( qualifs : & ConstQualifs ) -> Option < HasMutInteriorBehindRefState > {
204- HasMutInterior :: in_qualifs ( qualifs) . map ( |( ) | HasMutInteriorBehindRefState :: OnlyHasMutInterior )
212+ HasMutInterior :: in_qualifs ( qualifs)
213+ . map ( |( ) | HasMutInteriorBehindRefState :: OnlyHasMutInterior )
205214 }
206215
207- fn in_any_value_of_ty ( cx : & ConstCx < ' _ , ' tcx > , ty : Ty < ' tcx > ) -> Option < HasMutInteriorBehindRefState > {
216+ fn in_any_value_of_ty (
217+ cx : & ConstCx < ' _ , ' tcx > ,
218+ ty : Ty < ' tcx > ,
219+ ) -> Option < HasMutInteriorBehindRefState > {
208220 match ty. builtin_deref ( false ) {
209- None => HasMutInterior :: in_any_value_of_ty ( cx, ty) . map ( |( ) | HasMutInteriorBehindRefState :: OnlyHasMutInterior ) ,
210- Some ( tam) => HasMutInterior :: in_any_value_of_ty ( cx, tam. ty ) . map ( |( ) | HasMutInteriorBehindRefState :: Yes ) ,
221+ None => HasMutInterior :: in_any_value_of_ty ( cx, ty)
222+ . map ( |( ) | HasMutInteriorBehindRefState :: OnlyHasMutInterior ) ,
223+ Some ( tam) => HasMutInterior :: in_any_value_of_ty ( cx, tam. ty )
224+ . map ( |( ) | HasMutInteriorBehindRefState :: Yes ) ,
211225 }
212226 }
213227
214228 #[ instrument( skip( cx) ) ]
215- fn in_any_function_call ( cx : & ConstCx < ' _ , ' tcx > , ty : Ty < ' tcx > , mut args : Option < Self :: Result > ) -> Option < Self :: Result > {
216- args. join ( & HasMutInterior :: in_any_value_of_ty ( cx, ty) . map ( |( ) | HasMutInteriorBehindRefState :: OnlyHasMutInterior ) ) ;
229+ fn in_any_function_call (
230+ cx : & ConstCx < ' _ , ' tcx > ,
231+ ty : Ty < ' tcx > ,
232+ mut args : Option < Self :: Result > ,
233+ ) -> Option < Self :: Result > {
234+ args. join (
235+ & HasMutInterior :: in_any_value_of_ty ( cx, ty)
236+ . map ( |( ) | HasMutInteriorBehindRefState :: OnlyHasMutInterior ) ,
237+ ) ;
217238 args
218239 }
219240
220- fn in_adt_inherently ( cx : & ConstCx < ' _ , ' tcx > , adt : & ' tcx AdtDef , substs : SubstsRef < ' tcx > ) -> Option < HasMutInteriorBehindRefState > {
221- HasMutInterior :: in_adt_inherently ( cx, adt, substs) . map ( |( ) | HasMutInteriorBehindRefState :: OnlyHasMutInterior )
241+ fn in_adt_inherently (
242+ cx : & ConstCx < ' _ , ' tcx > ,
243+ adt : & ' tcx AdtDef ,
244+ substs : SubstsRef < ' tcx > ,
245+ ) -> Option < HasMutInteriorBehindRefState > {
246+ HasMutInterior :: in_adt_inherently ( cx, adt, substs)
247+ . map ( |( ) | HasMutInteriorBehindRefState :: OnlyHasMutInterior )
222248 }
223249
224- fn in_value_behind_ref ( qualif : Option < HasMutInteriorBehindRefState > ) -> Option < HasMutInteriorBehindRefState > {
250+ fn in_value_behind_ref (
251+ qualif : Option < HasMutInteriorBehindRefState > ,
252+ ) -> Option < HasMutInteriorBehindRefState > {
225253 qualif. map ( |_| HasMutInteriorBehindRefState :: Yes )
226254 }
227255}
@@ -244,7 +272,11 @@ impl Qualif for NeedsDrop {
244272 ty. needs_drop ( cx. tcx , cx. param_env ) . then_some ( ( ) )
245273 }
246274
247- fn in_adt_inherently ( cx : & ConstCx < ' _ , ' tcx > , adt : & ' tcx AdtDef , _: SubstsRef < ' tcx > ) -> Option < ( ) > {
275+ fn in_adt_inherently (
276+ cx : & ConstCx < ' _ , ' tcx > ,
277+ adt : & ' tcx AdtDef ,
278+ _: SubstsRef < ' tcx > ,
279+ ) -> Option < ( ) > {
248280 adt. has_dtor ( cx. tcx ) . then_some ( ( ) )
249281 }
250282}
@@ -283,7 +315,11 @@ impl Qualif for CustomEq {
283315
284316/// Returns `true` if this `Rvalue` contains qualif `Q`.
285317#[ instrument( skip( cx, in_local) , fields( Q =std:: any:: type_name:: <Q >( ) ) ) ]
286- pub ( crate ) fn in_rvalue < Q , F > ( cx : & ConstCx < ' _ , ' tcx > , in_local : & mut F , rvalue : & Rvalue < ' tcx > ) -> Option < Q :: Result >
318+ pub ( crate ) fn in_rvalue < Q , F > (
319+ cx : & ConstCx < ' _ , ' tcx > ,
320+ in_local : & mut F ,
321+ rvalue : & Rvalue < ' tcx > ,
322+ ) -> Option < Q :: Result >
287323where
288324 Q : Qualif ,
289325 F : FnMut ( Local ) -> Option < Q :: Result > ,
@@ -342,7 +378,11 @@ where
342378
343379/// Returns `true` if this `Place` contains qualif `Q`.
344380#[ instrument( skip( cx, in_local) , fields( Q =std:: any:: type_name:: <Q >( ) ) ) ]
345- pub ( crate ) fn in_place < Q , F > ( cx : & ConstCx < ' _ , ' tcx > , in_local : & mut F , place : PlaceRef < ' tcx > ) -> Option < Q :: Result >
381+ pub ( crate ) fn in_place < Q , F > (
382+ cx : & ConstCx < ' _ , ' tcx > ,
383+ in_local : & mut F ,
384+ place : PlaceRef < ' tcx > ,
385+ ) -> Option < Q :: Result >
346386where
347387 Q : Qualif ,
348388 F : FnMut ( Local ) -> Option < Q :: Result > ,
@@ -353,7 +393,7 @@ where
353393 match proj_elem {
354394 ProjectionElem :: Index ( index) => {
355395 result. join ( & in_local ( index) ) ;
356- } ,
396+ }
357397
358398 ProjectionElem :: Deref
359399 | ProjectionElem :: Field ( _, _)
@@ -378,7 +418,11 @@ where
378418
379419/// Returns `true` if this `Operand` contains qualif `Q`.
380420#[ instrument( skip( cx, in_local) , fields( Q =std:: any:: type_name:: <Q >( ) ) ) ]
381- pub ( crate ) fn in_operand < Q , F > ( cx : & ConstCx < ' _ , ' tcx > , in_local : & mut F , operand : & Operand < ' tcx > ) -> Option < Q :: Result >
421+ pub ( crate ) fn in_operand < Q , F > (
422+ cx : & ConstCx < ' _ , ' tcx > ,
423+ in_local : & mut F ,
424+ operand : & Operand < ' tcx > ,
425+ ) -> Option < Q :: Result >
382426where
383427 Q : Qualif ,
384428 F : FnMut ( Local ) -> Option < Q :: Result > ,
0 commit comments