@@ -1147,40 +1147,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11471147 ty,
11481148 ) ;
11491149
1150- // Construct an AnonConst where the expr is the "ty"'s path.
1151-
1152- let parent_def_id = self . current_hir_id_owner ;
1153- let node_id = self . next_node_id ( ) ;
1154- let span = self . lower_span ( ty. span ) ;
1155-
1156- // Add a definition for the in-band const def.
1157- let def_id = self . create_def (
1158- parent_def_id. def_id ,
1159- node_id,
1160- kw:: Empty ,
1161- DefKind :: AnonConst ,
1162- span,
1150+ let qpath = self . lower_qpath (
1151+ ty. id ,
1152+ & None ,
1153+ path,
1154+ ParamMode :: Optional ,
1155+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: Path ) ,
1156+ None ,
11631157 ) ;
1164-
1165- let path_expr = Expr {
1166- id : ty. id ,
1167- kind : ExprKind :: Path ( None , path. clone ( ) ) ,
1168- span,
1169- attrs : AttrVec :: new ( ) ,
1170- tokens : None ,
1171- } ;
1172-
1173- let ct = self . with_new_scopes ( span, |this| {
1174- self . arena . alloc ( hir:: AnonConst {
1175- def_id,
1176- hir_id : this. lower_node_id ( node_id) ,
1177- body : this
1178- . lower_const_body ( path_expr. span , Some ( & path_expr) ) ,
1179- span,
1180- } )
1181- } ) ;
11821158 return GenericArg :: Const ( ConstArg {
1183- kind : ConstArgKind :: Anon ( ct) ,
1159+ hir_id : self . lower_node_id ( ty. id ) ,
1160+ kind : ConstArgKind :: Path ( qpath) ,
11841161 is_desugared_from_effects : false ,
11851162 } ) ;
11861163 }
@@ -1190,10 +1167,39 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11901167 }
11911168 GenericArg :: Type ( self . lower_ty ( ty, itctx) )
11921169 }
1193- ast:: GenericArg :: Const ( ct) => GenericArg :: Const ( ConstArg {
1194- kind : ConstArgKind :: Anon ( self . lower_anon_const ( ct) ) ,
1195- is_desugared_from_effects : false ,
1196- } ) ,
1170+ ast:: GenericArg :: Const ( ct) => GenericArg :: Const ( self . lower_anon_const_as_const_arg ( ct) ) ,
1171+ }
1172+ }
1173+
1174+ fn lower_anon_const_as_const_arg ( & mut self , anon : & AnonConst ) -> hir:: ConstArg < ' hir > {
1175+ if let ExprKind :: Path ( qself, path) = & anon. value . kind {
1176+ let qpath = self . lower_qpath (
1177+ anon. id ,
1178+ qself,
1179+ path,
1180+ ParamMode :: Optional ,
1181+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: Path ) ,
1182+ None ,
1183+ ) ;
1184+ // FIXME(min_generic_const_exprs): for now we only lower params to ConstArgKind::Path
1185+ if let hir:: QPath :: Resolved (
1186+ _,
1187+ & hir:: Path { res : Res :: Def ( DefKind :: ConstParam , _) , .. } ,
1188+ ) = qpath
1189+ {
1190+ return ConstArg {
1191+ hir_id : self . lower_node_id ( anon. id ) ,
1192+ kind : ConstArgKind :: Path ( qpath) ,
1193+ is_desugared_from_effects : false ,
1194+ } ;
1195+ }
1196+ }
1197+
1198+ let lowered_anon = self . lower_anon_const ( anon) ;
1199+ ConstArg {
1200+ hir_id : lowered_anon. hir_id ,
1201+ kind : ConstArgKind :: Anon ( lowered_anon) ,
1202+ is_desugared_from_effects : false ,
11971203 }
11981204 }
11991205
@@ -2591,16 +2597,34 @@ impl<'hir> GenericArgsCtor<'hir> {
25912597 return ;
25922598 }
25932599
2594- let ( span, body) = match constness {
2600+ let id = lcx. next_node_id ( ) ;
2601+ let hir_id = lcx. next_id ( ) ;
2602+
2603+ let const_arg_kind = match constness {
25952604 BoundConstness :: Never => return ,
25962605 BoundConstness :: Always ( span) => {
25972606 let span = lcx. lower_span ( span) ;
25982607
25992608 let body = hir:: ExprKind :: Lit (
26002609 lcx. arena . alloc ( hir:: Lit { node : LitKind :: Bool ( false ) , span } ) ,
26012610 ) ;
2611+ let body = lcx. lower_body ( |lcx| ( & [ ] , lcx. expr ( span, body) ) ) ;
2612+
2613+ let def_id = lcx. create_def (
2614+ lcx. current_hir_id_owner . def_id ,
2615+ id,
2616+ kw:: Empty ,
2617+ DefKind :: AnonConst ,
2618+ span,
2619+ ) ;
26022620
2603- ( span, body)
2621+ lcx. children . push ( ( def_id, hir:: MaybeOwner :: NonOwner ( hir_id) ) ) ;
2622+ hir:: ConstArgKind :: Anon ( lcx. arena . alloc ( hir:: AnonConst {
2623+ def_id,
2624+ hir_id,
2625+ body,
2626+ span,
2627+ } ) )
26042628 }
26052629 BoundConstness :: Maybe ( span) => {
26062630 let span = lcx. lower_span ( span) ;
@@ -2613,48 +2637,26 @@ impl<'hir> GenericArgsCtor<'hir> {
26132637 return ;
26142638 } ;
26152639
2616- let hir_id = lcx. next_id ( ) ;
26172640 let res = Res :: Def ( DefKind :: ConstParam , host_param_id. to_def_id ( ) ) ;
2618- let body = hir:: ExprKind :: Path ( hir:: QPath :: Resolved (
2619- None ,
2620- lcx. arena . alloc ( hir:: Path {
2621- span,
2622- res,
2623- segments : arena_vec ! [
2624- lcx;
2625- hir:: PathSegment :: new(
2626- Ident { name: sym:: host, span } ,
2627- hir_id,
2628- res
2629- )
2630- ] ,
2631- } ) ,
2632- ) ) ;
2633-
2634- ( span, body)
2641+ let path = lcx. arena . alloc ( hir:: Path {
2642+ span,
2643+ res,
2644+ segments : arena_vec ! [
2645+ lcx;
2646+ hir:: PathSegment :: new(
2647+ Ident { name: sym:: host, span } ,
2648+ hir_id,
2649+ res
2650+ )
2651+ ] ,
2652+ } ) ;
2653+ hir:: ConstArgKind :: Path ( hir:: QPath :: Resolved ( None , path) )
26352654 }
26362655 } ;
2637- let body = lcx. lower_body ( |lcx| ( & [ ] , lcx. expr ( span, body) ) ) ;
2638-
2639- let id = lcx. next_node_id ( ) ;
2640- let hir_id = lcx. next_id ( ) ;
2641-
2642- let def_id = lcx. create_def (
2643- lcx. current_hir_id_owner . def_id ,
2644- id,
2645- kw:: Empty ,
2646- DefKind :: AnonConst ,
2647- span,
2648- ) ;
26492656
2650- lcx. children . push ( ( def_id, hir:: MaybeOwner :: NonOwner ( hir_id) ) ) ;
26512657 self . args . push ( hir:: GenericArg :: Const ( hir:: ConstArg {
2652- kind : hir:: ConstArgKind :: Anon ( lcx. arena . alloc ( hir:: AnonConst {
2653- def_id,
2654- hir_id,
2655- body,
2656- span,
2657- } ) ) ,
2658+ hir_id,
2659+ kind : const_arg_kind,
26582660 is_desugared_from_effects : true ,
26592661 } ) )
26602662 }
0 commit comments