@@ -1232,24 +1232,34 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1232
1232
1233
1233
#[ instrument( level = "debug" , skip( self ) ) ]
1234
1234
fn lower_anon_const_as_const_arg_direct ( & mut self , anon : & AnonConst ) -> hir:: ConstArg < ' hir > {
1235
- let maybe_res = self
1236
- . resolver
1237
- . get_partial_res ( anon. value . id )
1238
- . and_then ( |partial_res| partial_res. full_res ( ) ) ;
1235
+ // Unwrap a block, so that e.g. `{ P }` is recognised as a parameter. Const arguments
1236
+ // currently have to be wrapped in curly brackets, so it's necessary to special-case.
1237
+ let expr = if let ExprKind :: Block ( block, _) = & anon. value . kind
1238
+ && let [ stmt] = block. stmts . as_slice ( )
1239
+ && let StmtKind :: Expr ( expr) = & stmt. kind
1240
+ && let ExprKind :: Path ( ..) = & expr. kind
1241
+ {
1242
+ expr
1243
+ } else {
1244
+ & anon. value
1245
+ } ;
1246
+ let maybe_res =
1247
+ self . resolver . get_partial_res ( expr. id ) . and_then ( |partial_res| partial_res. full_res ( ) ) ;
1239
1248
debug ! ( "res={:?}" , maybe_res) ;
1240
- if let ExprKind :: Path ( qself, path) = & anon. value . kind
1241
- && let Some ( res) = maybe_res
1242
- // FIXME(min_generic_const_exprs): for now we only lower params to ConstArgKind::Path
1249
+ // FIXME(min_generic_const_exprs): for now we only lower params to ConstArgKind::Path
1250
+ if let Some ( res) = maybe_res
1243
1251
&& let Res :: Def ( DefKind :: ConstParam , _) = res
1252
+ && let ExprKind :: Path ( qself, path) = & expr. kind
1244
1253
{
1245
1254
let qpath = self . lower_qpath (
1246
- anon . value . id ,
1255
+ expr . id ,
1247
1256
qself,
1248
1257
path,
1249
1258
ParamMode :: Optional ,
1250
1259
ImplTraitContext :: Disallowed ( ImplTraitPosition :: Path ) ,
1251
1260
None ,
1252
1261
) ;
1262
+
1253
1263
return ConstArg {
1254
1264
hir_id : self . next_id ( ) ,
1255
1265
kind : ConstArgKind :: Path ( qpath) ,
0 commit comments