Skip to content

Commit c166004

Browse files
authored
Merge pull request #1888 from topecongiro/no-panic-against-invalid-attr
Do not panic against files with invalid attributes
2 parents 02cb9a1 + 5282000 commit c166004

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

src/visitor.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -684,18 +684,13 @@ impl<'a> FmtVisitor<'a> {
684684
return false;
685685
}
686686

687-
let first = &attrs[0];
688-
self.format_missing_with_indent(source!(self, first.span).lo);
689-
690-
let rewrite = attrs
691-
.rewrite(
692-
&self.get_context(),
693-
Shape::indented(self.block_indent, self.config),
694-
)
695-
.unwrap();
696-
self.buffer.push_str(&rewrite);
697-
let last = attrs.last().unwrap();
698-
self.last_pos = source!(self, last.span).hi;
687+
let rewrite = attrs.rewrite(
688+
&self.get_context(),
689+
Shape::indented(self.block_indent, self.config),
690+
);
691+
let span = mk_sp(attrs[0].span.lo, attrs[attrs.len() - 1].span.hi);
692+
self.push_rewrite(span, rewrite);
693+
699694
false
700695
}
701696

tests/source/attrib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// rustfmt-wrap_comments: true
22
// Test attributes and doc comments are preserved.
33

4+
#[invalid attribute]
5+
fn foo() {}
6+
47
/// Blah blah blah.
58
/// Blah blah blah.
69
/// Blah blah blah.

tests/target/attrib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// rustfmt-wrap_comments: true
22
// Test attributes and doc comments are preserved.
33

4+
#[invalid attribute]
5+
fn foo() {}
6+
47
/// Blah blah blah.
58
/// Blah blah blah.
69
/// Blah blah blah.

0 commit comments

Comments
 (0)