@@ -186,6 +186,19 @@ pub struct Body<'tcx> {
186186 /// FIXME(oli-obk): rewrite the promoted during promotion to eliminate the cell components.
187187 pub ignore_interior_mut_in_const_validation : bool ,
188188
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+
189202 predecessor_cache : PredecessorCache ,
190203}
191204
@@ -208,7 +221,7 @@ impl<'tcx> Body<'tcx> {
208221 local_decls. len( )
209222 ) ;
210223
211- Body {
224+ let mut body = Body {
212225 phase : MirPhase :: Build ,
213226 basic_blocks,
214227 source_scopes,
@@ -224,8 +237,11 @@ impl<'tcx> Body<'tcx> {
224237 span,
225238 required_consts : Vec :: new ( ) ,
226239 ignore_interior_mut_in_const_validation : false ,
240+ is_polymorphic : false ,
227241 predecessor_cache : PredecessorCache :: new ( ) ,
228- }
242+ } ;
243+ body. is_polymorphic = body. has_param_types_or_consts ( ) ;
244+ body
229245 }
230246
231247 /// Returns a partially initialized MIR body containing only a list of basic blocks.
@@ -234,7 +250,7 @@ impl<'tcx> Body<'tcx> {
234250 /// is only useful for testing but cannot be `#[cfg(test)]` because it is used in a different
235251 /// crate.
236252 pub fn new_cfg_only ( basic_blocks : IndexVec < BasicBlock , BasicBlockData < ' tcx > > ) -> Self {
237- Body {
253+ let mut body = Body {
238254 phase : MirPhase :: Build ,
239255 basic_blocks,
240256 source_scopes : IndexVec :: new ( ) ,
@@ -250,8 +266,11 @@ impl<'tcx> Body<'tcx> {
250266 generator_kind : None ,
251267 var_debug_info : Vec :: new ( ) ,
252268 ignore_interior_mut_in_const_validation : false ,
269+ is_polymorphic : false ,
253270 predecessor_cache : PredecessorCache :: new ( ) ,
254- }
271+ } ;
272+ body. is_polymorphic = body. has_param_types_or_consts ( ) ;
273+ body
255274 }
256275
257276 #[ inline]
0 commit comments