From 90f6219f496596233d504244cfbbdbded7df5a30 Mon Sep 17 00:00:00 2001 From: Without Boats Date: Fri, 9 Dec 2016 10:54:05 -0800 Subject: 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. --- src/libsyntax/parse/parser.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index bdd1606805f..f6cebdc372f 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -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`. 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; -- cgit 1.4.1-3-g733a5 From ddae271b78b08f2700c839eb220b21654e405f7b Mon Sep 17 00:00:00 2001 From: Without Boats Date: Fri, 9 Dec 2016 20:39:42 -0800 Subject: Improve error message. --- src/libsyntax/parse/parser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index f6cebdc372f..2c6e6e3fea3 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -4389,7 +4389,7 @@ impl<'a> Parser<'a> { *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?")); + self.err("syntax `where` is reserved for future use"); } } } -- cgit 1.4.1-3-g733a5 From 14e4b00933c13a4c419f2192df11b135d5bb0c85 Mon Sep 17 00:00:00 2001 From: Without Boats Date: Fri, 9 Dec 2016 21:17:58 -0800 Subject: Fix mistake. --- src/libsyntax/parse/parser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 2c6e6e3fea3..53377ee0236 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -4389,7 +4389,7 @@ impl<'a> Parser<'a> { *t == token::Gt || *t == token::Comma || *t == token::Colon }); if gt_comma_or_colon { - self.err("syntax `where` is reserved for future use"); + self.span_err(self.span, "syntax `where` is reserved for future use"); } } } -- cgit 1.4.1-3-g733a5