@@ -383,23 +383,25 @@ pub struct Body<'tcx> {
383383
384384 /// Constants that are required to evaluate successfully for this MIR to be well-formed.
385385 /// We hold in this field all the constants we are not able to evaluate yet.
386+ /// `None` indicates that the list has not been computed yet.
386387 ///
387388 /// This is soundness-critical, we make a guarantee that all consts syntactically mentioned in a
388389 /// function have successfully evaluated if the function ever gets executed at runtime.
389- pub required_consts : Vec < ConstOperand < ' tcx > > ,
390+ pub required_consts : Option < Vec < ConstOperand < ' tcx > > > ,
390391
391392 /// Further items that were mentioned in this function and hence *may* become monomorphized,
392393 /// depending on optimizations. We use this to avoid optimization-dependent compile errors: the
393394 /// collector recursively traverses all "mentioned" items and evaluates all their
394395 /// `required_consts`.
396+ /// `None` indicates that the list has not been computed yet.
395397 ///
396398 /// This is *not* soundness-critical and the contents of this list are *not* a stable guarantee.
397399 /// All that's relevant is that this set is optimization-level-independent, and that it includes
398400 /// everything that the collector would consider "used". (For example, we currently compute this
399401 /// set after drop elaboration, so some drop calls that can never be reached are not considered
400402 /// "mentioned".) See the documentation of `CollectionMode` in
401403 /// `compiler/rustc_monomorphize/src/collector.rs` for more context.
402- pub mentioned_items : Vec < Spanned < MentionedItem < ' tcx > > > ,
404+ pub mentioned_items : Option < Vec < Spanned < MentionedItem < ' tcx > > > > ,
403405
404406 /// Does this body use generic parameters. This is used for the `ConstEvaluatable` check.
405407 ///
@@ -477,8 +479,8 @@ impl<'tcx> Body<'tcx> {
477479 spread_arg : None ,
478480 var_debug_info,
479481 span,
480- required_consts : Vec :: new ( ) ,
481- mentioned_items : Vec :: new ( ) ,
482+ required_consts : None ,
483+ mentioned_items : None ,
482484 is_polymorphic : false ,
483485 injection_phase : None ,
484486 tainted_by_errors,
@@ -507,8 +509,8 @@ impl<'tcx> Body<'tcx> {
507509 arg_count : 0 ,
508510 spread_arg : None ,
509511 span : DUMMY_SP ,
510- required_consts : Vec :: new ( ) ,
511- mentioned_items : Vec :: new ( ) ,
512+ required_consts : None ,
513+ mentioned_items : None ,
512514 var_debug_info : Vec :: new ( ) ,
513515 is_polymorphic : false ,
514516 injection_phase : None ,
@@ -785,6 +787,40 @@ impl<'tcx> Body<'tcx> {
785787 // No inlined `SourceScope`s, or all of them were `#[track_caller]`.
786788 caller_location. unwrap_or_else ( || from_span ( source_info. span ) )
787789 }
790+
791+ #[ track_caller]
792+ pub fn set_required_consts ( & mut self , required_consts : Vec < ConstOperand < ' tcx > > ) {
793+ assert ! (
794+ self . required_consts. is_none( ) ,
795+ "required_consts for {:?} have already been set" ,
796+ self . source. def_id( )
797+ ) ;
798+ self . required_consts = Some ( required_consts) ;
799+ }
800+ #[ track_caller]
801+ pub fn required_consts ( & self ) -> & [ ConstOperand < ' tcx > ] {
802+ match & self . required_consts {
803+ Some ( l) => l,
804+ None => panic ! ( "required_consts for {:?} have not yet been set" , self . source. def_id( ) ) ,
805+ }
806+ }
807+
808+ #[ track_caller]
809+ pub fn set_mentioned_items ( & mut self , mentioned_items : Vec < Spanned < MentionedItem < ' tcx > > > ) {
810+ assert ! (
811+ self . mentioned_items. is_none( ) ,
812+ "mentioned_items for {:?} have already been set" ,
813+ self . source. def_id( )
814+ ) ;
815+ self . mentioned_items = Some ( mentioned_items) ;
816+ }
817+ #[ track_caller]
818+ pub fn mentioned_items ( & self ) -> & [ Spanned < MentionedItem < ' tcx > > ] {
819+ match & self . mentioned_items {
820+ Some ( l) => l,
821+ None => panic ! ( "mentioned_items for {:?} have not yet been set" , self . source. def_id( ) ) ,
822+ }
823+ }
788824}
789825
790826impl < ' tcx > Index < BasicBlock > for Body < ' tcx > {
0 commit comments