Skip to content

cargo clean accepts --target but ignores it without --package #17311

Description

@datdenkikniet

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

  1. cargo init --lib clean-test
  2. cargo build --target host-tuple # target/<host tuple> is created
  3. cargo clean --target host-tuple
  4. 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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bugCommand-cleanS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions