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