Skip to content

Commit f62ea61

Browse files
committed
Find arrow with find_last_uncommented
1 parent 0b73d9e commit f62ea61

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

src/matches.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::iter::repeat;
55
use rustc_ast::{ast, ptr};
66
use rustc_span::{BytePos, Span};
77

8-
use crate::comment::{combine_strs_with_missing_comments, rewrite_comment};
8+
use crate::comment::{combine_strs_with_missing_comments, rewrite_comment, FindUncommented};
99
use crate::config::lists::*;
1010
use crate::config::{Config, ControlBraceStyle, IndentStyle, MatchArmLeadingPipe, Version};
1111
use crate::expr::{
@@ -402,16 +402,7 @@ fn rewrite_match_body(
402402
let arrow_snippet = context.snippet(arrow_span).trim();
403403
// search for the arrow starting from the end of the snippet since there may be a match
404404
// expression within the guard
405-
let mut arrow_index = arrow_snippet.rfind("=>").unwrap();
406-
// check whether `=>` is included in the comment
407-
if arrow_index != 0 {
408-
let prev_arrow = arrow_snippet[..arrow_index].trim();
409-
let single_line_comment_index = prev_arrow.rfind("//").unwrap_or(0);
410-
let new_line_index = prev_arrow.rfind("\n").unwrap_or(0);
411-
if single_line_comment_index > new_line_index {
412-
arrow_index = 0;
413-
}
414-
}
405+
let arrow_index = arrow_snippet.find_last_uncommented("=>").unwrap();
415406
// 2 = `=>`
416407
let comment_str = arrow_snippet[arrow_index + 2..].trim();
417408
if comment_str.is_empty() {

0 commit comments

Comments
 (0)