diff --git a/src/visitor.rs b/src/visitor.rs index 6faaf8805b3..c5d91fee5b3 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -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), + ); + let span = mk_sp(attrs[0].span.lo, attrs[attrs.len() - 1].span.hi); + self.push_rewrite(span, rewrite); - 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; false } diff --git a/tests/source/attrib.rs b/tests/source/attrib.rs index beabed88510..55815371947 100644 --- a/tests/source/attrib.rs +++ b/tests/source/attrib.rs @@ -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. diff --git a/tests/target/attrib.rs b/tests/target/attrib.rs index fc2dfc11ad9..542ed3676f0 100644 --- a/tests/target/attrib.rs +++ b/tests/target/attrib.rs @@ -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.