From 61ea8b33d03b2b434793e6fc8f0a3cc67b90a72a Mon Sep 17 00:00:00 2001 From: bombless Date: Thu, 19 Feb 2015 22:01:57 +0800 Subject: [PATCH 1/3] Fix issue #22426 #22447 --- src/libsyntax/parse/parser.rs | 3 +++ src/test/compile-fail/issue-22426-1.rs | 16 ++++++++++++++++ src/test/compile-fail/issue-22426-2.rs | 11 +++++++++++ src/test/compile-fail/issue-22426.rs | 21 +++++++++++++++++++++ src/test/run-pass/issue-22426.rs | 21 +++++++++++++++++++++ 5 files changed, 72 insertions(+) create mode 100644 src/test/compile-fail/issue-22426-1.rs create mode 100644 src/test/compile-fail/issue-22426-2.rs create mode 100644 src/test/compile-fail/issue-22426.rs create mode 100644 src/test/run-pass/issue-22426.rs 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 or the MIT license +// , 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 or the MIT license +// , 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct Foo(T, T); + +impl Foo { + fn foo(&self) { + match *self { + Foo(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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct Foo(T, T); + +impl Foo { + fn foo(&self) { + match *self { + Foo::(ref x, ref y) => { //~ ERROR unexpected token `<` + println!("Goodbye, World!") + } + } + } +} From 0643494bc4d093dd660044b86c1d43820c40daf8 Mon Sep 17 00:00:00 2001 From: bombless Date: Fri, 20 Feb 2015 03:10:31 +0800 Subject: [PATCH 2/3] Fix tests --- src/test/compile-fail/issue-22426-1.rs | 3 ++- src/test/compile-fail/issue-22426-2.rs | 3 ++- .../compile-fail/{issue-22426.rs => issue-22426-3.rs} | 3 ++- src/test/run-pass/issue-22426.rs | 9 ++++++++- 4 files changed, 14 insertions(+), 4 deletions(-) rename src/test/compile-fail/{issue-22426.rs => issue-22426-3.rs} (89%) diff --git a/src/test/compile-fail/issue-22426-1.rs b/src/test/compile-fail/issue-22426-1.rs index edc56ae1939..f026a5db551 100644 --- a/src/test/compile-fail/issue-22426-1.rs +++ b/src/test/compile-fail/issue-22426-1.rs @@ -10,7 +10,8 @@ fn main() { match 42 { - x < 7 => (), //~ ERROR unexpected token `<` + 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 index c24de36ec75..ea5180e3eec 100644 --- a/src/test/compile-fail/issue-22426-2.rs +++ b/src/test/compile-fail/issue-22426-2.rs @@ -8,4 +8,5 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn a(B<) {} //~ ERROR unexpected token `<` +fn a(B<) {} + //~^ error: unexpected token: `<` diff --git a/src/test/compile-fail/issue-22426.rs b/src/test/compile-fail/issue-22426-3.rs similarity index 89% rename from src/test/compile-fail/issue-22426.rs rename to src/test/compile-fail/issue-22426-3.rs index 37625e69a43..2e0b5d6b80f 100644 --- a/src/test/compile-fail/issue-22426.rs +++ b/src/test/compile-fail/issue-22426-3.rs @@ -13,7 +13,8 @@ struct Foo(T, T); impl Foo { fn foo(&self) { match *self { - Foo(x, y) => { //~ ERROR unexpected token `<` + Foo(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 index d1d1b037d8d..f067d7fd3b1 100644 --- a/src/test/run-pass/issue-22426.rs +++ b/src/test/run-pass/issue-22426.rs @@ -13,9 +13,16 @@ struct Foo(T, T); impl Foo { fn foo(&self) { match *self { - Foo::(ref x, ref y) => { //~ ERROR unexpected token `<` + Foo::(ref x, ref y) => { println!("Goodbye, World!") } } } } + +fn main() { + match 42 { + x if x < 7 => (), + _ => () + } +} From b13e072c9eb18796ffa7b61af5de0f0965186d24 Mon Sep 17 00:00:00 2001 From: bombless Date: Fri, 20 Feb 2015 03:36:40 +0800 Subject: [PATCH 3/3] Remove questionable pattern --- src/test/run-pass/issue-22426.rs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/test/run-pass/issue-22426.rs b/src/test/run-pass/issue-22426.rs index f067d7fd3b1..b1c8f9c23c5 100644 --- a/src/test/run-pass/issue-22426.rs +++ b/src/test/run-pass/issue-22426.rs @@ -8,18 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct Foo(T, T); - -impl Foo { - fn foo(&self) { - match *self { - Foo::(ref x, ref y) => { - println!("Goodbye, World!") - } - } - } -} - fn main() { match 42 { x if x < 7 => (),