]> git.lizzy.rs Git - rust.git/commitdiff
recover from missing type annotation
authorhkalbasi <hamidrezakalbasi@protonmail.com>
Fri, 1 Apr 2022 12:50:54 +0000 (17:20 +0430)
committerhkalbasi <hamidrezakalbasi@protonmail.com>
Fri, 1 Apr 2022 12:50:54 +0000 (17:20 +0430)
crates/hir_ty/src/tests/simple.rs
crates/parser/src/grammar/types.rs

index df7b3df3d5b2f1da8c9a0797a3d28ffbf89cffe7..baed34ce2388281c68783503e0e8b95922917e2d 100644 (file)
@@ -2556,6 +2556,20 @@ fn f() {
     )
 }
 
+#[test]
+fn infer_missing_type() {
+    check_types(
+        r#"
+struct S;
+
+fn f() {
+    let s: = S;
+      //^ S
+}
+    "#,
+    );
+}
+
 #[test]
 fn infer_type_alias_variant() {
     check_infer(
index ff067f5293d74664c19c9dc1e28f9feba29eef75..46db487d02c0c29999ba2b647a14f28ddc4eb97c 100644 (file)
@@ -57,6 +57,12 @@ fn type_with_bounds_cond(p: &mut Parser, allow_bounds: bool) {
 pub(super) fn ascription(p: &mut Parser) {
     assert!(p.at(T![:]));
     p.bump(T![:]);
+    if p.at(T![=]) {
+        // recover from `let x: = expr;`, `const X: = expr;` and similars
+        // hopefully no type starts with `=`
+        p.error("missing type");
+        return;
+    }
     type_(p);
 }