@@ -409,6 +409,27 @@ fn erase_ty<'tcx>(ctxt: &Context<'tcx>, state: &mut State, ty: &Ty<'tcx>) -> Typ
409409 TyKind :: Alias ( rustc_middle:: ty:: AliasKind :: Projection , t) => {
410410 // Note: even if rust_to_vir_base decides to normalize t,
411411 // we don't have to normalize t here, since we're generating Rust code, not VIR.
412+ // However, normalizing means we might reach less stuff so it's
413+ // still useful.
414+
415+ // Try normalization:
416+ use crate :: rustc_trait_selection:: infer:: TyCtxtInferExt ;
417+ use crate :: rustc_trait_selection:: traits:: NormalizeExt ;
418+ if let Some ( fun_id) = state. enclosing_fun_id {
419+ let param_env = ctxt. tcx . param_env ( fun_id) ;
420+ let infcx = ctxt. tcx . infer_ctxt ( ) . ignoring_regions ( ) . build ( ) ;
421+ let cause = rustc_infer:: traits:: ObligationCause :: dummy ( ) ;
422+ let at = infcx. at ( & cause, param_env) ;
423+ let resolved_ty = infcx. resolve_vars_if_possible ( * ty) ;
424+ if !rustc_middle:: ty:: TypeVisitableExt :: has_escaping_bound_vars ( & resolved_ty) {
425+ let norm = at. normalize ( * ty) ;
426+ if norm. value != * ty {
427+ return erase_ty ( ctxt, state, & norm. value ) ;
428+ }
429+ }
430+ }
431+
432+ // If normalization isn't possible:
412433 let assoc_item = ctxt. tcx . associated_item ( t. def_id ) ;
413434 let name = state. typ_param ( assoc_item. name . to_string ( ) , None ) ;
414435 let trait_def = ctxt. tcx . generics_of ( t. def_id ) . parent ;
@@ -722,10 +743,21 @@ fn erase_call<'tcx>(
722743
723744 // Maybe resolve from trait function to a specific implementation
724745
725- let mut node_substs = node_substs;
746+ let node_substs = node_substs;
726747 let mut fn_def_id = fn_def_id. expect ( "call id" ) ;
727748
728749 let param_env = ctxt. tcx . param_env ( state. enclosing_fun_id . expect ( "enclosing_fun_id" ) ) ;
750+
751+ let rust_item = crate :: verus_items:: get_rust_item ( ctxt. tcx , fn_def_id) ;
752+ let mut node_substs = crate :: fn_call_to_vir:: fix_node_substs (
753+ ctxt. tcx ,
754+ ctxt. types ( ) ,
755+ node_substs,
756+ rust_item,
757+ & args_slice. iter ( ) . collect :: < Vec < _ > > ( ) ,
758+ expr,
759+ ) ;
760+
729761 let normalized_substs = ctxt. tcx . normalize_erasing_regions ( param_env, node_substs) ;
730762 let inst = rustc_middle:: ty:: Instance :: resolve (
731763 ctxt. tcx ,
@@ -1738,6 +1770,8 @@ fn erase_fn_common<'tcx>(
17381770 & mut typ_params,
17391771 & mut generic_bounds,
17401772 ) ;
1773+
1774+ state. enclosing_fun_id = Some ( id) ;
17411775 let mut params: Vec < Param > = Vec :: new ( ) ;
17421776 for ( ( input, param) , param_info) in
17431777 inputs. iter ( ) . zip ( f_vir. x . params . iter ( ) ) . zip ( params_info. iter ( ) )
@@ -1772,6 +1806,7 @@ fn erase_fn_common<'tcx>(
17721806 } else {
17731807 Some ( ( None , erase_ty ( ctxt, state, & fn_sig. output ( ) . skip_binder ( ) ) ) )
17741808 } ;
1809+ state. enclosing_fun_id = None ;
17751810 let decl = FunDecl {
17761811 sig_span : sig_span,
17771812 name_span,
0 commit comments