Problem
It appears that cargo clean is ignoring target selection completely, unless the --package is not specified.
I'm not sure that there is a good use-case for cargo clean --target, but it seems strange that the option is accepted and promptly ignored.
See also #17310
Steps
cargo init --lib clean-test
cargo build --target host-tuple # target/<host tuple> is created
cargo clean --target host-tuple
- The entire
target directory is removed (instead of just target/<host tuple> )
This would be acceptable if it were only host-tuple, but this also happens for non-host-tuples, e.g. thumbv7m-none-eabi.
Possible Solution(s)
No response
Notes
No response
Version
cargo 1.99.0-nightly (7c83d4cc0 2026-07-29)
release: 1.99.0-nightly
commit-hash: 7c83d4cc0953b81d823e47d640c64da9b8bd4fac
commit-date: 2026-07-29
host: x86_64-unknown-linux-gnu
libgit2: 1.9.6 (sys:0.21.0 vendored)
libcurl: 8.21.0-DEV (sys:0.4.90+curl-8.21.0 vendored ssl:OpenSSL/3.6.3)
ssl: OpenSSL 3.6.3 9 Jun 2026
os: Ubuntu 24.4.0 (noble) [64-bit]
Problem
It appears that
cargo cleanis ignoring target selection completely, unless the--packageis not specified.I'm not sure that there is a good use-case for
cargo clean --target, but it seems strange that the option is accepted and promptly ignored.See also #17310
Steps
cargo init --lib clean-testcargo build --target host-tuple#target/<host tuple>is createdcargo clean --target host-tupletargetdirectory is removed (instead of justtarget/<host tuple>)This would be acceptable if it were only
host-tuple, but this also happens for non-host-tuples, e.g.thumbv7m-none-eabi.Possible Solution(s)
No response
Notes
No response
Version