From 184f5102b37c9a52342382fe9e88144a62cd9782 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 7 Dec 2012 19:09:25 -0800 Subject: [PATCH] libsyntax: Fix parsing of module-qualified structure patterns. rs=bugfix --- src/libsyntax/parse/parser.rs | 30 +------------------ .../module-qualified-struct-destructure.rs | 12 ++++++++ 2 files changed, 13 insertions(+), 29 deletions(-) create mode 100644 src/test/run-pass/module-qualified-struct-destructure.rs diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index a9a0c1bdc76..8e354f7017d 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2046,8 +2046,6 @@ impl Parser { pat = self.parse_pat_ident(refutable, bind_by_value); } else if self.eat_keyword(~"move") { pat = self.parse_pat_ident(refutable, bind_by_move); - } else if !is_plain_ident(self.token) { - pat = self.parse_enum_variant(refutable); } else { let binding_mode; // XXX: Aren't these two cases deadcode? -- bblum @@ -2066,7 +2064,7 @@ impl Parser { let cannot_be_enum_or_struct; match self.look_ahead(1) { token::LPAREN | token::LBRACKET | token::LT | - token::LBRACE => + token::LBRACE | token::MOD_SEP => cannot_be_enum_or_struct = false, _ => cannot_be_enum_or_struct = true @@ -2163,32 +2161,6 @@ impl Parser { pat_ident(binding_mode, name, sub) } - fn parse_enum_variant(refutable: bool) -> ast::pat_ { - let enum_path = self.parse_path_with_tps(true); - match self.token { - token::LPAREN => { - match self.look_ahead(1u) { - token::BINOP(token::STAR) => { // foo(*) - self.expect(token::LPAREN); - self.expect(token::BINOP(token::STAR)); - self.expect(token::RPAREN); - pat_enum(enum_path, None) - } - _ => { // foo(a, ..., z) - let args = self.parse_unspanned_seq( - token::LPAREN, token::RPAREN, - seq_sep_trailing_disallowed(token::COMMA), - |p| p.parse_pat(refutable)); - pat_enum(enum_path, Some(args)) - } - } - } - _ => { // option::None - pat_enum(enum_path, Some(~[])) - } - } - } - fn parse_local(is_mutbl: bool, allow_init: bool) -> @local { let lo = self.span.lo; diff --git a/src/test/run-pass/module-qualified-struct-destructure.rs b/src/test/run-pass/module-qualified-struct-destructure.rs new file mode 100644 index 00000000000..ee7359b0a6d --- /dev/null +++ b/src/test/run-pass/module-qualified-struct-destructure.rs @@ -0,0 +1,12 @@ +mod m { + pub struct S { + x: int, + y: int + } +} + +fn main() { + let x = m::S { x: 1, y: 2 }; + let m::S { x: a, y: b } = x; +} +