Skip to content

Commit

Permalink
Handle #![rustfmt_skip] in block statements
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-mcallister committed Oct 20, 2017
1 parent 108e2cd commit 1853d02
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 75 deletions.
13 changes: 11 additions & 2 deletions src/visitor.rs
Expand Up @@ -150,8 +150,17 @@ impl<'a> FmtVisitor<'a> {
}

// Format inner attributes if available.
if let Some(attrs) = inner_attrs {
self.visit_attrs(attrs, ast::AttrStyle::Inner);
let skip_rewrite = if let Some(attrs) = inner_attrs {
self.visit_attrs(attrs, ast::AttrStyle::Inner)
} else {
false
};

if skip_rewrite {
self.push_rewrite(b.span, None);
self.close_block(false);
self.last_pos = source!(self, b.span).hi();
return;
}

self.walk_block_stmts(b);
Expand Down
73 changes: 0 additions & 73 deletions tests/source/skip.rs

This file was deleted.

14 changes: 14 additions & 0 deletions tests/target/skip.rs
Expand Up @@ -31,6 +31,20 @@ fn issue1346() {
}

fn skip_on_statements() {
// Outside block
#[rustfmt_skip]
{
foo; bar;
// junk
}

{
// Inside block
#![rustfmt_skip]
foo; bar;
// junk
}

// Semi
#[cfg_attr(rustfmt, rustfmt_skip)]
foo(
Expand Down

0 comments on commit 1853d02

Please sign in to comment.