Skip to content

Commit

Permalink
Add version gate for arrow finding fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ding-young committed Mar 9, 2024
1 parent 234fe10 commit b33aa37
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,11 @@ fn rewrite_match_body(
let arrow_snippet = context.snippet(arrow_span).trim();
// search for the arrow starting from the end of the snippet since there may be a match
// expression within the guard
let arrow_index = arrow_snippet.find_last_uncommented("=>").unwrap();
let arrow_index = if context.config.version() == Version::One {
arrow_snippet.rfind("=>").unwrap()
} else {
arrow_snippet.find_last_uncommented("=>").unwrap()
};
// 2 = `=>`
let comment_str = arrow_snippet[arrow_index + 2..].trim();
if comment_str.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion tests/source/arrow_in_comments/arrow_in_single_comment.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// rustfmt-wrap_comments: true
// rustfmt-version: Two
fn main() {
match a {
_ =>
Expand Down
2 changes: 1 addition & 1 deletion tests/source/arrow_in_comments/multiple_arrows.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// rustfmt-wrap_comments: true
// rustfmt-version: Two
fn main() {
match a {
_ => // comment with =>
Expand Down
2 changes: 1 addition & 1 deletion tests/target/arrow_in_comments/arrow_in_single_comment.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// rustfmt-wrap_comments: true
// rustfmt-version: Two
fn main() {
match a {
_ =>
Expand Down
2 changes: 1 addition & 1 deletion tests/target/arrow_in_comments/multiple_arrows.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// rustfmt-wrap_comments: true
// rustfmt-version: Two
fn main() {
match a {
_ =>
Expand Down

0 comments on commit b33aa37

Please sign in to comment.