]> git.lizzy.rs Git - rust.git/blobdiff - crates/parser/src/grammar/items/consts.rs
feat: improve parser error recovery for function parameters
[rust.git] / crates / parser / src / grammar / items / consts.rs
index eb7d1f8281dee00d6d2fab4f316663d36e13d597..1b317dd84a94b76a54962c7c43772c432214e487 100644 (file)
@@ -1,5 +1,3 @@
-//! FIXME: write short doc here
-
 use super::*;
 
 pub(super) fn static_(p: &mut Parser, m: Marker) {
@@ -13,7 +11,7 @@ pub(super) fn konst(p: &mut Parser, m: Marker) {
 fn const_or_static(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) {
     assert!(p.at(kw));
     p.bump(kw);
-    p.eat(T![mut]); // FIXME: validator to forbid const mut
+    p.eat(T![mut]);
 
     // Allow `_` in place of an identifier in a `const`.
     let is_const_underscore = kw == T![const] && p.eat(T![_]);
@@ -23,8 +21,11 @@ fn const_or_static(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) {
 
     // test_err static_underscore
     // static _: i32 = 5;
-
-    types::ascription(p);
+    if p.at(T![:]) {
+        types::ascription(p);
+    } else {
+        p.error("missing type for `const` or `static`")
+    }
     if p.eat(T![=]) {
         expressions::expr(p);
     }