@@ -94,7 +94,7 @@ pub(super) fn enter_wf_checking_ctxt<'tcx, F>(
94
94
f : F ,
95
95
) -> Result < ( ) , ErrorGuaranteed >
96
96
where
97
- F : for < ' a > FnOnce ( & WfCheckingCtxt < ' a , ' tcx > ) ,
97
+ F : for < ' a > FnOnce ( & WfCheckingCtxt < ' a , ' tcx > ) -> Result < ( ) , ErrorGuaranteed > ,
98
98
{
99
99
let param_env = tcx. param_env ( body_def_id) ;
100
100
let infcx = & tcx. infer_ctxt ( ) . build ( ) ;
@@ -105,7 +105,7 @@ where
105
105
if !tcx. features ( ) . trivial_bounds {
106
106
wfcx. check_false_global_bounds ( )
107
107
}
108
- f ( & mut wfcx) ;
108
+ f ( & mut wfcx) ? ;
109
109
110
110
let assumed_wf_types = wfcx. ocx . assumed_wf_types_and_report_errors ( param_env, body_def_id) ?;
111
111
@@ -875,6 +875,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(),
875
875
ty,
876
876
trait_def_id,
877
877
) ;
878
+ Ok ( ( ) )
878
879
} )
879
880
} else {
880
881
let mut diag = match ty. kind ( ) {
@@ -961,6 +962,7 @@ fn check_associated_item(
961
962
let ty = tcx. type_of ( item. def_id ) . instantiate_identity ( ) ;
962
963
let ty = wfcx. normalize ( span, Some ( WellFormedLoc :: Ty ( item_id) ) , ty) ;
963
964
wfcx. register_wf_obligation ( span, loc, ty. into ( ) ) ;
965
+ Ok ( ( ) )
964
966
}
965
967
ty:: AssocKind :: Fn => {
966
968
let sig = tcx. fn_sig ( item. def_id ) . instantiate_identity ( ) ;
@@ -972,7 +974,7 @@ fn check_associated_item(
972
974
hir_sig. decl ,
973
975
item. def_id . expect_local ( ) ,
974
976
) ;
975
- check_method_receiver ( wfcx, hir_sig, item, self_ty) ;
977
+ check_method_receiver ( wfcx, hir_sig, item, self_ty)
976
978
}
977
979
ty:: AssocKind :: Type => {
978
980
if let ty:: AssocItemContainer :: TraitContainer = item. container {
@@ -983,6 +985,7 @@ fn check_associated_item(
983
985
let ty = wfcx. normalize ( span, Some ( WellFormedLoc :: Ty ( item_id) ) , ty) ;
984
986
wfcx. register_wf_obligation ( span, loc, ty. into ( ) ) ;
985
987
}
988
+ Ok ( ( ) )
986
989
}
987
990
}
988
991
} )
@@ -1097,6 +1100,7 @@ fn check_type_defn<'tcx>(
1097
1100
}
1098
1101
1099
1102
check_where_clauses ( wfcx, item. span , item. owner_id . def_id ) ;
1103
+ Ok ( ( ) )
1100
1104
} )
1101
1105
}
1102
1106
@@ -1121,7 +1125,8 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) -> Result<(), ErrorGuarant
1121
1125
}
1122
1126
1123
1127
let res = enter_wf_checking_ctxt ( tcx, item. span , def_id, |wfcx| {
1124
- check_where_clauses ( wfcx, item. span , def_id)
1128
+ check_where_clauses ( wfcx, item. span , def_id) ;
1129
+ Ok ( ( ) )
1125
1130
} ) ;
1126
1131
1127
1132
// Only check traits, don't check trait aliases
@@ -1164,6 +1169,7 @@ fn check_item_fn(
1164
1169
enter_wf_checking_ctxt ( tcx, span, def_id, |wfcx| {
1165
1170
let sig = tcx. fn_sig ( def_id) . instantiate_identity ( ) ;
1166
1171
check_fn_or_method ( wfcx, ident. span , sig, decl, def_id) ;
1172
+ Ok ( ( ) )
1167
1173
} )
1168
1174
}
1169
1175
@@ -1218,6 +1224,7 @@ fn check_item_type(
1218
1224
tcx. require_lang_item ( LangItem :: Sync , Some ( ty_span) ) ,
1219
1225
) ;
1220
1226
}
1227
+ Ok ( ( ) )
1221
1228
} )
1222
1229
}
1223
1230
@@ -1276,6 +1283,7 @@ fn check_impl<'tcx>(
1276
1283
}
1277
1284
1278
1285
check_where_clauses ( wfcx, item. span , item. owner_id . def_id ) ;
1286
+ Ok ( ( ) )
1279
1287
} )
1280
1288
}
1281
1289
@@ -1548,11 +1556,11 @@ fn check_method_receiver<'tcx>(
1548
1556
fn_sig : & hir:: FnSig < ' _ > ,
1549
1557
method : ty:: AssocItem ,
1550
1558
self_ty : Ty < ' tcx > ,
1551
- ) {
1559
+ ) -> Result < ( ) , ErrorGuaranteed > {
1552
1560
let tcx = wfcx. tcx ( ) ;
1553
1561
1554
1562
if !method. fn_has_self_parameter {
1555
- return ;
1563
+ return Ok ( ( ) ) ;
1556
1564
}
1557
1565
1558
1566
let span = fn_sig. decl . inputs [ 0 ] . span ;
@@ -1571,11 +1579,11 @@ fn check_method_receiver<'tcx>(
1571
1579
if tcx. features ( ) . arbitrary_self_types {
1572
1580
if !receiver_is_valid ( wfcx, span, receiver_ty, self_ty, true ) {
1573
1581
// Report error; `arbitrary_self_types` was enabled.
1574
- e0307 ( tcx, span, receiver_ty) ;
1582
+ return Err ( e0307 ( tcx, span, receiver_ty) ) ;
1575
1583
}
1576
1584
} else {
1577
1585
if !receiver_is_valid ( wfcx, span, receiver_ty, self_ty, false ) {
1578
- if receiver_is_valid ( wfcx, span, receiver_ty, self_ty, true ) {
1586
+ return Err ( if receiver_is_valid ( wfcx, span, receiver_ty, self_ty, true ) {
1579
1587
// Report error; would have worked with `arbitrary_self_types`.
1580
1588
feature_err (
1581
1589
& tcx. sess . parse_sess ,
@@ -1587,16 +1595,17 @@ fn check_method_receiver<'tcx>(
1587
1595
) ,
1588
1596
)
1589
1597
. help ( HELP_FOR_SELF_TYPE )
1590
- . emit ( ) ;
1598
+ . emit ( )
1591
1599
} else {
1592
1600
// Report error; would not have worked with `arbitrary_self_types`.
1593
- e0307 ( tcx, span, receiver_ty) ;
1594
- }
1601
+ e0307 ( tcx, span, receiver_ty)
1602
+ } ) ;
1595
1603
}
1596
1604
}
1605
+ Ok ( ( ) )
1597
1606
}
1598
1607
1599
- fn e0307 ( tcx : TyCtxt < ' _ > , span : Span , receiver_ty : Ty < ' _ > ) {
1608
+ fn e0307 ( tcx : TyCtxt < ' _ > , span : Span , receiver_ty : Ty < ' _ > ) -> ErrorGuaranteed {
1600
1609
struct_span_err ! (
1601
1610
tcx. sess. diagnostic( ) ,
1602
1611
span,
@@ -1605,7 +1614,7 @@ fn e0307(tcx: TyCtxt<'_>, span: Span, receiver_ty: Ty<'_>) {
1605
1614
)
1606
1615
. note ( "type of `self` must be `Self` or a type that dereferences to it" )
1607
1616
. help ( HELP_FOR_SELF_TYPE )
1608
- . emit ( ) ;
1617
+ . emit ( )
1609
1618
}
1610
1619
1611
1620
/// Returns whether `receiver_ty` would be considered a valid receiver type for `self_ty`. If
0 commit comments