Skip to content

Commit 6950786

Browse files
committed
Add test for let outside function recovery
1 parent 4edbda5 commit 6950786

4 files changed

+34
-3
lines changed
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
let a = 1;
2+
//~^ ERROR `let` is invalid outside of a function
3+
4+
fn main() {
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: `let` is invalid outside of a function
2+
--> $DIR/let-outside-function.rs:1:1
3+
|
4+
LL | let a = 1;
5+
| ^^^
6+
|
7+
help: consider using `static` instead of `let`
8+
|
9+
LL | static a = 1;
10+
| ~~~~~~
11+
help: consider using `const` instead of `let`
12+
|
13+
LL | const a = 1;
14+
| ~~~~~
15+
16+
error: aborting due to previous error
17+

tests/ui/parser/suggest-const-for-global-var.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
let X: i32 = 12;
2-
//~^ ERROR expected item, found keyword `let`
2+
//~^ ERROR `let` is invalid outside of a function
33

44
fn main() {
55
println!("{}", X);
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
error: expected item, found keyword `let`
1+
error: `let` is invalid outside of a function
22
--> $DIR/suggest-const-for-global-var.rs:1:1
33
|
44
LL | let X: i32 = 12;
5-
| ^^^ consider using `const` or `static` instead of `let` for global variables
5+
| ^^^
6+
|
7+
help: consider using `static` instead of `let`
8+
|
9+
LL | static X: i32 = 12;
10+
| ~~~~~~
11+
help: consider using `const` instead of `let`
12+
|
13+
LL | const X: i32 = 12;
14+
| ~~~~~
615

716
error: aborting due to previous error
817

0 commit comments

Comments
 (0)