@@ -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 , Debug , 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,21 @@ 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 avoid optimization-dependent compile errors: the
396+ /// collector recursively traverses all "mentioned" items and evaluates all their
397+ /// `requiered_consts`.
398+ ///
399+ /// This is *not* soundness-critical and the contents of this list are *not* a stable guarantee.
400+ /// See the documentation of `CollectionMode` in `compiler/rustc_monomorphize/src/collector.rs`
401+ /// for more context.
402+ pub mentioned_items : Vec < Spanned < MentionedItem < ' tcx > > > ,
403+
380404 /// Does this body use generic parameters. This is used for the `ConstEvaluatable` check.
381405 ///
382406 /// Note that this does not actually mean that this body is not computable right now.
@@ -453,6 +477,7 @@ impl<'tcx> Body<'tcx> {
453477 var_debug_info,
454478 span,
455479 required_consts : Vec :: new ( ) ,
480+ mentioned_items : Vec :: new ( ) ,
456481 is_polymorphic : false ,
457482 injection_phase : None ,
458483 tainted_by_errors,
@@ -482,6 +507,7 @@ impl<'tcx> Body<'tcx> {
482507 spread_arg : None ,
483508 span : DUMMY_SP ,
484509 required_consts : Vec :: new ( ) ,
510+ mentioned_items : Vec :: new ( ) ,
485511 var_debug_info : Vec :: new ( ) ,
486512 is_polymorphic : false ,
487513 injection_phase : None ,
0 commit comments