From 4bb90f5cc8e0347534436612f45a3c22c7e265bb Mon Sep 17 00:00:00 2001 From: Hirokazu Hata Date: Sat, 9 Feb 2019 16:14:30 +0900 Subject: Fix rust_2018_idioms warnings --- src/patterns.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/patterns.rs') diff --git a/src/patterns.rs b/src/patterns.rs index acfb6ee1933..6114362e76f 100644 --- a/src/patterns.rs +++ b/src/patterns.rs @@ -64,7 +64,7 @@ fn is_short_pattern_inner(pat: &ast::Pat) -> bool { } impl Rewrite for Pat { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { match self.node { PatKind::Box(ref pat) => rewrite_unary_prefix(context, "box ", &**pat, shape), PatKind::Ident(binding_mode, ident, ref sub_pat) => { @@ -174,7 +174,7 @@ fn rewrite_struct_pat( fields: &[source_map::Spanned], ellipsis: bool, span: Span, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, ) -> Option { // 2 = ` {` @@ -240,7 +240,7 @@ fn rewrite_struct_pat( } impl Rewrite for FieldPat { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { let pat = self.pat.rewrite(context, shape); if self.is_shorthand { pat @@ -271,7 +271,7 @@ pub enum TuplePatField<'a> { } impl<'a> Rewrite for TuplePatField<'a> { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { match *self { TuplePatField::Pat(p) => p.rewrite(context, shape), TuplePatField::Dotdot(_) => Some("..".to_string()), @@ -288,7 +288,7 @@ impl<'a> Spanned for TuplePatField<'a> { } } -pub fn can_be_overflowed_pat(context: &RewriteContext, pat: &TuplePatField, len: usize) -> bool { +pub fn can_be_overflowed_pat(context: &RewriteContext<'_>, pat: &TuplePatField<'_>, len: usize) -> bool { match *pat { TuplePatField::Pat(pat) => match pat.node { ast::PatKind::Path(..) @@ -310,7 +310,7 @@ fn rewrite_tuple_pat( dotdot_pos: Option, path_str: Option, span: Span, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, ) -> Option { let mut pat_vec: Vec<_> = pats.iter().map(|x| TuplePatField::Pat(x)).collect(); @@ -379,8 +379,8 @@ fn rewrite_tuple_pat( } fn count_wildcard_suffix_len( - context: &RewriteContext, - patterns: &[TuplePatField], + context: &RewriteContext<'_>, + patterns: &[TuplePatField<'_>], span: Span, shape: Shape, ) -> usize { -- cgit 1.4.1-3-g733a5 From 8183b949c49cfdd5889859162e82fab4c8e64065 Mon Sep 17 00:00:00 2001 From: Hirokazu Hata Date: Sat, 9 Feb 2019 16:20:38 +0900 Subject: cargo fmt --- src/cargo-fmt/main.rs | 1 - src/chains.rs | 14 +++++++++++--- src/expr.rs | 12 ++++++++++-- src/items.rs | 12 ++++++++++-- src/macros.rs | 12 ++++++++++-- src/overflow.rs | 5 ++++- src/patterns.rs | 6 +++++- 7 files changed, 50 insertions(+), 12 deletions(-) (limited to 'src/patterns.rs') diff --git a/src/cargo-fmt/main.rs b/src/cargo-fmt/main.rs index 05861743963..3873671781c 100644 --- a/src/cargo-fmt/main.rs +++ b/src/cargo-fmt/main.rs @@ -16,7 +16,6 @@ use cargo_metadata; use getopts; - use std::collections::{HashMap, HashSet}; use std::env; use std::fs; diff --git a/src/chains.rs b/src/chains.rs index 37bbde1f4ee..66862116323 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -84,7 +84,11 @@ use crate::utils::{ trimmed_last_line_width, wrap_str, }; -pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext<'_>, shape: Shape) -> Option { +pub fn rewrite_chain( + expr: &ast::Expr, + context: &RewriteContext<'_>, + shape: Shape, +) -> Option { let chain = Chain::from_ast(expr, context); debug!("rewrite_chain {:?} {:?}", chain, shape); @@ -419,8 +423,12 @@ impl Rewrite for Chain { debug!("rewrite chain {:?} {:?}", self, shape); let mut formatter = match context.config.indent_style() { - IndentStyle::Block => Box::new(ChainFormatterBlock::new(self)) as Box, - IndentStyle::Visual => Box::new(ChainFormatterVisual::new(self)) as Box, + IndentStyle::Block => { + Box::new(ChainFormatterBlock::new(self)) as Box + } + IndentStyle::Visual => { + Box::new(ChainFormatterVisual::new(self)) as Box + } }; formatter.format_root(&self.parent, context, shape)?; diff --git a/src/expr.rs b/src/expr.rs index 14a5ebd28ee..5b59a5114b5 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -590,7 +590,11 @@ impl Rewrite for ast::Stmt { } // Rewrite condition if the given expression has one. -pub fn rewrite_cond(context: &RewriteContext<'_>, expr: &ast::Expr, shape: Shape) -> Option { +pub fn rewrite_cond( + context: &RewriteContext<'_>, + expr: &ast::Expr, + shape: Shape, +) -> Option { match expr.node { ast::ExprKind::Match(ref cond, _) => { // `match `cond` {` @@ -1337,7 +1341,11 @@ pub fn is_every_expr_simple(lists: &[OverflowableItem<'_>]) -> bool { lists.iter().all(OverflowableItem::is_simple) } -pub fn can_be_overflowed_expr(context: &RewriteContext<'_>, expr: &ast::Expr, args_len: usize) -> bool { +pub fn can_be_overflowed_expr( + context: &RewriteContext<'_>, + expr: &ast::Expr, + args_len: usize, +) -> bool { match expr.node { ast::ExprKind::Match(..) => { (context.use_block_indent() && args_len == 1) diff --git a/src/items.rs b/src/items.rs index b272a42ba18..a18cba69d65 100644 --- a/src/items.rs +++ b/src/items.rs @@ -998,7 +998,11 @@ fn format_struct( } } -pub fn format_trait(context: &RewriteContext<'_>, item: &ast::Item, offset: Indent) -> Option { +pub fn format_trait( + context: &RewriteContext<'_>, + item: &ast::Item, + offset: Indent, +) -> Option { if let ast::ItemKind::Trait( is_auto, unsafety, @@ -1172,7 +1176,11 @@ pub fn format_trait_alias( rewrite_assign_rhs(context, lhs, generic_bounds, shape.sub_width(1)?).map(|s| s + ";") } -fn format_unit_struct(context: &RewriteContext<'_>, p: &StructParts<'_>, offset: Indent) -> Option { +fn format_unit_struct( + context: &RewriteContext<'_>, + p: &StructParts<'_>, + offset: Indent, +) -> Option { let header_str = format_header(context, p.prefix, p.ident, p.vis); let generics_str = if let Some(generics) = p.generics { let hi = if generics.where_clause.predicates.is_empty() { diff --git a/src/macros.rs b/src/macros.rs index 8243b6a9734..47985a4d6c0 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1027,7 +1027,11 @@ fn wrap_macro_args_inner( // // We always try and format on one line. // FIXME: Use multi-line when every thing does not fit on one line. -fn format_macro_args(context: &RewriteContext<'_>, toks: TokenStream, shape: Shape) -> Option { +fn format_macro_args( + context: &RewriteContext<'_>, + toks: TokenStream, + shape: Shape, +) -> Option { if !context.config.format_macro_matchers() { let token_stream: TokenStream = toks.into(); let span = span_for_token_stream(&token_stream); @@ -1340,7 +1344,11 @@ impl MacroBranch { /// [pub] static ref NAME_N: TYPE_N = EXPR_N; /// } /// ``` -fn format_lazy_static(context: &RewriteContext<'_>, shape: Shape, ts: &TokenStream) -> Option { +fn format_lazy_static( + context: &RewriteContext<'_>, + shape: Shape, + ts: &TokenStream, +) -> Option { let mut result = String::with_capacity(1024); let mut parser = new_parser_from_tts(context.parse_session, ts.trees().collect()); let nested_shape = shape diff --git a/src/overflow.rs b/src/overflow.rs index 8f50f08ed2a..3bd57711be9 100644 --- a/src/overflow.rs +++ b/src/overflow.rs @@ -758,7 +758,10 @@ fn no_long_items(list: &[ListItem]) -> bool { } /// In case special-case style is required, returns an offset from which we start horizontal layout. -pub fn maybe_get_args_offset(callee_str: &str, args: &[OverflowableItem<'_>]) -> Option<(bool, usize)> { +pub fn maybe_get_args_offset( + callee_str: &str, + args: &[OverflowableItem<'_>], +) -> Option<(bool, usize)> { if let Some(&(_, num_args_before)) = args .get(0)? .whitelist() diff --git a/src/patterns.rs b/src/patterns.rs index 6114362e76f..956ce56bdf1 100644 --- a/src/patterns.rs +++ b/src/patterns.rs @@ -288,7 +288,11 @@ impl<'a> Spanned for TuplePatField<'a> { } } -pub fn can_be_overflowed_pat(context: &RewriteContext<'_>, pat: &TuplePatField<'_>, len: usize) -> bool { +pub fn can_be_overflowed_pat( + context: &RewriteContext<'_>, + pat: &TuplePatField<'_>, + len: usize, +) -> bool { match *pat { TuplePatField::Pat(pat) => match pat.node { ast::PatKind::Path(..) -- cgit 1.4.1-3-g733a5