From ba936766c6182fa5bb15c85243d070b326b690dc Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Mon, 23 Nov 2015 09:20:53 +1300 Subject: [PATCH] Take rustfmt_skip attribute into account on modules Closes #632 --- src/visitor.rs | 21 +++++++++++---------- tests/source/multiple.rs | 7 +++++++ tests/target/multiple.rs | 7 +++++++ 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/visitor.rs b/src/visitor.rs index 6448ccbabbc..6cbac8592dd 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -28,7 +28,7 @@ pub struct FmtVisitor<'a> { pub codemap: &'a CodeMap, pub buffer: StringBuffer, pub last_pos: BytePos, - // TODO: RAII util for indenting + // FIXME: use an RAII util or closure for indenting pub block_indent: Indent, pub config: &'a Config, pub write_mode: Option, @@ -99,7 +99,7 @@ impl<'a> FmtVisitor<'a> { } } - // TODO: we should compress any newlines here to just one + // FIXME: we should compress any newlines here to just one self.format_missing_with_indent(b.span.hi - brace_compensation); self.close_block(); self.last_pos = b.span.hi; @@ -178,12 +178,17 @@ impl<'a> FmtVisitor<'a> { } fn visit_item(&mut self, item: &ast::Item) { - // Don't look at attributes for modules. + // Don't look at attributes for modules (except for rustfmt_skip). // We want to avoid looking at attributes in another file, which the AST - // doesn't distinguish. FIXME This is overly conservative and means we miss - // attributes on inline modules. + // doesn't distinguish. + // FIXME This is overly conservative and means we miss attributes on + // inline modules. match item.node { - ast::Item_::ItemMod(_) => {} + ast::Item_::ItemMod(_) => { + if utils::contains_skip(&item.attrs) { + return; + } + } _ => { if self.visit_attrs(&item.attrs) { return; @@ -406,10 +411,6 @@ impl<'a> FmtVisitor<'a> { // Returns true if we should skip the following item. pub fn visit_attrs(&mut self, attrs: &[ast::Attribute]) -> bool { - if attrs.is_empty() { - return false; - } - if utils::contains_skip(attrs) { return true; } diff --git a/tests/source/multiple.rs b/tests/source/multiple.rs index 38d7d8ca941..863d20f50ea 100644 --- a/tests/source/multiple.rs +++ b/tests/source/multiple.rs @@ -123,3 +123,10 @@ fn deconstruct(foo: Bar) -> (SocketAddr, Method, Headers, RequestUri, HttpVersion, AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA) { } + +#[rustfmt_skip] +mod a{ +fn foo(x: T) { + let x: T = dfasdf; +} +} diff --git a/tests/target/multiple.rs b/tests/target/multiple.rs index 7b371409fba..e29bb259ece 100644 --- a/tests/target/multiple.rs +++ b/tests/target/multiple.rs @@ -158,3 +158,10 @@ fn deconstruct(foo: Bar) HttpVersion, AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA) { } + +#[rustfmt_skip] +mod a{ +fn foo(x: T) { + let x: T = dfasdf; +} +}