mirror of
https://github.com/Noratrieb/cargo-minimize.git
synced 2026-01-17 09:45:01 +01:00
Compare commits
No commits in common. "060b4afb17366b3ccfebf477022522693eedba28" and "887aade4217245cb9c12051743b644543611ad3f" have entirely different histories.
060b4afb17
...
887aade421
8 changed files with 167 additions and 537 deletions
665
Cargo.lock
generated
665
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -23,7 +23,8 @@ opt-level = 1
|
|||
anyhow = "1.0.65"
|
||||
clap = { version = "4.0.29", features = ["derive"] }
|
||||
ctrlc = "3.2.5"
|
||||
genemichaels = { package = "genemichaels-lib", version = "0.7.2" }
|
||||
genemichaels = "0.1.21"
|
||||
markdown = { version = "=1.0.0-alpha.14" } # pinning the version to ensure genemichaels builds.
|
||||
libloading = "0.8.0"
|
||||
owo-colors = "3.5.0"
|
||||
proc-macro2 = { version = "1.0.48", features = ["span-locations"] }
|
||||
|
|
@ -31,7 +32,7 @@ quote = "1.0.23"
|
|||
rustfix = "0.6.1"
|
||||
serde = { version = "1.0.151", features = ["derive"] }
|
||||
serde_json = "1.0.90"
|
||||
syn = { version = "2.0.101", features = ["full", "visit-mut"] }
|
||||
syn = { version = "1.0.101", features = ["full", "visit-mut"] }
|
||||
tempfile = "3.3.0"
|
||||
tracing = "0.1.37"
|
||||
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use anyhow::Context;
|
||||
use genemichaels::FormatConfig;
|
||||
|
||||
pub fn format(file: syn::File) -> anyhow::Result<String> {
|
||||
Ok(
|
||||
genemichaels::format_ast(file, &FormatConfig::default(), HashMap::new())
|
||||
.map_err(|e| anyhow::format_err!("formatting source file: {:?}", e))?
|
||||
.context("formatting source file")?
|
||||
.rendered,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,12 +26,9 @@ impl VisitMut for Visitor<'_> {
|
|||
fn visit_block_mut(&mut self, block: &mut syn::Block) {
|
||||
match block.stmts.as_slice() {
|
||||
[
|
||||
syn::Stmt::Expr(
|
||||
syn::Expr::Loop(syn::ExprLoop {
|
||||
body: loop_body, ..
|
||||
}),
|
||||
_semi,
|
||||
),
|
||||
syn::Stmt::Expr(syn::Expr::Loop(syn::ExprLoop {
|
||||
body: loop_body, ..
|
||||
})),
|
||||
] if loop_body.stmts.is_empty() => {}
|
||||
// Empty bodies are empty already, no need to loopify them.
|
||||
[] => {}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
use quote::ToTokens;
|
||||
use syn::{
|
||||
Item, ItemConst, ItemEnum, ItemExternCrate, ItemFn, ItemMacro, ItemMod, ItemStatic, ItemStruct,
|
||||
ItemTrait, ItemTraitAlias, ItemType, ItemUnion, ItemUse, Signature, visit_mut::VisitMut,
|
||||
Item, ItemConst, ItemEnum, ItemExternCrate, ItemFn, ItemMacro, ItemMacro2, ItemMod, ItemStatic,
|
||||
ItemStruct, ItemTrait, ItemTraitAlias, ItemType, ItemUnion, ItemUse, Signature,
|
||||
visit_mut::VisitMut,
|
||||
};
|
||||
|
||||
use crate::processor::{Pass, PassController, ProcessState, SourceFile, tracking};
|
||||
|
|
@ -62,6 +63,7 @@ impl<'a> Visitor<'a> {
|
|||
| Item::Macro(ItemMacro {
|
||||
ident: Some(ident), ..
|
||||
})
|
||||
| Item::Macro2(ItemMacro2 { ident, .. })
|
||||
| Item::Static(ItemStatic { ident, .. })
|
||||
| Item::Mod(ItemMod { ident, .. })
|
||||
| Item::ExternCrate(ItemExternCrate { ident, .. }) => {
|
||||
|
|
@ -109,7 +111,7 @@ impl VisitMut for Visitor<'_> {
|
|||
}
|
||||
|
||||
tracking!(visit_item_fn_mut);
|
||||
tracking!(visit_impl_item_fn_mut);
|
||||
tracking!(visit_impl_item_method_mut);
|
||||
tracking!(visit_item_impl_mut);
|
||||
tracking!(visit_field_mut);
|
||||
tracking!(visit_item_struct_mut);
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ impl VisitMut for Visitor<'_> {
|
|||
}
|
||||
|
||||
tracking!(visit_item_fn_mut);
|
||||
tracking!(visit_impl_item_fn_mut);
|
||||
tracking!(visit_impl_item_method_mut);
|
||||
tracking!(visit_item_impl_mut);
|
||||
tracking!(visit_field_mut);
|
||||
tracking!(visit_item_struct_mut);
|
||||
|
|
|
|||
|
|
@ -268,7 +268,7 @@ impl Minimizer {
|
|||
macro_rules! tracking {
|
||||
() => {
|
||||
tracking!(visit_item_fn_mut);
|
||||
tracking!(visit_impl_item_fn_mut);
|
||||
tracking!(visit_impl_item_method_mut);
|
||||
tracking!(visit_item_impl_mut);
|
||||
tracking!(visit_item_mod_mut);
|
||||
tracking!(visit_field_mut);
|
||||
|
|
@ -282,10 +282,10 @@ macro_rules! tracking {
|
|||
self.current_path.pop();
|
||||
}
|
||||
};
|
||||
(visit_impl_item_fn_mut) => {
|
||||
fn visit_impl_item_fn_mut(&mut self, method: &mut syn::ImplItemFn) {
|
||||
(visit_impl_item_method_mut) => {
|
||||
fn visit_impl_item_method_mut(&mut self, method: &mut syn::ImplItemMethod) {
|
||||
self.current_path.push(method.sig.ident.to_string());
|
||||
syn::visit_mut::visit_impl_item_fn_mut(self, method);
|
||||
syn::visit_mut::visit_impl_item_method_mut(self, method);
|
||||
self.current_path.pop();
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -244,7 +244,7 @@ impl VisitMut for FindUnusedFunction<'_> {
|
|||
.push(item_impl.self_ty.clone().into_token_stream().to_string());
|
||||
|
||||
item_impl.items.retain(|item| match item {
|
||||
ImplItem::Fn(method) => {
|
||||
ImplItem::Method(method) => {
|
||||
self.current_path.push(method.sig.ident.to_string());
|
||||
|
||||
let span = method.sig.ident.span();
|
||||
|
|
@ -303,7 +303,7 @@ impl VisitMut for FindUnusedFunction<'_> {
|
|||
}
|
||||
|
||||
tracking!(visit_item_fn_mut);
|
||||
tracking!(visit_impl_item_fn_mut);
|
||||
tracking!(visit_impl_item_method_mut);
|
||||
tracking!(visit_field_mut);
|
||||
tracking!(visit_item_struct_mut);
|
||||
tracking!(visit_item_trait_mut);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue