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