@@ -797,10 +797,10 @@ fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> {
797797 vis. visit_body ( & body) ;
798798
799799 // If the MIR is already monomorphic, we can transform it to codegen MIR right away.
800- if !tcx. generics_of ( did) . requires_monomorphization ( tcx) && !vis . contains_ubcheck {
801- if vis. contains_alias {
802- eprintln ! ( "alias: {:?}" , did ) ;
803- }
800+ if !tcx. generics_of ( did) . requires_monomorphization ( tcx)
801+ && ! vis. contains_ubcheck
802+ && !vis . contains_alias
803+ {
804804 let instance = Instance :: mono ( tcx, did. into ( ) ) ;
805805 body = instance. instantiate_mir_and_normalize_erasing_regions (
806806 tcx,
@@ -817,6 +817,12 @@ use rustc_middle::mir::visit::{TyContext, Visitor};
817817use rustc_middle:: mir:: { Location , NullOp } ;
818818use rustc_middle:: ty:: { Ty , TypeFlags } ;
819819
820+ // FIXME: This visitor looks for properties of MIR that would forbid using optimized MIR as codegen
821+ // MIR.
822+ // Currently, it looks for NullOp::UbChecks because that must be resolved at codegen, and also for
823+ // type projections because those are the only way I've found to realize that we are generating MIR
824+ // for a body with an unsatisafiable predicate. Such bodies cannot be normalized, so we must not
825+ // try to create codegen MIR for them.
820826struct MonoCompatVisitor {
821827 contains_alias : bool ,
822828 contains_ubcheck : bool ,
@@ -825,7 +831,7 @@ struct MonoCompatVisitor {
825831impl < ' tcx > Visitor < ' tcx > for MonoCompatVisitor {
826832 fn visit_ty ( & mut self , ty : Ty < ' tcx > , _: TyContext ) {
827833 debug ! ( "{:?} {:?}" , ty, ty. flags( ) ) ;
828- if ty. flags ( ) . contains ( TypeFlags :: HAS_ALIAS ) {
834+ if ty. has_aliases ( ) || ty . flags ( ) . contains ( TypeFlags :: HAS_TY_PROJECTION ) {
829835 self . contains_alias = true ;
830836 }
831837 }
0 commit comments