@@ -42,7 +42,6 @@ extern crate tracing;
4242
4343use crate :: errors:: { AssocTyParentheses , AssocTyParenthesesSub , MisplacedImplTrait , TraitFnAsync } ;
4444
45- use hir:: ConstArgKind ;
4645use rustc_ast:: ptr:: P ;
4746use rustc_ast:: visit;
4847use rustc_ast:: { self as ast, * } ;
@@ -1205,38 +1204,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12051204 ty,
12061205 ) ;
12071206
1208- // Construct an AnonConst where the expr is the "ty"'s path.
1209-
1210- let parent_def_id = self . current_hir_id_owner ;
1211- let node_id = self . next_node_id ( ) ;
1212- let span = self . lower_span ( ty. span ) ;
1213-
1214- // Add a definition for the in-band const def.
1215- let def_id = self . create_def (
1216- parent_def_id. def_id ,
1217- node_id,
1218- DefPathData :: AnonConst ,
1219- span,
1220- ) ;
1221-
1222- let path_expr = Expr {
1223- id : ty. id ,
1224- kind : ExprKind :: Path ( None , path. clone ( ) ) ,
1225- span,
1226- attrs : AttrVec :: new ( ) ,
1227- tokens : None ,
1228- } ;
1229-
1230- let ct = self . with_new_scopes ( |this| hir:: AnonConst {
1231- def_id,
1232- hir_id : this. lower_node_id ( node_id) ,
1233- body : this. lower_const_body ( path_expr. span , Some ( & path_expr) ) ,
1234- } ) ;
1235- // FIXME(const_arg_kind)
12361207 return GenericArg :: Const (
1237- self . arena . alloc ( ConstArg {
1238- kind : ConstArgKind :: AnonConst ( span, ct) ,
1239- } ) ,
1208+ self . lower_const_arg_param ( ty. id , path, itctx) ,
12401209 ) ;
12411210 }
12421211 }
@@ -1245,16 +1214,41 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12451214 }
12461215 GenericArg :: Type ( self . lower_ty ( & ty, itctx) )
12471216 }
1248- ast:: GenericArg :: Const ( ct) => GenericArg :: Const ( self . arena . alloc ( ConstArg {
1249- // FIXME(const_arg_kind)
1250- kind : ConstArgKind :: AnonConst (
1251- self . lower_span ( ct. value . span ) ,
1252- self . lower_anon_const ( & ct) ,
1217+ ast:: GenericArg :: Const ( ct) => GenericArg :: Const ( self . lower_const_arg ( ct, itctx) ) ,
1218+ }
1219+ }
1220+
1221+ #[ instrument( level = "debug" , skip( self ) , ret) ]
1222+ fn lower_const_arg (
1223+ & mut self ,
1224+ c : & AnonConst ,
1225+ itctx : & ImplTraitContext ,
1226+ ) -> & ' hir hir:: ConstArg < ' hir > {
1227+ match c. value . is_potential_trivial_const_arg ( ) {
1228+ Some ( ( path_id, param_path) ) => self . lower_const_arg_param ( path_id, param_path, itctx) ,
1229+ None => self . arena . alloc ( ConstArg {
1230+ kind : hir:: ConstArgKind :: AnonConst (
1231+ self . lower_span ( c. value . span ) ,
1232+ self . lower_anon_const ( c) ,
12531233 ) ,
1254- } ) ) ,
1234+ } ) ,
12551235 }
12561236 }
12571237
1238+ fn lower_const_arg_param (
1239+ & mut self ,
1240+ path_id : NodeId ,
1241+ param_path : & Path ,
1242+ itctx : & ImplTraitContext ,
1243+ ) -> & ' hir hir:: ConstArg < ' hir > {
1244+ self . arena . alloc ( ConstArg {
1245+ kind : hir:: ConstArgKind :: Param (
1246+ self . lower_node_id ( path_id) ,
1247+ self . lower_qpath ( path_id, & None , param_path, ParamMode :: ExplicitNamed , itctx) ,
1248+ ) ,
1249+ } )
1250+ }
1251+
12581252 #[ instrument( level = "debug" , skip( self ) ) ]
12591253 fn lower_ty ( & mut self , t : & Ty , itctx : & ImplTraitContext ) -> & ' hir hir:: Ty < ' hir > {
12601254 self . arena . alloc ( self . lower_ty_direct ( t, itctx) )
0 commit comments