mirror of
https://github.com/Noratrieb/cargo-minimize.git
synced 2026-01-14 08:25:01 +01:00
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..
This commit is contained in:
parent
78a3cec9d6
commit
7e3dc837a4
1 changed files with 20 additions and 0 deletions
|
|
@ -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!();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue