diff --git a/src/items.rs b/src/items.rs
index 6216c79975e..a2bf023a33e 100644
--- a/src/items.rs
+++ b/src/items.rs
@@ -24,7 +24,7 @@ use comment::{
combine_strs_with_missing_comments, contains_comment, recover_comment_removed,
recover_missing_comment_in_span, rewrite_missing_comment, FindUncommented,
};
-use config::{BraceStyle, Config, Density, IndentStyle};
+use config::{BraceStyle, Config, Density, IndentStyle, Version};
use expr::{
format_expr, is_empty_block, is_simple_block_stmt, rewrite_assign_rhs, rewrite_assign_rhs_with,
ExprType, RhsTactics,
@@ -2085,11 +2085,18 @@ fn rewrite_fn_base(
.lines()
.last()
.map_or(false, |last_line| last_line.contains("//"));
- result.push(')');
- if closing_paren_overflow_max_width || args_last_line_contains_comment {
- result.push_str(&indent.to_string_with_newline(context.config));
- no_args_and_over_max_width = true;
+ if context.config.version() == Version::Two {
+ result.push(')');
+ if closing_paren_overflow_max_width || args_last_line_contains_comment {
+ result.push_str(&indent.to_string_with_newline(context.config));
+ no_args_and_over_max_width = true;
+ }
+ } else {
+ if closing_paren_overflow_max_width || args_last_line_contains_comment {
+ result.push_str(&indent.to_string_with_newline(context.config));
+ }
+ result.push(')');
}
}
@@ -2130,9 +2137,14 @@ fn rewrite_fn_base(
result.push_str(&indent.to_string_with_newline(context.config));
indent
} else {
- if arg_str.len() != 0 || !no_args_and_over_max_width {
+ if context.config.version() == Version::Two {
+ if arg_str.len() != 0 || !no_args_and_over_max_width {
+ result.push(' ');
+ }
+ } else {
result.push(' ');
}
+
Indent::new(indent.block_indent, last_line_width(&result))
};
diff --git a/tests/source/issue-3278.rs b/tests/source/issue-3278.rs
deleted file mode 100644
index f86caafc541..00000000000
--- a/tests/source/issue-3278.rs
+++ /dev/null
@@ -1,3 +0,0 @@
-pub fn parse_conditional<'a, I: 'a>() -> impl Parser + 'a
-where I: Stream-
-{}
\ No newline at end of file
diff --git a/tests/source/issue-3278/version_one.rs b/tests/source/issue-3278/version_one.rs
new file mode 100644
index 00000000000..580679fbae3
--- /dev/null
+++ b/tests/source/issue-3278/version_one.rs
@@ -0,0 +1,8 @@
+// rustfmt-version: One
+
+pub fn parse_conditional<'a, I: 'a>(
+) -> impl Parser + 'a
+where
+ I: Stream
- ,
+{
+}
diff --git a/tests/target/issue-3278.rs b/tests/source/issue-3278/version_two.rs
similarity index 84%
rename from tests/target/issue-3278.rs
rename to tests/source/issue-3278/version_two.rs
index 07219295a7a..c17b1742d39 100644
--- a/tests/target/issue-3278.rs
+++ b/tests/source/issue-3278/version_two.rs
@@ -1,3 +1,5 @@
+// rustfmt-version: Two
+
pub fn parse_conditional<'a, I: 'a>()
-> impl Parser + 'a
where
diff --git a/tests/source/long-fn-1.rs b/tests/source/long-fn-1/version_one.rs
similarity index 96%
rename from tests/source/long-fn-1.rs
rename to tests/source/long-fn-1/version_one.rs
index 1f53d78802d..d6832c2af09 100644
--- a/tests/source/long-fn-1.rs
+++ b/tests/source/long-fn-1/version_one.rs
@@ -1,3 +1,4 @@
+// rustfmt-version: One
// Tests that a function which is almost short enough, but not quite, gets
// formatted correctly.
diff --git a/tests/source/long-fn-1/version_two.rs b/tests/source/long-fn-1/version_two.rs
new file mode 100644
index 00000000000..f402a26e8b6
--- /dev/null
+++ b/tests/source/long-fn-1/version_two.rs
@@ -0,0 +1,21 @@
+// rustfmt-version: Two
+// Tests that a function which is almost short enough, but not quite, gets
+// formatted correctly.
+
+impl Foo {
+ fn some_input(&mut self, input: Input, input_path: Option, ) -> (Input, Option) {}
+
+ fn some_inpu(&mut self, input: Input, input_path: Option) -> (Input, Option) {}
+}
+
+// #1843
+#[allow(non_snake_case)]
+pub extern "C" fn Java_com_exonum_binding_storage_indices_ValueSetIndexProxy_nativeContainsByHash() -> bool {
+ false
+}
+
+// #3009
+impl Something {
+ fn my_function_name_is_way_to_long_but_used_as_a_case_study_or_an_example_its_fine(
+) -> Result< (), String > {}
+}
diff --git a/tests/target/issue-3278/version_one.rs b/tests/target/issue-3278/version_one.rs
new file mode 100644
index 00000000000..580679fbae3
--- /dev/null
+++ b/tests/target/issue-3278/version_one.rs
@@ -0,0 +1,8 @@
+// rustfmt-version: One
+
+pub fn parse_conditional<'a, I: 'a>(
+) -> impl Parser + 'a
+where
+ I: Stream
- ,
+{
+}
diff --git a/tests/target/issue-3278/version_two.rs b/tests/target/issue-3278/version_two.rs
new file mode 100644
index 00000000000..c17b1742d39
--- /dev/null
+++ b/tests/target/issue-3278/version_two.rs
@@ -0,0 +1,8 @@
+// rustfmt-version: Two
+
+pub fn parse_conditional<'a, I: 'a>()
+-> impl Parser + 'a
+where
+ I: Stream
- ,
+{
+}
diff --git a/tests/target/long-fn-1/version_one.rs b/tests/target/long-fn-1/version_one.rs
new file mode 100644
index 00000000000..05f69953c26
--- /dev/null
+++ b/tests/target/long-fn-1/version_one.rs
@@ -0,0 +1,29 @@
+// rustfmt-version: One
+// Tests that a function which is almost short enough, but not quite, gets
+// formatted correctly.
+
+impl Foo {
+ fn some_input(
+ &mut self,
+ input: Input,
+ input_path: Option,
+ ) -> (Input, Option) {
+ }
+
+ fn some_inpu(&mut self, input: Input, input_path: Option) -> (Input, Option) {
+ }
+}
+
+// #1843
+#[allow(non_snake_case)]
+pub extern "C" fn Java_com_exonum_binding_storage_indices_ValueSetIndexProxy_nativeContainsByHash(
+) -> bool {
+ false
+}
+
+// #3009
+impl Something {
+ fn my_function_name_is_way_to_long_but_used_as_a_case_study_or_an_example_its_fine(
+ ) -> Result<(), String> {
+ }
+}
diff --git a/tests/target/long-fn-1.rs b/tests/target/long-fn-1/version_two.rs
similarity index 96%
rename from tests/target/long-fn-1.rs
rename to tests/target/long-fn-1/version_two.rs
index 320617f2772..32794bccde2 100644
--- a/tests/target/long-fn-1.rs
+++ b/tests/target/long-fn-1/version_two.rs
@@ -1,3 +1,4 @@
+// rustfmt-version: Two
// Tests that a function which is almost short enough, but not quite, gets
// formatted correctly.