@@ -20,6 +20,7 @@ use rustc_hir::def_id::{DefId, CRATE_DEF_ID};
2020use rustc_hir:: { self , CoroutineDesugaring , CoroutineKind , ImplicitSelfKind } ;
2121use rustc_hir:: { self as hir, HirId } ;
2222use rustc_session:: Session ;
23+ use rustc_span:: source_map:: Spanned ;
2324use rustc_target:: abi:: { FieldIdx , VariantIdx } ;
2425
2526use polonius_engine:: Atom ;
@@ -312,6 +313,16 @@ impl<'tcx> CoroutineInfo<'tcx> {
312313 }
313314}
314315
316+ /// Some item that needs to monomorphize successfully for a MIR body to be considered well-formed.
317+ #[ derive( Copy , Clone , PartialEq , Eq , Debug , Hash , HashStable , TyEncodable , TyDecodable ) ]
318+ #[ derive( TypeFoldable , TypeVisitable ) ]
319+ pub enum MentionedItem < ' tcx > {
320+ Fn ( DefId , GenericArgsRef < ' tcx > ) ,
321+ Drop ( Ty < ' tcx > ) ,
322+ // FIXME: add Vtable { source_ty: Ty<'tcx>, target_ty: Ty<'tcx> },
323+ // FIXME: do we have to add closures?
324+ }
325+
315326/// The lowered representation of a single function.
316327#[ derive( Clone , TyEncodable , TyDecodable , Debug , HashStable , TypeFoldable , TypeVisitable ) ]
317328pub struct Body < ' tcx > {
@@ -375,8 +386,18 @@ pub struct Body<'tcx> {
375386
376387 /// Constants that are required to evaluate successfully for this MIR to be well-formed.
377388 /// We hold in this field all the constants we are not able to evaluate yet.
389+ ///
390+ /// This is soundness-critical, we make a guarantee that all consts syntactically mentioned in a
391+ /// function have successfully evaluated if the function ever gets executed at runtime.
378392 pub required_consts : Vec < ConstOperand < ' tcx > > ,
379393
394+ /// Further items that were mentioned in this function and hence *may* become monomorphized,
395+ /// depending on optimizations. We use this to ensure their consts evaluate successfully even if
396+ /// they do not get monomorphized, to avoid optimization-dependent compile errors.
397+ ///
398+ /// This is *not* soundness-critical and the contents of this list are *not* a stable guarantee.
399+ pub mentioned_items : Vec < Spanned < MentionedItem < ' tcx > > > ,
400+
380401 /// Does this body use generic parameters. This is used for the `ConstEvaluatable` check.
381402 ///
382403 /// Note that this does not actually mean that this body is not computable right now.
@@ -453,6 +474,7 @@ impl<'tcx> Body<'tcx> {
453474 var_debug_info,
454475 span,
455476 required_consts : Vec :: new ( ) ,
477+ mentioned_items : Vec :: new ( ) ,
456478 is_polymorphic : false ,
457479 injection_phase : None ,
458480 tainted_by_errors,
@@ -482,6 +504,7 @@ impl<'tcx> Body<'tcx> {
482504 spread_arg : None ,
483505 span : DUMMY_SP ,
484506 required_consts : Vec :: new ( ) ,
507+ mentioned_items : Vec :: new ( ) ,
485508 var_debug_info : Vec :: new ( ) ,
486509 is_polymorphic : false ,
487510 injection_phase : None ,
0 commit comments