Skip to content

Hint correct extern constant syntax #43720

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

Merged
merged 3 commits into from
Aug 10, 2017
Merged
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6007,7 +6007,9 @@ impl<'a> Parser<'a> {
}

if self.check_keyword(keywords::Const) {
return Err(self.span_fatal(self.span, "extern items cannot be `const`"));
let mut err = self.span_fatal(self.span, "extern items cannot be `const`");
err.help("use `static` instead");
return Err(err);
Copy link
Contributor

Choose a reason for hiding this comment

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

This can use better recovery - you can report a non-fatal error and then return the same successful result as self.check_keyword(keywords::Static) does.
You'll have to move self.expect_keyword(keywords::Static) from parse_item_foreign_static though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would be better, but I just wanted to improve the error message. I don't feel the need to rework the error handling here.

Copy link
Contributor

Choose a reason for hiding this comment

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

You could also use span_suggestion instead of help to replace the const with static

}

// FIXME #5668: this will occur for a macro invocation:
Expand Down