Skip to content

Commit d6bb2e1

Browse files
committed
Do not touch module with #![rustfmt::skip]
1 parent 8fb4fa5 commit d6bb2e1

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/formatting.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use std::time::{Duration, Instant};
44

5-
use rustc_ast::ast;
5+
use rustc_ast::{ast, attr::HasAttrs};
66
use rustc_span::symbol;
77

88
pub(crate) use syntux::session::ParseSess;
@@ -14,7 +14,7 @@ use crate::formatting::{
1414
newline_style::apply_newline_style,
1515
report::NonFormattedRange,
1616
syntux::parser::{DirectoryOwnership, Parser, ParserError},
17-
utils::count_newlines,
17+
utils::{contains_skip, count_newlines},
1818
visitor::FmtVisitor,
1919
};
2020
use crate::{
@@ -129,6 +129,10 @@ fn format_project(
129129
if (!operation_setting.recursive && path != &main_file) || should_ignore {
130130
continue;
131131
}
132+
if contains_skip(module.attrs()) {
133+
continue;
134+
}
135+
132136
should_emit_verbose(input_is_stdin, operation_setting.verbosity, || {
133137
println!("Formatting {}", path)
134138
});

src/formatting/visitor.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -959,12 +959,14 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
959959

960960
pub(crate) fn format_separate_mod(&mut self, m: &Module<'_>, end_pos: BytePos) {
961961
self.block_indent = Indent::empty();
962-
if self.visit_attrs(m.attrs(), ast::AttrStyle::Inner) {
963-
self.push_skipped_with_span(m.attrs(), m.as_ref().inner, m.as_ref().inner);
964-
} else {
965-
self.walk_mod_items(m.as_ref());
966-
self.format_missing_with_indent(end_pos);
967-
}
962+
let skipped = self.visit_attrs(m.attrs(), ast::AttrStyle::Inner);
963+
assert!(
964+
!skipped,
965+
"Skipping module must be handled before reaching this line.",
966+
);
967+
968+
self.walk_mod_items(m.as_ref());
969+
self.format_missing_with_indent(end_pos);
968970
}
969971

970972
pub(crate) fn skip_empty_lines(&mut self, end_pos: BytePos) {

0 commit comments

Comments
 (0)