about summary refs log tree commit diff
path: root/compiler/rustc_parse
diff options
context:
space:
mode:
authorTakayuki Maeda <takoyaki0316@gmail.com>2022-03-08 17:07:35 +0900
committerTakayuki Maeda <takoyaki0316@gmail.com>2022-03-08 17:07:35 +0900
commit529fd2da894ff290668d6c1524909ba218d5822b (patch)
treea4389c223922884f3203573bae237cc8cff1d093 /compiler/rustc_parse
parentd53e19540e7e201042c8b07a236e5351de085a42 (diff)
downloadrust-529fd2da894ff290668d6c1524909ba218d5822b.tar.gz
rust-529fd2da894ff290668d6c1524909ba218d5822b.zip
suggest adding `{ .. }` around a const function with arguments
Diffstat (limited to 'compiler/rustc_parse')
-rw-r--r--compiler/rustc_parse/src/parser/path.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs
index 5e537d7b95c..0bccf4dc2ce 100644
--- a/compiler/rustc_parse/src/parser/path.rs
+++ b/compiler/rustc_parse/src/parser/path.rs
@@ -624,9 +624,18 @@ impl<'a> Parser<'a> {
             GenericArg::Const(self.parse_const_arg()?)
         } else if self.check_type() {
             // Parse type argument.
+            let is_const_fn = self.look_ahead(1, |t| t.kind == token::OpenDelim(token::Paren));
+            let mut snapshot = self.clone();
             match self.parse_ty() {
                 Ok(ty) => GenericArg::Type(ty),
                 Err(err) => {
+                    if is_const_fn {
+                        if let Ok(expr) = snapshot.parse_expr_res(Restrictions::CONST_EXPR, None) {
+                            *self = snapshot;
+                            return Ok(Some(self.dummy_const_arg_needs_braces(err, expr.span)));
+                        }
+                    }
+                    // self.parse_fn_call_expr();
                     // Try to recover from possible `const` arg without braces.
                     return self.recover_const_arg(start, err).map(Some);
                 }