Skip to content

Prevent where < ident > from parsing. #38268

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 4 commits into from
Dec 24, 2016
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
17 changes: 17 additions & 0 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4377,6 +4377,23 @@ impl<'a> Parser<'a> {
return Ok(where_clause);
}

// This is a temporary hack.
//
// We are considering adding generics to the `where` keyword as an alternative higher-rank
// parameter syntax (as in `where<'a>` or `where<T>`. To avoid that being a breaking
// change, for now we refuse to parse `where < (ident | lifetime) (> | , | :)`.
if token::Lt == self.token {
let ident_or_lifetime = self.look_ahead(1, |t| t.is_ident() || t.is_lifetime());
if ident_or_lifetime {
let gt_comma_or_colon = self.look_ahead(2, |t| {
*t == token::Gt || *t == token::Comma || *t == token::Colon
});
if gt_comma_or_colon {
return Err(self.fatal("TODO How to even explain this error?"));
Copy link
Contributor

@petrochenkov petrochenkov Dec 9, 2016

Choose a reason for hiding this comment

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

This is a recoverable error, no need to return Err.
self.err("syntax `where<T>` is reserved for future use"); would be more appropriate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we consume tokens until the the next Gt in that case?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nah, if it's indeed <A>::B: Tr (more likely), then it'll parse successfully without consuming extra tokens, otherwise (less likely) it doesn't matter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But don't we want it to parse as ::B: Tr1? I suppose it doesn't matter much since it errors anyway.

}
}
}

let mut parsed_something = false;
loop {
let lo = self.span.lo;
Expand Down