Skip to content

Native completions have incorrect behavior when completing in the middle with sudo #6107

@epage

Description

@epage

Problem

cargo does not complete correctly when I try to complete in the middle with sudo using the native-completions feature.

Steps

  1. Run source <(CARGO_COMPLETE=bash cargo +nightly) to ensure that we're using native-completions feature
  2. Create a cargo project with two examples, apple and banana
  3. Invoke completion like this:
cargo build --example ap<TAB> --example banana
  1. Notice that we've got the correct result:
cargo build --example apple --example banana
  1. Prepend with sudo and invoke completion again:
sudo cargo build --example ap<TAB> --example banana
  1. Notice that we've got the wrong result:
sudo cargo build --example banana --example banana

Possible Solution(s)

No response

Notes

Completions by rustup completions bash are correct in both cases, and this bug only occurs when using completions by CARGO_COMPLETE=bash cargo +nightly.

Version

$ cargo +nightly version --verbose
cargo 1.91.0-nightly (71eb84f21 2025-08-17)
release: 1.91.0-nightly
commit-hash: 71eb84f21aef43c07580c6aed6f806a6299f5042
commit-date: 2025-08-17
host: x86_64-unknown-linux-gnu
libgit2: 1.9.1 (sys:0.20.2 vendored)
libcurl: 8.14.1-DEV (sys:0.4.82+curl-8.14.1 vendored ssl:OpenSSL/3.5.0)
ssl: OpenSSL 3.5.0 8 Apr 2025
os: Ubuntu 24.4.0 (noble) [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-completionArea: completion generatorC-enhancementCategory: Raise on the bar on expectationsE-hardCall for participation: Experience needed to fix: Hard / a lotE-help-wantedCall for participation: Help is requested to fix this issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions