Skip to content

Do not panic against files with invalid attributes #1888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions src/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
.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
}

Expand Down
3 changes: 3 additions & 0 deletions tests/source/attrib.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 3 additions & 0 deletions tests/target/attrib.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down