]> git.lizzy.rs Git - rust.git/commitdiff
Do not panic against files with invalid attributes
authortopecongiro <seuchida@gmail.com>
Tue, 15 Aug 2017 15:11:20 +0000 (00:11 +0900)
committertopecongiro <seuchida@gmail.com>
Tue, 15 Aug 2017 15:11:20 +0000 (00:11 +0900)
src/visitor.rs
tests/source/attrib.rs
tests/target/attrib.rs

index 6faaf8805b3d3fc251207fde730b8914ae66b00d..c5d91fee5b3b65c821f0f5a1ab7d61e70ecd9f68 100644 (file)
@@ -684,18 +684,13 @@ pub fn visit_attrs(&mut self, attrs: &[ast::Attribute], style: ast::AttrStyle) -
             return false;
         }
 
-        let first = &attrs[0];
-        self.format_missing_with_indent(source!(self, first.span).lo);
-
-        let rewrite = attrs
-            .rewrite(
-                &self.get_context(),
-                Shape::indented(self.block_indent, self.config),
-            )
-            .unwrap();
-        self.buffer.push_str(&rewrite);
-        let last = attrs.last().unwrap();
-        self.last_pos = source!(self, last.span).hi;
+        let rewrite = attrs.rewrite(
+            &self.get_context(),
+            Shape::indented(self.block_indent, self.config),
+        );
+        let span = mk_sp(attrs[0].span.lo, attrs[attrs.len() - 1].span.hi);
+        self.push_rewrite(span, rewrite);
+
         false
     }
 
index beabed88510d39c0a2b9115b8b8950de1fc1d1b4..558153719475f6f7d9cd6a8bbb9a93d0bfc31433 100644 (file)
@@ -1,6 +1,9 @@
 // rustfmt-wrap_comments: true
 // Test attributes and doc comments are preserved.
 
+#[invalid attribute]
+fn foo() {}
+
 /// Blah blah blah.
 /// Blah blah blah.
 /// Blah blah blah.
index fc2dfc11ad97de4f7693cb86f72479e136b28c53..542ed3676f0dddf5c4b130459c58a33484d89582 100644 (file)
@@ -1,6 +1,9 @@
 // rustfmt-wrap_comments: true
 // Test attributes and doc comments are preserved.
 
+#[invalid attribute]
+fn foo() {}
+
 /// Blah blah blah.
 /// Blah blah blah.
 /// Blah blah blah.