mirror of
https://github.com/Noratrieb/cargo-minimize.git
synced 2026-01-14 16:35:01 +01:00
edition 2024 format
This commit is contained in:
parent
b7019e1e43
commit
45a5fda1a3
12 changed files with 42 additions and 38 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
use anyhow::{bail, ensure, Context, Result};
|
use anyhow::{Context, Result, bail, ensure};
|
||||||
use rustfix::diagnostics::Diagnostic;
|
use rustfix::diagnostics::Diagnostic;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::{
|
use std::{
|
||||||
|
|
@ -10,7 +10,7 @@ use std::{
|
||||||
rc::Rc,
|
rc::Rc,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{dylib_flag::RustFunction, EnvVar, Options};
|
use crate::{EnvVar, Options, dylib_flag::RustFunction};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Build {
|
pub struct Build {
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,18 @@
|
||||||
// this code is pretty neat i guess but i dont have a use for it right now
|
// this code is pretty neat i guess but i dont have a use for it right now
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
use anyhow::{bail, Context, Result};
|
use anyhow::{Context, Result, bail};
|
||||||
use cargo::{
|
use cargo::{
|
||||||
core::{
|
core::{
|
||||||
|
Workspace,
|
||||||
compiler::{BuildContext, Unit, UnitInterner},
|
compiler::{BuildContext, Unit, UnitInterner},
|
||||||
manifest::TargetSourcePath,
|
manifest::TargetSourcePath,
|
||||||
Workspace,
|
|
||||||
},
|
},
|
||||||
ops::{self, CompileOptions},
|
ops::{self, CompileOptions},
|
||||||
util::{command_prelude::CompileMode, Config},
|
util::{Config, command_prelude::CompileMode},
|
||||||
};
|
};
|
||||||
use std::{collections::BTreeSet, fmt::Debug, ops::Not, path::Path, process::Command};
|
use std::{collections::BTreeSet, fmt::Debug, ops::Not, path::Path, process::Command};
|
||||||
use syn::{visit_mut::VisitMut, File, Item, ItemExternCrate, ItemMod, ItemUse, Visibility};
|
use syn::{File, Item, ItemExternCrate, ItemMod, ItemUse, Visibility, visit_mut::VisitMut};
|
||||||
|
|
||||||
fn cargo_expand(cargo_dir: &TargetSourcePath) -> Result<syn::File> {
|
fn cargo_expand(cargo_dir: &TargetSourcePath) -> Result<syn::File> {
|
||||||
let cargo_dir = cargo_dir
|
let cargo_dir = cargo_dir
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ extern crate tracing;
|
||||||
use std::{
|
use std::{
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
str::FromStr,
|
str::FromStr,
|
||||||
sync::{atomic::AtomicBool, Arc},
|
sync::{Arc, atomic::AtomicBool},
|
||||||
};
|
};
|
||||||
|
|
||||||
mod build;
|
mod build;
|
||||||
|
|
@ -23,7 +23,7 @@ use anyhow::{Context, Result};
|
||||||
use dylib_flag::RustFunction;
|
use dylib_flag::RustFunction;
|
||||||
use processor::{Minimizer, PassSelection};
|
use processor::{Minimizer, PassSelection};
|
||||||
use tracing::Level;
|
use tracing::Level;
|
||||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Registry};
|
use tracing_subscriber::{EnvFilter, Registry, layer::SubscriberExt, util::SubscriberInitExt};
|
||||||
|
|
||||||
use crate::processor::Pass;
|
use crate::processor::Pass;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@
|
||||||
extern crate tracing;
|
extern crate tracing;
|
||||||
|
|
||||||
use std::sync::{
|
use std::sync::{
|
||||||
atomic::{AtomicBool, Ordering},
|
|
||||||
Arc,
|
Arc,
|
||||||
|
atomic::{AtomicBool, Ordering},
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use cargo_minimize::{Cargo, Parser};
|
use cargo_minimize::{Cargo, Parser};
|
||||||
use tracing::{error, Level};
|
use tracing::{Level, error};
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
let Cargo::Minimize(options) = Cargo::parse();
|
let Cargo::Minimize(options) = Cargo::parse();
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use quote::ToTokens;
|
use quote::ToTokens;
|
||||||
use syn::{parse_quote, visit_mut::VisitMut};
|
use syn::{parse_quote, visit_mut::VisitMut};
|
||||||
|
|
||||||
use crate::processor::{tracking, Pass, PassController, ProcessState, SourceFile};
|
use crate::processor::{Pass, PassController, ProcessState, SourceFile, tracking};
|
||||||
|
|
||||||
struct Visitor<'a> {
|
struct Visitor<'a> {
|
||||||
current_path: Vec<String>,
|
current_path: Vec<String>,
|
||||||
|
|
@ -25,9 +25,11 @@ impl<'a> Visitor<'a> {
|
||||||
impl VisitMut for Visitor<'_> {
|
impl VisitMut for Visitor<'_> {
|
||||||
fn visit_block_mut(&mut self, block: &mut syn::Block) {
|
fn visit_block_mut(&mut self, block: &mut syn::Block) {
|
||||||
match block.stmts.as_slice() {
|
match block.stmts.as_slice() {
|
||||||
[syn::Stmt::Expr(syn::Expr::Loop(syn::ExprLoop {
|
[
|
||||||
body: loop_body, ..
|
syn::Stmt::Expr(syn::Expr::Loop(syn::ExprLoop {
|
||||||
}))] if loop_body.stmts.is_empty() => {}
|
body: loop_body, ..
|
||||||
|
})),
|
||||||
|
] if loop_body.stmts.is_empty() => {}
|
||||||
// Empty bodies are empty already, no need to loopify them.
|
// Empty bodies are empty already, no need to loopify them.
|
||||||
[] => {}
|
[] => {}
|
||||||
_ if self.checker.can_process(&self.current_path) => {
|
_ if self.checker.can_process(&self.current_path) => {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use quote::ToTokens;
|
use quote::ToTokens;
|
||||||
use syn::{visit_mut::VisitMut, Fields};
|
use syn::{Fields, visit_mut::VisitMut};
|
||||||
|
|
||||||
use crate::processor::{tracking, Pass, PassController, ProcessState, SourceFile};
|
use crate::processor::{Pass, PassController, ProcessState, SourceFile, tracking};
|
||||||
|
|
||||||
struct Visitor<'a> {
|
struct Visitor<'a> {
|
||||||
current_path: Vec<String>,
|
current_path: Vec<String>,
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
use quote::ToTokens;
|
use quote::ToTokens;
|
||||||
use syn::{
|
use syn::{
|
||||||
visit_mut::VisitMut, Item, ItemConst, ItemEnum, ItemExternCrate, ItemFn, ItemMacro, ItemMacro2,
|
Item, ItemConst, ItemEnum, ItemExternCrate, ItemFn, ItemMacro, ItemMacro2, ItemMod, ItemStatic,
|
||||||
ItemMod, ItemStatic, ItemStruct, ItemTrait, ItemTraitAlias, ItemType, ItemUnion, ItemUse,
|
ItemStruct, ItemTrait, ItemTraitAlias, ItemType, ItemUnion, ItemUse, Signature,
|
||||||
Signature,
|
visit_mut::VisitMut,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::processor::{tracking, Pass, PassController, ProcessState, SourceFile};
|
use crate::processor::{Pass, PassController, ProcessState, SourceFile, tracking};
|
||||||
|
|
||||||
struct Visitor<'a> {
|
struct Visitor<'a> {
|
||||||
current_path: Vec<String>,
|
current_path: Vec<String>,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use quote::ToTokens;
|
use quote::ToTokens;
|
||||||
use syn::{parse_quote, visit_mut::VisitMut, Visibility};
|
use syn::{Visibility, parse_quote, visit_mut::VisitMut};
|
||||||
|
|
||||||
use crate::processor::{tracking, Pass, PassController, ProcessState, SourceFile};
|
use crate::processor::{Pass, PassController, ProcessState, SourceFile, tracking};
|
||||||
|
|
||||||
struct Visitor<'a> {
|
struct Visitor<'a> {
|
||||||
pub_crate: Visibility,
|
pub_crate: Visibility,
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
use std::ops::DerefMut;
|
use std::ops::DerefMut;
|
||||||
|
|
||||||
use crate::processor::{tracking, Pass, PassController, ProcessState, SourceFile};
|
use crate::processor::{Pass, PassController, ProcessState, SourceFile, tracking};
|
||||||
use quote::ToTokens;
|
use quote::ToTokens;
|
||||||
|
|
||||||
use syn::{visit_mut::VisitMut, Item, ItemUse, UseName, UsePath, UseRename, UseTree};
|
use syn::{Item, ItemUse, UseName, UsePath, UseRename, UseTree, visit_mut::VisitMut};
|
||||||
|
|
||||||
struct Visitor<'a> {
|
struct Visitor<'a> {
|
||||||
process_state: ProcessState,
|
process_state: ProcessState,
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,9 @@ impl PassController {
|
||||||
pub fn does_not_reproduce(&mut self) {
|
pub fn does_not_reproduce(&mut self) {
|
||||||
match &mut self.state {
|
match &mut self.state {
|
||||||
PassControllerState::InitialCollection { candidates: _ } => {
|
PassControllerState::InitialCollection { candidates: _ } => {
|
||||||
unreachable!("we should have made no changes on initial collection, what do you mean it does not reproduce?!?")
|
unreachable!(
|
||||||
|
"we should have made no changes on initial collection, what do you mean it does not reproduce?!?"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
PassControllerState::Bisecting {
|
PassControllerState::Bisecting {
|
||||||
committed,
|
committed,
|
||||||
|
|
@ -194,7 +196,9 @@ impl PassController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PassControllerState::Bisecting { current, .. } => {
|
PassControllerState::Bisecting { current, .. } => {
|
||||||
unreachable!("Pass said it didn't change anything in the bisection phase, nora forgot what this means: {current:?}");
|
unreachable!(
|
||||||
|
"Pass said it didn't change anything in the bisection phase, nora forgot what this means: {current:?}"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
PassControllerState::Success { .. } => {}
|
PassControllerState::Success { .. } => {}
|
||||||
}
|
}
|
||||||
|
|
@ -247,11 +251,7 @@ impl PassController {
|
||||||
pub const fn div_ceil(lhs: usize, rhs: usize) -> usize {
|
pub const fn div_ceil(lhs: usize, rhs: usize) -> usize {
|
||||||
let d = lhs / rhs;
|
let d = lhs / rhs;
|
||||||
let r = lhs % rhs;
|
let r = lhs % rhs;
|
||||||
if r > 0 && rhs > 0 {
|
if r > 0 && rhs > 0 { d + 1 } else { d }
|
||||||
d + 1
|
|
||||||
} else {
|
|
||||||
d
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Splits an owned container in half.
|
/// Splits an owned container in half.
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,11 @@ mod files;
|
||||||
mod reaper;
|
mod reaper;
|
||||||
|
|
||||||
pub(crate) use self::files::SourceFile;
|
pub(crate) use self::files::SourceFile;
|
||||||
use crate::{build::Build, processor::files::Changes, Options};
|
use crate::{Options, build::Build, processor::files::Changes};
|
||||||
use anyhow::{bail, Context, Result};
|
use anyhow::{Context, Result, bail};
|
||||||
use owo_colors::OwoColorize;
|
use owo_colors::OwoColorize;
|
||||||
use std::sync::atomic::Ordering;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::sync::atomic::Ordering;
|
||||||
use std::{collections::HashSet, ffi::OsStr, fmt::Debug, sync::atomic::AtomicBool};
|
use std::{collections::HashSet, ffi::OsStr, fmt::Debug, sync::atomic::AtomicBool};
|
||||||
|
|
||||||
pub(crate) use self::checker::PassController;
|
pub(crate) use self::checker::PassController;
|
||||||
|
|
@ -61,7 +61,9 @@ impl std::str::FromStr for PassSelection {
|
||||||
let values = s.split(',').collect::<Vec<_>>();
|
let values = s.split(',').collect::<Vec<_>>();
|
||||||
let have_negative = values.iter().any(|v| v.starts_with("no-"));
|
let have_negative = values.iter().any(|v| v.starts_with("no-"));
|
||||||
if have_negative && !values.iter().all(|v| v.starts_with("no-")) {
|
if have_negative && !values.iter().all(|v| v.starts_with("no-")) {
|
||||||
return Err("Pass exclusion is supported, by mixing positive pass selection with negative is not allowed (because it's pointless and confusing)");
|
return Err(
|
||||||
|
"Pass exclusion is supported, by mixing positive pass selection with negative is not allowed (because it's pointless and confusing)",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
let actual_values = values
|
let actual_values = values
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@
|
||||||
|
|
||||||
use crate::build::Build;
|
use crate::build::Build;
|
||||||
|
|
||||||
use super::{files::Changes, tracking, Minimizer, Pass, PassController, ProcessState, SourceFile};
|
use super::{Minimizer, Pass, PassController, ProcessState, SourceFile, files::Changes, tracking};
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use proc_macro2::Span;
|
use proc_macro2::Span;
|
||||||
use quote::ToTokens;
|
use quote::ToTokens;
|
||||||
use rustfix::{diagnostics::Diagnostic, Suggestion};
|
use rustfix::{Suggestion, diagnostics::Diagnostic};
|
||||||
use std::{collections::HashMap, ops::Range, path::Path};
|
use std::{collections::HashMap, ops::Range, path::Path};
|
||||||
use syn::{visit_mut::VisitMut, ImplItem, Item};
|
use syn::{ImplItem, Item, visit_mut::VisitMut};
|
||||||
|
|
||||||
fn file_for_suggestion(suggestion: &Suggestion) -> &Path {
|
fn file_for_suggestion(suggestion: &Suggestion) -> &Path {
|
||||||
Path::new(&suggestion.solutions[0].replacements[0].snippet.file_name)
|
Path::new(&suggestion.solutions[0].replacements[0].snippet.file_name)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue