]> git.lizzy.rs Git - rust.git/commitdiff
Use rewrite instead of visitor for attributes
authortopecongiro <seuchida@gmail.com>
Mon, 12 Jun 2017 08:25:07 +0000 (17:25 +0900)
committertopecongiro <seuchida@gmail.com>
Mon, 12 Jun 2017 08:25:07 +0000 (17:25 +0900)
src/expr.rs

index aa5913e5f0fa9bb613558f67400b2de9f49eb99c..e6889991b07e91747d4d1478d3caa7ae4913d650 100644 (file)
@@ -1321,20 +1321,13 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
             ref body,
         } = self;
 
-        // FIXME this is all a bit grotty, would be nice to abstract out the
-        // treatment of attributes.
         let attr_str = if !attrs.is_empty() {
-            // We only use this visitor for the attributes, should we use it for
-            // more?
-            let mut attr_visitor = FmtVisitor::from_codemap(context.parse_session, context.config);
-            attr_visitor.block_indent = shape.indent.block_only();
-            attr_visitor.last_pos = attrs[0].span.lo;
-            if attr_visitor.visit_attrs(attrs) {
-                // Attributes included a skip instruction.
+            if contains_skip(attrs) {
                 return None;
             }
-            attr_visitor.format_missing(pats[0].span.lo);
-            attr_visitor.buffer.to_string()
+            format!("{}\n{}",
+                    try_opt!(attrs.rewrite(context, shape)),
+                    shape.indent.to_string(context.config))
         } else {
             String::new()
         };