@@ -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 ( ) {
@@ -956,6 +957,8 @@ fn check_associated_item(
956
957
ty:: ImplContainer => tcx. type_of ( item. container_id ( tcx) ) . instantiate_identity ( ) ,
957
958
} ;
958
959
960
+ let mut res = Ok ( ( ) ) ;
961
+
959
962
match item. kind {
960
963
ty:: AssocKind :: Const => {
961
964
let ty = tcx. type_of ( item. def_id ) . instantiate_identity ( ) ;
@@ -972,7 +975,7 @@ fn check_associated_item(
972
975
hir_sig. decl ,
973
976
item. def_id . expect_local ( ) ,
974
977
) ;
975
- check_method_receiver ( wfcx, hir_sig, item, self_ty) ;
978
+ res = res . and ( check_method_receiver ( wfcx, hir_sig, item, self_ty) ) ;
976
979
}
977
980
ty:: AssocKind :: Type => {
978
981
if let ty:: AssocItemContainer :: TraitContainer = item. container {
@@ -985,6 +988,7 @@ fn check_associated_item(
985
988
}
986
989
}
987
990
}
991
+ res
988
992
} )
989
993
}
990
994
@@ -1097,6 +1101,7 @@ fn check_type_defn<'tcx>(
1097
1101
}
1098
1102
1099
1103
check_where_clauses ( wfcx, item. span , item. owner_id . def_id ) ;
1104
+ Ok ( ( ) )
1100
1105
} )
1101
1106
}
1102
1107
@@ -1121,7 +1126,8 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) -> Result<(), ErrorGuarant
1121
1126
}
1122
1127
1123
1128
let res = enter_wf_checking_ctxt ( tcx, item. span , def_id, |wfcx| {
1124
- check_where_clauses ( wfcx, item. span , def_id)
1129
+ check_where_clauses ( wfcx, item. span , def_id) ;
1130
+ Ok ( ( ) )
1125
1131
} ) ;
1126
1132
1127
1133
// Only check traits, don't check trait aliases
@@ -1164,6 +1170,7 @@ fn check_item_fn(
1164
1170
enter_wf_checking_ctxt ( tcx, span, def_id, |wfcx| {
1165
1171
let sig = tcx. fn_sig ( def_id) . instantiate_identity ( ) ;
1166
1172
check_fn_or_method ( wfcx, ident. span , sig, decl, def_id) ;
1173
+ Ok ( ( ) )
1167
1174
} )
1168
1175
}
1169
1176
@@ -1218,6 +1225,7 @@ fn check_item_type(
1218
1225
tcx. require_lang_item ( LangItem :: Sync , Some ( ty_span) ) ,
1219
1226
) ;
1220
1227
}
1228
+ Ok ( ( ) )
1221
1229
} )
1222
1230
}
1223
1231
@@ -1276,6 +1284,7 @@ fn check_impl<'tcx>(
1276
1284
}
1277
1285
1278
1286
check_where_clauses ( wfcx, item. span , item. owner_id . def_id ) ;
1287
+ Ok ( ( ) )
1279
1288
} )
1280
1289
}
1281
1290
@@ -1548,11 +1557,11 @@ fn check_method_receiver<'tcx>(
1548
1557
fn_sig : & hir:: FnSig < ' _ > ,
1549
1558
method : ty:: AssocItem ,
1550
1559
self_ty : Ty < ' tcx > ,
1551
- ) {
1560
+ ) -> Result < ( ) , ErrorGuaranteed > {
1552
1561
let tcx = wfcx. tcx ( ) ;
1553
1562
1554
1563
if !method. fn_has_self_parameter {
1555
- return ;
1564
+ return Ok ( ( ) ) ;
1556
1565
}
1557
1566
1558
1567
let span = fn_sig. decl . inputs [ 0 ] . span ;
@@ -1571,11 +1580,11 @@ fn check_method_receiver<'tcx>(
1571
1580
if tcx. features ( ) . arbitrary_self_types {
1572
1581
if !receiver_is_valid ( wfcx, span, receiver_ty, self_ty, true ) {
1573
1582
// Report error; `arbitrary_self_types` was enabled.
1574
- e0307 ( tcx, span, receiver_ty) ;
1583
+ return Err ( e0307 ( tcx, span, receiver_ty) ) ;
1575
1584
}
1576
1585
} else {
1577
1586
if !receiver_is_valid ( wfcx, span, receiver_ty, self_ty, false ) {
1578
- if receiver_is_valid ( wfcx, span, receiver_ty, self_ty, true ) {
1587
+ return Err ( if receiver_is_valid ( wfcx, span, receiver_ty, self_ty, true ) {
1579
1588
// Report error; would have worked with `arbitrary_self_types`.
1580
1589
feature_err (
1581
1590
& tcx. sess . parse_sess ,
@@ -1587,16 +1596,17 @@ fn check_method_receiver<'tcx>(
1587
1596
) ,
1588
1597
)
1589
1598
. help ( HELP_FOR_SELF_TYPE )
1590
- . emit ( ) ;
1599
+ . emit ( )
1591
1600
} else {
1592
1601
// Report error; would not have worked with `arbitrary_self_types`.
1593
- e0307 ( tcx, span, receiver_ty) ;
1594
- }
1602
+ e0307 ( tcx, span, receiver_ty)
1603
+ } ) ;
1595
1604
}
1596
1605
}
1606
+ Ok ( ( ) )
1597
1607
}
1598
1608
1599
- fn e0307 ( tcx : TyCtxt < ' _ > , span : Span , receiver_ty : Ty < ' _ > ) {
1609
+ fn e0307 ( tcx : TyCtxt < ' _ > , span : Span , receiver_ty : Ty < ' _ > ) -> ErrorGuaranteed {
1600
1610
struct_span_err ! (
1601
1611
tcx. sess. diagnostic( ) ,
1602
1612
span,
@@ -1605,7 +1615,7 @@ fn e0307(tcx: TyCtxt<'_>, span: Span, receiver_ty: Ty<'_>) {
1605
1615
)
1606
1616
. note ( "type of `self` must be `Self` or a type that dereferences to it" )
1607
1617
. help ( HELP_FOR_SELF_TYPE )
1608
- . emit ( ) ;
1618
+ . emit ( )
1609
1619
}
1610
1620
1611
1621
/// Returns whether `receiver_ty` would be considered a valid receiver type for `self_ty`. If
0 commit comments