Skip to content

Commit

Permalink
Do not complain about missing main when a block has been recovered
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Jan 8, 2020
1 parent 56446fe commit 0423893
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
6 changes: 6 additions & 0 deletions src/librustc_parse/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,12 @@ impl<'a> Parser<'a> {
consume_close: ConsumeClosingDelim,
) {
let mut brace_depth = 0;
// Avoid complaining about main in
// `src/test/ui/parser/mismatched-braces/missing-close-brace-in-trait.rs`.
// We set this here because we can't be sure that we're not going to hit `Eof` shortly
// afterwards, but handling this case in other parts of the parser would complicate the
// logic too much.
*self.sess.reached_eof.borrow_mut() = true;
loop {
if self.eat(&token::OpenDelim(delim)) {
brace_depth += 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
trait T {
//~^ ERROR `main` function not found in crate `missing_close_brace_in_trait`
fn foo(&self);

pub(crate) struct Bar<T>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: this file contains an unclosed delimiter
--> $DIR/missing-close-brace-in-trait.rs:12:65
--> $DIR/missing-close-brace-in-trait.rs:11:65
|
LL | trait T {
| - unclosed delimiter
Expand All @@ -8,23 +8,10 @@ LL | fn main() {}
| ^

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

error[E0601]: `main` function not found in crate `missing_close_brace_in_trait`
--> $DIR/missing-close-brace-in-trait.rs:1:1
|
LL | / trait T {
LL | |
LL | | fn foo(&self);
LL | |
... |
LL | |
LL | | fn main() {}
| |________________________________________________________________^ consider adding a `main` function to `$DIR/missing-close-brace-in-trait.rs`

error: aborting due to 3 previous errors
error: aborting due to 2 previous errors

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

0 comments on commit 0423893

Please sign in to comment.