@@ -364,7 +364,7 @@ fn typeck_with_fallback<'tcx>(
364364
365365 let typeck_results = Inherited :: build ( tcx, def_id) . enter ( |inh| {
366366 let param_env = tcx. param_env ( def_id) ;
367- let fcx = if let Some ( hir:: FnSig { header, decl, .. } ) = fn_sig {
367+ let ( fcx, wf_tys ) = if let Some ( hir:: FnSig { header, decl, .. } ) = fn_sig {
368368 let fn_sig = if crate :: collect:: get_infer_ret_ty ( & decl. output ) . is_some ( ) {
369369 let fcx = FnCtxt :: new ( & inh, param_env, body. value . hir_id ) ;
370370 <dyn AstConv < ' _ > >:: ty_of_fn (
@@ -383,17 +383,25 @@ fn typeck_with_fallback<'tcx>(
383383
384384 check_abi ( tcx, id, span, fn_sig. abi ( ) ) ;
385385
386+ // When normalizing the function signature, we assume all types are
387+ // well-formed. So, we don't need to worry about the obligations
388+ // from normalization. We could just discard these, but to align with
389+ // compare_method and elsewhere, we just add implied bounds for
390+ // these types.
391+ let mut wf_tys = vec ! [ ] ;
386392 // Compute the fty from point of view of inside the fn.
387393 let fn_sig = tcx. liberate_late_bound_regions ( def_id. to_def_id ( ) , fn_sig) ;
394+ wf_tys. extend ( fn_sig. inputs_and_output . iter ( ) ) ;
388395 let fn_sig = inh. normalize_associated_types_in (
389396 body. value . span ,
390397 body_id. hir_id ,
391398 param_env,
392399 fn_sig,
393400 ) ;
401+ wf_tys. extend ( fn_sig. inputs_and_output . iter ( ) ) ;
394402
395403 let fcx = check_fn ( & inh, param_env, fn_sig, decl, id, body, None , true ) . 0 ;
396- fcx
404+ ( fcx, wf_tys )
397405 } else {
398406 let fcx = FnCtxt :: new ( & inh, param_env, body. value . hir_id ) ;
399407 let expected_type = body_ty
@@ -443,7 +451,7 @@ fn typeck_with_fallback<'tcx>(
443451
444452 fcx. write_ty ( id, expected_type) ;
445453
446- fcx
454+ ( fcx, vec ! [ ] )
447455 } ;
448456
449457 let fallback_has_occurred = fcx. type_inference_fallback ( ) ;
@@ -467,7 +475,7 @@ fn typeck_with_fallback<'tcx>(
467475 fcx. select_all_obligations_or_error ( ) ;
468476
469477 if fn_sig. is_some ( ) {
470- fcx. regionck_fn ( id, body) ;
478+ fcx. regionck_fn ( id, body, span , & wf_tys ) ;
471479 } else {
472480 fcx. regionck_expr ( body) ;
473481 }
0 commit comments