@@ -29,10 +29,9 @@ use rustc_errors::codes::*;
2929use rustc_errors:: {
3030 Applicability , Diag , DiagCtxtHandle , ErrorGuaranteed , FatalError , struct_span_code_err,
3131} ;
32- use rustc_hir as hir;
3332use rustc_hir:: def:: { CtorKind , CtorOf , DefKind , Namespace , Res } ;
3433use rustc_hir:: def_id:: { DefId , LocalDefId } ;
35- use rustc_hir:: { GenericArg , GenericArgs , HirId } ;
34+ use rustc_hir:: { self as hir , AnonConst , GenericArg , GenericArgs , HirId } ;
3635use rustc_infer:: infer:: { InferCtxt , TyCtxtInferExt } ;
3736use rustc_infer:: traits:: ObligationCause ;
3837use rustc_middle:: middle:: stability:: AllowUnstable ;
@@ -2089,7 +2088,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
20892088 qpath. span ( ) ,
20902089 format ! ( "Const::lower_const_arg: invalid qpath {qpath:?}" ) ,
20912090 ) ,
2092- hir:: ConstArgKind :: Anon ( anon) => self . lower_anon_const ( anon. def_id ) ,
2091+ hir:: ConstArgKind :: Anon ( anon) => self . lower_anon_const ( anon) ,
20932092 hir:: ConstArgKind :: Infer ( span) => self . ct_infer ( None , span) ,
20942093 }
20952094 }
@@ -2180,27 +2179,22 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
21802179 /// Literals and const generic parameters are eagerly converted to a constant, everything else
21812180 /// becomes `Unevaluated`.
21822181 #[ instrument( skip( self ) , level = "debug" ) ]
2183- fn lower_anon_const ( & self , def : LocalDefId ) -> Const < ' tcx > {
2182+ fn lower_anon_const ( & self , anon : & AnonConst ) -> Const < ' tcx > {
21842183 let tcx = self . tcx ( ) ;
21852184
2186- let body_id = match tcx. hir_node_by_def_id ( def) {
2187- hir:: Node :: AnonConst ( ac) => ac. body ,
2188- node => span_bug ! (
2189- tcx. def_span( def. to_def_id( ) ) ,
2190- "from_anon_const can only process anonymous constants, not {node:?}"
2191- ) ,
2192- } ;
2193-
2194- let expr = & tcx. hir ( ) . body ( body_id) . value ;
2185+ let expr = & tcx. hir ( ) . body ( anon. body ) . value ;
21952186 debug ! ( ?expr) ;
21962187
2197- let ty = tcx. type_of ( def) . no_bound_vars ( ) . expect ( "const parameter types cannot be generic" ) ;
2188+ let ty = tcx
2189+ . type_of ( anon. def_id )
2190+ . no_bound_vars ( )
2191+ . expect ( "const parameter types cannot be generic" ) ;
21982192
21992193 match self . try_lower_anon_const_lit ( ty, expr) {
22002194 Some ( v) => v,
22012195 None => ty:: Const :: new_unevaluated ( tcx, ty:: UnevaluatedConst {
2202- def : def . to_def_id ( ) ,
2203- args : ty:: GenericArgs :: identity_for_item ( tcx, def . to_def_id ( ) ) ,
2196+ def : anon . def_id . to_def_id ( ) ,
2197+ args : ty:: GenericArgs :: identity_for_item ( tcx, anon . def_id . to_def_id ( ) ) ,
22042198 } ) ,
22052199 }
22062200 }
0 commit comments