From 6d4331b16bffc37f01638b78fac63d32f6cab572 Mon Sep 17 00:00:00 2001 From: moxian Date: Sun, 30 Mar 2025 22:37:54 -0700 Subject: [PATCH] Allow bisecting privatizer use changes Currently all the use items have the same AstPath, which means that privatizer tries to change all of them at once. Which means that if *any* of them can't get privated, then *all* of them stay unprivated, with all the consequences.. --- src/passes/privatize.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/passes/privatize.rs b/src/passes/privatize.rs index c2aa30d..749237f 100644 --- a/src/passes/privatize.rs +++ b/src/passes/privatize.rs @@ -24,12 +24,32 @@ impl<'a> Visitor<'a> { impl VisitMut for Visitor<'_> { fn visit_visibility_mut(&mut self, vis: &mut Visibility) { if let Visibility::Public(_) = vis { + self.current_path.push("{{vis}}".to_string()); if self.checker.can_process(&self.current_path) { self.process_state = ProcessState::Changed; *vis = self.pub_crate.clone(); } + self.current_path.pop(); } } + fn visit_item_mut(&mut self, item: &mut syn::Item) { + match item { + syn::Item::Use(u) => { + if let Visibility::Public(_) = u.vis { + let mut path = self.current_path.clone(); + path.push(u.to_token_stream().to_string()); + if self.checker.can_process(&path) { + self.process_state = ProcessState::Changed; + u.vis = self.pub_crate.clone(); + } + path.pop(); + } + return; // early return; do not walk the child items + } + _ => {} + } + syn::visit_mut::visit_item_mut(self, item); + } tracking!(); }