From 233497aceb3542aaa40fd8011bb8e5339f5ed60f Mon Sep 17 00:00:00 2001 From: rChaser53 Date: Thu, 24 Oct 2019 22:16:56 +0900 Subject: [PATCH] fix Unparsable code when formmating (#3883) --- src/items.rs | 10 ++++++++-- tests/target/issue-3882.rs | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 tests/target/issue-3882.rs diff --git a/src/items.rs b/src/items.rs index 401cf78d721..64ed2d9294c 100644 --- a/src/items.rs +++ b/src/items.rs @@ -2218,10 +2218,16 @@ fn rewrite_fn_base( .map_or(false, |last_line| last_line.contains("//")); if context.config.version() == Version::Two { - result.push(')'); - if closing_paren_overflow_max_width || params_last_line_contains_comment { + if closing_paren_overflow_max_width { + result.push(')'); result.push_str(&indent.to_string_with_newline(context.config)); no_params_and_over_max_width = true; + } else if params_last_line_contains_comment { + result.push_str(&indent.to_string_with_newline(context.config)); + result.push(')'); + no_params_and_over_max_width = true; + } else { + result.push(')'); } } else { if closing_paren_overflow_max_width || params_last_line_contains_comment { diff --git a/tests/target/issue-3882.rs b/tests/target/issue-3882.rs new file mode 100644 index 00000000000..5eb442af974 --- /dev/null +++ b/tests/target/issue-3882.rs @@ -0,0 +1,4 @@ +// rustfmt-version: Two +fn bar(_t: T, // bar +) { +}