From dae63e98ce0c5d4f40c4c350e58e813057e88213 Mon Sep 17 00:00:00 2001 From: topecongiro Date: Fri, 7 Jun 2019 14:55:41 +0900 Subject: [PATCH 1/2] Ignore sub-modules when skip-children is used --- src/formatting.rs | 2 +- src/modules.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index 47d885ef2e3..06bffd4dad8 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -105,7 +105,7 @@ fn format_project( 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))?; diff --git a/src/modules.rs b/src/modules.rs index 3d009b2098b..f8496b9566a 100644 --- a/src/modules.rs +++ b/src/modules.rs @@ -17,7 +17,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)] @@ -31,7 +31,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 { @@ -40,7 +40,7 @@ pub(crate) fn new( }, file_map: BTreeMap::new(), source_map, - is_input_stdin, + recursive, } } @@ -56,7 +56,7 @@ pub(crate) fn visit_crate(mut self, krate: &'a ast::Crate) -> Result Date: Sat, 8 Jun 2019 14:52:49 +0900 Subject: [PATCH 2/2] Add a test for #3493 --- tests/source/configs/skip_children/true.rs | 1 + tests/target/configs/skip_children/true.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/source/configs/skip_children/true.rs b/tests/source/configs/skip_children/true.rs index cb2b6fce2d2..e51889dd4c9 100644 --- a/tests/source/configs/skip_children/true.rs +++ b/tests/source/configs/skip_children/true.rs @@ -1,3 +1,4 @@ // rustfmt-skip_children: true mod foo ; +mod void; diff --git a/tests/target/configs/skip_children/true.rs b/tests/target/configs/skip_children/true.rs index 3ea9f46fdf2..33fd782b4fa 100644 --- a/tests/target/configs/skip_children/true.rs +++ b/tests/target/configs/skip_children/true.rs @@ -1,3 +1,4 @@ // rustfmt-skip_children: true mod foo; +mod void;