Merge pull request #1888 from topecongiro/no-panic-against-invalid-attr

Do not panic against files with invalid attributes
This commit is contained in:
Nick Cameron 2017-08-16 16:28:15 +12:00 committed by GitHub
commit c166004e6d
3 changed files with 12 additions and 11 deletions

View File

@ -684,18 +684,13 @@ impl<'a> FmtVisitor<'a> {
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
}

View 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.

View 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.