2
2
//!
3
3
//! See the `Qualif` trait for more info.
4
4
5
+ use crate :: dataflow:: { fmt:: DebugWithContext , JoinSemiLattice } ;
5
6
use rustc_errors:: ErrorReported ;
7
+ use rustc_index:: bit_set:: BitSet ;
8
+ use rustc_index:: vec:: IndexVec ;
6
9
use rustc_middle:: mir:: * ;
7
10
use rustc_middle:: ty:: { self , subst:: SubstsRef , AdtDef , Ty } ;
8
11
use rustc_span:: DUMMY_SP ;
9
12
use rustc_trait_selection:: traits;
10
- use rustc_index:: vec:: IndexVec ;
11
- use rustc_index:: bit_set:: BitSet ;
12
- use crate :: dataflow:: { JoinSemiLattice , fmt:: DebugWithContext } ;
13
13
14
14
use super :: ConstCx ;
15
15
@@ -64,7 +64,11 @@ pub(crate) trait Qualif {
64
64
65
65
/// Sometimes const fn calls cannot possibly contain the qualif, so we can treat function
66
66
/// 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 > {
68
72
Self :: in_any_value_of_ty ( cx, ty)
69
73
}
70
74
@@ -159,7 +163,11 @@ impl Qualif for HasMutInterior {
159
163
( !ty. is_freeze ( cx. tcx . at ( DUMMY_SP ) , cx. param_env ) ) . then_some ( ( ) )
160
164
}
161
165
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 < ( ) > {
163
171
// Exactly one type, `UnsafeCell`, has the `HasMutInterior` qualif inherently.
164
172
// It arises structurally for all other types.
165
173
( Some ( adt. did ) == cx. tcx . lang_items ( ) . unsafe_cell_type ( ) ) . then_some ( ( ) )
@@ -190,7 +198,7 @@ impl JoinSemiLattice for HasMutInteriorBehindRefState {
190
198
( Self :: OnlyHasMutInterior , Self :: Yes ) => {
191
199
* self = Self :: Yes ;
192
200
true
193
- } ,
201
+ }
194
202
( Self :: OnlyHasMutInterior , Self :: OnlyHasMutInterior ) => false ,
195
203
}
196
204
}
@@ -201,27 +209,47 @@ impl Qualif for HasMutInteriorBehindRef {
201
209
type Result = HasMutInteriorBehindRefState ;
202
210
203
211
fn in_qualifs ( qualifs : & ConstQualifs ) -> Option < HasMutInteriorBehindRefState > {
204
- HasMutInterior :: in_qualifs ( qualifs) . map ( |( ) | HasMutInteriorBehindRefState :: OnlyHasMutInterior )
212
+ HasMutInterior :: in_qualifs ( qualifs)
213
+ . map ( |( ) | HasMutInteriorBehindRefState :: OnlyHasMutInterior )
205
214
}
206
215
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 > {
208
220
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 ) ,
211
225
}
212
226
}
213
227
214
228
#[ 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
+ ) ;
217
238
args
218
239
}
219
240
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 )
222
248
}
223
249
224
- fn in_value_behind_ref ( qualif : Option < HasMutInteriorBehindRefState > ) -> Option < HasMutInteriorBehindRefState > {
250
+ fn in_value_behind_ref (
251
+ qualif : Option < HasMutInteriorBehindRefState > ,
252
+ ) -> Option < HasMutInteriorBehindRefState > {
225
253
qualif. map ( |_| HasMutInteriorBehindRefState :: Yes )
226
254
}
227
255
}
@@ -244,7 +272,11 @@ impl Qualif for NeedsDrop {
244
272
ty. needs_drop ( cx. tcx , cx. param_env ) . then_some ( ( ) )
245
273
}
246
274
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 < ( ) > {
248
280
adt. has_dtor ( cx. tcx ) . then_some ( ( ) )
249
281
}
250
282
}
@@ -283,7 +315,11 @@ impl Qualif for CustomEq {
283
315
284
316
/// Returns `true` if this `Rvalue` contains qualif `Q`.
285
317
#[ 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 >
287
323
where
288
324
Q : Qualif ,
289
325
F : FnMut ( Local ) -> Option < Q :: Result > ,
@@ -342,7 +378,11 @@ where
342
378
343
379
/// Returns `true` if this `Place` contains qualif `Q`.
344
380
#[ 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 >
346
386
where
347
387
Q : Qualif ,
348
388
F : FnMut ( Local ) -> Option < Q :: Result > ,
@@ -353,7 +393,7 @@ where
353
393
match proj_elem {
354
394
ProjectionElem :: Index ( index) => {
355
395
result. join ( & in_local ( index) ) ;
356
- } ,
396
+ }
357
397
358
398
ProjectionElem :: Deref
359
399
| ProjectionElem :: Field ( _, _)
@@ -378,7 +418,11 @@ where
378
418
379
419
/// Returns `true` if this `Operand` contains qualif `Q`.
380
420
#[ 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 >
382
426
where
383
427
Q : Qualif ,
384
428
F : FnMut ( Local ) -> Option < Q :: Result > ,
0 commit comments