]> git.lizzy.rs Git - rust.git/blobdiff - src/visitor.rs
Use concat() instead of join("")
[rust.git] / src / visitor.rs
index ba87efb5052715f8ad690cd1c25e768c1070a87d..63e2c6bdcac57c88c8128682b20880aaa8975a67 100644 (file)
@@ -112,7 +112,7 @@ fn visit_stmt(&mut self, stmt: &ast::Stmt) {
                 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 @@ pub fn visit_item(&mut self, item: &ast::Item) {
                 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);
             }
@@ -498,6 +498,7 @@ pub fn visit_trait_item(&mut self, ti: &ast::TraitItem) {
                 let rewrite = rewrite_associated_type(
                     ti.ident,
                     type_default.as_ref(),
+                    &ti.generics,
                     Some(generic_bounds),
                     &self.get_context(),
                     self.block_indent,
@@ -536,6 +537,7 @@ pub fn visit_impl_item(&mut self, ii: &ast::ImplItem) {
                     ii.ident,
                     ii.defaultness,
                     Some(ty),
+                    &ii.generics,
                     &self.get_context(),
                     self.block_indent,
                 );
@@ -545,6 +547,7 @@ pub fn visit_impl_item(&mut self, ii: &ast::ImplItem) {
                 let rewrite = rewrite_existential_impl_type(
                     &self.get_context(),
                     ii.ident,
+                    &ii.generics,
                     generic_bounds,
                     self.block_indent,
                 );
@@ -649,20 +652,19 @@ pub fn visit_attrs(&mut self, attrs: &[ast::Attribute], style: ast::AttrStyle) -
                         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) {
@@ -789,13 +791,9 @@ pub fn with_context<F>(&mut self, f: F) -> Option<String>
     where
         F: Fn(&RewriteContext) -> Option<String>,
     {
-        let result;
-        let macro_rewrite_failure = {
-            let context = self.get_context();
-            result = f(&context);
-            unsafe { *context.macro_rewrite_failure.as_ptr() }
-        };
-        self.macro_rewrite_failure |= macro_rewrite_failure;
+        let context = self.get_context();
+        let result = f(&context);
+        self.macro_rewrite_failure |= *context.macro_rewrite_failure.borrow();
         result
     }