Skip to content

Commit

Permalink
Auto merge of #38268 - withoutboats:parse_where_higher_rank_hack, r=e…
Browse files Browse the repository at this point in the history
…ddyb

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.
  • Loading branch information
bors committed Dec 24, 2016
2 parents 4d07320 + 14e4b00 commit 8d65c8d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4368,6 +4368,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 {
self.span_err(self.span, "syntax `where<T>` is reserved for future use");
}
}
}

let mut parsed_something = false;
loop {
let lo = self.span.lo;
Expand Down
16 changes: 16 additions & 0 deletions src/test/parse-fail/where_with_bound.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z parse-only

fn foo<T>() where <T>::Item: ToString, T: Iterator { }
//~^ syntax `where<T>` is reserved for future use

fn main() {}

0 comments on commit 8d65c8d

Please sign in to comment.