@@ -1152,40 +1152,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11521152 ty,
11531153 ) ;
11541154
1155- // Construct an AnonConst where the expr is the "ty"'s path.
1156-
1157- let parent_def_id = self . current_hir_id_owner ;
1158- let node_id = self . next_node_id ( ) ;
1159- let span = self . lower_span ( ty. span ) ;
1160-
1161- // Add a definition for the in-band const def.
1162- let def_id = self . create_def (
1163- parent_def_id. def_id ,
1164- node_id,
1165- kw:: Empty ,
1166- DefKind :: AnonConst ,
1167- span,
1155+ let qpath = self . lower_qpath (
1156+ ty. id ,
1157+ & None ,
1158+ path,
1159+ ParamMode :: Optional ,
1160+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: Path ) ,
1161+ None ,
11681162 ) ;
1169-
1170- let path_expr = Expr {
1171- id : ty. id ,
1172- kind : ExprKind :: Path ( None , path. clone ( ) ) ,
1173- span,
1174- attrs : AttrVec :: new ( ) ,
1175- tokens : None ,
1176- } ;
1177-
1178- let ct = self . with_new_scopes ( span, |this| {
1179- self . arena . alloc ( hir:: AnonConst {
1180- def_id,
1181- hir_id : this. lower_node_id ( node_id) ,
1182- body : this
1183- . lower_const_body ( path_expr. span , Some ( & path_expr) ) ,
1184- span,
1185- } )
1186- } ) ;
11871163 return GenericArg :: Const ( ConstArg {
1188- kind : ConstArgKind :: Anon ( ct) ,
1164+ hir_id : self . lower_node_id ( ty. id ) ,
1165+ kind : ConstArgKind :: Path ( qpath) ,
11891166 is_desugared_from_effects : false ,
11901167 } ) ;
11911168 }
@@ -1195,10 +1172,39 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11951172 }
11961173 GenericArg :: Type ( self . lower_ty ( ty, itctx) )
11971174 }
1198- ast:: GenericArg :: Const ( ct) => GenericArg :: Const ( ConstArg {
1199- kind : ConstArgKind :: Anon ( self . lower_anon_const ( ct) ) ,
1200- is_desugared_from_effects : false ,
1201- } ) ,
1175+ ast:: GenericArg :: Const ( ct) => GenericArg :: Const ( self . lower_anon_const_as_const_arg ( ct) ) ,
1176+ }
1177+ }
1178+
1179+ fn lower_anon_const_as_const_arg ( & mut self , anon : & AnonConst ) -> hir:: ConstArg < ' hir > {
1180+ if let ExprKind :: Path ( qself, path) = & anon. value . kind {
1181+ let qpath = self . lower_qpath (
1182+ anon. id ,
1183+ qself,
1184+ path,
1185+ ParamMode :: Optional ,
1186+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: Path ) ,
1187+ None ,
1188+ ) ;
1189+ // FIXME(min_generic_const_exprs): for now we only lower params to ConstArgKind::Path
1190+ if let hir:: QPath :: Resolved (
1191+ _,
1192+ & hir:: Path { res : Res :: Def ( DefKind :: ConstParam , _) , .. } ,
1193+ ) = qpath
1194+ {
1195+ return ConstArg {
1196+ hir_id : self . lower_node_id ( anon. id ) ,
1197+ kind : ConstArgKind :: Path ( qpath) ,
1198+ is_desugared_from_effects : false ,
1199+ } ;
1200+ }
1201+ }
1202+
1203+ let lowered_anon = self . lower_anon_const ( anon) ;
1204+ ConstArg {
1205+ hir_id : lowered_anon. hir_id ,
1206+ kind : ConstArgKind :: Anon ( lowered_anon) ,
1207+ is_desugared_from_effects : false ,
12021208 }
12031209 }
12041210
@@ -2596,16 +2602,34 @@ impl<'hir> GenericArgsCtor<'hir> {
25962602 return ;
25972603 }
25982604
2599- let ( span, body) = match constness {
2605+ let id = lcx. next_node_id ( ) ;
2606+ let hir_id = lcx. next_id ( ) ;
2607+
2608+ let const_arg_kind = match constness {
26002609 BoundConstness :: Never => return ,
26012610 BoundConstness :: Always ( span) => {
26022611 let span = lcx. lower_span ( span) ;
26032612
26042613 let body = hir:: ExprKind :: Lit (
26052614 lcx. arena . alloc ( hir:: Lit { node : LitKind :: Bool ( false ) , span } ) ,
26062615 ) ;
2616+ let body = lcx. lower_body ( |lcx| ( & [ ] , lcx. expr ( span, body) ) ) ;
2617+
2618+ let def_id = lcx. create_def (
2619+ lcx. current_hir_id_owner . def_id ,
2620+ id,
2621+ kw:: Empty ,
2622+ DefKind :: AnonConst ,
2623+ span,
2624+ ) ;
26072625
2608- ( span, body)
2626+ lcx. children . push ( ( def_id, hir:: MaybeOwner :: NonOwner ( hir_id) ) ) ;
2627+ hir:: ConstArgKind :: Anon ( lcx. arena . alloc ( hir:: AnonConst {
2628+ def_id,
2629+ hir_id,
2630+ body,
2631+ span,
2632+ } ) )
26092633 }
26102634 BoundConstness :: Maybe ( span) => {
26112635 let span = lcx. lower_span ( span) ;
@@ -2618,48 +2642,26 @@ impl<'hir> GenericArgsCtor<'hir> {
26182642 return ;
26192643 } ;
26202644
2621- let hir_id = lcx. next_id ( ) ;
26222645 let res = Res :: Def ( DefKind :: ConstParam , host_param_id. to_def_id ( ) ) ;
2623- let body = hir:: ExprKind :: Path ( hir:: QPath :: Resolved (
2624- None ,
2625- lcx. arena . alloc ( hir:: Path {
2626- span,
2627- res,
2628- segments : arena_vec ! [
2629- lcx;
2630- hir:: PathSegment :: new(
2631- Ident { name: sym:: host, span } ,
2632- hir_id,
2633- res
2634- )
2635- ] ,
2636- } ) ,
2637- ) ) ;
2638-
2639- ( span, body)
2646+ let path = lcx. arena . alloc ( hir:: Path {
2647+ span,
2648+ res,
2649+ segments : arena_vec ! [
2650+ lcx;
2651+ hir:: PathSegment :: new(
2652+ Ident { name: sym:: host, span } ,
2653+ hir_id,
2654+ res
2655+ )
2656+ ] ,
2657+ } ) ;
2658+ hir:: ConstArgKind :: Path ( hir:: QPath :: Resolved ( None , path) )
26402659 }
26412660 } ;
2642- let body = lcx. lower_body ( |lcx| ( & [ ] , lcx. expr ( span, body) ) ) ;
2643-
2644- let id = lcx. next_node_id ( ) ;
2645- let hir_id = lcx. next_id ( ) ;
2646-
2647- let def_id = lcx. create_def (
2648- lcx. current_hir_id_owner . def_id ,
2649- id,
2650- kw:: Empty ,
2651- DefKind :: AnonConst ,
2652- span,
2653- ) ;
26542661
2655- lcx. children . push ( ( def_id, hir:: MaybeOwner :: NonOwner ( hir_id) ) ) ;
26562662 self . args . push ( hir:: GenericArg :: Const ( hir:: ConstArg {
2657- kind : hir:: ConstArgKind :: Anon ( lcx. arena . alloc ( hir:: AnonConst {
2658- def_id,
2659- hir_id,
2660- body,
2661- span,
2662- } ) ) ,
2663+ hir_id,
2664+ kind : const_arg_kind,
26632665 is_desugared_from_effects : true ,
26642666 } ) )
26652667 }
0 commit comments