Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not complain about missing main when a block has been recovered #67413

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that we actually reach Eof in all cases, e.g. the return below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to change it back. Setting reached_eof before all of the returns in the loop would cause the missing main error to come up (!?).

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`.