@@ -53,10 +53,8 @@ use rustc_data_structures::sync::Lrc;
53
53
use rustc_errors:: { DiagArgFromDisplay , DiagCtxtHandle , StashKey } ;
54
54
use rustc_hir:: def:: { DefKind , LifetimeRes , Namespace , PartialRes , PerNS , Res } ;
55
55
use rustc_hir:: def_id:: { LocalDefId , LocalDefIdMap , CRATE_DEF_ID , LOCAL_CRATE } ;
56
- use rustc_hir:: { self as hir, ConstArgKind } ;
57
- use rustc_hir:: {
58
- ConstArg , GenericArg , HirId , ItemLocalMap , MissingLifetimeKind , ParamName , TraitCandidate ,
59
- } ;
56
+ use rustc_hir:: { self as hir} ;
57
+ use rustc_hir:: { GenericArg , HirId , ItemLocalMap , MissingLifetimeKind , ParamName , TraitCandidate } ;
60
58
use rustc_index:: { Idx , IndexSlice , IndexVec } ;
61
59
use rustc_macros:: extension;
62
60
use rustc_middle:: span_bug;
@@ -1064,7 +1062,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1064
1062
AssocItemConstraintKind :: Equality { term } => {
1065
1063
let term = match term {
1066
1064
Term :: Ty ( ty) => self . lower_ty ( ty, itctx) . into ( ) ,
1067
- Term :: Const ( c) => self . lower_anon_const ( c) . into ( ) ,
1065
+ Term :: Const ( c) => self . lower_anon_const_to_anon_const ( c) . into ( ) ,
1068
1066
} ;
1069
1067
hir:: AssocItemConstraintKind :: Equality { term }
1070
1068
}
@@ -1170,53 +1168,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1170
1168
ty,
1171
1169
) ;
1172
1170
1173
- // Construct an AnonConst where the expr is the "ty"'s path.
1174
-
1175
- let parent_def_id = self . current_def_id_parent ;
1176
- let node_id = self . next_node_id ( ) ;
1177
- let span = self . lower_span ( ty. span ) ;
1178
-
1179
- // Add a definition for the in-band const def.
1180
- let def_id = self . create_def (
1181
- parent_def_id,
1182
- node_id,
1183
- kw:: Empty ,
1184
- DefKind :: AnonConst ,
1185
- span,
1186
- ) ;
1187
-
1188
- let path_expr = Expr {
1189
- id : ty. id ,
1190
- kind : ExprKind :: Path ( None , path. clone ( ) ) ,
1191
- span,
1192
- attrs : AttrVec :: new ( ) ,
1193
- tokens : None ,
1194
- } ;
1195
-
1196
- let ct = self . with_new_scopes ( span, |this| {
1197
- self . arena . alloc ( hir:: AnonConst {
1198
- def_id,
1199
- hir_id : this. lower_node_id ( node_id) ,
1200
- body : this
1201
- . lower_const_body ( path_expr. span , Some ( & path_expr) ) ,
1202
- span,
1203
- } )
1204
- } ) ;
1205
- return GenericArg :: Const ( ConstArg {
1206
- kind : ConstArgKind :: Anon ( ct) ,
1207
- is_desugared_from_effects : false ,
1208
- } ) ;
1171
+ let ct =
1172
+ self . lower_const_path_to_const_arg ( path, res, ty. id , ty. span ) ;
1173
+ return GenericArg :: Const ( ct) ;
1209
1174
}
1210
1175
}
1211
1176
}
1212
1177
_ => { }
1213
1178
}
1214
1179
GenericArg :: Type ( self . lower_ty ( ty, itctx) )
1215
1180
}
1216
- ast:: GenericArg :: Const ( ct) => GenericArg :: Const ( ConstArg {
1217
- kind : ConstArgKind :: Anon ( self . lower_anon_const ( ct) ) ,
1218
- is_desugared_from_effects : false ,
1219
- } ) ,
1181
+ ast:: GenericArg :: Const ( ct) => GenericArg :: Const ( self . lower_anon_const_to_const_arg ( ct) ) ,
1220
1182
}
1221
1183
}
1222
1184
@@ -1375,7 +1337,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1375
1337
TyKind :: Array ( ty, length) => {
1376
1338
hir:: TyKind :: Array ( self . lower_ty ( ty, itctx) , self . lower_array_length ( length) )
1377
1339
}
1378
- TyKind :: Typeof ( expr) => hir:: TyKind :: Typeof ( self . lower_anon_const ( expr) ) ,
1340
+ TyKind :: Typeof ( expr) => hir:: TyKind :: Typeof ( self . lower_anon_const_to_anon_const ( expr) ) ,
1379
1341
TyKind :: TraitObject ( bounds, kind) => {
1380
1342
let mut lifetime_bound = None ;
1381
1343
let ( bounds, lifetime_bound) = self . with_dyn_type_scope ( true , |this| {
@@ -2242,7 +2204,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2242
2204
false
2243
2205
}
2244
2206
} )
2245
- . map ( |def| self . lower_anon_const ( def) ) ;
2207
+ . map ( |def| self . lower_anon_const_to_anon_const ( def) ) ;
2246
2208
2247
2209
(
2248
2210
hir:: ParamName :: Plain ( self . lower_ident ( param. ident ) ) ,
@@ -2380,14 +2342,66 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2380
2342
"using `_` for array lengths is unstable" ,
2381
2343
)
2382
2344
. stash ( c. value . span , StashKey :: UnderscoreForArrayLengths ) ;
2383
- hir:: ArrayLen :: Body ( self . lower_anon_const ( c) )
2345
+ hir:: ArrayLen :: Body ( self . lower_anon_const_to_anon_const ( c) )
2384
2346
}
2385
2347
}
2386
- _ => hir:: ArrayLen :: Body ( self . lower_anon_const ( c) ) ,
2348
+ _ => hir:: ArrayLen :: Body ( self . lower_anon_const_to_anon_const ( c) ) ,
2349
+ }
2350
+ }
2351
+
2352
+ fn lower_const_path_to_const_arg (
2353
+ & mut self ,
2354
+ path : & Path ,
2355
+ _res : Res < NodeId > ,
2356
+ ty_id : NodeId ,
2357
+ span : Span ,
2358
+ ) -> & ' hir hir:: ConstArg < ' hir > {
2359
+ // Construct an AnonConst where the expr is the "ty"'s path.
2360
+
2361
+ let parent_def_id = self . current_def_id_parent ;
2362
+ let node_id = self . next_node_id ( ) ;
2363
+ let span = self . lower_span ( span) ;
2364
+
2365
+ // Add a definition for the in-band const def.
2366
+ let def_id = self . create_def ( parent_def_id, node_id, kw:: Empty , DefKind :: AnonConst , span) ;
2367
+
2368
+ let path_expr = Expr {
2369
+ id : ty_id,
2370
+ kind : ExprKind :: Path ( None , path. clone ( ) ) ,
2371
+ span,
2372
+ attrs : AttrVec :: new ( ) ,
2373
+ tokens : None ,
2374
+ } ;
2375
+
2376
+ let ct = self . with_new_scopes ( span, |this| {
2377
+ self . arena . alloc ( hir:: AnonConst {
2378
+ def_id,
2379
+ hir_id : this. lower_node_id ( node_id) ,
2380
+ body : this. lower_const_body ( path_expr. span , Some ( & path_expr) ) ,
2381
+ span,
2382
+ } )
2383
+ } ) ;
2384
+
2385
+ self . arena . alloc ( hir:: ConstArg {
2386
+ kind : hir:: ConstArgKind :: Anon ( ct) ,
2387
+ is_desugared_from_effects : false ,
2388
+ } )
2389
+ }
2390
+
2391
+ fn lower_anon_const_to_const_arg ( & mut self , anon : & AnonConst ) -> & ' hir hir:: ConstArg < ' hir > {
2392
+ self . arena . alloc ( self . lower_anon_const_to_const_arg_direct ( anon) )
2393
+ }
2394
+
2395
+ #[ instrument( level = "debug" , skip( self ) ) ]
2396
+ fn lower_anon_const_to_const_arg_direct ( & mut self , anon : & AnonConst ) -> hir:: ConstArg < ' hir > {
2397
+ let lowered_anon = self . lower_anon_const_to_anon_const ( anon) ;
2398
+ hir:: ConstArg {
2399
+ kind : hir:: ConstArgKind :: Anon ( lowered_anon) ,
2400
+ is_desugared_from_effects : false ,
2387
2401
}
2388
2402
}
2389
2403
2390
- fn lower_anon_const ( & mut self , c : & AnonConst ) -> & ' hir hir:: AnonConst {
2404
+ fn lower_anon_const_to_anon_const ( & mut self , c : & AnonConst ) -> & ' hir hir:: AnonConst {
2391
2405
self . arena . alloc ( self . with_new_scopes ( c. value . span , |this| hir:: AnonConst {
2392
2406
def_id : this. local_def_id ( c. id ) ,
2393
2407
hir_id : this. lower_node_id ( c. id ) ,
0 commit comments