@@ -67,12 +67,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
6767 }
6868
6969 Pointer ( PointerCast :: ReifyFnPointer ) => {
70+ // All reifications must be monomorphic, bail out otherwise.
71+ ensure_monomorphic_enough ( * self . tcx , src. layout . ty ) ?;
72+
7073 // The src operand does not matter, just its type
7174 match * src. layout . ty . kind ( ) {
7275 ty:: FnDef ( def_id, substs) => {
73- // All reifications must be monomorphic, bail out otherwise.
74- ensure_monomorphic_enough ( * self . tcx , src. layout . ty ) ?;
75-
7676 let instance = ty:: Instance :: resolve_for_fn_ptr (
7777 * self . tcx ,
7878 self . param_env ,
@@ -100,12 +100,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
100100 }
101101
102102 Pointer ( PointerCast :: ClosureFnPointer ( _) ) => {
103+ // All reifications must be monomorphic, bail out otherwise.
104+ ensure_monomorphic_enough ( * self . tcx , src. layout . ty ) ?;
105+
103106 // The src operand does not matter, just its type
104107 match * src. layout . ty . kind ( ) {
105108 ty:: Closure ( def_id, substs) => {
106- // All reifications must be monomorphic, bail out otherwise.
107- ensure_monomorphic_enough ( * self . tcx , src. layout . ty ) ?;
108-
109109 let instance = ty:: Instance :: resolve_closure (
110110 * self . tcx ,
111111 def_id,
@@ -359,8 +359,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
359359 let val = Immediate :: new_dyn_trait ( ptr, vtable, & * self . tcx ) ;
360360 self . write_immediate ( val, dest)
361361 }
362-
363362 _ => {
363+ // Do not ICE if we are not monomorphic enough.
364+ ensure_monomorphic_enough ( * self . tcx , src. layout . ty ) ?;
365+ ensure_monomorphic_enough ( * self . tcx , cast_ty) ?;
366+
364367 span_bug ! (
365368 self . cur_span( ) ,
366369 "invalid pointer unsizing {:?} -> {:?}" ,
@@ -404,12 +407,18 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
404407 }
405408 Ok ( ( ) )
406409 }
407- _ => span_bug ! (
408- self . cur_span( ) ,
409- "unsize_into: invalid conversion: {:?} -> {:?}" ,
410- src. layout,
411- dest. layout
412- ) ,
410+ _ => {
411+ // Do not ICE if we are not monomorphic enough.
412+ ensure_monomorphic_enough ( * self . tcx , src. layout . ty ) ?;
413+ ensure_monomorphic_enough ( * self . tcx , cast_ty. ty ) ?;
414+
415+ span_bug ! (
416+ self . cur_span( ) ,
417+ "unsize_into: invalid conversion: {:?} -> {:?}" ,
418+ src. layout,
419+ dest. layout
420+ )
421+ }
413422 }
414423 }
415424}
0 commit comments