@@ -66,12 +66,18 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
66
66
span : Span ,
67
67
loc : Option < WellFormedLoc > ,
68
68
arg : ty:: GenericArg < ' tcx > ,
69
+ override_constness : Option < hir:: Constness > ,
69
70
) {
70
71
let cause =
71
72
traits:: ObligationCause :: new ( span, self . body_id , ObligationCauseCode :: WellFormed ( loc) ) ;
73
+ let param_env = if let Some ( constness) = override_constness {
74
+ self . param_env . with_constness ( constness)
75
+ } else {
76
+ self . param_env
77
+ } ;
72
78
self . ocx . register_obligation ( traits:: Obligation :: new (
73
79
cause,
74
- self . param_env ,
80
+ param_env,
75
81
ty:: Binder :: dummy ( ty:: PredicateKind :: WellFormed ( arg) ) . to_predicate ( self . tcx ( ) ) ,
76
82
) ) ;
77
83
}
@@ -985,7 +991,7 @@ fn check_associated_item(
985
991
ty:: AssocKind :: Const => {
986
992
let ty = tcx. type_of ( item. def_id ) ;
987
993
let ty = wfcx. normalize ( span, Some ( WellFormedLoc :: Ty ( item_id) ) , ty) ;
988
- wfcx. register_wf_obligation ( span, loc, ty. into ( ) ) ;
994
+ wfcx. register_wf_obligation ( span, loc, ty. into ( ) , None ) ;
989
995
}
990
996
ty:: AssocKind :: Fn => {
991
997
let sig = tcx. fn_sig ( item. def_id ) ;
@@ -1006,7 +1012,7 @@ fn check_associated_item(
1006
1012
if item. defaultness ( tcx) . has_value ( ) {
1007
1013
let ty = tcx. type_of ( item. def_id ) ;
1008
1014
let ty = wfcx. normalize ( span, Some ( WellFormedLoc :: Ty ( item_id) ) , ty) ;
1009
- wfcx. register_wf_obligation ( span, loc, ty. into ( ) ) ;
1015
+ wfcx. register_wf_obligation ( span, loc, ty. into ( ) , None ) ;
1010
1016
}
1011
1017
}
1012
1018
}
@@ -1042,6 +1048,7 @@ fn check_type_defn<'tcx, F>(
1042
1048
field. span ,
1043
1049
Some ( WellFormedLoc :: Ty ( field. def_id ) ) ,
1044
1050
field. ty . into ( ) ,
1051
+ None ,
1045
1052
)
1046
1053
}
1047
1054
@@ -1191,7 +1198,12 @@ fn check_item_type(tcx: TyCtxt<'_>, item_id: LocalDefId, ty_span: Span, allow_fo
1191
1198
}
1192
1199
}
1193
1200
1194
- wfcx. register_wf_obligation ( ty_span, Some ( WellFormedLoc :: Ty ( item_id) ) , item_ty. into ( ) ) ;
1201
+ wfcx. register_wf_obligation (
1202
+ ty_span,
1203
+ Some ( WellFormedLoc :: Ty ( item_id) ) ,
1204
+ item_ty. into ( ) ,
1205
+ None ,
1206
+ ) ;
1195
1207
if forbid_unsized {
1196
1208
wfcx. register_bound (
1197
1209
traits:: ObligationCause :: new ( ty_span, wfcx. body_id , traits:: WellFormed ( None ) ) ,
@@ -1260,6 +1272,7 @@ fn check_impl<'tcx>(
1260
1272
ast_self_ty. span ,
1261
1273
Some ( WellFormedLoc :: Ty ( item. hir_id ( ) . expect_owner ( ) ) ) ,
1262
1274
self_ty. into ( ) ,
1275
+ None ,
1263
1276
) ;
1264
1277
}
1265
1278
}
@@ -1300,7 +1313,12 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
1300
1313
// parameter includes another (e.g., `<T, U = T>`). In those cases, we can't
1301
1314
// be sure if it will error or not as user might always specify the other.
1302
1315
if !ty. needs_subst ( ) {
1303
- wfcx. register_wf_obligation ( tcx. def_span ( param. def_id ) , None , ty. into ( ) ) ;
1316
+ wfcx. register_wf_obligation (
1317
+ tcx. def_span ( param. def_id ) ,
1318
+ None ,
1319
+ ty. into ( ) ,
1320
+ None ,
1321
+ ) ;
1304
1322
}
1305
1323
}
1306
1324
}
@@ -1316,6 +1334,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
1316
1334
tcx. def_span ( param. def_id ) ,
1317
1335
None ,
1318
1336
default_ct. into ( ) ,
1337
+ None ,
1319
1338
) ;
1320
1339
}
1321
1340
}
@@ -1496,10 +1515,17 @@ fn check_fn_or_method<'tcx>(
1496
1515
ty. span ,
1497
1516
Some ( WellFormedLoc :: Param { function : def_id, param_idx : i. try_into ( ) . unwrap ( ) } ) ,
1498
1517
input_ty. into ( ) ,
1518
+ None ,
1499
1519
) ;
1500
1520
}
1501
1521
1502
- wfcx. register_wf_obligation ( hir_decl. output . span ( ) , None , sig. output ( ) . into ( ) ) ;
1522
+ // override the env when checking the return type. `~const` bounds can be fulfilled with non-const implementations.
1523
+ wfcx. register_wf_obligation (
1524
+ hir_decl. output . span ( ) ,
1525
+ None ,
1526
+ sig. output ( ) . into ( ) ,
1527
+ Some ( hir:: Constness :: NotConst ) ,
1528
+ ) ;
1503
1529
1504
1530
check_where_clauses ( wfcx, span, def_id) ;
1505
1531
}
0 commit comments