Merge pull request #3607 from topecongiro/issue-3493

Ignore sub-modules when skip-children is used
This commit is contained in:
Stéphane Campinas 2019-06-08 09:50:12 +02:00 committed by GitHub
commit 87565c42ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 5 deletions

View File

@ -101,7 +101,7 @@ fn format_project<T: FormatHandler>(
let files = modules::ModResolver::new(
context.parse_session.source_map(),
directory_ownership.unwrap_or(parse::DirectoryOwnership::UnownedViaMod(false)),
input_is_stdin,
!(input_is_stdin || config.skip_children()),
)
.visit_crate(&krate)
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;

View File

@ -18,7 +18,7 @@ pub(crate) struct ModResolver<'a, 'b> {
source_map: &'b source_map::SourceMap,
directory: Directory,
file_map: FileModMap<'a>,
is_input_stdin: bool,
recursive: bool,
}
#[derive(Clone)]
@ -32,7 +32,7 @@ impl<'a, 'b> ModResolver<'a, 'b> {
pub(crate) fn new(
source_map: &'b source_map::SourceMap,
directory_ownership: DirectoryOwnership,
is_input_stdin: bool,
recursive: bool,
) -> Self {
ModResolver {
directory: Directory {
@ -41,7 +41,7 @@ pub(crate) fn new(
},
file_map: BTreeMap::new(),
source_map,
is_input_stdin,
recursive,
}
}
@ -57,7 +57,7 @@ pub(crate) fn visit_crate(mut self, krate: &'a ast::Crate) -> Result<FileModMap<
};
// Skip visiting sub modules when the input is from stdin.
if !self.is_input_stdin {
if self.recursive {
self.visit_mod(&krate.module)?;
}

View File

@ -1,3 +1,4 @@
// rustfmt-skip_children: true
mod foo ;
mod void;

View File

@ -1,3 +1,4 @@
// rustfmt-skip_children: true
mod foo;
mod void;