mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-30 10:45:18 +00:00
fix the logic for retaining a comment before the arrow in a match
This commit is contained in:
parent
cd8bb50aea
commit
9467033a8e
@ -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() {
|
||||
|
8
tests/source/issue-3131.rs
Normal file
8
tests/source/issue-3131.rs
Normal file
@ -0,0 +1,8 @@
|
||||
fn main() {
|
||||
match 3 {
|
||||
t if match t {
|
||||
_ => true,
|
||||
} => {},
|
||||
_ => {}
|
||||
}
|
||||
}
|
8
tests/target/issue-3131.rs
Normal file
8
tests/target/issue-3131.rs
Normal file
@ -0,0 +1,8 @@
|
||||
fn main() {
|
||||
match 3 {
|
||||
t if match t {
|
||||
_ => true,
|
||||
} => {}
|
||||
_ => {}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user