From ffe9c9d834469e583a623f64b5a778402109c80a Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Thu, 7 Jan 2016 12:13:45 +0530 Subject: [PATCH] Clippy rustfmt --- src/expr.rs | 2 +- src/items.rs | 28 ++++++++++++---------------- src/lists.rs | 14 +++++--------- src/missed_spans.rs | 3 +-- src/types.rs | 2 +- src/utils.rs | 3 +-- 6 files changed, 21 insertions(+), 31 deletions(-) diff --git a/src/expr.rs b/src/expr.rs index 350b9c53a253..0e05f506d9bd 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -382,7 +382,7 @@ fn rewrite_closure(capture: ast::CaptureClause, let rewrite = inner_expr.rewrite(context, budget, offset + extra_offset); // Checks if rewrite succeeded and fits on a single line. - let accept_rewrite = rewrite.as_ref().map(|result| !result.contains('\n')).unwrap_or(false); + let accept_rewrite = rewrite.as_ref().map_or(false, |result| !result.contains('\n')); if accept_rewrite { return Some(format!("{}{}{}{}", prefix, spacer, rewrite.unwrap(), closer)); diff --git a/src/items.rs b/src/items.rs index ed59d41fd4a0..d9c21c339cbc 100644 --- a/src/items.rs +++ b/src/items.rs @@ -693,17 +693,15 @@ fn format_tuple_struct(context: &RewriteContext, let where_budget = try_opt!(context.config .max_width .checked_sub(last_line_width(&result))); - let where_clause_str = try_opt!(rewrite_where_clause(context, - &generics.where_clause, - context.config, - context.config.item_brace_style, - context.block_indent, - where_budget, - Density::Compressed, - ";", - None)); - - where_clause_str + try_opt!(rewrite_where_clause(context, + &generics.where_clause, + context.config, + context.config.item_brace_style, + context.block_indent, + where_budget, + Density::Compressed, + ";", + None)) } None => "".to_owned(), }; @@ -1114,8 +1112,7 @@ fn rewrite_fn_base(context: &RewriteContext, // A conservative estimation, to goal is to be over all parens in generics let args_start = generics.ty_params .last() - .map(|tp| end_typaram(tp)) - .unwrap_or(span.lo); + .map_or(span.lo, |tp| end_typaram(tp)); let args_span = mk_sp(span_after(mk_sp(args_start, span.hi), "(", context.codemap), span_for_return(&fd.output).lo); let arg_str = try_opt!(rewrite_args(context, @@ -1243,11 +1240,10 @@ fn rewrite_args(context: &RewriteContext, let min_args = explicit_self.and_then(|explicit_self| { rewrite_explicit_self(explicit_self, args, context) }) - .map(|self_str| { + .map_or(1, |self_str| { arg_item_strs[0] = self_str; 2 - }) - .unwrap_or(1); + }); // Comments between args. let mut arg_items = Vec::new(); diff --git a/src/lists.rs b/src/lists.rs index 4dd2e5d1dce6..b251a8ee255f 100644 --- a/src/lists.rs +++ b/src/lists.rs @@ -129,9 +129,8 @@ pub struct ListItem { impl ListItem { pub fn is_multiline(&self) -> bool { - self.item.as_ref().map(|s| s.contains('\n')).unwrap_or(false) || - self.pre_comment.is_some() || - self.post_comment.as_ref().map(|s| s.contains('\n')).unwrap_or(false) + self.item.as_ref().map_or(false, |s| s.contains('\n')) || self.pre_comment.is_some() || + self.post_comment.as_ref().map_or(false, |s| s.contains('\n')) } pub fn has_line_pre_comment(&self) -> bool { @@ -156,10 +155,7 @@ pub enum DefinitiveListTactic { Mixed, } -pub fn definitive_tactic<'t, I, T>(items: I, - tactic: ListTactic, - width: usize) - -> DefinitiveListTactic +pub fn definitive_tactic(items: I, tactic: ListTactic, width: usize) -> DefinitiveListTactic where I: IntoIterator + Clone, T: AsRef { @@ -493,7 +489,7 @@ fn needs_trailing_separator(separator_tactic: SeparatorTactic, } /// Returns the count and total width of the list items. -fn calculate_width<'li, I, T>(items: I) -> (usize, usize) +fn calculate_width(items: I) -> (usize, usize) where I: IntoIterator, T: AsRef { @@ -505,7 +501,7 @@ fn calculate_width<'li, I, T>(items: I) -> (usize, usize) fn total_item_width(item: &ListItem) -> usize { comment_len(item.pre_comment.as_ref().map(|x| &(*x)[..])) + comment_len(item.post_comment.as_ref().map(|x| &(*x)[..])) + - item.item.as_ref().map(|str| str.len()).unwrap_or(0) + item.item.as_ref().map_or(0, |str| str.len()) } fn comment_len(comment: Option<&str>) -> usize { diff --git a/src/missed_spans.rs b/src/missed_spans.rs index c123a9bc81bc..67661143ddf2 100644 --- a/src/missed_spans.rs +++ b/src/missed_spans.rs @@ -122,8 +122,7 @@ impl<'a> FmtVisitor<'a> { .skip_while(|rev_c| [' ', '\t'].contains(&rev_c)) .next(); - let fix_indent = last_char.map(|rev_c| ['{', '\n'].contains(&rev_c)) - .unwrap_or(true); + let fix_indent = last_char.map_or(true, |rev_c| ['{', '\n'].contains(&rev_c)); if rewrite_next_comment && fix_indent { if let Some('{') = last_char { diff --git a/src/types.rs b/src/types.rs index 911bf925293c..82a335c30124 100644 --- a/src/types.rs +++ b/src/types.rs @@ -30,7 +30,7 @@ pub fn rewrite_path(context: &RewriteContext, width: usize, offset: Indent) -> Option { - let skip_count = qself.map(|x| x.position).unwrap_or(0); + let skip_count = qself.map_or(0, |x| x.position); let mut result = if path.global { "::".to_owned() diff --git a/src/utils.rs b/src/utils.rs index a13ca2479649..78677495a91c 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -117,13 +117,12 @@ pub fn contains_skip(attrs: &[Attribute]) -> bool { pub fn end_typaram(typaram: &ast::TyParam) -> BytePos { typaram.bounds .last() - .map(|bound| { + .map_or(typaram.span, |bound| { match *bound { ast::RegionTyParamBound(ref lt) => lt.span, ast::TraitTyParamBound(ref prt, _) => prt.span, } }) - .unwrap_or(typaram.span) .hi }