@@ -97,21 +97,22 @@ pub(super) fn enter_wf_checking_ctxt<'tcx, F>(
97
97
let infcx = & tcx. infer_ctxt ( ) . build ( ) ;
98
98
let ocx = ObligationCtxt :: new ( infcx) ;
99
99
100
- let assumed_wf_types = ocx. assumed_wf_types ( param_env, span, body_def_id) ;
101
-
102
100
let mut wfcx = WfCheckingCtxt { ocx, span, body_id, param_env } ;
103
101
104
102
if !tcx. features ( ) . trivial_bounds {
105
103
wfcx. check_false_global_bounds ( )
106
104
}
107
105
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
+
108
110
let errors = wfcx. select_all_or_error ( ) ;
109
111
if !errors. is_empty ( ) {
110
112
infcx. err_ctxt ( ) . report_fulfillment_errors ( & errors, None ) ;
111
113
return ;
112
114
}
113
115
114
- let implied_bounds = infcx. implied_bounds_tys ( param_env, body_id, assumed_wf_types) ;
115
116
let outlives_environment =
116
117
OutlivesEnvironment :: with_bounds ( param_env, Some ( infcx) , implied_bounds) ;
117
118
@@ -1489,54 +1490,38 @@ fn check_fn_or_method<'tcx>(
1489
1490
def_id : LocalDefId ,
1490
1491
) {
1491
1492
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) ;
1493
1494
1494
1495
// Normalize the input and output types one at a time, using a different
1495
1496
// `WellFormedLoc` for each. We cannot call `normalize_associated_types`
1496
1497
// on the entire `FnSig`, since this would use the same `WellFormedLoc`
1497
1498
// for each type, preventing the HIR wf check from generating
1498
1499
// 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
+ } ) ) ;
1522
1516
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 ( ) {
1524
1518
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 ( ) ,
1528
1522
) ;
1529
1523
}
1530
1524
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
-
1540
1525
check_where_clauses ( wfcx, span, def_id) ;
1541
1526
1542
1527
check_return_position_impl_trait_in_trait_bounds (
0 commit comments