fix the logic for retaining a comment before the arrow in a match

This commit is contained in:
Stéphane Campinas 2018-11-07 15:00:33 +01:00
parent cd8bb50aea
commit 9467033a8e
No known key found for this signature in database
GPG Key ID: 6D5620D908210133
3 changed files with 19 additions and 1 deletions

View File

@ -379,7 +379,9 @@ fn rewrite_match_body(
// Look for comments between `=>` and the start of the body.
let arrow_comment = {
let arrow_snippet = context.snippet(arrow_span).trim();
let arrow_index = arrow_snippet.find("=>").unwrap();
// 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.rfind("=>").unwrap();
// 2 = `=>`
let comment_str = arrow_snippet[arrow_index + 2..].trim();
if comment_str.is_empty() {

View File

@ -0,0 +1,8 @@
fn main() {
match 3 {
t if match t {
_ => true,
} => {},
_ => {}
}
}

View File

@ -0,0 +1,8 @@
fn main() {
match 3 {
t if match t {
_ => true,
} => {}
_ => {}
}
}