Skip to content

Commit f8a21e4

Browse files
bors[bot]HKalbasi
andauthored
Merge #11870
11870: Recover from missing type annotation r=Veykril a=HKalbasi We were missing the init expression in case of `let x: = 2`, which breaks type inference of that variable (previously x were `{unknown}`, now it is `i32`). Co-authored-by: hkalbasi <[email protected]>
2 parents b337a49 + 049f0a6 commit f8a21e4

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

crates/hir_ty/src/tests/simple.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2556,6 +2556,20 @@ fn f() {
25562556
)
25572557
}
25582558

2559+
#[test]
2560+
fn infer_missing_type() {
2561+
check_types(
2562+
r#"
2563+
struct S;
2564+
2565+
fn f() {
2566+
let s: = S;
2567+
//^ S
2568+
}
2569+
"#,
2570+
);
2571+
}
2572+
25592573
#[test]
25602574
fn infer_type_alias_variant() {
25612575
check_infer(

crates/parser/src/grammar/types.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ fn type_with_bounds_cond(p: &mut Parser, allow_bounds: bool) {
5757
pub(super) fn ascription(p: &mut Parser) {
5858
assert!(p.at(T![:]));
5959
p.bump(T![:]);
60+
if p.at(T![=]) {
61+
// recover from `let x: = expr;`, `const X: = expr;` and similars
62+
// hopefully no type starts with `=`
63+
p.error("missing type");
64+
return;
65+
}
6066
type_(p);
6167
}
6268

0 commit comments

Comments
 (0)