about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorvarkor <github@varkor.com>2019-05-11 00:08:19 +0100
committervarkor <github@varkor.com>2019-05-11 00:08:19 +0100
commit0686daab4ec82a4127d317c01324d46c58ef47b3 (patch)
tree4aeb995e6f27d2a33038ff28687a4b5112a8726a /src
parentcff1bdbd77d29a28a94ff9f5bf1e1c84e5bb6259 (diff)
downloadrust-0686daab4ec82a4127d317c01324d46c58ef47b3.tar.gz
rust-0686daab4ec82a4127d317c01324d46c58ef47b3.zip
Unwrap singleton block expressions in const arguments
Diffstat (limited to 'src')
-rw-r--r--src/librustc_typeck/astconv.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs
index 16033c6c50f..da47ccf38a0 100644
--- a/src/librustc_typeck/astconv.rs
+++ b/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 {