Skip to content

Commit 0423893

Browse files
committed
Do not complain about missing main when a block has been recovered
1 parent 56446fe commit 0423893

File tree

3 files changed

+9
-17
lines changed

3 files changed

+9
-17
lines changed

src/librustc_parse/parser/diagnostics.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,12 @@ impl<'a> Parser<'a> {
13971397
consume_close: ConsumeClosingDelim,
13981398
) {
13991399
let mut brace_depth = 0;
1400+
// Avoid complaining about main in
1401+
// `src/test/ui/parser/mismatched-braces/missing-close-brace-in-trait.rs`.
1402+
// We set this here because we can't be sure that we're not going to hit `Eof` shortly
1403+
// afterwards, but handling this case in other parts of the parser would complicate the
1404+
// logic too much.
1405+
*self.sess.reached_eof.borrow_mut() = true;
14001406
loop {
14011407
if self.eat(&token::OpenDelim(delim)) {
14021408
brace_depth += 1;

src/test/ui/parser/mismatched-braces/missing-close-brace-in-trait.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
trait T {
2-
//~^ ERROR `main` function not found in crate `missing_close_brace_in_trait`
32
fn foo(&self);
43

54
pub(crate) struct Bar<T>();
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this file contains an unclosed delimiter
2-
--> $DIR/missing-close-brace-in-trait.rs:12:65
2+
--> $DIR/missing-close-brace-in-trait.rs:11:65
33
|
44
LL | trait T {
55
| - unclosed delimiter
@@ -8,23 +8,10 @@ LL | fn main() {}
88
| ^
99

1010
error: expected one of `async`, `const`, `default`, `extern`, `fn`, `type`, or `unsafe`, found keyword `struct`
11-
--> $DIR/missing-close-brace-in-trait.rs:5:12
11+
--> $DIR/missing-close-brace-in-trait.rs:4:12
1212
|
1313
LL | pub(crate) struct Bar<T>();
1414
| ^^^^^^ expected one of 7 possible tokens
1515

16-
error[E0601]: `main` function not found in crate `missing_close_brace_in_trait`
17-
--> $DIR/missing-close-brace-in-trait.rs:1:1
18-
|
19-
LL | / trait T {
20-
LL | |
21-
LL | | fn foo(&self);
22-
LL | |
23-
... |
24-
LL | |
25-
LL | | fn main() {}
26-
| |________________________________________________________________^ consider adding a `main` function to `$DIR/missing-close-brace-in-trait.rs`
27-
28-
error: aborting due to 3 previous errors
16+
error: aborting due to 2 previous errors
2917

30-
For more information about this error, try `rustc --explain E0601`.

0 commit comments

Comments
 (0)