From ead6c4b9d44f43945db6e91c92f14cef31240c64 Mon Sep 17 00:00:00 2001 From: P1start Date: Mon, 6 Oct 2014 13:36:53 +1300 Subject: Add a lint for not using field pattern shorthands Closes #17792. --- src/libsyntax/ext/build.rs | 4 ++-- src/libsyntax/ext/deriving/generic/mod.rs | 5 ++++- src/libsyntax/ext/tt/macro_parser.rs | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 437efbf96f8..dc4eaf7d7ad 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -169,7 +169,7 @@ pub trait AstBuilder { bm: ast::BindingMode) -> P; fn pat_enum(&self, span: Span, path: ast::Path, subpats: Vec> ) -> P; fn pat_struct(&self, span: Span, - path: ast::Path, field_pats: Vec ) -> P; + path: ast::Path, field_pats: Vec> ) -> P; fn pat_tuple(&self, span: Span, pats: Vec>) -> P; fn pat_some(&self, span: Span, pat: P) -> P; @@ -796,7 +796,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.pat(span, pat) } fn pat_struct(&self, span: Span, - path: ast::Path, field_pats: Vec) -> P { + path: ast::Path, field_pats: Vec>) -> P { let pat = ast::PatStruct(path, field_pats, false); self.pat(span, pat) } diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs index 2310a4460e2..533a28998bd 100644 --- a/src/libsyntax/ext/deriving/generic/mod.rs +++ b/src/libsyntax/ext/deriving/generic/mod.rs @@ -1248,7 +1248,10 @@ impl<'a> TraitDef<'a> { let pattern = if struct_type == Record { let field_pats = subpats.into_iter().zip(ident_expr.iter()).map(|(pat, &(_, id, _))| { // id is guaranteed to be Some - ast::FieldPat { ident: id.unwrap(), pat: pat } + codemap::Spanned { + span: pat.span, + node: ast::FieldPat { ident: id.unwrap(), pat: pat, is_shorthand: true }, + } }).collect(); cx.pat_struct(self.span, matching_path, field_pats) } else { diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 78fcd729aae..f2081674fb7 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -250,7 +250,7 @@ pub fn parse(sess: &ParseSess, let mut next_eis = Vec::new(); // or proceed normally let mut eof_eis = Vec::new(); - let TokenAndSpan {tok: tok, sp: sp} = rdr.peek(); + let TokenAndSpan { tok, sp } = rdr.peek(); /* we append new items to this while we go */ loop { -- cgit 1.4.1-3-g733a5