Merge pull request #3181 from scampi/issue3131

fix the logic for retaining a comment before the arrow in a match
This commit is contained in:
Seiichi Uchida 2018-11-08 14:15:09 +09:00 committed by GitHub
commit f10b2256a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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,
} => {}
_ => {}
}
}