@@ -1232,24 +1232,34 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12321232
12331233 #[ instrument( level = "debug" , skip( self ) ) ]
12341234 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 ( ) ) ;
12391248 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
12431251 && let Res :: Def ( DefKind :: ConstParam , _) = res
1252+ && let ExprKind :: Path ( qself, path) = & expr. kind
12441253 {
12451254 let qpath = self . lower_qpath (
1246- anon . value . id ,
1255+ expr . id ,
12471256 qself,
12481257 path,
12491258 ParamMode :: Optional ,
12501259 ImplTraitContext :: Disallowed ( ImplTraitPosition :: Path ) ,
12511260 None ,
12521261 ) ;
1262+
12531263 return ConstArg {
12541264 hir_id : self . next_id ( ) ,
12551265 kind : ConstArgKind :: Path ( qpath) ,
0 commit comments