Skip to content

Commit 0686daa

Browse files
committed
Unwrap singleton block expressions in const arguments
1 parent cff1bdb commit 0686daa

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/librustc_typeck/astconv.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1902,7 +1902,18 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
19021902
ty,
19031903
};
19041904

1905-
let expr = &tcx.hir().body(ast_const.body).value;
1905+
let mut expr = &tcx.hir().body(ast_const.body).value;
1906+
1907+
// Unwrap a block, so that e.g. `{ P }` is recognised as a parameter. Const arguments
1908+
// currently have to be wrapped in curly brackets, so it's necessary to special-case.
1909+
if let ExprKind::Block(block, _) = &expr.node {
1910+
if block.stmts.is_empty() {
1911+
if let Some(trailing) = &block.expr {
1912+
expr = &trailing;
1913+
}
1914+
}
1915+
}
1916+
19061917
if let ExprKind::Path(ref qpath) = expr.node {
19071918
if let hir::QPath::Resolved(_, ref path) = qpath {
19081919
if let Res::Def(DefKind::ConstParam, def_id) = path.res {

0 commit comments

Comments
 (0)