diff options
| author | P1start <rewi-github@whanau.org> | 2014-10-06 13:36:53 +1300 |
|---|---|---|
| committer | P1start <rewi-github@whanau.org> | 2014-10-24 15:44:18 +1300 |
| commit | ead6c4b9d44f43945db6e91c92f14cef31240c64 (patch) | |
| tree | 5ed3696f210ea21982c5b827f32bd5bb51fc24e4 /src/libsyntax/parse/parser.rs | |
| parent | 56d544f7adc455fc1d7dfaec80315ea44e46d9ae (diff) | |
| download | rust-ead6c4b9d44f43945db6e91c92f14cef31240c64.tar.gz rust-ead6c4b9d44f43945db6e91c92f14cef31240c64.zip | |
Add a lint for not using field pattern shorthands
Closes #17792.
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index ed806ad803a..5abf79836f5 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3100,7 +3100,7 @@ impl<'a> Parser<'a> { } /// Parse the fields of a struct-like pattern - fn parse_pat_fields(&mut self) -> (Vec<ast::FieldPat> , bool) { + fn parse_pat_fields(&mut self) -> (Vec<codemap::Spanned<ast::FieldPat>> , bool) { let mut fields = Vec::new(); let mut etc = false; let mut first = true; @@ -3113,6 +3113,9 @@ impl<'a> Parser<'a> { if self.token == token::RBRACE { break } } + let lo = self.span.lo; + let hi; + if self.token == token::DOTDOT { self.bump(); if self.token != token::RBRACE { @@ -3134,7 +3137,7 @@ impl<'a> Parser<'a> { let fieldname = self.parse_ident(); - let subpat = if self.token == token::COLON { + let (subpat, is_shorthand) = if self.token == token::COLON { match bind_type { BindByRef(..) | BindByValue(MutMutable) => { let token_str = self.this_token_to_string(); @@ -3145,16 +3148,22 @@ impl<'a> Parser<'a> { } self.bump(); - self.parse_pat() + let pat = self.parse_pat(); + hi = pat.span.hi; + (pat, false) } else { + hi = self.last_span.hi; let fieldpath = codemap::Spanned{span:self.last_span, node: fieldname}; - P(ast::Pat { + (P(ast::Pat { id: ast::DUMMY_NODE_ID, node: PatIdent(bind_type, fieldpath, None), span: self.last_span - }) + }), true) }; - fields.push(ast::FieldPat { ident: fieldname, pat: subpat }); + fields.push(codemap::Spanned { span: mk_sp(lo, hi), + node: ast::FieldPat { ident: fieldname, + pat: subpat, + is_shorthand: is_shorthand }}); } return (fields, etc); } @@ -3665,9 +3674,9 @@ impl<'a> Parser<'a> { // wouldn't it be more uniform to parse view items only, here? let ParsedItemsAndViewItems { - attrs_remaining: attrs_remaining, - view_items: view_items, - items: items, + attrs_remaining, + view_items, + items, .. } = self.parse_items_and_view_items(first_item_attrs, false, false); @@ -4705,8 +4714,8 @@ impl<'a> Parser<'a> { // parse all of the items up to closing or an attribute. // view items are legal here. let ParsedItemsAndViewItems { - attrs_remaining: attrs_remaining, - view_items: view_items, + attrs_remaining, + view_items, items: starting_items, .. } = self.parse_items_and_view_items(first_item_attrs, true, true); @@ -4978,10 +4987,10 @@ impl<'a> Parser<'a> { first_item_attrs: Vec<Attribute> ) -> ForeignMod { let ParsedItemsAndViewItems { - attrs_remaining: attrs_remaining, - view_items: view_items, + attrs_remaining, + view_items, items: _, - foreign_items: foreign_items + foreign_items, } = self.parse_foreign_items(first_item_attrs, true); if !attrs_remaining.is_empty() { let last_span = self.last_span; |
