@@ -142,6 +142,8 @@ struct LoweringContext<'a, 'hir> {
142
142
/// defined on the TAIT, so we have type Foo<'a1> = ... and we establish a mapping in this
143
143
/// field from the original parameter 'a to the new parameter 'a1.
144
144
generics_def_id_map : Vec < FxHashMap < LocalDefId , LocalDefId > > ,
145
+
146
+ host_param_id : Option < hir:: HirId > ,
145
147
}
146
148
147
149
trait ResolverAstLoweringExt {
@@ -1267,6 +1269,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1267
1269
span : t. span
1268
1270
} ,
1269
1271
itctx,
1272
+ // TODO?
1273
+ ast:: Const :: No ,
1270
1274
) ;
1271
1275
let bounds = this. arena . alloc_from_iter ( [ bound] ) ;
1272
1276
let lifetime_bound = this. elided_dyn_bound ( t. span ) ;
@@ -1277,7 +1281,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1277
1281
}
1278
1282
1279
1283
let id = self . lower_node_id ( t. id ) ;
1280
- let qpath = self . lower_qpath ( t. id , qself, path, param_mode, itctx) ;
1284
+ let qpath = self . lower_qpath ( t. id , qself, path, param_mode, itctx, None ) ;
1281
1285
self . ty_path ( id, t. span , qpath)
1282
1286
}
1283
1287
@@ -1361,10 +1365,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1361
1365
this. arena . alloc_from_iter ( bounds. iter ( ) . filter_map ( |bound| match bound {
1362
1366
GenericBound :: Trait (
1363
1367
ty,
1364
- TraitBoundModifier :: None
1368
+ modifier @ ( TraitBoundModifier :: None
1365
1369
| TraitBoundModifier :: MaybeConst
1366
- | TraitBoundModifier :: Negative ,
1367
- ) => Some ( this. lower_poly_trait_ref ( ty, itctx) ) ,
1370
+ | TraitBoundModifier :: Negative ) ,
1371
+ ) => Some ( this. lower_poly_trait_ref ( ty, itctx, modifier . to_constness ( ) ) ) ,
1368
1372
// `~const ?Bound` will cause an error during AST validation
1369
1373
// anyways, so treat it like `?Bound` as compilation proceeds.
1370
1374
GenericBound :: Trait (
@@ -2189,7 +2193,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2189
2193
) -> hir:: GenericBound < ' hir > {
2190
2194
match tpb {
2191
2195
GenericBound :: Trait ( p, modifier) => hir:: GenericBound :: Trait (
2192
- self . lower_poly_trait_ref ( p, itctx) ,
2196
+ self . lower_poly_trait_ref ( p, itctx, modifier . to_constness ( ) ) ,
2193
2197
self . lower_trait_bound_modifier ( * modifier) ,
2194
2198
) ,
2195
2199
GenericBound :: Outlives ( lifetime) => {
@@ -2332,8 +2336,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2332
2336
}
2333
2337
}
2334
2338
2335
- fn lower_trait_ref ( & mut self , p : & TraitRef , itctx : & ImplTraitContext ) -> hir:: TraitRef < ' hir > {
2336
- let path = match self . lower_qpath ( p. ref_id , & None , & p. path , ParamMode :: Explicit , itctx) {
2339
+ fn lower_trait_ref ( & mut self , constness : ast :: Const , p : & TraitRef , itctx : & ImplTraitContext ) -> hir:: TraitRef < ' hir > {
2340
+ let path = match self . lower_qpath ( p. ref_id , & None , & p. path , ParamMode :: Explicit , itctx, Some ( constness ) ) {
2337
2341
hir:: QPath :: Resolved ( None , path) => path,
2338
2342
qpath => panic ! ( "lower_trait_ref: unexpected QPath `{qpath:?}`" ) ,
2339
2343
} ;
@@ -2345,10 +2349,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2345
2349
& mut self ,
2346
2350
p : & PolyTraitRef ,
2347
2351
itctx : & ImplTraitContext ,
2352
+ constness : ast:: Const ,
2348
2353
) -> hir:: PolyTraitRef < ' hir > {
2349
2354
let bound_generic_params =
2350
2355
self . lower_lifetime_binder ( p. trait_ref . ref_id , & p. bound_generic_params ) ;
2351
- let trait_ref = self . lower_trait_ref ( & p. trait_ref , itctx) ;
2356
+ let trait_ref = self . lower_trait_ref ( constness , & p. trait_ref , itctx, ) ;
2352
2357
hir:: PolyTraitRef { bound_generic_params, trait_ref, span : self . lower_span ( p. span ) }
2353
2358
}
2354
2359
@@ -2702,6 +2707,28 @@ struct GenericArgsCtor<'hir> {
2702
2707
}
2703
2708
2704
2709
impl < ' hir > GenericArgsCtor < ' hir > {
2710
+ fn push_constness ( & mut self , lcx : & mut LoweringContext < ' _ , ' hir > , constness : ast:: Const ) {
2711
+ let span = if let ast:: Const :: Yes ( sp) = constness {
2712
+ sp
2713
+ } else {
2714
+ DUMMY_SP
2715
+ } ;
2716
+ let id = lcx. next_node_id ( ) ;
2717
+ lcx. lower_body ( |lcx| {
2718
+ ( & [ ] , match constness {
2719
+ ast:: Const :: Yes ( _) => lcx. expr_ident_mut ( span, Ident { name : sym:: host, span } , binding) ,
2720
+ ast:: Const :: No => lcx. expr ( span, hir:: ExprKind :: Lit ( lcx. arena . alloc ( hir:: Lit { span, node : ast:: LitKind :: Bool ( true ) } ) ) ) ,
2721
+ } )
2722
+ } ) ;
2723
+ let def = lcx. create_def ( lcx. current_hir_id_owner . def_id , id, DefPathData :: AnonConst , span) ;
2724
+ self . args . push ( hir:: GenericArg :: Const ( hir:: ConstArg {
2725
+ value : hir:: AnonConst {
2726
+ def_id,
2727
+ } ,
2728
+ span,
2729
+ } ) )
2730
+ }
2731
+
2705
2732
fn is_empty ( & self ) -> bool {
2706
2733
self . args . is_empty ( )
2707
2734
&& self . bindings . is_empty ( )
0 commit comments