@@ -22,6 +22,7 @@ use crate::traits::error_reporting::InferCtxtExt as _;
22
22
use rustc_data_structures:: sso:: SsoHashSet ;
23
23
use rustc_data_structures:: stack:: ensure_sufficient_stack;
24
24
use rustc_errors:: ErrorReported ;
25
+ use rustc_hir:: def:: DefKind ;
25
26
use rustc_hir:: def_id:: DefId ;
26
27
use rustc_hir:: lang_items:: LangItem ;
27
28
use rustc_infer:: infer:: resolve:: OpportunisticRegionResolver ;
@@ -200,7 +201,7 @@ fn project_and_unify_type<'cx, 'tcx>(
200
201
let infcx = selcx. infcx ( ) ;
201
202
match obligation. predicate . term {
202
203
ty:: Term :: Ty ( obligation_pred_ty) => {
203
- let normalized_ty = match opt_normalize_projection_type :: < false > (
204
+ let normalized_ty = match opt_normalize_projection_type (
204
205
selcx,
205
206
obligation. param_env ,
206
207
obligation. predicate . projection_ty ,
@@ -215,7 +216,7 @@ fn project_and_unify_type<'cx, 'tcx>(
215
216
debug ! ( ?normalized_ty, ?obligations, "project_and_unify_type result" ) ;
216
217
match infcx
217
218
. at ( & obligation. cause , obligation. param_env )
218
- . eq ( normalized_ty, obligation_pred_ty. into ( ) )
219
+ . eq ( normalized_ty, obligation_pred_ty)
219
220
{
220
221
Ok ( InferOk { obligations : inferred_obligations, value : ( ) } ) => {
221
222
obligations. extend ( inferred_obligations) ;
@@ -228,7 +229,7 @@ fn project_and_unify_type<'cx, 'tcx>(
228
229
}
229
230
}
230
231
ty:: Term :: Const ( obligation_pred_const) => {
231
- let normalized_const = match opt_normalize_projection_type :: < true > (
232
+ let normalized_const = match opt_normalize_projection_type (
232
233
selcx,
233
234
obligation. param_env ,
234
235
obligation. predicate . projection_ty ,
@@ -492,7 +493,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
492
493
let ( data, mapped_regions, mapped_types, mapped_consts) =
493
494
BoundVarReplacer :: replace_bound_vars ( infcx, & mut self . universes , data) ;
494
495
let data = data. super_fold_with ( self ) ;
495
- let normalized_ty = opt_normalize_projection_type :: < false > (
496
+ let normalized_ty = opt_normalize_projection_type (
496
497
self . selcx ,
497
498
self . param_env ,
498
499
data,
@@ -826,7 +827,7 @@ pub fn normalize_projection_type<'a, 'b, 'tcx>(
826
827
depth : usize ,
827
828
obligations : & mut Vec < PredicateObligation < ' tcx > > ,
828
829
) -> Term < ' tcx > {
829
- opt_normalize_projection_type :: < false > (
830
+ opt_normalize_projection_type (
830
831
selcx,
831
832
param_env,
832
833
projection_ty,
@@ -859,7 +860,7 @@ pub fn normalize_projection_type<'a, 'b, 'tcx>(
859
860
/// function takes an obligations vector and appends to it directly, which is
860
861
/// slightly uglier but avoids the need for an extra short-lived allocation.
861
862
#[ instrument( level = "debug" , skip( selcx, param_env, cause, obligations) ) ]
862
- fn opt_normalize_projection_type < ' a , ' b , ' tcx , const INTO_CONST : bool > (
863
+ fn opt_normalize_projection_type < ' a , ' b , ' tcx > (
863
864
selcx : & ' a mut SelectionContext < ' b , ' tcx > ,
864
865
param_env : ty:: ParamEnv < ' tcx > ,
865
866
projection_ty : ty:: ProjectionTy < ' tcx > ,
@@ -946,7 +947,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx, const INTO_CONST: bool>(
946
947
947
948
let obligation = Obligation :: with_depth ( cause. clone ( ) , depth, param_env, projection_ty) ;
948
949
949
- match project :: < INTO_CONST > ( selcx, & obligation) {
950
+ match project ( selcx, & obligation) {
950
951
Ok ( Projected :: Progress ( Progress {
951
952
term : projected_term,
952
953
obligations : mut projected_obligations,
@@ -1087,7 +1088,7 @@ impl<'tcx> Progress<'tcx> {
1087
1088
/// IMPORTANT:
1088
1089
/// - `obligation` must be fully normalized
1089
1090
#[ tracing:: instrument( level = "info" , skip( selcx) ) ]
1090
- fn project < ' cx , ' tcx , const INTO_CONST : bool > (
1091
+ fn project < ' cx , ' tcx > (
1091
1092
selcx : & mut SelectionContext < ' cx , ' tcx > ,
1092
1093
obligation : & ProjectionTyObligation < ' tcx > ,
1093
1094
) -> Result < Projected < ' tcx > , ProjectionError < ' tcx > > {
@@ -1123,7 +1124,7 @@ fn project<'cx, 'tcx, const INTO_CONST: bool>(
1123
1124
1124
1125
match candidates {
1125
1126
ProjectionCandidateSet :: Single ( candidate) => {
1126
- Ok ( Projected :: Progress ( confirm_candidate :: < INTO_CONST > ( selcx, obligation, candidate) ) )
1127
+ Ok ( Projected :: Progress ( confirm_candidate ( selcx, obligation, candidate) ) )
1127
1128
}
1128
1129
ProjectionCandidateSet :: None => Ok ( Projected :: NoProgress (
1129
1130
selcx
@@ -1525,7 +1526,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
1525
1526
} ) ;
1526
1527
}
1527
1528
1528
- fn confirm_candidate < ' cx , ' tcx , const INTO_CONST : bool > (
1529
+ fn confirm_candidate < ' cx , ' tcx > (
1529
1530
selcx : & mut SelectionContext < ' cx , ' tcx > ,
1530
1531
obligation : & ProjectionTyObligation < ' tcx > ,
1531
1532
candidate : ProjectionCandidate < ' tcx > ,
@@ -1542,7 +1543,7 @@ fn confirm_candidate<'cx, 'tcx, const INTO_CONST: bool>(
1542
1543
}
1543
1544
1544
1545
ProjectionCandidate :: Select ( impl_source) => {
1545
- confirm_select_candidate :: < INTO_CONST > ( selcx, obligation, impl_source)
1546
+ confirm_select_candidate ( selcx, obligation, impl_source)
1546
1547
}
1547
1548
} ;
1548
1549
@@ -1558,15 +1559,13 @@ fn confirm_candidate<'cx, 'tcx, const INTO_CONST: bool>(
1558
1559
progress
1559
1560
}
1560
1561
1561
- fn confirm_select_candidate < ' cx , ' tcx , const INTO_CONST : bool > (
1562
+ fn confirm_select_candidate < ' cx , ' tcx > (
1562
1563
selcx : & mut SelectionContext < ' cx , ' tcx > ,
1563
1564
obligation : & ProjectionTyObligation < ' tcx > ,
1564
1565
impl_source : Selection < ' tcx > ,
1565
1566
) -> Progress < ' tcx > {
1566
1567
match impl_source {
1567
- super :: ImplSource :: UserDefined ( data) => {
1568
- confirm_impl_candidate :: < INTO_CONST > ( selcx, obligation, data)
1569
- }
1568
+ super :: ImplSource :: UserDefined ( data) => confirm_impl_candidate ( selcx, obligation, data) ,
1570
1569
super :: ImplSource :: Generator ( data) => confirm_generator_candidate ( selcx, obligation, data) ,
1571
1570
super :: ImplSource :: Closure ( data) => confirm_closure_candidate ( selcx, obligation, data) ,
1572
1571
super :: ImplSource :: FnPointer ( data) => confirm_fn_pointer_candidate ( selcx, obligation, data) ,
@@ -1836,7 +1835,7 @@ fn confirm_param_env_candidate<'cx, 'tcx>(
1836
1835
}
1837
1836
}
1838
1837
1839
- fn confirm_impl_candidate < ' cx , ' tcx , const INTO_CONST : bool > (
1838
+ fn confirm_impl_candidate < ' cx , ' tcx > (
1840
1839
selcx : & mut SelectionContext < ' cx , ' tcx > ,
1841
1840
obligation : & ProjectionTyObligation < ' tcx > ,
1842
1841
impl_impl_source : ImplSourceUserDefinedData < ' tcx , PredicateObligation < ' tcx > > ,
@@ -1874,10 +1873,12 @@ fn confirm_impl_candidate<'cx, 'tcx, const INTO_CONST: bool>(
1874
1873
let substs =
1875
1874
translate_substs ( selcx. infcx ( ) , param_env, impl_def_id, substs, assoc_ty. defining_node ) ;
1876
1875
let ty = tcx. type_of ( assoc_ty. item . def_id ) ;
1877
- let term: ty:: Term < ' tcx > = if INTO_CONST {
1878
- // FIXME(associated_const_equality): what are the right substs?
1876
+ let is_const = matches ! ( tcx. def_kind( assoc_ty. item. def_id) , DefKind :: AssocConst ) ;
1877
+ let term: ty:: Term < ' tcx > = if is_const {
1878
+ let identity_substs =
1879
+ crate :: traits:: InternalSubsts :: identity_for_item ( tcx, assoc_ty. item . def_id ) ;
1879
1880
let did = ty:: WithOptConstParam :: unknown ( assoc_ty. item . def_id ) ;
1880
- let val = ty:: ConstKind :: Unevaluated ( ty:: Unevaluated :: new ( did, substs ) ) ;
1881
+ let val = ty:: ConstKind :: Unevaluated ( ty:: Unevaluated :: new ( did, identity_substs ) ) ;
1881
1882
tcx. mk_const ( ty:: Const { ty, val } ) . into ( )
1882
1883
} else {
1883
1884
ty. into ( )
0 commit comments