Skip to content

Commit 3ae6d0a

Browse files
committed
Special-case const params wrapped in block
1 parent 4dd2942 commit 3ae6d0a

File tree

1 file changed

+18
-8
lines changed
  • compiler/rustc_ast_lowering/src

1 file changed

+18
-8
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,24 +1234,34 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12341234

12351235
#[instrument(level = "debug", skip(self))]
12361236
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());
12411250
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
12451253
&& let Res::Def(DefKind::ConstParam, _) = res
1254+
&& let ExprKind::Path(qself, path) = &expr.kind
12461255
{
12471256
let qpath = self.lower_qpath(
1248-
anon.value.id,
1257+
expr.id,
12491258
qself,
12501259
path,
12511260
ParamMode::Optional,
12521261
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
12531262
None,
12541263
);
1264+
12551265
return ConstArg {
12561266
hir_id: self.next_id(),
12571267
kind: ConstArgKind::Path(qpath),

0 commit comments

Comments
 (0)