@@ -1636,17 +1636,30 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
1636
1636
infer:: LateBoundRegionConversionTime :: HigherRankedType ,
1637
1637
bound_predicate. rebind ( data) ,
1638
1638
) ;
1639
- let normalized_ty = ocx. normalize (
1640
- & obligation. cause ,
1641
- obligation. param_env ,
1642
- self . tcx . mk_projection ( data. projection_ty . def_id , data. projection_ty . substs ) ,
1643
- ) ;
1639
+ let unnormalized_term = match data. term . unpack ( ) {
1640
+ ty:: TermKind :: Ty ( _) => self
1641
+ . tcx
1642
+ . mk_projection ( data. projection_ty . def_id , data. projection_ty . substs )
1643
+ . into ( ) ,
1644
+ ty:: TermKind :: Const ( ct) => self
1645
+ . tcx
1646
+ . mk_const (
1647
+ ty:: UnevaluatedConst {
1648
+ def : ty:: WithOptConstParam :: unknown ( data. projection_ty . def_id ) ,
1649
+ substs : data. projection_ty . substs ,
1650
+ } ,
1651
+ ct. ty ( ) ,
1652
+ )
1653
+ . into ( ) ,
1654
+ } ;
1655
+ let normalized_term =
1656
+ ocx. normalize ( & obligation. cause , obligation. param_env , unnormalized_term) ;
1644
1657
1645
1658
debug ! ( ?obligation. cause, ?obligation. param_env) ;
1646
1659
1647
- debug ! ( ?normalized_ty , data. ty = ?data. term) ;
1660
+ debug ! ( ?normalized_term , data. ty = ?data. term) ;
1648
1661
1649
- let is_normalized_ty_expected = !matches ! (
1662
+ let is_normalized_term_expected = !matches ! (
1650
1663
obligation. cause. code( ) . peel_derives( ) ,
1651
1664
ObligationCauseCode :: ItemObligation ( _)
1652
1665
| ObligationCauseCode :: BindingObligation ( _, _)
@@ -1655,7 +1668,6 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
1655
1668
| ObligationCauseCode :: ObjectCastObligation ( ..)
1656
1669
| ObligationCauseCode :: OpaqueType
1657
1670
) ;
1658
- let expected_ty = data. term . ty ( ) . unwrap_or_else ( || self . tcx . ty_error ( ) ) ;
1659
1671
1660
1672
// constrain inference variables a bit more to nested obligations from normalize so
1661
1673
// we can have more helpful errors.
@@ -1664,11 +1676,11 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
1664
1676
if let Err ( new_err) = ocx. eq_exp (
1665
1677
& obligation. cause ,
1666
1678
obligation. param_env ,
1667
- is_normalized_ty_expected ,
1668
- normalized_ty ,
1669
- expected_ty ,
1679
+ is_normalized_term_expected ,
1680
+ normalized_term ,
1681
+ data . term ,
1670
1682
) {
1671
- ( Some ( ( data, is_normalized_ty_expected , normalized_ty , expected_ty ) ) , new_err)
1683
+ ( Some ( ( data, is_normalized_term_expected , normalized_term , data . term ) ) , new_err)
1672
1684
} else {
1673
1685
( None , error. err )
1674
1686
}
@@ -1677,12 +1689,8 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
1677
1689
} ;
1678
1690
1679
1691
let msg = values
1680
- . and_then ( |( predicate, _, normalized_ty, expected_ty) | {
1681
- self . maybe_detailed_projection_msg (
1682
- predicate,
1683
- normalized_ty. into ( ) ,
1684
- expected_ty. into ( ) ,
1685
- )
1692
+ . and_then ( |( predicate, _, normalized_term, expected_term) | {
1693
+ self . maybe_detailed_projection_msg ( predicate, normalized_term, expected_term)
1686
1694
} )
1687
1695
. unwrap_or_else ( || format ! ( "type mismatch resolving `{}`" , predicate) ) ;
1688
1696
let mut diag = struct_span_err ! ( self . tcx. sess, obligation. cause. span, E0271 , "{msg}" ) ;
0 commit comments