@@ -1152,20 +1152,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11521152 ty,
11531153 ) ;
11541154
1155- let qpath = self . lower_qpath (
1156- ty. id ,
1157- & None ,
1158- path,
1159- ParamMode :: Optional ,
1160- ImplTraitContext :: Disallowed ( ImplTraitPosition :: Path ) ,
1161- None ,
1162- ) ;
1163- let const_arg = ConstArg {
1164- hir_id : self . next_id ( ) ,
1165- kind : ConstArgKind :: Path ( qpath) ,
1166- is_desugared_from_effects : false ,
1167- } ;
1168- return GenericArg :: Const ( self . arena . alloc ( const_arg) ) ;
1155+ let ct =
1156+ self . lower_const_path_as_const_arg ( path, res, ty. id , ty. span ) ;
1157+ return GenericArg :: Const ( ct) ;
11691158 }
11701159 }
11711160 }
@@ -1177,6 +1166,68 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11771166 }
11781167 }
11791168
1169+ fn lower_const_path_as_const_arg (
1170+ & mut self ,
1171+ path : & Path ,
1172+ res : Res < NodeId > ,
1173+ ty_id : NodeId ,
1174+ span : Span ,
1175+ ) -> & ' hir hir:: ConstArg < ' hir > {
1176+ let ct_kind = match res {
1177+ Res :: Def ( DefKind :: ConstParam , _) => {
1178+ let qpath = self . lower_qpath (
1179+ ty_id,
1180+ & None ,
1181+ path,
1182+ ParamMode :: Optional ,
1183+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: Path ) ,
1184+ None ,
1185+ ) ;
1186+ ConstArgKind :: Path ( qpath)
1187+ }
1188+ _ => {
1189+ // Construct an AnonConst where the expr is the "ty"'s path.
1190+
1191+ let parent_def_id = self . current_hir_id_owner ;
1192+ let node_id = self . next_node_id ( ) ;
1193+ let span = self . lower_span ( span) ;
1194+
1195+ // Add a definition for the in-band const def.
1196+ let def_id = self . create_def (
1197+ parent_def_id. def_id ,
1198+ node_id,
1199+ kw:: Empty ,
1200+ DefKind :: AnonConst ,
1201+ span,
1202+ ) ;
1203+
1204+ let path_expr = Expr {
1205+ id : ty_id,
1206+ kind : ExprKind :: Path ( None , path. clone ( ) ) ,
1207+ span,
1208+ attrs : AttrVec :: new ( ) ,
1209+ tokens : None ,
1210+ } ;
1211+
1212+ let ct = self . with_new_scopes ( span, |this| {
1213+ self . arena . alloc ( hir:: AnonConst {
1214+ def_id,
1215+ hir_id : this. lower_node_id ( node_id) ,
1216+ body : this. lower_const_body ( path_expr. span , Some ( & path_expr) ) ,
1217+ span,
1218+ } )
1219+ } ) ;
1220+ hir:: ConstArgKind :: Anon ( ct)
1221+ }
1222+ } ;
1223+
1224+ self . arena . alloc ( hir:: ConstArg {
1225+ hir_id : self . next_id ( ) ,
1226+ kind : ct_kind,
1227+ is_desugared_from_effects : false ,
1228+ } )
1229+ }
1230+
11801231 fn lower_anon_const_as_const_arg ( & mut self , anon : & AnonConst ) -> & ' hir hir:: ConstArg < ' hir > {
11811232 self . arena . alloc ( self . lower_anon_const_as_const_arg_direct ( anon) )
11821233 }
0 commit comments