@@ -2018,23 +2018,24 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
20182018 ///
20192019 /// Early-bound const parameters get lowered to [`ty::ConstKind::Param`]
20202020 /// and late-bound ones to [`ty::ConstKind::Bound`].
2021- pub ( crate ) fn lower_const_param ( & self , hir_id : HirId ) -> Const < ' tcx > {
2021+ pub ( crate ) fn lower_const_param ( & self , param_def_id : DefId , path_hir_id : HirId ) -> Const < ' tcx > {
20222022 let tcx = self . tcx ( ) ;
2023- match tcx. named_bound_var ( hir_id) {
2024- Some ( rbv:: ResolvedArg :: EarlyBound ( def_id) ) => {
2023+
2024+ match tcx. named_bound_var ( path_hir_id) {
2025+ Some ( rbv:: ResolvedArg :: EarlyBound ( _) ) => {
20252026 // Find the name and index of the const parameter by indexing the generics of
20262027 // the parent item and construct a `ParamConst`.
2027- let item_def_id = tcx. local_parent ( def_id ) ;
2028+ let item_def_id = tcx. parent ( param_def_id ) ;
20282029 let generics = tcx. generics_of ( item_def_id) ;
2029- let index = generics. param_def_id_to_index [ & def_id . to_def_id ( ) ] ;
2030- let name = tcx. item_name ( def_id . to_def_id ( ) ) ;
2030+ let index = generics. param_def_id_to_index [ & param_def_id ] ;
2031+ let name = tcx. item_name ( param_def_id ) ;
20312032 ty:: Const :: new_param ( tcx, ty:: ParamConst :: new ( index, name) )
20322033 }
20332034 Some ( rbv:: ResolvedArg :: LateBound ( debruijn, index, _) ) => {
20342035 ty:: Const :: new_bound ( tcx, debruijn, ty:: BoundVar :: from_u32 ( index) )
20352036 }
20362037 Some ( rbv:: ResolvedArg :: Error ( guar) ) => ty:: Const :: new_error ( tcx, guar) ,
2037- arg => bug ! ( "unexpected bound var resolution for {:?}: {arg:?}" , hir_id ) ,
2038+ arg => bug ! ( "unexpected bound var resolution for {:?}: {arg:?}" , path_hir_id ) ,
20382039 }
20392040 }
20402041
@@ -2063,10 +2064,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
20632064 fn lower_const_arg_path ( & self , qpath : hir:: QPath < ' tcx > , hir_id : HirId ) -> Const < ' tcx > {
20642065 let tcx = self . tcx ( ) ;
20652066
2066- // TODO: handle path args properly
20672067 match qpath {
20682068 hir:: QPath :: Resolved ( _, & hir:: Path { res : Res :: Def ( DefKind :: ConstParam , did) , .. } ) => {
2069- self . lower_const_arg_param ( did, hir_id)
2069+ self . lower_const_param ( did, hir_id)
20702070 }
20712071 hir:: QPath :: Resolved (
20722072 _,
@@ -2076,31 +2076,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
20762076 qpath. span ( ) ,
20772077 "fn's cannot be used as const args" ,
20782078 ) ,
2079- // hir::QPath::Resolved(_, path @ &hir::Path { res: Res::Def(_, did), .. }) => {
2080- // let (item_segment, _) = path.segments.split_last().unwrap();
2081- // let args = self.lower_generic_args_of_path_segment(path.span, did, item_segment);
2082- // ty::Const::new_unevaluated(tcx, ty::UnevaluatedConst::new(did, args))
2083- // }
2084- // // TODO: type-relative paths
2085- // _ => ty::Const::new_error_with_message(
2086- // tcx,
2087- // qpath.span(),
2088- // "Const::lower_const_arg_path: invalid qpath",
2089- // ),
20902079 hir:: QPath :: Resolved ( maybe_qself, path) => {
20912080 debug ! ( ?maybe_qself, ?path) ;
20922081 let opt_self_ty = maybe_qself. as_ref ( ) . map ( |qself| self . lower_ty ( qself) ) ;
20932082 self . lower_const_path_resolved ( opt_self_ty, path, hir_id)
20942083 }
2095-
2096- // TODO: type-relative paths
2097- // hir::QPath::TypeRelative(qself, segment) => {
2098- // debug!(?qself, ?segment);
2099- // let ty = self.lower_ty(qself);
2100- // self.lower_assoc_path(hir_ty.hir_id, hir_ty.span, ty, qself, segment, false)
2101- // .map(|(ty, _, _)| ty)
2102- // .unwrap_or_else(|guar| Ty::new_error(tcx, guar))
2103- // }
21042084 _ => ty:: Const :: new_error_with_message (
21052085 tcx,
21062086 qpath. span ( ) ,
@@ -2124,7 +2104,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
21242104 path. segments . iter ( ) ,
21252105 GenericsArgsErrExtend :: Param ( def_id) ,
21262106 ) ;
2127- self . lower_const_arg_param ( def_id, hir_id)
2107+ self . lower_const_param ( def_id, hir_id)
21282108 }
21292109 Res :: Def ( DefKind :: Const | DefKind :: Ctor ( _, CtorKind :: Const ) , did) => {
21302110 assert_eq ! ( opt_self_ty, None ) ;
@@ -2139,37 +2119,13 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
21392119 ) ;
21402120 ty:: Const :: new_unevaluated ( tcx, ty:: UnevaluatedConst :: new ( did, args) )
21412121 }
2142- // TODO: DefKind::AssocConst?
21432122 _ => Const :: new_error (
21442123 tcx,
21452124 tcx. dcx ( ) . span_delayed_bug ( span, "invalid Res for const path" ) ,
21462125 ) ,
21472126 }
21482127 }
21492128
2150- /// Lower a const param to a [`Const`]. This is only meant as a helper for [`Self::lower_const_arg_path`].
2151- /// FIXME: dedup with lower_const_param
2152- fn lower_const_arg_param ( & self , param_def_id : DefId , path_hir_id : HirId ) -> Const < ' tcx > {
2153- let tcx = self . tcx ( ) ;
2154-
2155- match tcx. named_bound_var ( path_hir_id) {
2156- Some ( rbv:: ResolvedArg :: EarlyBound ( _) ) => {
2157- // Find the name and index of the const parameter by indexing the generics of
2158- // the parent item and construct a `ParamConst`.
2159- let item_def_id = tcx. parent ( param_def_id) ;
2160- let generics = tcx. generics_of ( item_def_id) ;
2161- let index = generics. param_def_id_to_index [ & param_def_id] ;
2162- let name = tcx. item_name ( param_def_id) ;
2163- ty:: Const :: new_param ( tcx, ty:: ParamConst :: new ( index, name) )
2164- }
2165- Some ( rbv:: ResolvedArg :: LateBound ( debruijn, index, _) ) => {
2166- ty:: Const :: new_bound ( tcx, debruijn, ty:: BoundVar :: from_u32 ( index) )
2167- }
2168- Some ( rbv:: ResolvedArg :: Error ( guar) ) => ty:: Const :: new_error ( tcx, guar) ,
2169- arg => bug ! ( "unexpected bound var resolution for {:?}: {arg:?}" , path_hir_id) ,
2170- }
2171- }
2172-
21732129 fn lower_delegation_ty ( & self , idx : hir:: InferDelegationKind ) -> Ty < ' tcx > {
21742130 let delegation_sig = self . tcx ( ) . inherit_sig_for_delegation_item ( self . item_def_id ( ) ) ;
21752131 match idx {
@@ -2365,7 +2321,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
23652321 . type_of ( def_id)
23662322 . no_bound_vars ( )
23672323 . expect ( "const parameter types cannot be generic" ) ;
2368- let ct = self . lower_const_param ( expr. hir_id ) ;
2324+ let ct = self . lower_const_param ( def_id , expr. hir_id ) ;
23692325 ( ct, ty)
23702326 }
23712327
0 commit comments