File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
compiler/rustc_monomorphize/src Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -473,6 +473,33 @@ fn collect_items_rec<'tcx>(
473473 recursion_limit,
474474 ) ) ;
475475
476+ // Check whether the MIR body is malformed. Usually it's due to normalization overflow.
477+ // FIXME: I assume that there are few type errors at post-analysis stage, but not
478+ // entirely sure.
479+ // Plenty of code paths later assume that everything can be normalized.
480+ // Check normalization here to provide better diagnostics.
481+ let body = tcx. instance_mir ( instance. def ) ;
482+ let normalization_failed = body. local_decls . iter ( ) . any ( |local| {
483+ instance
484+ . try_instantiate_mir_and_normalize_erasing_regions (
485+ tcx,
486+ ty:: TypingEnv :: fully_monomorphized ( ) ,
487+ ty:: EarlyBinder :: bind ( local. ty ) ,
488+ )
489+ . is_err ( )
490+ } ) ;
491+ if normalization_failed {
492+ let def_id = instance. def_id ( ) ;
493+ let def_span = tcx. def_span ( def_id) ;
494+ let def_path_str = tcx. def_path_str ( def_id) ;
495+ tcx. dcx ( ) . emit_fatal ( RecursionLimit {
496+ span : starting_item. span ,
497+ instance,
498+ def_span,
499+ def_path_str,
500+ } ) ;
501+ }
502+
476503 rustc_data_structures:: stack:: ensure_sufficient_stack ( || {
477504 let ( used, mentioned) = tcx. items_of_instance ( ( instance, mode) ) ;
478505 used_items. extend ( used. into_iter ( ) . copied ( ) ) ;
You can’t perform that action at this time.
0 commit comments