mirror of
https://github.com/Noratrieb/cargo-minimize.git
synced 2026-01-14 16:35:01 +01:00
Clippy fixes
This commit is contained in:
parent
e1fd83b4d9
commit
92826697a3
6 changed files with 22 additions and 22 deletions
14
src/build.rs
14
src/build.rs
|
|
@ -64,7 +64,7 @@ impl Build {
|
|||
let mut cmd = Command::new("cargo");
|
||||
cmd.arg("build");
|
||||
|
||||
for arg in args.into_iter().flatten() {
|
||||
for arg in args.iter().flatten() {
|
||||
cmd.arg(arg);
|
||||
}
|
||||
|
||||
|
|
@ -129,7 +129,7 @@ impl Build {
|
|||
let mut cmd = Command::new("cargo");
|
||||
cmd.args(["build", "--message-format=json"]);
|
||||
|
||||
for arg in args.into_iter().flatten() {
|
||||
for arg in args.iter().flatten() {
|
||||
cmd.arg(arg);
|
||||
}
|
||||
|
||||
|
|
@ -138,19 +138,19 @@ impl Build {
|
|||
}
|
||||
|
||||
let cmd_output = cmd.output()?;
|
||||
let output = String::from_utf8(cmd_output.stdout.clone())?;
|
||||
let output = String::from_utf8(cmd_output.stdout)?;
|
||||
|
||||
let messages = serde_json::Deserializer::from_str(&output)
|
||||
.into_iter::<CargoJsonCompileMessage>()
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
let diags = messages
|
||||
|
||||
|
||||
messages
|
||||
.into_iter()
|
||||
.filter(|msg| msg.reason == "compiler-message")
|
||||
.flat_map(|msg| msg.message)
|
||||
.collect();
|
||||
|
||||
diags
|
||||
.collect()
|
||||
}
|
||||
BuildMode::Rustc => {
|
||||
let mut cmd = std::process::Command::new("rustc");
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ impl<'ws, 'cfg> DepExpander<'ws, 'cfg> {
|
|||
let name = unit.target.crate_name();
|
||||
|
||||
let ast =
|
||||
cargo_expand(unit.target.src_path()).context(format!("expanding crate `{}`", name))?;
|
||||
cargo_expand(unit.target.src_path()).context(format!("expanding crate `{name}`"))?;
|
||||
|
||||
let deps = self
|
||||
.bcx
|
||||
|
|
@ -230,10 +230,10 @@ impl VisitMut for MakePubCrateVisitor {
|
|||
|
||||
fn clean_items_general(items: &mut Vec<Item>) {
|
||||
items.retain(|item| match item {
|
||||
Item::ExternCrate(ItemExternCrate { ident, .. }) if ident.to_string() == "std" => false,
|
||||
Item::ExternCrate(ItemExternCrate { ident, .. }) if *ident == "std" => false,
|
||||
Item::Use(ItemUse { attrs, .. }) => attrs
|
||||
.get(0)
|
||||
.map(|attr| attr.path.segments[0].ident.to_string() != "prelude_import")
|
||||
.map(|attr| attr.path.segments[0].ident != "prelude_import")
|
||||
.unwrap_or(true),
|
||||
_ => true,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use anyhow::{Context, Result};
|
|||
use clap::Parser;
|
||||
use processor::Minimizer;
|
||||
|
||||
use crate::{everybody_loops::EverybodyLoops, privatize::Privatize, processor::Processor};
|
||||
use crate::{processor::Processor};
|
||||
|
||||
#[derive(clap::Parser)]
|
||||
#[command(version, about, name = "cargo", bin_name = "cargo")]
|
||||
|
|
@ -50,7 +50,7 @@ struct EnvVar {
|
|||
impl FromStr for EnvVar {
|
||||
type Err = &'static str;
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let mut split = s.split("=");
|
||||
let mut split = s.split('=');
|
||||
let key = split
|
||||
.next()
|
||||
.ok_or("env var must have KEY=VALUE format")?
|
||||
|
|
@ -71,8 +71,8 @@ pub fn minimize() -> Result<()> {
|
|||
let mut minimizer = Minimizer::new_glob_dir(&options.path, build);
|
||||
|
||||
minimizer.run_passes([
|
||||
Box::new(Privatize::default()) as Box<dyn Processor>,
|
||||
Box::new(EverybodyLoops::default()) as Box<dyn Processor>,
|
||||
Box::<privatize::Privatize>::default() as Box<dyn Processor>,
|
||||
Box::<everybody_loops::EverybodyLoops>::default() as Box<dyn Processor>,
|
||||
])?;
|
||||
|
||||
minimizer.delete_dead_code().context("deleting dead code")?;
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ impl FileChange<'_, '_> {
|
|||
|
||||
pub fn write(&mut self, new: &str) -> Result<()> {
|
||||
self.has_written_change = true;
|
||||
fs::write(&self.path, new).with_context(|| format!("writing file {}", self.path.display()))
|
||||
fs::write(self.path, new).with_context(|| format!("writing file {}", self.path.display()))
|
||||
}
|
||||
|
||||
pub fn rollback(mut self) -> Result<()> {
|
||||
|
|
@ -48,7 +48,7 @@ impl FileChange<'_, '_> {
|
|||
impl Drop for FileChange<'_, '_> {
|
||||
fn drop(&mut self) {
|
||||
if self.has_written_change {
|
||||
fs::write(&self.path, self.before_content()).ok();
|
||||
fs::write(self.path, self.before_content()).ok();
|
||||
if !std::thread::panicking() {
|
||||
panic!("File contains unsaved changes!");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ impl Minimizer {
|
|||
passes: impl IntoIterator<Item = Box<dyn Processor + 'a>>,
|
||||
) -> Result<()> {
|
||||
let inital_build = self.build.build()?;
|
||||
println!("Initial build: {}", inital_build);
|
||||
println!("Initial build: {inital_build}");
|
||||
inital_build.require_reproduction("Initial")?;
|
||||
|
||||
for mut pass in passes {
|
||||
|
|
@ -106,7 +106,7 @@ impl Minimizer {
|
|||
}
|
||||
|
||||
if !changes.had_changes() {
|
||||
if !refresh_and_try_again && invalidated_files.len() > 0 {
|
||||
if !refresh_and_try_again && !invalidated_files.is_empty() {
|
||||
// A few files have been invalidated, let's refresh and try these again.
|
||||
pass.refresh_state().context("refreshing state for pass")?;
|
||||
invalidated_files.clear();
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ fn file_for_suggestion(suggestion: &Suggestion) -> &str {
|
|||
impl Minimizer {
|
||||
pub fn delete_dead_code(&mut self) -> Result<()> {
|
||||
let inital_build = self.build.build()?;
|
||||
println!("Before reaper: {}", inital_build);
|
||||
println!("Before reaper: {inital_build}");
|
||||
|
||||
inital_build.require_reproduction("Initial")?;
|
||||
|
||||
|
|
@ -51,7 +51,7 @@ impl Minimizer {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn apply_unused_imports<'a>(
|
||||
fn apply_unused_imports(
|
||||
&mut self,
|
||||
suggestions: &HashMap<&str, Vec<&Suggestion>>,
|
||||
) -> Result<()> {
|
||||
|
|
@ -63,9 +63,9 @@ impl Minimizer {
|
|||
continue;
|
||||
};
|
||||
|
||||
let mut changes = &mut Changes::default();
|
||||
let changes = &mut Changes::default();
|
||||
|
||||
let mut change = file.try_change(&mut changes)?;
|
||||
let mut change = file.try_change(changes)?;
|
||||
|
||||
let desired_suggestions = suggestions
|
||||
.iter()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue