]> git.lizzy.rs Git - rust.git/commitdiff
Unwrap singleton block expressions in const arguments
authorvarkor <github@varkor.com>
Fri, 10 May 2019 23:08:19 +0000 (00:08 +0100)
committervarkor <github@varkor.com>
Fri, 10 May 2019 23:08:19 +0000 (00:08 +0100)
src/librustc_typeck/astconv.rs

index 16033c6c50fd0c91c143eac552b20aaeb20e5c5f..da47ccf38a0263416dba53b6d62585b2d90a1955 100644 (file)
@@ -1902,7 +1902,18 @@ pub fn ast_const_to_const(
             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 {