]> git.lizzy.rs Git - rust.git/commitdiff
Prevent where < ident > from parsing.
authorWithout Boats <woboats@gmail.com>
Fri, 9 Dec 2016 18:54:05 +0000 (10:54 -0800)
committerWithout Boats <woboats@gmail.com>
Fri, 9 Dec 2016 18:54:05 +0000 (10:54 -0800)
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.

src/libsyntax/parse/parser.rs

index bdd1606805fefa2573a98230d581b3f858916e4f..f6cebdc372feffc4311b5aaa011f60f6ad478550 100644 (file)
@@ -4377,6 +4377,23 @@ pub fn parse_where_clause(&mut self) -> PResult<'a, ast::WhereClause> {
             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?"));
+                }
+            }
+        }
+
         let mut parsed_something = false;
         loop {
             let lo = self.span.lo;