@@ -38,6 +38,7 @@ use rustc_trait_selection::traits::query::method_autoderef::{
38
38
CandidateStep , MethodAutoderefStepsResult ,
39
39
} ;
40
40
use rustc_trait_selection:: traits:: query:: CanonicalTyGoal ;
41
+ use rustc_trait_selection:: traits:: NormalizeExt ;
41
42
use rustc_trait_selection:: traits:: ObligationCtxt ;
42
43
use rustc_trait_selection:: traits:: { self , ObligationCause } ;
43
44
use std:: cell:: RefCell ;
@@ -1376,7 +1377,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1376
1377
let impl_ty = self . tcx . type_of ( impl_def_id) . instantiate ( self . tcx , impl_args) ;
1377
1378
( xform_self_ty, xform_ret_ty) =
1378
1379
self . xform_self_ty ( probe. item , impl_ty, impl_args) ;
1379
- xform_self_ty = ocx. normalize ( cause, self . param_env , xform_self_ty) ;
1380
+ let InferOk { value : normalized, mut obligations } =
1381
+ self . at ( cause, self . param_env ) . normalize ( xform_self_ty) ;
1382
+ xform_self_ty = normalized;
1380
1383
// FIXME: Make this `ocx.sup` once we define opaques more eagerly.
1381
1384
match self . at ( cause, self . param_env ) . sup (
1382
1385
DefineOpaqueTypes :: No ,
@@ -1398,7 +1401,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1398
1401
let impl_bounds =
1399
1402
self . tcx . predicates_of ( impl_def_id) . instantiate ( self . tcx , impl_args) ;
1400
1403
let impl_bounds = ocx. normalize ( cause, self . param_env , impl_bounds) ;
1401
- for obligation in traits:: predicates_for_generics (
1404
+ obligations . extend ( traits:: predicates_for_generics (
1402
1405
|idx, span| {
1403
1406
let code = if span. is_dummy ( ) {
1404
1407
traits:: ExprItemObligation ( impl_def_id, self . scope_expr_id , idx)
@@ -1414,7 +1417,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1414
1417
} ,
1415
1418
self . param_env ,
1416
1419
impl_bounds,
1417
- ) {
1420
+ ) ) ;
1421
+
1422
+ for obligation in obligations {
1418
1423
if self . infcx . next_trait_solver ( ) {
1419
1424
ocx. register_obligation ( obligation) ;
1420
1425
} else {
@@ -1460,7 +1465,11 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1460
1465
let trait_ref = ocx. normalize ( cause, self . param_env , trait_ref) ;
1461
1466
( xform_self_ty, xform_ret_ty) =
1462
1467
self . xform_self_ty ( probe. item , trait_ref. self_ty ( ) , trait_ref. args ) ;
1463
- xform_self_ty = ocx. normalize ( cause, self . param_env , xform_self_ty) ;
1468
+
1469
+ let InferOk { value : normalized, obligations : normalize_obligations } =
1470
+ self . at ( cause, self . param_env ) . normalize ( xform_self_ty) ;
1471
+ xform_self_ty = normalized;
1472
+
1464
1473
// FIXME: Make this `ocx.sup` once we define opaques more eagerly.
1465
1474
match self . at ( cause, self . param_env ) . sup (
1466
1475
DefineOpaqueTypes :: No ,
@@ -1475,6 +1484,33 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1475
1484
return ProbeResult :: NoMatch ;
1476
1485
}
1477
1486
}
1487
+
1488
+ for obligation in normalize_obligations {
1489
+ if self . infcx . next_trait_solver ( ) {
1490
+ ocx. register_obligation ( obligation) ;
1491
+ } else {
1492
+ match self . infcx . evaluate_obligation_no_overflow ( & obligation) {
1493
+ EvaluationResult :: EvaluatedToOk => {
1494
+ // No side-effects, no need to register obligations.
1495
+ }
1496
+ EvaluationResult :: EvaluatedToOkModuloRegions
1497
+ | EvaluationResult :: EvaluatedToOkModuloOpaqueTypes
1498
+ | EvaluationResult :: EvaluatedToAmbig
1499
+ | EvaluationResult :: EvaluatedToAmbigStackDependent => {
1500
+ ocx. register_obligation ( obligation) ;
1501
+ }
1502
+ EvaluationResult :: EvaluatedToErr => {
1503
+ result = ProbeResult :: NoMatch ;
1504
+ possibly_unsatisfied_predicates. push ( (
1505
+ self . resolve_vars_if_possible ( obligation. predicate ) ,
1506
+ None ,
1507
+ Some ( obligation. cause . clone ( ) ) ,
1508
+ ) ) ;
1509
+ }
1510
+ }
1511
+ }
1512
+ }
1513
+
1478
1514
let obligation = traits:: Obligation :: new (
1479
1515
self . tcx ,
1480
1516
cause. clone ( ) ,
@@ -1527,7 +1563,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1527
1563
) ;
1528
1564
( xform_self_ty, xform_ret_ty) =
1529
1565
self . xform_self_ty ( probe. item , trait_ref. self_ty ( ) , trait_ref. args ) ;
1530
- xform_self_ty = ocx. normalize ( cause, self . param_env , xform_self_ty) ;
1566
+ let InferOk { value : normalized, obligations : normalize_obligations } =
1567
+ self . at ( cause, self . param_env ) . normalize ( xform_self_ty) ;
1568
+ xform_self_ty = normalized;
1569
+
1531
1570
// FIXME: Make this `ocx.sup` once we define opaques more eagerly.
1532
1571
match self . at ( cause, self . param_env ) . sup (
1533
1572
DefineOpaqueTypes :: No ,
@@ -1542,6 +1581,32 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1542
1581
return ProbeResult :: NoMatch ;
1543
1582
}
1544
1583
}
1584
+
1585
+ for obligation in normalize_obligations {
1586
+ if self . infcx . next_trait_solver ( ) {
1587
+ ocx. register_obligation ( obligation) ;
1588
+ } else {
1589
+ match self . infcx . evaluate_obligation_no_overflow ( & obligation) {
1590
+ EvaluationResult :: EvaluatedToOk => {
1591
+ // No side-effects, no need to register obligations.
1592
+ }
1593
+ EvaluationResult :: EvaluatedToOkModuloRegions
1594
+ | EvaluationResult :: EvaluatedToOkModuloOpaqueTypes
1595
+ | EvaluationResult :: EvaluatedToAmbig
1596
+ | EvaluationResult :: EvaluatedToAmbigStackDependent => {
1597
+ ocx. register_obligation ( obligation) ;
1598
+ }
1599
+ EvaluationResult :: EvaluatedToErr => {
1600
+ result = ProbeResult :: NoMatch ;
1601
+ possibly_unsatisfied_predicates. push ( (
1602
+ self . resolve_vars_if_possible ( obligation. predicate ) ,
1603
+ None ,
1604
+ Some ( obligation. cause . clone ( ) ) ,
1605
+ ) ) ;
1606
+ }
1607
+ }
1608
+ }
1609
+ }
1545
1610
}
1546
1611
}
1547
1612
0 commit comments