]> git.lizzy.rs Git - rust.git/commit
Update connector search in ControlFlow::rewrite_pat_expr for for loops
authorYacin Tmimi <ytmimi@horizonmedia.com>
Wed, 6 Oct 2021 17:09:24 +0000 (13:09 -0400)
committerCaleb Cartwright <calebcartwright@users.noreply.github.com>
Thu, 14 Oct 2021 00:36:37 +0000 (19:36 -0500)
commitf2fb3c9659e072d7df6315906f1adbd06c3bc9e3
tree51b08981e28b333454a1cf4cb4024a214893b4e9
parentf7c4a44149b4e3a683f5506929050f2b50117328
Update connector search in ControlFlow::rewrite_pat_expr for for loops

Resolves 5009

For loops represented by a ControlFlow object use " in" as their connector.
rustfmt searches for the first uncommented occurrence of the word "in" within the
current span and adjusts it's starting point to look for comments right after that.
visually this looks like this:

    rustfmt starts looking for comments here
            |
            V
    for x in /* ... */ 0..1 {}

This works well in most cases, however when the pattern also contains
the word "in", this leads to issues.

    rustfmt starts looking for comments here
          |
          V
    for in_here in /* ... */ 0..1 {}
        -------
        pattern

In order to correctly identify the connector, the new approach first
updates the span to start after the pattern and then searches for the
first uncommented occurrence of "in".
src/expr.rs
tests/target/issue-5009/1_minimum_example.rs [new file with mode: 0644]
tests/target/issue-5009/2_many_in_connectors_in_pattern.rs [new file with mode: 0644]
tests/target/issue-5009/3_nested_for_loop_with_connector_in_pattern.rs [new file with mode: 0644]
tests/target/issue-5009/4_nested_for_loop_with_if_elseif_else.rs [new file with mode: 0644]
tests/target/issue-5009/5_nested_for_loop_with_connector_in_if_elseif_else.rs [new file with mode: 0644]
tests/target/issue-5009/6_deeply_nested_for_loop_with_connector_in_pattern.rs [new file with mode: 0644]