@@ -97,21 +97,22 @@ pub(super) fn enter_wf_checking_ctxt<'tcx, F>(
9797 let infcx = & tcx. infer_ctxt ( ) . build ( ) ;
9898 let ocx = ObligationCtxt :: new ( infcx) ;
9999
100- let assumed_wf_types = ocx. assumed_wf_types ( param_env, span, body_def_id) ;
101-
102100 let mut wfcx = WfCheckingCtxt { ocx, span, body_id, param_env } ;
103101
104102 if !tcx. features ( ) . trivial_bounds {
105103 wfcx. check_false_global_bounds ( )
106104 }
107105 f ( & mut wfcx) ;
106+
107+ let assumed_wf_types = wfcx. ocx . assumed_wf_types ( param_env, span, body_def_id) ;
108+ let implied_bounds = infcx. implied_bounds_tys ( param_env, body_id, assumed_wf_types) ;
109+
108110 let errors = wfcx. select_all_or_error ( ) ;
109111 if !errors. is_empty ( ) {
110112 infcx. err_ctxt ( ) . report_fulfillment_errors ( & errors, None ) ;
111113 return ;
112114 }
113115
114- let implied_bounds = infcx. implied_bounds_tys ( param_env, body_id, assumed_wf_types) ;
115116 let outlives_environment =
116117 OutlivesEnvironment :: with_bounds ( param_env, Some ( infcx) , implied_bounds) ;
117118
@@ -1489,54 +1490,38 @@ fn check_fn_or_method<'tcx>(
14891490 def_id : LocalDefId ,
14901491) {
14911492 let tcx = wfcx. tcx ( ) ;
1492- let sig = tcx. liberate_late_bound_regions ( def_id. to_def_id ( ) , sig) ;
1493+ let mut sig = tcx. liberate_late_bound_regions ( def_id. to_def_id ( ) , sig) ;
14931494
14941495 // Normalize the input and output types one at a time, using a different
14951496 // `WellFormedLoc` for each. We cannot call `normalize_associated_types`
14961497 // on the entire `FnSig`, since this would use the same `WellFormedLoc`
14971498 // for each type, preventing the HIR wf check from generating
14981499 // a nice error message.
1499- let ty:: FnSig { mut inputs_and_output, c_variadic, unsafety, abi } = sig;
1500- inputs_and_output = tcx. mk_type_list ( inputs_and_output. iter ( ) . enumerate ( ) . map ( |( i, ty) | {
1501- wfcx. normalize (
1502- span,
1503- Some ( WellFormedLoc :: Param {
1504- function : def_id,
1505- // Note that the `param_idx` of the output type is
1506- // one greater than the index of the last input type.
1507- param_idx : i. try_into ( ) . unwrap ( ) ,
1508- } ) ,
1509- ty,
1510- )
1511- } ) ) ;
1512- // Manually call `normalize_associated_types_in` on the other types
1513- // in `FnSig`. This ensures that if the types of these fields
1514- // ever change to include projections, we will start normalizing
1515- // them automatically.
1516- let sig = ty:: FnSig {
1517- inputs_and_output,
1518- c_variadic : wfcx. normalize ( span, None , c_variadic) ,
1519- unsafety : wfcx. normalize ( span, None , unsafety) ,
1520- abi : wfcx. normalize ( span, None , abi) ,
1521- } ;
1500+ let arg_span =
1501+ |idx| hir_decl. inputs . get ( idx) . map_or ( hir_decl. output . span ( ) , |arg : & hir:: Ty < ' _ > | arg. span ) ;
1502+
1503+ sig. inputs_and_output =
1504+ tcx. mk_type_list ( sig. inputs_and_output . iter ( ) . enumerate ( ) . map ( |( idx, ty) | {
1505+ wfcx. normalize (
1506+ arg_span ( idx) ,
1507+ Some ( WellFormedLoc :: Param {
1508+ function : def_id,
1509+ // Note that the `param_idx` of the output type is
1510+ // one greater than the index of the last input type.
1511+ param_idx : idx. try_into ( ) . unwrap ( ) ,
1512+ } ) ,
1513+ ty,
1514+ )
1515+ } ) ) ;
15221516
1523- for ( i , ( & input_ty , ty) ) in iter :: zip ( sig. inputs ( ) , hir_decl . inputs ) . enumerate ( ) {
1517+ for ( idx , ty) in sig. inputs_and_output . iter ( ) . enumerate ( ) {
15241518 wfcx. register_wf_obligation (
1525- ty . span ,
1526- Some ( WellFormedLoc :: Param { function : def_id, param_idx : i . try_into ( ) . unwrap ( ) } ) ,
1527- input_ty . into ( ) ,
1519+ arg_span ( idx ) ,
1520+ Some ( WellFormedLoc :: Param { function : def_id, param_idx : idx . try_into ( ) . unwrap ( ) } ) ,
1521+ ty . into ( ) ,
15281522 ) ;
15291523 }
15301524
1531- wfcx. register_wf_obligation (
1532- hir_decl. output . span ( ) ,
1533- Some ( WellFormedLoc :: Param {
1534- function : def_id,
1535- param_idx : sig. inputs ( ) . len ( ) . try_into ( ) . unwrap ( ) ,
1536- } ) ,
1537- sig. output ( ) . into ( ) ,
1538- ) ;
1539-
15401525 check_where_clauses ( wfcx, span, def_id) ;
15411526
15421527 check_return_position_impl_trait_in_trait_bounds (
0 commit comments