@@ -42,7 +42,6 @@ extern crate tracing;
42
42
43
43
use crate :: errors:: { AssocTyParentheses , AssocTyParenthesesSub , MisplacedImplTrait , TraitFnAsync } ;
44
44
45
- use hir:: ConstArgKind ;
46
45
use rustc_ast:: ptr:: P ;
47
46
use rustc_ast:: visit;
48
47
use rustc_ast:: { self as ast, * } ;
@@ -1205,38 +1204,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1205
1204
ty,
1206
1205
) ;
1207
1206
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)
1236
1207
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) ,
1240
1209
) ;
1241
1210
}
1242
1211
}
@@ -1245,16 +1214,41 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1245
1214
}
1246
1215
GenericArg :: Type ( self . lower_ty ( & ty, itctx) )
1247
1216
}
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) ,
1253
1233
) ,
1254
- } ) ) ,
1234
+ } ) ,
1255
1235
}
1256
1236
}
1257
1237
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
+
1258
1252
#[ instrument( level = "debug" , skip( self ) ) ]
1259
1253
fn lower_ty ( & mut self , t : & Ty , itctx : & ImplTraitContext ) -> & ' hir hir:: Ty < ' hir > {
1260
1254
self . arena . alloc ( self . lower_ty_direct ( t, itctx) )
0 commit comments