From 90f6219f496596233d504244cfbbdbded7df5a30 Mon Sep 17 00:00:00 2001 From: Without Boats Date: Fri, 9 Dec 2016 10:54:05 -0800 Subject: [PATCH 1/4] 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(+) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index bdd1606805fef..f6cebdc372fef 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; From ddae271b78b08f2700c839eb220b21654e405f7b Mon Sep 17 00:00:00 2001 From: Without Boats Date: Fri, 9 Dec 2016 20:39:42 -0800 Subject: [PATCH 2/4] Improve error message. --- src/libsyntax/parse/parser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index f6cebdc372fef..2c6e6e3fea321 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"); } } } From e93e00f3ae34a644a9c679652309c26150c3d4b3 Mon Sep 17 00:00:00 2001 From: Without Boats Date: Fri, 9 Dec 2016 20:40:01 -0800 Subject: [PATCH 3/4] Add test. --- src/test/parse-fail/where_with_bound.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/test/parse-fail/where_with_bound.rs diff --git a/src/test/parse-fail/where_with_bound.rs b/src/test/parse-fail/where_with_bound.rs new file mode 100644 index 0000000000000..cb57500df797e --- /dev/null +++ b/src/test/parse-fail/where_with_bound.rs @@ -0,0 +1,16 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags: -Z parse-only + +fn foo() where ::Item: ToString, T: Iterator { } + //~^ syntax `where` is reserved for future use + +fn main() {} From 14e4b00933c13a4c419f2192df11b135d5bb0c85 Mon Sep 17 00:00:00 2001 From: Without Boats Date: Fri, 9 Dec 2016 21:17:58 -0800 Subject: [PATCH 4/4] Fix mistake. --- src/libsyntax/parse/parser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 2c6e6e3fea321..53377ee023638 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"); } } }