diff --git a/src/bin/cargo-fmt.rs b/src/bin/cargo-fmt.rs index 3c3ce223318..9d2733f5820 100644 --- a/src/bin/cargo-fmt.rs +++ b/src/bin/cargo-fmt.rs @@ -123,15 +123,15 @@ enum TargetKind { impl TargetKind { fn is_lib(&self) -> bool { - match self { - &TargetKind::Lib => true, + match *self { + TargetKind::Lib => true, _ => false, } } fn is_bin(&self) -> bool { - match self { - &TargetKind::Bin => true, + match *self { + TargetKind::Bin => true, _ => false, } } @@ -180,8 +180,8 @@ fn target_from_json(jtarget: &Json) -> Target { } } -fn format_files(files: &Vec, - fmt_args: &Vec, +fn format_files(files: &[PathBuf], + fmt_args: &[String], verbosity: Verbosity) -> Result { let stdout = if verbosity == Verbosity::Quiet { diff --git a/src/bin/rustfmt.rs b/src/bin/rustfmt.rs index 3434f01ac9f..ab41fbb7de7 100644 --- a/src/bin/rustfmt.rs +++ b/src/bin/rustfmt.rs @@ -198,7 +198,7 @@ fn execute(opts: &Options) -> FmtResult { match try!(determine_operation(&matches)) { Operation::Help => { - print_usage(&opts, ""); + print_usage(opts, ""); Ok(Summary::new()) } Operation::Version => { diff --git a/src/chains.rs b/src/chains.rs index 4a0b21a01e2..77835d0414e 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -186,7 +186,7 @@ pub fn rewrite_chain(expr: &ast::Expr, format!("\n{}", indent.to_string(context.config)) }; - let first_connector = if extend || subexpr_list.len() == 0 { + let first_connector = if extend || subexpr_list.is_empty() { "" } else if let ast::ExprKind::Try(_) = subexpr_list[0].node { "" diff --git a/src/checkstyle.rs b/src/checkstyle.rs index c43a37cf813..3fc117904c7 100644 --- a/src/checkstyle.rs +++ b/src/checkstyle.rs @@ -45,18 +45,14 @@ pub fn output_checkstyle_file(mut writer: T, try!(write!(writer, "", filename)); for mismatch in diff { for line in mismatch.lines { - match line { - DiffLine::Expected(ref str) => { - let message = xml_escape_str(&str); - try!(write!(writer, - "", - mismatch.line_number, - message)); - } - _ => { - // Do nothing with context and expected. - } + // Do nothing with `DiffLine::Context` and `DiffLine::Resulting`. + if let DiffLine::Expected(ref str) = line { + let message = xml_escape_str(str); + try!(write!(writer, + "", + mismatch.line_number, + message)); } } } diff --git a/src/comment.rs b/src/comment.rs index 062e4ba0ca7..979d3bef90e 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -94,7 +94,7 @@ pub fn rewrite_comment(orig: &str, let mut result = opener.to_owned(); for line in lines { if result == opener { - if line.len() == 0 { + if line.is_empty() { continue; } } else { @@ -107,7 +107,7 @@ pub fn rewrite_comment(orig: &str, let rewrite = rewrite_string(line, &fmt).unwrap_or(line.to_owned()); result.push_str(&rewrite); } else { - if line.len() == 0 { + if line.is_empty() { // Remove space if this is an empty comment or a doc comment. result.pop(); } @@ -136,7 +136,7 @@ fn left_trim_comment_line(line: &str) -> &str { } else if line.starts_with("/*") || line.starts_with("* ") || line.starts_with("//") || line.starts_with("**") { &line[2..] - } else if line.starts_with("*") { + } else if line.starts_with('*') { &line[1..] } else { line @@ -524,7 +524,7 @@ pub fn recover_comment_removed(new: String, if changed_comment_content(&snippet, &new) { // We missed some comments // Keep previous formatting if it satisfies the constrains - return wrap_str(snippet, context.config.max_width, width, offset); + wrap_str(snippet, context.config.max_width, width, offset) } else { Some(new) } diff --git a/src/expr.rs b/src/expr.rs index 1fea4f40e17..0f0526dba6d 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -298,7 +298,7 @@ pub fn rewrite_array<'a, I>(expr_iter: I, |item| item.span.lo, |item| item.span.hi, // 1 = [ - |item| item.rewrite(&inner_context, max_item_width, offset), + |item| item.rewrite(inner_context, max_item_width, offset), span.lo, span.hi) .collect::>(); @@ -493,7 +493,7 @@ fn and_one_line(x: Option) -> Option { fn nop_block_collapse(block_str: Option, budget: usize) -> Option { block_str.map(|block_str| { - if block_str.starts_with("{") && budget >= 2 && + if block_str.starts_with('{') && budget >= 2 && (block_str[1..].find(|c: char| !c.is_whitespace()).unwrap() == block_str.len() - 2) { "{}".to_owned() } else { @@ -772,7 +772,7 @@ fn rewrite_if_else(context: &RewriteContext, pat.map_or(cond.span.lo, |_| context.codemap.span_before(span, "let"))); - let between_if_cond_comment = extract_comment(between_if_cond, &context, offset, width); + let between_if_cond_comment = extract_comment(between_if_cond, context, offset, width); let after_cond_comment = extract_comment(mk_sp(cond.span.hi, if_block.span.lo), context, @@ -831,13 +831,13 @@ fn rewrite_if_else(context: &RewriteContext, mk_sp(if_block.span.hi, context.codemap.span_before(mk_sp(if_block.span.hi, else_block.span.lo), "else")); let between_if_else_block_comment = - extract_comment(between_if_else_block, &context, offset, width); + extract_comment(between_if_else_block, context, offset, width); let after_else = mk_sp(context.codemap .span_after(mk_sp(if_block.span.hi, else_block.span.lo), "else"), else_block.span.lo); - let after_else_comment = extract_comment(after_else, &context, offset, width); + let after_else_comment = extract_comment(after_else, context, offset, width); let between_sep = match context.config.else_if_brace_style { ElseIfBraceStyle::AlwaysNextLine | @@ -854,7 +854,7 @@ fn rewrite_if_else(context: &RewriteContext, .map_or(between_sep, |str| &**str), after_else_comment.as_ref().map_or(after_sep, |str| &**str)) .ok()); - result.push_str(&&try_opt!(rewrite)); + result.push_str(&try_opt!(rewrite)); } Some(result) @@ -1021,7 +1021,7 @@ fn rewrite_match(context: &RewriteContext, // We couldn't format the arm, just reproduce the source. let snippet = context.snippet(mk_sp(arm_start_pos(arm), arm_end_pos(arm))); result.push_str(&snippet); - result.push_str(arm_comma(&context.config, &arm, &arm.body)); + result.push_str(arm_comma(context.config, arm, &arm.body)); } } // BytePos(1) = closing match brace. @@ -1102,7 +1102,7 @@ fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Opt .map(|p| p.rewrite(context, pat_budget, offset)) .collect::>>()); - let all_simple = pat_strs.iter().all(|p| pat_is_simple(&p)); + let all_simple = pat_strs.iter().all(|p| pat_is_simple(p)); let items: Vec<_> = pat_strs.into_iter().map(ListItem::from_str).collect(); let fmt = ListFormatting { tactic: if all_simple { @@ -1145,7 +1145,7 @@ fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Opt ref x => x, }; - let comma = arm_comma(&context.config, self, body); + let comma = arm_comma(context.config, self, body); let alt_block_sep = String::from("\n") + &context.block_indent.to_string(context.config); // Let's try and get the arm body on the same line as the condition. @@ -1305,7 +1305,7 @@ fn rewrite_pat_expr(context: &RewriteContext, expr.rewrite(context, try_opt!(context.config.max_width.checked_sub(pat_offset.width())), pat_offset); - result.push_str(&&try_opt!(expr_rewrite)); + result.push_str(&try_opt!(expr_rewrite)); Some(result) } @@ -1433,7 +1433,7 @@ fn rewrite_call_inner(context: &RewriteContext, ")", |item| item.span.lo, |item| item.span.hi, - |item| item.rewrite(&inner_context, remaining_width, offset), + |item| item.rewrite(inner_context, remaining_width, offset), span.lo, span.hi); let mut item_vec: Vec<_> = items.collect(); @@ -1454,7 +1454,7 @@ fn rewrite_call_inner(context: &RewriteContext, // first arguments. if overflow_last { let inner_context = &RewriteContext { block_indent: context.block_indent, ..*context }; - let rewrite = args.last().unwrap().rewrite(&inner_context, remaining_width, offset); + let rewrite = args.last().unwrap().rewrite(inner_context, remaining_width, offset); if let Some(rewrite) = rewrite { let rewrite_first_line = Some(rewrite[..first_line_width(&rewrite)].to_owned()); @@ -1557,8 +1557,8 @@ enum StructLitField<'a> { "}", |item| { match *item { - StructLitField::Regular(ref field) => field.span.lo, - StructLitField::Base(ref expr) => { + StructLitField::Regular(field) => field.span.lo, + StructLitField::Base(expr) => { let last_field_hi = fields.last().map_or(span.lo, |field| field.span.hi); let snippet = context.snippet(mk_sp(last_field_hi, expr.span.lo)); let pos = snippet.find_uncommented("..").unwrap(); @@ -1568,19 +1568,19 @@ enum StructLitField<'a> { }, |item| { match *item { - StructLitField::Regular(ref field) => field.span.hi, - StructLitField::Base(ref expr) => expr.span.hi, + StructLitField::Regular(field) => field.span.hi, + StructLitField::Base(expr) => expr.span.hi, } }, |item| { match *item { - StructLitField::Regular(ref field) => { + StructLitField::Regular(field) => { rewrite_field(inner_context, - &field, + field, v_budget.checked_sub(1).unwrap_or(0), indent) } - StructLitField::Base(ref expr) => { + StructLitField::Base(expr) => { // 2 = .. expr.rewrite(inner_context, try_opt!(v_budget.checked_sub(2)), indent + 2) .map(|s| format!("..{}", s)) @@ -1678,7 +1678,7 @@ fn rewrite_field(context: &RewriteContext, match expr { Some(e) => Some(format!("{}{}{}", name, separator, e)), None => { - let expr_offset = offset.block_indent(&context.config); + let expr_offset = offset.block_indent(context.config); let expr = field.expr.rewrite(context, try_opt!(context.config .max_width @@ -1843,7 +1843,7 @@ fn rewrite_assignment(context: &RewriteContext, try_opt!(lhs.rewrite(context, max_width, offset)), operator_str); - rewrite_assign_rhs(&context, lhs_str, rhs, width, offset) + rewrite_assign_rhs(context, lhs_str, rhs, width, offset) } // The left hand side must contain everything up to, and including, the @@ -1863,7 +1863,7 @@ pub fn rewrite_assign_rhs>(context: &RewriteContext, }; // 1 = space between operator and rhs. let max_width = try_opt!(width.checked_sub(last_line_width + 1)); - let rhs = ex.rewrite(&context, max_width, offset + last_line_width + 1); + let rhs = ex.rewrite(context, max_width, offset + last_line_width + 1); fn count_line_breaks(src: &str) -> usize { src.chars().filter(|&x| x == '\n').count() diff --git a/src/imports.rs b/src/imports.rs index bc343307272..8ae3b06e28b 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -21,10 +21,10 @@ use syntax::{ast, ptr}; fn path_of(a: &ast::ViewPath_) -> &ast::Path { - match a { - &ast::ViewPath_::ViewPathSimple(_, ref p) => p, - &ast::ViewPath_::ViewPathGlob(ref p) => p, - &ast::ViewPath_::ViewPathList(ref p, _) => p, + match *a { + ast::ViewPath_::ViewPathSimple(_, ref p) => p, + ast::ViewPath_::ViewPathGlob(ref p) => p, + ast::ViewPath_::ViewPathList(ref p, _) => p, } } @@ -203,7 +203,7 @@ pub fn format_imports(&mut self, use_items: &[ptr::P]) { // Fake out the formatter by setting `self.last_pos` to the appropriate location before // each item before visiting it. self.last_pos = ordered.1; - self.visit_item(&ordered.0); + self.visit_item(ordered.0); } self.last_pos = pos_after_last_use_item; } diff --git a/src/issues.rs b/src/issues.rs index 64797de2fda..5282ee603ac 100644 --- a/src/issues.rs +++ b/src/issues.rs @@ -22,11 +22,7 @@ // irrelevant outside the issues module impl ReportTactic { fn is_enabled(&self) -> bool { - match *self { - ReportTactic::Always => true, - ReportTactic::Unnumbered => true, - ReportTactic::Never => false, - } + *self != ReportTactic::Never } } diff --git a/src/items.rs b/src/items.rs index 55b4f8b9dcd..b8fde7fbb0b 100644 --- a/src/items.rs +++ b/src/items.rs @@ -276,7 +276,7 @@ fn single_line_fn(&self, fn_str: &str, block: &ast::Block) -> Option { self.block_indent) .map(|s| s + suffix) .or_else(|| Some(self.snippet(e.span))) - } else if let Some(ref stmt) = block.stmts.first() { + } else if let Some(stmt) = block.stmts.first() { stmt.rewrite(&self.get_context(), self.config.max_width - self.block_indent.width(), self.block_indent) @@ -324,7 +324,7 @@ pub fn visit_enum(&mut self, self.block_indent = self.block_indent.block_indent(self.config); let variant_list = self.format_variant_list(enum_def, body_start, span.hi - BytePos(1)); match variant_list { - Some(ref body_str) => self.buffer.push_str(&body_str), + Some(ref body_str) => self.buffer.push_str(body_str), None => { if contains_comment(&enum_snippet[brace_pos..]) { self.format_missing_no_indent(span.hi - BytePos(1)) @@ -554,7 +554,7 @@ pub fn format_impl(context: &RewriteContext, item: &ast::Item, offset: Indent) - visitor.last_pos = item.span.lo + BytePos(open_pos as u32); for item in items { - visitor.visit_impl_item(&item); + visitor.visit_impl_item(item); } visitor.format_missing(item.span.hi - BytePos(1)); @@ -564,7 +564,7 @@ pub fn format_impl(context: &RewriteContext, item: &ast::Item, offset: Indent) - result.push('\n'); result.push_str(&inner_indent_str); - result.push_str(&trim_newlines(&visitor.buffer.to_string().trim())); + result.push_str(trim_newlines(visitor.buffer.to_string().trim())); result.push('\n'); result.push_str(&outer_indent_str); } @@ -581,7 +581,7 @@ pub fn format_impl(context: &RewriteContext, item: &ast::Item, offset: Indent) - } fn is_impl_single_line(context: &RewriteContext, - items: &Vec, + items: &[ImplItem], result: &str, where_clause_str: &str, item: &ast::Item) @@ -713,7 +713,7 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent) BraceStyle::PreferSameLine => result.push(' '), BraceStyle::SameLineWhere => { if !where_clause_str.is_empty() && - (trait_items.len() > 0 || result.contains('\n')) { + (!trait_items.is_empty() || result.contains('\n')) { result.push('\n'); result.push_str(&offset.to_string(context.config)); } else { @@ -732,7 +732,7 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent) visitor.last_pos = item.span.lo + BytePos(open_pos as u32); for item in trait_items { - visitor.visit_trait_item(&item); + visitor.visit_trait_item(item); } visitor.format_missing(item.span.hi - BytePos(1)); @@ -742,7 +742,7 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent) result.push('\n'); result.push_str(&inner_indent_str); - result.push_str(&trim_newlines(&visitor.buffer.to_string().trim())); + result.push_str(trim_newlines(visitor.buffer.to_string().trim())); result.push('\n'); result.push_str(&outer_indent_str); } else if result.contains('\n') { @@ -876,7 +876,7 @@ fn format_tuple_struct(context: &RewriteContext, }; let where_clause_str = match generics { - Some(ref generics) => { + Some(generics) => { let generics_str = try_opt!(rewrite_generics(context, generics, offset, @@ -951,7 +951,7 @@ pub fn rewrite_type_alias(context: &RewriteContext, -> Option { let mut result = String::new(); - result.push_str(&format_visibility(&vis)); + result.push_str(&format_visibility(vis)); result.push_str("type "); result.push_str(&ident.to_string()); @@ -1069,7 +1069,7 @@ pub fn rewrite_static(prefix: &str, prefix.len() - 2, context.block_indent)); - if let Some(ref expr) = expr_opt { + if let Some(expr) = expr_opt { let lhs = format!("{}{} =", prefix, ty_str); // 1 = ; let remaining_width = context.config.max_width - context.block_indent.width() - 1; @@ -1090,7 +1090,7 @@ pub fn rewrite_associated_type(ident: ast::Ident, let prefix = format!("type {}", ident); let type_bounds_str = if let Some(ty_param_bounds) = ty_param_bounds_opt { - let bounds: &[_] = &ty_param_bounds; + let bounds: &[_] = ty_param_bounds; let bound_str = try_opt!(bounds.iter() .map(|ty_bound| ty_bound.rewrite(context, context.config.max_width, indent)) .intersperse(Some(" + ".to_string())) @@ -1374,7 +1374,7 @@ fn rewrite_fn_base(context: &RewriteContext, FnArgLayoutStyle::Block => multi_line_arg_str, FnArgLayoutStyle::BlockAlways => true, _ => false, - } && fd.inputs.len() > 0; + } && !fd.inputs.is_empty(); if put_args_in_block { arg_indent = indent.block_indent(context.config); @@ -1410,7 +1410,7 @@ fn rewrite_fn_base(context: &RewriteContext, let overlong_sig = sig_length > context.config.max_width; - result.contains("\n") || multi_line_ret_str || overlong_sig + result.contains('\n') || multi_line_ret_str || overlong_sig } }; let ret_indent = if ret_should_indent { @@ -1647,7 +1647,7 @@ fn compute_budgets_for_args(context: &RewriteContext, newline_brace: bool) -> Option<((usize, usize, Indent))> { // Try keeping everything on the same line. - if !result.contains("\n") { + if !result.contains('\n') { // 3 = `() `, space is before ret_string. let mut used_space = indent.width() + result.len() + ret_str_len + 3; if !newline_brace { @@ -1710,8 +1710,8 @@ fn rewrite_generics(context: &RewriteContext, // FIXME: might need to insert a newline if the generics are really long. // Strings for the generics. - let lt_strs = lifetimes.iter().map(|lt| lt.rewrite(&context, h_budget, offset)); - let ty_strs = tys.iter().map(|ty_param| ty_param.rewrite(&context, h_budget, offset)); + let lt_strs = lifetimes.iter().map(|lt| lt.rewrite(context, h_budget, offset)); + let ty_strs = tys.iter().map(|ty_param| ty_param.rewrite(context, h_budget, offset)); // Extract comments between generics. let lt_spans = lifetimes.iter().map(|l| { @@ -1743,7 +1743,7 @@ fn rewrite_trait_bounds(context: &RewriteContext, indent: Indent, width: usize) -> Option { - let bounds: &[_] = &type_param_bounds; + let bounds: &[_] = type_param_bounds; if bounds.is_empty() { return Some(String::new()); @@ -1801,7 +1801,7 @@ fn rewrite_where_clause(context: &RewriteContext, terminator, |pred| span_for_where_pred(pred).lo, |pred| span_for_where_pred(pred).hi, - |pred| pred.rewrite(&context, budget, offset), + |pred| pred.rewrite(context, budget, offset), span_start, span_end); let item_vec = items.collect::>(); @@ -1825,9 +1825,9 @@ fn rewrite_where_clause(context: &RewriteContext, // If the brace is on the next line we don't need to count it otherwise it needs two // characters " {" match brace_style { - BraceStyle::AlwaysNextLine => 0, - BraceStyle::PreferSameLine => 2, + BraceStyle::AlwaysNextLine | BraceStyle::SameLineWhere => 0, + BraceStyle::PreferSameLine => 2, } } else if terminator == "=" { 2 diff --git a/src/lib.rs b/src/lib.rs index 17af40d9b37..dd6a2a5d079 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -254,7 +254,7 @@ fn new() -> FormatReport { } pub fn warning_count(&self) -> usize { - self.file_error_map.iter().map(|(_, ref errors)| errors.len()).fold(0, |acc, x| acc + x) + self.file_error_map.iter().map(|(_, errors)| errors.len()).fold(0, |acc, x| acc + x) } pub fn has_warnings(&self) -> bool { @@ -392,9 +392,9 @@ fn parse_input(input: Input, parse_session: &ParseSess) -> Result> { let result = match input { - Input::File(file) => parse::parse_crate_from_file(&file, Vec::new(), &parse_session), + Input::File(file) => parse::parse_crate_from_file(&file, Vec::new(), parse_session), Input::Text(text) => { - parse::parse_crate_from_source_str("stdin".to_owned(), text, Vec::new(), &parse_session) + parse::parse_crate_from_source_str("stdin".to_owned(), text, Vec::new(), parse_session) } }; diff --git a/src/lists.rs b/src/lists.rs index 2bd4becc57f..9607039e1d2 100644 --- a/src/lists.rs +++ b/src/lists.rs @@ -357,7 +357,7 @@ fn next(&mut self) -> Option { // Post-comment let next_start = match self.inner.peek() { - Some(ref next_item) => (self.get_lo)(next_item), + Some(next_item) => (self.get_lo)(next_item), None => self.next_span_start, }; let post_snippet = self.codemap @@ -420,7 +420,7 @@ fn next(&mut self) -> Option { let post_snippet_trimmed = if post_snippet.starts_with(',') { post_snippet[1..].trim_matches(white_space) - } else if post_snippet.ends_with(",") { + } else if post_snippet.ends_with(',') { post_snippet[..(post_snippet.len() - 1)].trim_matches(white_space) } else { post_snippet diff --git a/src/macros.rs b/src/macros.rs index 9cb0f8619c0..5b87f6cc7ec 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -111,7 +111,7 @@ pub fn rewrite_macro(mac: &ast::Mac, _ => return None, } - let _ = parser.bump(); + parser.bump(); if parser.token == Token::Eof { return None; diff --git a/src/missed_spans.rs b/src/missed_spans.rs index 22f56ef5fe0..98d87ba4963 100644 --- a/src/missed_spans.rs +++ b/src/missed_spans.rs @@ -118,7 +118,7 @@ fn replace_chars(string: &str) -> String { let last_char = big_snippet[..(offset + big_diff)] .chars() .rev() - .skip_while(|rev_c| [' ', '\t'].contains(&rev_c)) + .skip_while(|rev_c| [' ', '\t'].contains(rev_c)) .next(); let fix_indent = last_char.map_or(true, |rev_c| ['{', '\n'].contains(&rev_c)); @@ -174,19 +174,17 @@ fn replace_chars(string: &str) -> String { line_start = i + 1; last_wspace = None; rewrite_next_comment = rewrite_next_comment || kind == CodeCharKind::Normal; - } else { - if c.is_whitespace() { - if last_wspace.is_none() { - last_wspace = Some(i); - } - } else { - rewrite_next_comment = rewrite_next_comment || kind == CodeCharKind::Normal; - last_wspace = None; + } else if c.is_whitespace() { + if last_wspace.is_none() { + last_wspace = Some(i); } + } else { + rewrite_next_comment = rewrite_next_comment || kind == CodeCharKind::Normal; + last_wspace = None; } } } - process_last_snippet(self, &snippet[line_start..], &snippet); + process_last_snippet(self, &snippet[line_start..], snippet); } } diff --git a/src/modules.rs b/src/modules.rs index e56fa57ac7b..6ea2248ed3c 100644 --- a/src/modules.rs +++ b/src/modules.rs @@ -64,11 +64,11 @@ fn module_file(id: ast::Ident, dir_path: &Path, codemap: &codemap::CodeMap) -> PathBuf { - if let Some(path) = parser::Parser::submod_path_from_attr(attrs, &dir_path) { + if let Some(path) = parser::Parser::submod_path_from_attr(attrs, dir_path) { return path; } - match parser::Parser::default_submod_path(id, &dir_path, codemap).result { + match parser::Parser::default_submod_path(id, dir_path, codemap).result { Ok(parser::ModulePathSuccess { path, .. }) => path, Err(_) => panic!("Couldn't find module {}", id), } diff --git a/src/patterns.rs b/src/patterns.rs index a0b15a0f8c9..c35dd25672d 100644 --- a/src/patterns.rs +++ b/src/patterns.rs @@ -153,7 +153,7 @@ fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Opt field_string.push_str(&offset.to_string(context.config)); field_string.push_str(".."); } else { - if field_string.len() > 0 { + if !field_string.is_empty() { field_string.push_str(", "); } field_string.push_str(".."); diff --git a/src/types.rs b/src/types.rs index 598ac3b6ac8..fff46b0750d 100644 --- a/src/types.rs +++ b/src/types.rs @@ -43,7 +43,7 @@ pub fn rewrite_path(context: &RewriteContext, let mut span_lo = path.span.lo; - if let Some(ref qself) = qself { + if let Some(qself) = qself { result.push('<'); let fmt_ty = try_opt!(qself.ty.rewrite(context, width, offset)); result.push_str(&fmt_ty); @@ -131,9 +131,9 @@ enum SegmentParam<'a> { impl<'a> SegmentParam<'a> { fn get_span(&self) -> Span { match *self { - SegmentParam::LifeTime(ref lt) => lt.span, - SegmentParam::Type(ref ty) => ty.span, - SegmentParam::Binding(ref binding) => binding.span, + SegmentParam::LifeTime(lt) => lt.span, + SegmentParam::Type(ty) => ty.span, + SegmentParam::Binding(binding) => binding.span, } } } @@ -141,9 +141,9 @@ fn get_span(&self) -> Span { impl<'a> Rewrite for SegmentParam<'a> { fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Option { match *self { - SegmentParam::LifeTime(ref lt) => lt.rewrite(context, width, offset), - SegmentParam::Type(ref ty) => ty.rewrite(context, width, offset), - SegmentParam::Binding(ref binding) => { + SegmentParam::LifeTime(lt) => lt.rewrite(context, width, offset), + SegmentParam::Type(ty) => ty.rewrite(context, width, offset), + SegmentParam::Binding(binding) => { let mut result = format!("{} = ", binding.ident); let budget = try_opt!(width.checked_sub(result.len())); let rewrite = try_opt!(binding.ty.rewrite(context, budget, offset + result.len())); @@ -306,7 +306,7 @@ enum ArgumentKind FunctionRetTy::Default(..) => String::new(), }; - let infix = if output.len() > 0 && output.len() + list_str.len() > width { + let infix = if !output.is_empty() && output.len() + list_str.len() > width { format!("\n{}", (offset - 1).to_string(context.config)) } else { String::new() @@ -622,7 +622,7 @@ fn rewrite_bare_fn(bare_fn: &ast::BareFnTy, result.push_str("> "); } - result.push_str(&::utils::format_unsafety(bare_fn.unsafety)); + result.push_str(::utils::format_unsafety(bare_fn.unsafety)); if bare_fn.abi != abi::Abi::Rust { result.push_str(&::utils::format_abi(bare_fn.abi, context.config.force_explicit_abi)); diff --git a/src/utils.rs b/src/utils.rs index 0978e552837..70f16386ec2 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -251,7 +251,7 @@ pub fn wrap_str>(s: S, max_width: usize, width: usize, offset: Ind } // The other lines must fit within the maximum width. - if lines.find(|line| line.len() > max_width).is_some() { + if lines.any(|line| line.len() > max_width) { return None; } diff --git a/src/visitor.rs b/src/visitor.rs index b89b97487a5..237866ed9ec 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -85,7 +85,7 @@ pub fn visit_block(&mut self, b: &ast::Block) { // Check if this block has braces. let snippet = self.snippet(b.span); - let has_braces = snippet.starts_with("{") || snippet.starts_with("unsafe"); + let has_braces = snippet.starts_with('{') || snippet.starts_with("unsafe"); let brace_compensation = if has_braces { BytePos(1) } else { BytePos(0) }; self.last_pos = self.last_pos + brace_compensation; @@ -93,7 +93,7 @@ pub fn visit_block(&mut self, b: &ast::Block) { self.buffer.push_str("{"); for stmt in &b.stmts { - self.visit_stmt(&stmt) + self.visit_stmt(stmt) } if let Some(ref e) = b.expr { @@ -144,7 +144,7 @@ fn visit_fn(&mut self, defaultness: ast::Defaultness) { let indent = self.block_indent; let rewrite = match fk { - visit::FnKind::ItemFn(ident, ref generics, unsafety, constness, abi, vis) => { + visit::FnKind::ItemFn(ident, generics, unsafety, constness, abi, vis) => { self.rewrite_fn(indent, ident, fd, @@ -155,9 +155,9 @@ fn visit_fn(&mut self, abi, vis, codemap::mk_sp(s.lo, b.span.lo), - &b) + b) } - visit::FnKind::Method(ident, ref sig, vis) => { + visit::FnKind::Method(ident, sig, vis) => { self.rewrite_fn(indent, ident, fd, @@ -168,7 +168,7 @@ fn visit_fn(&mut self, sig.abi, vis.unwrap_or(&ast::Visibility::Inherited), codemap::mk_sp(s.lo, b.span.lo), - &b) + b) } visit::FnKind::Closure => None, }; @@ -374,7 +374,7 @@ pub fn visit_trait_item(&mut self, ti: &ast::TraitItem) { ast::TraitItemKind::Method(ref sig, Some(ref body)) => { self.visit_fn(visit::FnKind::Method(ti.ident, sig, None), &sig.decl, - &body, + body, ti.span, ti.id, ast::Defaultness::Final); @@ -516,7 +516,7 @@ fn walk_mod_items(&mut self, m: &ast::Mod) { // `unwrap()` is safe here because we know `items_left` // has elements from the loop condition let (item, rest) = items_left.split_first().unwrap(); - self.visit_item(&item); + self.visit_item(item); items_left = rest; } }