mirror of
https://github.com/Noratrieb/cargo-minimize.git
synced 2026-01-14 16:35:01 +01:00
more
This commit is contained in:
parent
9243224163
commit
02b8eaa7b2
5 changed files with 30 additions and 9 deletions
|
|
@ -1,3 +1,5 @@
|
|||
#![feature(non_exhaustive_omitted_patterns_lint)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate tracing;
|
||||
|
||||
|
|
@ -32,7 +34,7 @@ pub enum Cargo {
|
|||
Minimize(Options),
|
||||
}
|
||||
|
||||
#[derive(clap::Args, Debug)]
|
||||
#[derive(clap::Args, Debug, Clone)]
|
||||
pub struct Options {
|
||||
/// Additional arguments to pass to cargo/rustc, separated by whitespace.
|
||||
#[arg(long)]
|
||||
|
|
@ -99,6 +101,9 @@ pub struct Options {
|
|||
/// Do not touch the following files.
|
||||
#[arg(long)]
|
||||
pub ignore_file: Vec<PathBuf>,
|
||||
|
||||
#[arg(skip)]
|
||||
pub no_delete_functions: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
@ -177,6 +182,7 @@ impl Default for Options {
|
|||
script_path: None,
|
||||
script_path_lints: None,
|
||||
ignore_file: Vec::new(),
|
||||
no_delete_functions: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use quote::ToTokens;
|
||||
use syn::{
|
||||
visit_mut::VisitMut, Item, ItemConst, ItemEnum, ItemMacro, ItemMacro2, ItemMod, ItemStatic,
|
||||
ItemStruct, ItemTrait, ItemType, ItemUnion,
|
||||
visit_mut::VisitMut, Item, ItemConst, ItemEnum, ItemExternCrate, ItemFn, ItemMacro, ItemMacro2,
|
||||
ItemMod, ItemStatic, ItemStruct, ItemTrait, ItemTraitAlias, ItemType, ItemUnion, Signature,
|
||||
};
|
||||
|
||||
use crate::processor::{tracking, Pass, PassController, ProcessState, SourceFile};
|
||||
|
|
@ -31,8 +31,6 @@ impl<'a> Visitor<'a> {
|
|||
|
||||
fn consider_deleting_item(&mut self, item: &Item) -> bool {
|
||||
match item {
|
||||
// N.B. Do not delete ItemFn because that makes testing way harder
|
||||
// and also the dead_lint should cover it all.
|
||||
Item::Impl(impl_) => {
|
||||
self.current_path
|
||||
.push(impl_.self_ty.clone().into_token_stream().to_string());
|
||||
|
|
@ -42,18 +40,25 @@ impl<'a> Visitor<'a> {
|
|||
self.current_path.pop();
|
||||
should_retain
|
||||
}
|
||||
Item::Struct(ItemStruct { ident, .. })
|
||||
Item::Fn(_) if self.checker.options.no_delete_functions => true,
|
||||
Item::Fn(ItemFn {
|
||||
sig: Signature { ident, .. },
|
||||
..
|
||||
})
|
||||
| Item::Struct(ItemStruct { ident, .. })
|
||||
| Item::Enum(ItemEnum { ident, .. })
|
||||
| Item::Union(ItemUnion { ident, .. })
|
||||
| Item::Const(ItemConst { ident, .. })
|
||||
| Item::Type(ItemType { ident, .. })
|
||||
| Item::Trait(ItemTrait { ident, .. })
|
||||
| Item::TraitAlias(ItemTraitAlias { ident, .. })
|
||||
| Item::Macro(ItemMacro {
|
||||
ident: Some(ident), ..
|
||||
})
|
||||
| Item::Macro2(ItemMacro2 { ident, .. })
|
||||
| Item::Static(ItemStatic { ident, .. })
|
||||
| Item::Mod(ItemMod { ident, .. }) => {
|
||||
| Item::Mod(ItemMod { ident, .. })
|
||||
| Item::ExternCrate(ItemExternCrate { ident, .. }) => {
|
||||
self.current_path.push(ident.to_string());
|
||||
|
||||
let should_retain = self.should_retain_item();
|
||||
|
|
@ -61,6 +66,11 @@ impl<'a> Visitor<'a> {
|
|||
self.current_path.pop();
|
||||
should_retain
|
||||
}
|
||||
Item::ForeignMod(_) => true,
|
||||
// We hope for the unused imports to show them all.
|
||||
Item::Use(_) => true,
|
||||
Item::Verbatim(_) => true,
|
||||
#[deny(non_exhaustive_omitted_patterns)]
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
use std::{borrow::Borrow, collections::BTreeSet, fmt::Debug, mem};
|
||||
|
||||
use crate::Options;
|
||||
|
||||
use self::worklist::Worklist;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
|
|
@ -20,6 +22,7 @@ impl Debug for AstPath {
|
|||
#[derive(Debug)]
|
||||
pub(crate) struct PassController {
|
||||
state: PassControllerState,
|
||||
pub(crate) options: Options,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
@ -86,11 +89,12 @@ fn split_owned<T, From: IntoIterator<Item = T>, A: FromIterator<T>, B: FromItera
|
|||
}
|
||||
|
||||
impl PassController {
|
||||
pub fn new() -> Self {
|
||||
pub fn new(options: Options) -> Self {
|
||||
Self {
|
||||
state: PassControllerState::InitialCollection {
|
||||
candidates: Vec::new(),
|
||||
},
|
||||
options,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ impl Minimizer {
|
|||
invalidated_files: &mut HashSet<&'file SourceFile>,
|
||||
changes: &mut Changes,
|
||||
) -> Result<()> {
|
||||
let mut checker = PassController::new();
|
||||
let mut checker = PassController::new(self.options.clone());
|
||||
loop {
|
||||
let file_display = file.path.display();
|
||||
let mut change = file.try_change(changes)?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue