diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index d2133f03335..680554e2ad7 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3496,6 +3496,9 @@ impl<'a> Parser<'a> { }; pat = PatIdent(BindByValue(MutImmutable), pth1, sub); } + } else if self.look_ahead(1, |t| *t == token::Lt) { + self.bump(); + self.unexpected() } else { // parse an enum pat let enum_path = self.parse_path(LifetimeAndTypesWithColons); diff --git a/src/test/compile-fail/issue-22426-1.rs b/src/test/compile-fail/issue-22426-1.rs new file mode 100644 index 00000000000..edc56ae1939 --- /dev/null +++ b/src/test/compile-fail/issue-22426-1.rs @@ -0,0 +1,16 @@ +// Copyright 2015 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. + +fn main() { + match 42 { + x < 7 => (), //~ ERROR unexpected token `<` + _ => () + } +} diff --git a/src/test/compile-fail/issue-22426-2.rs b/src/test/compile-fail/issue-22426-2.rs new file mode 100644 index 00000000000..c24de36ec75 --- /dev/null +++ b/src/test/compile-fail/issue-22426-2.rs @@ -0,0 +1,11 @@ +// Copyright 2015 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. + +fn a(B<) {} //~ ERROR unexpected token `<` diff --git a/src/test/compile-fail/issue-22426.rs b/src/test/compile-fail/issue-22426.rs new file mode 100644 index 00000000000..37625e69a43 --- /dev/null +++ b/src/test/compile-fail/issue-22426.rs @@ -0,0 +1,21 @@ +// Copyright 2015 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. + +struct Foo<T>(T, T); + +impl<T> Foo<T> { + fn foo(&self) { + match *self { + Foo<T>(x, y) => { //~ ERROR unexpected token `<` + println!("Goodbye, World!") + } + } + } +} diff --git a/src/test/run-pass/issue-22426.rs b/src/test/run-pass/issue-22426.rs new file mode 100644 index 00000000000..d1d1b037d8d --- /dev/null +++ b/src/test/run-pass/issue-22426.rs @@ -0,0 +1,21 @@ +// Copyright 2015 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. + +struct Foo<T>(T, T); + +impl<T> Foo<T> { + fn foo(&self) { + match *self { + Foo::<T>(ref x, ref y) => { //~ ERROR unexpected token `<` + println!("Goodbye, World!") + } + } + } +}