Skip to content
Permalink
Browse files

Unwrap singleton block expressions in const arguments

  • Loading branch information...
varkor committed May 10, 2019
1 parent cff1bdb commit 0686daab4ec82a4127d317c01324d46c58ef47b3
Showing with 12 additions and 1 deletion.
  1. +12 −1 src/librustc_typeck/astconv.rs
@@ -1902,7 +1902,18 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
ty,
};

let expr = &tcx.hir().body(ast_const.body).value;
let mut expr = &tcx.hir().body(ast_const.body).value;

// Unwrap a block, so that e.g. `{ P }` is recognised as a parameter. Const arguments
// currently have to be wrapped in curly brackets, so it's necessary to special-case.
if let ExprKind::Block(block, _) = &expr.node {
if block.stmts.is_empty() {
if let Some(trailing) = &block.expr {
expr = &trailing;
}
}
}

if let ExprKind::Path(ref qpath) = expr.node {
if let hir::QPath::Resolved(_, ref path) = qpath {
if let Res::Def(DefKind::ConstParam, def_id) = path.res {

0 comments on commit 0686daa

Please sign in to comment.
You can’t perform that action at this time.