Add a lint for not using field pattern shorthands

Closes #17792.
This commit is contained in:
P1start 2014-10-06 13:36:53 +13:00
parent 56d544f7ad
commit ead6c4b9d4
53 changed files with 266 additions and 203 deletions

View file

@ -169,7 +169,7 @@ pub trait AstBuilder {
bm: ast::BindingMode) -> P<ast::Pat>;
fn pat_enum(&self, span: Span, path: ast::Path, subpats: Vec<P<ast::Pat>> ) -> P<ast::Pat>;
fn pat_struct(&self, span: Span,
path: ast::Path, field_pats: Vec<ast::FieldPat> ) -> P<ast::Pat>;
path: ast::Path, field_pats: Vec<Spanned<ast::FieldPat>> ) -> P<ast::Pat>;
fn pat_tuple(&self, span: Span, pats: Vec<P<ast::Pat>>) -> P<ast::Pat>;
fn pat_some(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat>;
@ -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<ast::FieldPat>) -> P<ast::Pat> {
path: ast::Path, field_pats: Vec<Spanned<ast::FieldPat>>) -> P<ast::Pat> {
let pat = ast::PatStruct(path, field_pats, false);
self.pat(span, pat)
}

View file

@ -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 {

View file

@ -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 {