timonpost / cargo-unused-features Goto Github PK
View Code? Open in Web Editor NEWFind potential unused enabled feature flags and prune them.
License: MIT License
Find potential unused enabled feature flags and prune them.
License: MIT License
Can you please tag releases in this repository?
% rustc --version
rustc 1.71.1 (eb26296b5 2023-08-03)
% cargo install cargo-unused-features
[...]
error[E0599]: `Vec<u8>` is not an iterator
--> /home/lin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-0.68.0/src/cargo/core/compiler/future_incompat.rs:228:18
|
227 | / strip_ansi_escapes::strip(&to_display)
228 | | .map(|v| String::from_utf8(v).expect("utf8"))
| | -^^^ `Vec<u8>` is not an iterator; try calling `.into_iter()` or `.iter()`
| |_________________|
|
|
::: /home/lin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/vec/mod.rs:396:1
|
396 | pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> {
| ------------------------------------------------------------------------------------------------ doesn't satisfy `Vec<u8>: Iterator`
|
= note: the following trait bounds were not satisfied:
`Vec<u8>: Iterator`
which is required by `&mut Vec<u8>: Iterator`
`[u8]: Iterator`
which is required by `&mut [u8]: Iterator`
error[E0599]: `Vec<u8>` is not an iterator
--> /home/lin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-0.68.0/src/cargo/core/compiler/mod.rs:1514:26
|
1513 | / strip_ansi_escapes::strip(&msg.rendered)
1514 | | .map(|v| String::from_utf8(v).expect("utf8"))
| | -^^^ `Vec<u8>` is not an iterator; try calling `.into_iter()` or `.iter()`
| |_________________________|
|
|
::: /home/lin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/vec/mod.rs:396:1
|
396 | pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> {
| ------------------------------------------------------------------------------------------------ doesn't satisfy `Vec<u8>: Iterator`
|
= note: the following trait bounds were not satisfied:
`Vec<u8>: Iterator`
which is required by `&mut Vec<u8>: Iterator`
`[u8]: Iterator`
which is required by `&mut [u8]: Iterator`
error[E0599]: `Vec<u8>` is not an iterator
--> /home/lin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-0.68.0/src/cargo/core/compiler/mod.rs:1548:22
|
1547 | error.rendered = strip_ansi_escapes::strip(&error.rendered)
| __________________________________-
1548 | | .map(|v| String::from_utf8(v).expect("utf8"))
| | -^^^ `Vec<u8>` is not an iterator; try calling `.into_iter()` or `.iter()`
| |_____________________|
|
|
::: /home/lin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/vec/mod.rs:396:1
|
396 | pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> {
| ------------------------------------------------------------------------------------------------ doesn't satisfy `Vec<u8>: Iterator`
|
= note: the following trait bounds were not satisfied:
`Vec<u8>: Iterator`
which is required by `&mut Vec<u8>: Iterator`
`[u8]: Iterator`
which is required by `&mut [u8]: Iterator`
For more information about this error, try `rustc --explain E0599`.
error: could not compile `cargo` (lib) due to 3 previous errors
error: failed to compile `cargo-unused-features v0.2.0`, intermediate artifacts can be found at `/tmp/cargo-installQnrMA3`
Describe the bug
Unable to prune from report.json
❯ unused-features prune --input report.json
A
B
[2022-10-28T09:30:29Z INFO unused_features::subcommands::prune] Executing prune command.
[2022-10-28T09:30:29Z INFO unused_features::report] Loading report from report.json.
[2022-10-28T09:30:29Z ERROR unused_features] Failed to deserialize report from report.json, maybe an old report? Current version is 0, make sure this is the same one in the report.
Only change I have made to the report.json file is removing from reqwest's successfully_remove_features
the features rustls-tls and rustls-tls-webpki-roots
Provide the following information
Cargo.toml
[dependencies]
clap = { version = "4.0.15", features = ["derive"] }
regex = "1.5"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
reqwest = { version = "0.11", default-features = false, features = ["stream", "rustls-tls"] }
tokio = { version = "1.16.1", features = ["full"] }
anyhow = "1.0.52"
indicatif = "0.16.2"
futures-util = "0.3.14"
dirs = "4.0.0"
cfg-if = "1.0"
tracing = "0.1"
tracing-subscriber = "0.2"
yansi = "0.5.1"
From reddit.
Probably not a minimal example, but this fails for me:
cargo new bug
cd ./bug/
cargo add async-std
echo "fn main() { let _ = async_std::task::yield_now(); }" > ./src/main.rs
unused-features analyze
unused-features prune --input .\report.json
cargo check
I'm using this code in Cargo.toml
:
[package]
name = "app"
version.workspace = true
edition.workspace = true
publish.workspace = true
but when I run unused-features analyze
it errors with:
A
B
[2022-12-16T17:08:45Z INFO unused_features::subcommands::analyze] C:\projects\app
[2022-12-16T17:08:45Z ERROR unused_features::subcommands::analyze] Failed to load 'C:\projects\app/bin/app' crate. invalid type: map, expected a string for key `package.version` at line 3 column 21
Windows 10, rustc 1.65.0 (897e37553 2022-11-02), cargo 1.65.0 (4bc8f24d3 2022-10-20)
Provide the following information
Cargo.toml
file of your project (strip sensitive information If needed, dependencies are only relevant)[package]
name = "twinet-samples"
version = "0.3.0"
authors = ["skip"]
description = "skip"
edition = "2021"
publish = false
rust-version = "1.57"
[lints.rust]
unsafe_code = "warn"
[lints.clippy]
useless_attribute = "allow"
pedantic = "warn"
[dependencies]
rand = "0.8"
Describe the bug
cargo-unsued-features
is not a cargo subcommand, although it's called like that. This is confusing.
I rewrote rhack
to become cargo-rhack
, and the trick is to pass in cargo
via clap as the first arg and hide it, as can be seen here: https://github.com/nakabonne/rhack/pull/11/files#diff-ce6e52385823f89d6bf1ea627c887cfd2a80b6fb8fc97932e5e3a9372d4ad7bbR27
Describe the bug
Some tests are needed.
Describe the bug
Does this crate support workspace versioning? I'm getting an error when attempting to run it on prql-compiler. Here's the issue template:
Cargo.toml
file of your project https://github.com/prql/prql/blob/ca2e79f4b27787f5ec5b3fa2edd92790684421cf/Cargo.tomlcargo analyze --log-level debug
) — I get error: no such subcommand: analyze
, but with unused-features
:❯ unused-features analyze --log-level debug
[2022-12-09T00:21:11Z INFO unused_features::subcommands::analyze] /Users/maximilian/workspace/prql/prql-compiler
[2022-12-09T00:21:11Z DEBUG unused_features::cargo_project] Loading '/Users/maximilian/workspace/prql/prql-compiler/Cargo.toml' ...
[2022-12-09T00:21:11Z DEBUG unused_features::cargo_project] Successfully read the toml file.
[2022-12-09T00:21:11Z DEBUG unused_features::cargo_project] Parsing toml definition ...
[2022-12-09T00:21:11Z ERROR unused_features::subcommands::analyze] Failed to load '/Users/maximilian/workspace/prql/prql-compiler/Cargo.toml' crate. invalid type: map, expected a string for key `package.version` at line 8 column 21
[2022-12-09T00:21:11Z INFO unused_features] Finished the process
Thank you!
Describe the bug
unused-features analyze
on https://github.com/helix-editor/helix/ gives near-empty results in report.json
.
{
"version": 0,
"root_name": "Workspace",
"workspace_crates": {}
}
Removing rust-toolchain.toml
gets it to work again.
Running unused-features analyze --log-level debug
on https://github.com/manforowicz/gday generated empty reports for each crate:
{
"version": 0,
"root_name": "Workspace",
"workspace_crates": {}
}
The logs looked normal, other than this being outputted repeatedly:
[2024-03-24T20:39:29Z DEBUG unused_features::subcommands::analyze] [90.0%]: Failed to compile without feature flag. error: Failed to compile toml document: failed to select a version for `env_logger`.
... required by package `gday v0.1.0 (/home/marcin/Documents/gday/gday)`
versions that meet the requirements `^0.11.3` (locked to 0.11.3) are: 0.11.3
the package `gday` depends on `env_logger`, with features: `anstream` but `env_logger` does not have these features.
It has an optional dependency with that name, but that dependency uses the "dep:" syntax in the features table, so it does not have an implicit feature with that name.
Describe the bug
It is valid to use a wildcard in a workspace Cargo.toml. This tool does not accept it and gives an error such as:
[2024-01-15T11:26:54Z ERROR unused_features::subcommands::analyze] Failed to load '/xxxxx/servers/*' crate. No such file or directory (os error 2)
workspace]
resolver = "2"
members = [
"mycrate",
"servers/*",
"types/*",
]
When the Cargo registry sparse protocol is enabled as described here, unused-features generates an empty report.
The debug logs indicate:
Failed to compile without feature flag. error: Failed to compile toml document: failed to get `[dependency]` as a dependency of package `[package]`
A common fix for this issue is to delete ~/.cargo/registry/index
and retry, however this did not fix my issue.
In order to see more details of the problem, I patched the Anyhow error message to display the backtrace.
diff --git a/src/cargo_project.rs b/src/cargo_project.rs
index 67390f3..4c2aff1 100644
--- a/src/cargo_project.rs
+++ b/src/cargo_project.rs
@@ -204,7 +204,7 @@ impl CargoProject {
let workspace = Workspace::new(&self.toml_path(), &config)?;
cargo::ops::compile(&workspace, &compile_options)
- .map_err(|e| anyhow::anyhow!("Failed to compile toml document: {}", e))?;
+ .map_err(|e| anyhow::anyhow!("Failed to compile toml document: {e:?}"))?;
Ok(())
}
This indicated the source of the problem.
Caused by:
0: failed to load source for dependency `[dependency]`
1: Unable to update registry `crates-io`
2: usage of sparse registries requires `-Z sparse-registry`
Once the root cause was known, the workaround is to disable the sparse protocol in ~/.cargo/config.toml
.
I'm just opening this issue in case others run into the same problem. I don't see any way to pass cargo flags (-Z) to unused-features analyze
. I would also suggest updating Anyhow errors to include the backtrace to make identifying issues like this easier.
Can you please add Cargo.lock
to the repository and keep it up-to-date? It’s important especially for Linux distros for reproducible builds.
Describe the bug
The dependency progress in the debug log for finishing pruning features of a dependency uses the progress from the start instead of the end.
cargo-unused-features/src/subcommands/analyze.rs
Lines 230 to 234 in 315fb12
Provide the following information
Debug Log:
[2023-11-25T14:32:21Z INFO unused_features::subcommands::analyze] [85.7%]: Prune 'color' feature flag from 'clap'
[2023-11-25T14:32:21Z DEBUG unused_features::subcommands::analyze] [85.7%]: Try compiling without feature flag.
[2023-11-25T14:33:47Z DEBUG unused_features::subcommands::analyze] [85.7%]: Successfully compiled without feature.flag.
[2023-11-25T14:33:47Z INFO unused_features::subcommands::analyze] [92.9%]: Prune 'derive' feature flag from 'clap'
[2023-11-25T14:33:47Z DEBUG unused_features::subcommands::analyze] [92.9%]: Try compiling without feature flag.
[2023-11-25T14:35:13Z DEBUG unused_features::subcommands::analyze] [92.9%]: Failed to compile without feature flag. error: Failed to compile toml document: 1 job failed
[2023-11-25T14:35:13Z DEBUG unused_features::subcommands::analyze] [50.0%]: Finished stripping feature flags from dependency cli.
For more exact details, refer to #17.
Describe the bug
When removing all features of a specific crate fails with Failed to compile without feature flag. error: ...
, the following code prevents the report from containing the crate.
Although the behaviour is fine, there should be indication through the CLI output that no features could be pruned so it wasn't included in the output. Especially in workspaces, this may lead to confusion as the report json is written but does not contain the crate.
Provide the following information
--bin --libs --tests --examples
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.