Skip to content

disown_pair: unreachable Arg arm, a redundant second call, and the &! rule applied to fish where both spellings agree #4517

Open

Description

@KuSh

Three small refinements to disown_pair / opens_disown_pair (src/discover/lexer.rs), added in #4126 to stop RTK re-spelling the pairs an ampersand opens. The rule itself is correct and verified against real zsh 5.9.2 and fish 4.9.1; these are leftovers that cost nothing today but will mislead the next reader.

1. The TokenKind::Arg arm is unreachable

let pairs = match &token.kind {
    TokenKind::Pipe(_) => true,
    TokenKind::Shellism => token.value == "!",
    TokenKind::Arg => token.value.starts_with('!'),   // <- never fires
    _ => false,
};

An unquoted ! is unconditionally flushed into its own Shellism token by the '*' | '?' | '' | '(' | ')' | '{' | '}' | '!'arm oftokenize_inner, and every other producer of an Argprepends something: the quote branch keeps the opening delimiter invalue (&'!x'→Arg("'!x'")), the escape branch keeps the backslash (&!x→Arg("\!x")), and the $branch yields$name. So no Argvalue can begin with!`.

Evidence: removing the arm changes the verdict on 0 of 3,124 generated &-shaped wrapper inputs, and the mutation passes cargo test --all (4,158 tests) — it is dead, not merely untested. Every real detection (ls&!ls, git status &!cat) goes through the Shellism arm.

If the intent was "a word glued after &", the condition misses exactly the quoted and escaped spellings because of those prefixes — and nothing needs catching there, since &'!x' and &\!x are equivalent spaced in zsh.

2. The call inside contains_fish_only_construct is now redundant

contains_unattestable_construct_in returns true via opens_disown_pair for every dialect that is not Posix — Fish included — before the fish check runs:

if dialect != ShellDialect::Posix && opens_disown_pair(cmd) {
    return true;
}

so contains_fish_only_construct is only ever entered with disown_pair(tokens) == false, and its own leading disown_pair call cannot fire outside unit tests. The fish path also tokenizes the script twice, since opens_disown_pair re-tokenizes with the same NewlineMode::Conservative. Dropping either copy is behaviour-neutral; dropping the in-loop one keeps the rule in a single place.

3. The &! half is applied to fish, where it buys nothing

opens_disown_pair's own doc says "&| in fish and zsh, &! in zsh", but the gate is dialect != ShellDialect::Posix, so &! defers fish scripts too. In fish 4.9.1 and 3.7.0, echo a &! echo b and echo a & ! echo b behave identically (both print a then b), so the rewrite was already faithful:

before #4126's b969c3a1:  rtk rewrite "fish -c 'git status &! echo b'"
                            -> exit 3, fish -c 'rtk git status & ! echo b'
after:                      -> exit 1, rewrite lost

68 of the 174 inputs that commit changes are fish &! scripts losing their rewrite for no correctness gain. Only &| needs refusing for fish (echo a &| cat works; echo a & | cat is fish: Expected a string, but found a pipe).

Note the glued form fish -c 'git status &!echo b' should still defer, but for a reason this rule does not model: fish reads status&!echo as one literal word (echo a&!echo b prints a&!echo b). The precise fish rule is "& glued to a preceding non-blank is literal", not "& glued to |/!".

Why this is not a #4126 blocker

All three are behaviour-neutral or savings-only, and #4126's own tests kill every mutation of the decisions that matter. Filed from round 2 of #4126; rtk built from b969c3a10.

Activity

  1. added
    bug
    good first issue
    on Oct 11, 2026
  2. rtk-wshm-sync-bot commented on Oct 11, 2026

    @rtk-wshm-sync-bot

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟢 Priority low
    🎯 Confidence 82%

    Summary

    Three dead-code/correctness leftovers in disown_pair/opens_disown_pair (src/discover/lexer.rs): unreachable Arg match arm, redundant double-tokenize call in contains_fish_only_construct, and &! gate unnecessarily applied to fish.

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.

    📁 Relevant files
    • src/discover/lexer.rs

    Suggested Actions

    1. Remove the unreachable TokenKind::Arg arm in disown_pair's match in src/discover/lexer.rs
    2. Drop the redundant leading disown_pair/opens_disown_pair call inside contains_fish_only_construct to avoid double token…
    3. Restrict the &! defer rule to zsh only, since fish treats &! and & ! identically — keep &| deferral for fish
    4. Cross-reference Permission gate: a command glued to zsh's &! inside a -c wrapper escapes the inner deny scan #4516 (related disown_pair/zsh &! permission gate issue) and feat(rewrite): rewrite inner commands of a quoted fish -c wrapper #4126 (origin PR) when making the change

    Triaged automatically by wshm · This is an automated analysis, not a human review.

  3. cestercian commented on Oct 12, 2026

    @cestercian

    Claiming the disown_pair Arg arm / &! fish cleanup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:clibuggood first issuepriority:low

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions