@@ -22,6 +22,7 @@ use crate::traits::error_reporting::InferCtxtExt as _;
2222use rustc_data_structures:: sso:: SsoHashSet ;
2323use rustc_data_structures:: stack:: ensure_sufficient_stack;
2424use rustc_errors:: ErrorReported ;
25+ use rustc_hir:: def:: DefKind ;
2526use rustc_hir:: def_id:: DefId ;
2627use rustc_hir:: lang_items:: LangItem ;
2728use rustc_infer:: infer:: resolve:: OpportunisticRegionResolver ;
@@ -200,7 +201,7 @@ fn project_and_unify_type<'cx, 'tcx>(
200201 let infcx = selcx. infcx ( ) ;
201202 match obligation. predicate . term {
202203 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 (
204205 selcx,
205206 obligation. param_env ,
206207 obligation. predicate . projection_ty ,
@@ -215,7 +216,7 @@ fn project_and_unify_type<'cx, 'tcx>(
215216 debug ! ( ?normalized_ty, ?obligations, "project_and_unify_type result" ) ;
216217 match infcx
217218 . at ( & obligation. cause , obligation. param_env )
218- . eq ( normalized_ty, obligation_pred_ty. into ( ) )
219+ . eq ( normalized_ty, obligation_pred_ty)
219220 {
220221 Ok ( InferOk { obligations : inferred_obligations, value : ( ) } ) => {
221222 obligations. extend ( inferred_obligations) ;
@@ -228,7 +229,7 @@ fn project_and_unify_type<'cx, 'tcx>(
228229 }
229230 }
230231 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 (
232233 selcx,
233234 obligation. param_env ,
234235 obligation. predicate . projection_ty ,
@@ -492,7 +493,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
492493 let ( data, mapped_regions, mapped_types, mapped_consts) =
493494 BoundVarReplacer :: replace_bound_vars ( infcx, & mut self . universes , data) ;
494495 let data = data. super_fold_with ( self ) ;
495- let normalized_ty = opt_normalize_projection_type :: < false > (
496+ let normalized_ty = opt_normalize_projection_type (
496497 self . selcx ,
497498 self . param_env ,
498499 data,
@@ -826,7 +827,7 @@ pub fn normalize_projection_type<'a, 'b, 'tcx>(
826827 depth : usize ,
827828 obligations : & mut Vec < PredicateObligation < ' tcx > > ,
828829) -> Term < ' tcx > {
829- opt_normalize_projection_type :: < false > (
830+ opt_normalize_projection_type (
830831 selcx,
831832 param_env,
832833 projection_ty,
@@ -859,7 +860,7 @@ pub fn normalize_projection_type<'a, 'b, 'tcx>(
859860/// function takes an obligations vector and appends to it directly, which is
860861/// slightly uglier but avoids the need for an extra short-lived allocation.
861862#[ 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 > (
863864 selcx : & ' a mut SelectionContext < ' b , ' tcx > ,
864865 param_env : ty:: ParamEnv < ' tcx > ,
865866 projection_ty : ty:: ProjectionTy < ' tcx > ,
@@ -946,7 +947,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx, const INTO_CONST: bool>(
946947
947948 let obligation = Obligation :: with_depth ( cause. clone ( ) , depth, param_env, projection_ty) ;
948949
949- match project :: < INTO_CONST > ( selcx, & obligation) {
950+ match project ( selcx, & obligation) {
950951 Ok ( Projected :: Progress ( Progress {
951952 term : projected_term,
952953 obligations : mut projected_obligations,
@@ -1087,7 +1088,7 @@ impl<'tcx> Progress<'tcx> {
10871088/// IMPORTANT:
10881089/// - `obligation` must be fully normalized
10891090#[ tracing:: instrument( level = "info" , skip( selcx) ) ]
1090- fn project < ' cx , ' tcx , const INTO_CONST : bool > (
1091+ fn project < ' cx , ' tcx > (
10911092 selcx : & mut SelectionContext < ' cx , ' tcx > ,
10921093 obligation : & ProjectionTyObligation < ' tcx > ,
10931094) -> Result < Projected < ' tcx > , ProjectionError < ' tcx > > {
@@ -1123,7 +1124,7 @@ fn project<'cx, 'tcx, const INTO_CONST: bool>(
11231124
11241125 match candidates {
11251126 ProjectionCandidateSet :: Single ( candidate) => {
1126- Ok ( Projected :: Progress ( confirm_candidate :: < INTO_CONST > ( selcx, obligation, candidate) ) )
1127+ Ok ( Projected :: Progress ( confirm_candidate ( selcx, obligation, candidate) ) )
11271128 }
11281129 ProjectionCandidateSet :: None => Ok ( Projected :: NoProgress (
11291130 selcx
@@ -1525,7 +1526,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
15251526 } ) ;
15261527}
15271528
1528- fn confirm_candidate < ' cx , ' tcx , const INTO_CONST : bool > (
1529+ fn confirm_candidate < ' cx , ' tcx > (
15291530 selcx : & mut SelectionContext < ' cx , ' tcx > ,
15301531 obligation : & ProjectionTyObligation < ' tcx > ,
15311532 candidate : ProjectionCandidate < ' tcx > ,
@@ -1542,7 +1543,7 @@ fn confirm_candidate<'cx, 'tcx, const INTO_CONST: bool>(
15421543 }
15431544
15441545 ProjectionCandidate :: Select ( impl_source) => {
1545- confirm_select_candidate :: < INTO_CONST > ( selcx, obligation, impl_source)
1546+ confirm_select_candidate ( selcx, obligation, impl_source)
15461547 }
15471548 } ;
15481549
@@ -1558,15 +1559,13 @@ fn confirm_candidate<'cx, 'tcx, const INTO_CONST: bool>(
15581559 progress
15591560}
15601561
1561- fn confirm_select_candidate < ' cx , ' tcx , const INTO_CONST : bool > (
1562+ fn confirm_select_candidate < ' cx , ' tcx > (
15621563 selcx : & mut SelectionContext < ' cx , ' tcx > ,
15631564 obligation : & ProjectionTyObligation < ' tcx > ,
15641565 impl_source : Selection < ' tcx > ,
15651566) -> Progress < ' tcx > {
15661567 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) ,
15701569 super :: ImplSource :: Generator ( data) => confirm_generator_candidate ( selcx, obligation, data) ,
15711570 super :: ImplSource :: Closure ( data) => confirm_closure_candidate ( selcx, obligation, data) ,
15721571 super :: ImplSource :: FnPointer ( data) => confirm_fn_pointer_candidate ( selcx, obligation, data) ,
@@ -1836,7 +1835,7 @@ fn confirm_param_env_candidate<'cx, 'tcx>(
18361835 }
18371836}
18381837
1839- fn confirm_impl_candidate < ' cx , ' tcx , const INTO_CONST : bool > (
1838+ fn confirm_impl_candidate < ' cx , ' tcx > (
18401839 selcx : & mut SelectionContext < ' cx , ' tcx > ,
18411840 obligation : & ProjectionTyObligation < ' tcx > ,
18421841 impl_impl_source : ImplSourceUserDefinedData < ' tcx , PredicateObligation < ' tcx > > ,
@@ -1874,10 +1873,12 @@ fn confirm_impl_candidate<'cx, 'tcx, const INTO_CONST: bool>(
18741873 let substs =
18751874 translate_substs ( selcx. infcx ( ) , param_env, impl_def_id, substs, assoc_ty. defining_node ) ;
18761875 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 ) ;
18791880 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 ) ) ;
18811882 tcx. mk_const ( ty:: Const { ty, val } ) . into ( )
18821883 } else {
18831884 ty. into ( )
0 commit comments