@@ -186,6 +186,19 @@ pub struct Body<'tcx> {
186
186
/// FIXME(oli-obk): rewrite the promoted during promotion to eliminate the cell components.
187
187
pub ignore_interior_mut_in_const_validation : bool ,
188
188
189
+ /// Does this body use generic parameters. This is used for the `ConstEvaluatable` check.
190
+ ///
191
+ /// Note that this does not actually mean that this body is not computable right now.
192
+ /// The repeat count in the following example is polymorphic, but can still be evaluated
193
+ /// without knowing anything about the type parameter `T`.
194
+ ///
195
+ /// ```rust
196
+ /// fn test<T>() {
197
+ /// let _ = [0; std::mem::size_of::<*mut T>()];
198
+ /// }
199
+ /// ```
200
+ pub is_polymorphic : bool ,
201
+
189
202
predecessor_cache : PredecessorCache ,
190
203
}
191
204
@@ -208,7 +221,7 @@ impl<'tcx> Body<'tcx> {
208
221
local_decls. len( )
209
222
) ;
210
223
211
- Body {
224
+ let mut body = Body {
212
225
phase : MirPhase :: Build ,
213
226
basic_blocks,
214
227
source_scopes,
@@ -224,8 +237,11 @@ impl<'tcx> Body<'tcx> {
224
237
span,
225
238
required_consts : Vec :: new ( ) ,
226
239
ignore_interior_mut_in_const_validation : false ,
240
+ is_polymorphic : false ,
227
241
predecessor_cache : PredecessorCache :: new ( ) ,
228
- }
242
+ } ;
243
+ body. is_polymorphic = body. has_param_types_or_consts ( ) ;
244
+ body
229
245
}
230
246
231
247
/// Returns a partially initialized MIR body containing only a list of basic blocks.
@@ -234,7 +250,7 @@ impl<'tcx> Body<'tcx> {
234
250
/// is only useful for testing but cannot be `#[cfg(test)]` because it is used in a different
235
251
/// crate.
236
252
pub fn new_cfg_only ( basic_blocks : IndexVec < BasicBlock , BasicBlockData < ' tcx > > ) -> Self {
237
- Body {
253
+ let mut body = Body {
238
254
phase : MirPhase :: Build ,
239
255
basic_blocks,
240
256
source_scopes : IndexVec :: new ( ) ,
@@ -250,8 +266,11 @@ impl<'tcx> Body<'tcx> {
250
266
generator_kind : None ,
251
267
var_debug_info : Vec :: new ( ) ,
252
268
ignore_interior_mut_in_const_validation : false ,
269
+ is_polymorphic : false ,
253
270
predecessor_cache : PredecessorCache :: new ( ) ,
254
- }
271
+ } ;
272
+ body. is_polymorphic = body. has_param_types_or_consts ( ) ;
273
+ body
255
274
}
256
275
257
276
#[ inline]
0 commit comments