Skip to content

Commit 3308770

Browse files
withoutboatsnikomatsakis
authored andcommitted
Prevent where < ident > from parsing.
In order to be forward compatible with `where<'a>` syntax for higher rank parameters, prevent potential conflicts with UFCS from parsing correctly for the near term.
1 parent e3a2352 commit 3308770

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4378,6 +4378,23 @@ impl<'a> Parser<'a> {
43784378
return Ok(where_clause);
43794379
}
43804380

4381+
// This is a temporary hack.
4382+
//
4383+
// We are considering adding generics to the `where` keyword as an alternative higher-rank
4384+
// parameter syntax (as in `where<'a>` or `where<T>`. To avoid that being a breaking
4385+
// change, for now we refuse to parse `where < (ident | lifetime) (> | , | :)`.
4386+
if token::Lt == self.token {
4387+
let ident_or_lifetime = self.look_ahead(1, |t| t.is_ident() || t.is_lifetime());
4388+
if ident_or_lifetime {
4389+
let gt_comma_or_colon = self.look_ahead(2, |t| {
4390+
*t == token::Gt || *t == token::Comma || *t == token::Colon
4391+
});
4392+
if gt_comma_or_colon {
4393+
return Err(self.fatal("TODO How to even explain this error?"));
4394+
}
4395+
}
4396+
}
4397+
43814398
let mut parsed_something = false;
43824399
loop {
43834400
let lo = self.span.lo;

0 commit comments

Comments
 (0)