about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/format-diff/main.rs2
-rw-r--r--src/items.rs19
-rw-r--r--src/lists.rs2
-rw-r--r--src/macros.rs4
-rw-r--r--src/overflow.rs2
-rw-r--r--src/source_map.rs12
-rw-r--r--src/utils.rs2
-rw-r--r--src/visitor.rs33
8 files changed, 36 insertions, 40 deletions
diff --git a/src/format-diff/main.rs b/src/format-diff/main.rs
index d509a4429b4..aacfa12d437 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 1673bffbce9..b35e8ea4587 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 57f778896d3..92990fe9a17 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 dab27d8a073..1e668cf1d87 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<ast::Expr> {
-    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 fc1803b2ab6..053ce1b9212 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 dee5e4f7601..ed081adcd86 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<BytePos> {
diff --git a/src/utils.rs b/src/utils.rs
index 7ef9254a482..2ff3b7e525a 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 7b952c20f52..63e2c6bdcac 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) {