Skip to content

Invalid syntax produced if "in" is a subset of a variable name between for ... in. #5009

Closed
@SimonWoodburyForget

Description

@SimonWoodburyForget

If the subset of a variable name is "in" inside of the for-loop's for ... in section and requires formatting with a comment around the in-keyword, an invalid output is produced.

For this input:

fn main() {
    for variable_in_here /* ... */ in 0..1 {}
    for variable_in_here in /* ... */ 0..1 {}
    for variable_in_here
    in /* ... */ 0..1 {}
    for variable_in_here
    /* ... */ in 0..1 {}
}

The output becomes invalid syntax:

fn main() {
    for variable_in_here in _here /* ... */ in 0..1 {}
    for variable_in_here in _here in /* ... */ 0..1 {}
    for variable_in_here in
        _here
        in /* ... */
        0..1
    {}
    for variable_in_here in
        _here
        /* ... */ in
        0..1
    {}
}

If the characters "in" are removed from the input, the output will remain valid syntax:

fn main() {
    for variable__here /* ... */ in 0..1 {}
    for variable__here in /* ... */ 0..1 {}
    for variable__here in /* ... */ 0..1 {}
    for variable__here
    /* ... */ in 0..1 {}
}

$ rustfmt --version
rustfmt 1.4.37-stable (a178d03 2021-07-26)

Metadata

Metadata

Assignees

No one assigned

    Labels

    2x-port:pendingbugPanic, non-idempotency, invalid code, etc.good first issueIssues up for grabs, also good candidates for new rustfmt contributorshelp wanted

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions