diff --git a/src/format-diff/main.rs b/src/format-diff/main.rs index d509a4429b49..aacfa12d437e 100644 --- a/src/format-diff/main.rs +++ b/src/format-diff/main.rs @@ -83,7 +83,7 @@ fn main() { ); if let Err(e) = run(&opts) { - println!("{}", opts.usage(&format!("{}", e))); + println!("{}", opts.usage(&e.to_string())); process::exit(1); } } diff --git a/src/items.rs b/src/items.rs index 1673bffbce9b..b35e8ea45878 100644 --- a/src/items.rs +++ b/src/items.rs @@ -1543,7 +1543,7 @@ pub fn rewrite_struct_field_prefix( rewrite_ident(context, name), type_annotation_spacing.0 ), - None => format!("{}", vis), + None => vis.to_string(), }) } @@ -2004,18 +2004,13 @@ fn rewrite_fn_base( one_line_budget, multi_line_budget, arg_indent ); + result.push('('); // Check if vertical layout was forced. - if one_line_budget == 0 { - if snuggle_angle_bracket { - result.push('('); - } else { - result.push_str("("); - if context.config.indent_style() == IndentStyle::Visual { - result.push_str(&arg_indent.to_string_with_newline(context.config)); - } - } - } else { - result.push('('); + if one_line_budget == 0 + && !snuggle_angle_bracket + && context.config.indent_style() == IndentStyle::Visual + { + result.push_str(&arg_indent.to_string_with_newline(context.config)); } // Skip `pub(crate)`. diff --git a/src/lists.rs b/src/lists.rs index 57f778896d30..92990fe9a171 100644 --- a/src/lists.rs +++ b/src/lists.rs @@ -50,7 +50,7 @@ impl<'a> ListFormatting<'a> { ends_with_newline: true, preserve_newline: false, nested: false, - config: config, + config, } } diff --git a/src/macros.rs b/src/macros.rs index dab27d8a073b..1e668cf1d872 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1073,7 +1073,7 @@ fn next_space(tok: &Token) -> SpaceState { /// when the macro is not an instance of try! (or parsing the inner expression /// failed). pub fn convert_try_mac(mac: &ast::Mac, context: &RewriteContext) -> Option { - if &format!("{}", mac.node.path) == "try" { + if &mac.node.path.to_string() == "try" { let ts: TokenStream = mac.node.tts.clone().into(); let mut parser = new_parser_from_tts(context.parse_session, ts.trees().collect()); @@ -1491,5 +1491,5 @@ fn rewrite_macro_with_items( result.push_str(&shape.indent.to_string_with_newline(context.config)); result.push_str(closer); result.push_str(trailing_semicolon); - return Some(result); + Some(result) } diff --git a/src/overflow.rs b/src/overflow.rs index fc1803b2ab6a..053ce1b92128 100644 --- a/src/overflow.rs +++ b/src/overflow.rs @@ -425,7 +425,7 @@ impl<'a> Context<'a> { _ => expr.rewrite(self.context, shape), } } - item @ _ => item.rewrite(self.context, shape), + item => item.rewrite(self.context, shape), }; if let Some(rewrite) = rewrite { diff --git a/src/source_map.rs b/src/source_map.rs index dee5e4f76011..ed081adcd86d 100644 --- a/src/source_map.rs +++ b/src/source_map.rs @@ -51,11 +51,13 @@ impl<'a> SpanUtils for SnippetProvider<'a> { } fn span_before(&self, original: Span, needle: &str) -> BytePos { - self.opt_span_before(original, needle).expect(&format!( - "bad span: {}: {}", - needle, - self.span_to_snippet(original).unwrap() - )) + self.opt_span_before(original, needle).unwrap_or_else(|| { + panic!( + "bad span: {}: {}", + needle, + self.span_to_snippet(original).unwrap() + ) + }) } fn opt_span_after(&self, original: Span, needle: &str) -> Option { diff --git a/src/utils.rs b/src/utils.rs index 7ef9254a4820..2ff3b7e525a3 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -45,7 +45,7 @@ pub fn is_same_visibility(a: &Visibility, b: &Visibility) -> bool { ( VisibilityKind::Restricted { path: p, .. }, VisibilityKind::Restricted { path: q, .. }, - ) => format!("{}", p) == format!("{}", q), + ) => p.to_string() == q.to_string(), (VisibilityKind::Public, VisibilityKind::Public) | (VisibilityKind::Inherited, VisibilityKind::Inherited) | ( diff --git a/src/visitor.rs b/src/visitor.rs index 7b952c20f525..63e2c6bdcac5 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -112,7 +112,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { if contains_skip(get_attrs_from_stmt(stmt)) { self.push_skipped_with_span(stmt.span()); } else { - let shape = self.shape().clone(); + let shape = self.shape(); let rewrite = self.with_context(|ctx| stmt.rewrite(&ctx, shape)); self.push_rewrite(stmt.span(), rewrite) } @@ -367,13 +367,13 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { let where_span_end = snippet .find_uncommented("{") .map(|x| BytePos(x as u32) + source!(self, item.span).lo()); - let block_indent = self.block_indent.clone(); + let block_indent = self.block_indent; let rw = self.with_context(|ctx| format_impl(&ctx, item, block_indent, where_span_end)); self.push_rewrite(item.span, rw); } ast::ItemKind::Trait(..) => { - let block_indent = self.block_indent.clone(); + let block_indent = self.block_indent; let rw = self.with_context(|ctx| format_trait(&ctx, item, block_indent)); self.push_rewrite(item.span, rw); } @@ -652,20 +652,19 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { ErrorKind::DeprecatedAttr, )], ); - } else if attr.path.segments[0].ident.to_string() == "rustfmt" { - if attr.path.segments.len() == 1 - || attr.path.segments[1].ident.to_string() != "skip" - { - let file_name = self.source_map.span_to_filename(attr.span).into(); - self.report.append( - file_name, - vec![FormattingError::from_span( - attr.span, - &self.source_map, - ErrorKind::BadAttr, - )], - ); - } + } else if attr.path.segments[0].ident.to_string() == "rustfmt" + && (attr.path.segments.len() == 1 + || attr.path.segments[1].ident.to_string() != "skip") + { + let file_name = self.source_map.span_to_filename(attr.span).into(); + self.report.append( + file_name, + vec![FormattingError::from_span( + attr.span, + &self.source_map, + ErrorKind::BadAttr, + )], + ); } } if contains_skip(attrs) {