@@ -1149,40 +1149,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11491149 ty,
11501150 ) ;
11511151
1152- // Construct an AnonConst where the expr is the "ty"'s path.
1153-
1154- let parent_def_id = self . current_hir_id_owner ;
1155- let node_id = self . next_node_id ( ) ;
1156- let span = self . lower_span ( ty. span ) ;
1157-
1158- // Add a definition for the in-band const def.
1159- let def_id = self . create_def (
1160- parent_def_id. def_id ,
1161- node_id,
1162- kw:: Empty ,
1163- DefKind :: AnonConst ,
1164- span,
1152+ let qpath = self . lower_qpath (
1153+ ty. id ,
1154+ & None ,
1155+ path,
1156+ ParamMode :: Optional ,
1157+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: Path ) ,
1158+ None ,
11651159 ) ;
1166-
1167- let path_expr = Expr {
1168- id : ty. id ,
1169- kind : ExprKind :: Path ( None , path. clone ( ) ) ,
1170- span,
1171- attrs : AttrVec :: new ( ) ,
1172- tokens : None ,
1173- } ;
1174-
1175- let ct = self . with_new_scopes ( span, |this| {
1176- self . arena . alloc ( hir:: AnonConst {
1177- def_id,
1178- hir_id : this. lower_node_id ( node_id) ,
1179- body : this
1180- . lower_const_body ( path_expr. span , Some ( & path_expr) ) ,
1181- span,
1182- } )
1183- } ) ;
11841160 return GenericArg :: Const ( ConstArg {
1185- kind : ConstArgKind :: Anon ( ct) ,
1161+ hir_id : self . lower_node_id ( ty. id ) ,
1162+ kind : ConstArgKind :: Path ( qpath) ,
11861163 is_desugared_from_effects : false ,
11871164 } ) ;
11881165 }
@@ -1192,10 +1169,39 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11921169 }
11931170 GenericArg :: Type ( self . lower_ty ( ty, itctx) )
11941171 }
1195- ast:: GenericArg :: Const ( ct) => GenericArg :: Const ( ConstArg {
1196- kind : ConstArgKind :: Anon ( self . lower_anon_const ( ct) ) ,
1197- is_desugared_from_effects : false ,
1198- } ) ,
1172+ ast:: GenericArg :: Const ( ct) => GenericArg :: Const ( self . lower_anon_const_as_const_arg ( ct) ) ,
1173+ }
1174+ }
1175+
1176+ fn lower_anon_const_as_const_arg ( & mut self , anon : & AnonConst ) -> hir:: ConstArg < ' hir > {
1177+ if let ExprKind :: Path ( qself, path) = & anon. value . kind {
1178+ let qpath = self . lower_qpath (
1179+ anon. id ,
1180+ qself,
1181+ path,
1182+ ParamMode :: Optional ,
1183+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: Path ) ,
1184+ None ,
1185+ ) ;
1186+ // FIXME(min_generic_const_exprs): for now we only lower params to ConstArgKind::Path
1187+ if let hir:: QPath :: Resolved (
1188+ _,
1189+ & hir:: Path { res : Res :: Def ( DefKind :: ConstParam , _) , .. } ,
1190+ ) = qpath
1191+ {
1192+ return ConstArg {
1193+ hir_id : self . lower_node_id ( anon. id ) ,
1194+ kind : ConstArgKind :: Path ( qpath) ,
1195+ is_desugared_from_effects : false ,
1196+ } ;
1197+ }
1198+ }
1199+
1200+ let lowered_anon = self . lower_anon_const ( anon) ;
1201+ ConstArg {
1202+ hir_id : lowered_anon. hir_id ,
1203+ kind : ConstArgKind :: Anon ( lowered_anon) ,
1204+ is_desugared_from_effects : false ,
11991205 }
12001206 }
12011207
@@ -2593,16 +2599,34 @@ impl<'hir> GenericArgsCtor<'hir> {
25932599 return ;
25942600 }
25952601
2596- let ( span, body) = match constness {
2602+ let id = lcx. next_node_id ( ) ;
2603+ let hir_id = lcx. next_id ( ) ;
2604+
2605+ let const_arg_kind = match constness {
25972606 BoundConstness :: Never => return ,
25982607 BoundConstness :: Always ( span) => {
25992608 let span = lcx. lower_span ( span) ;
26002609
26012610 let body = hir:: ExprKind :: Lit (
26022611 lcx. arena . alloc ( hir:: Lit { node : LitKind :: Bool ( false ) , span } ) ,
26032612 ) ;
2613+ let body = lcx. lower_body ( |lcx| ( & [ ] , lcx. expr ( span, body) ) ) ;
2614+
2615+ let def_id = lcx. create_def (
2616+ lcx. current_hir_id_owner . def_id ,
2617+ id,
2618+ kw:: Empty ,
2619+ DefKind :: AnonConst ,
2620+ span,
2621+ ) ;
26042622
2605- ( span, body)
2623+ lcx. children . push ( ( def_id, hir:: MaybeOwner :: NonOwner ( hir_id) ) ) ;
2624+ hir:: ConstArgKind :: Anon ( lcx. arena . alloc ( hir:: AnonConst {
2625+ def_id,
2626+ hir_id,
2627+ body,
2628+ span,
2629+ } ) )
26062630 }
26072631 BoundConstness :: Maybe ( span) => {
26082632 let span = lcx. lower_span ( span) ;
@@ -2615,48 +2639,26 @@ impl<'hir> GenericArgsCtor<'hir> {
26152639 return ;
26162640 } ;
26172641
2618- let hir_id = lcx. next_id ( ) ;
26192642 let res = Res :: Def ( DefKind :: ConstParam , host_param_id. to_def_id ( ) ) ;
2620- let body = hir:: ExprKind :: Path ( hir:: QPath :: Resolved (
2621- None ,
2622- lcx. arena . alloc ( hir:: Path {
2623- span,
2624- res,
2625- segments : arena_vec ! [
2626- lcx;
2627- hir:: PathSegment :: new(
2628- Ident { name: sym:: host, span } ,
2629- hir_id,
2630- res
2631- )
2632- ] ,
2633- } ) ,
2634- ) ) ;
2635-
2636- ( span, body)
2643+ let path = lcx. arena . alloc ( hir:: Path {
2644+ span,
2645+ res,
2646+ segments : arena_vec ! [
2647+ lcx;
2648+ hir:: PathSegment :: new(
2649+ Ident { name: sym:: host, span } ,
2650+ hir_id,
2651+ res
2652+ )
2653+ ] ,
2654+ } ) ;
2655+ hir:: ConstArgKind :: Path ( hir:: QPath :: Resolved ( None , path) )
26372656 }
26382657 } ;
2639- let body = lcx. lower_body ( |lcx| ( & [ ] , lcx. expr ( span, body) ) ) ;
2640-
2641- let id = lcx. next_node_id ( ) ;
2642- let hir_id = lcx. next_id ( ) ;
2643-
2644- let def_id = lcx. create_def (
2645- lcx. current_hir_id_owner . def_id ,
2646- id,
2647- kw:: Empty ,
2648- DefKind :: AnonConst ,
2649- span,
2650- ) ;
26512658
2652- lcx. children . push ( ( def_id, hir:: MaybeOwner :: NonOwner ( hir_id) ) ) ;
26532659 self . args . push ( hir:: GenericArg :: Const ( hir:: ConstArg {
2654- kind : hir:: ConstArgKind :: Anon ( lcx. arena . alloc ( hir:: AnonConst {
2655- def_id,
2656- hir_id,
2657- body,
2658- span,
2659- } ) ) ,
2660+ hir_id,
2661+ kind : const_arg_kind,
26602662 is_desugared_from_effects : true ,
26612663 } ) )
26622664 }
0 commit comments