forked from rust-lang/rustfmt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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".
- Loading branch information
1 parent
f7c4a44
commit f2fb3c9
Showing
7 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
fn main() { | ||
// the "in" inside the pattern produced invalid syntax | ||
for variable_in_here /* ... */ in 0..1 {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
for in_in_in_in_in_in_in_in /* ... */ in 0..1 {} | ||
} |
5 changes: 5 additions & 0 deletions
5
tests/target/issue-5009/3_nested_for_loop_with_connector_in_pattern.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
fn main() { | ||
for variable_in_x /* ... */ in 0..1 { | ||
for variable_in_y /* ... */ in 0..1 {} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
tests/target/issue-5009/4_nested_for_loop_with_if_elseif_else.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
fn main() { | ||
for variable_in_x /* ... */ in 0..1 { | ||
for variable_in_y /* ... */ in 0..1 { | ||
if false { | ||
|
||
} else if false { | ||
|
||
} else { | ||
|
||
} | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
tests/target/issue-5009/5_nested_for_loop_with_connector_in_if_elseif_else.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
fn main() { | ||
let in_ = false; | ||
|
||
for variable_in_x /* ... */ in 0..1 { | ||
for variable_in_y /* ... */ in 0..1 { | ||
if in_ { | ||
|
||
} else if in_ { | ||
|
||
} else { | ||
|
||
} | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
tests/target/issue-5009/6_deeply_nested_for_loop_with_connector_in_pattern.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
fn main() { | ||
for variable_in_a /* ... */ in 0..1 { | ||
for variable_in_b /* ... */ in 0..1 { | ||
for variable_in_c /* ... */ in 0..1 { | ||
for variable_in_d /* ... */ in 0..1 { | ||
for variable_in_e /* ... */ in 0..1 { | ||
for variable_in_f /* ... */ in 0..1 { | ||
for variable_in_g /* ... */ in 0..1 { | ||
for variable_in_h /* ... */ in 0..1 { | ||
for variable_in_i /* ... */ in 0..1 { | ||
for variable_in_j /* ... */ in 0..1 { | ||
for variable_in_k /* ... */ in 0..1 { | ||
for variable_in_l /* ... */ in 0..1 { | ||
for variable_in_m /* ... */ in 0..1 { | ||
for variable_in_n /* ... */ in 0..1 { | ||
for variable_in_o /* ... */ in 0..1 { | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |