Skip to content

Commit f92f3e3

Browse files
committed
add the version gate to the code and test
1 parent 7b99654 commit f92f3e3

File tree

10 files changed

+96
-9
lines changed

10 files changed

+96
-9
lines changed

src/items.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use comment::{
2424
combine_strs_with_missing_comments, contains_comment, recover_comment_removed,
2525
recover_missing_comment_in_span, rewrite_missing_comment, FindUncommented,
2626
};
27-
use config::{BraceStyle, Config, Density, IndentStyle};
27+
use config::{BraceStyle, Config, Density, IndentStyle, Version};
2828
use expr::{
2929
format_expr, is_empty_block, is_simple_block_stmt, rewrite_assign_rhs, rewrite_assign_rhs_with,
3030
ExprType, RhsTactics,
@@ -2085,11 +2085,18 @@ fn rewrite_fn_base(
20852085
.lines()
20862086
.last()
20872087
.map_or(false, |last_line| last_line.contains("//"));
2088-
result.push(')');
20892088

2090-
if closing_paren_overflow_max_width || args_last_line_contains_comment {
2091-
result.push_str(&indent.to_string_with_newline(context.config));
2092-
no_args_and_over_max_width = true;
2089+
if context.config.version() == Version::Two {
2090+
result.push(')');
2091+
if closing_paren_overflow_max_width || args_last_line_contains_comment {
2092+
result.push_str(&indent.to_string_with_newline(context.config));
2093+
no_args_and_over_max_width = true;
2094+
}
2095+
} else {
2096+
if closing_paren_overflow_max_width || args_last_line_contains_comment {
2097+
result.push_str(&indent.to_string_with_newline(context.config));
2098+
}
2099+
result.push(')');
20932100
}
20942101
}
20952102

@@ -2130,9 +2137,14 @@ fn rewrite_fn_base(
21302137
result.push_str(&indent.to_string_with_newline(context.config));
21312138
indent
21322139
} else {
2133-
if arg_str.len() != 0 || !no_args_and_over_max_width {
2140+
if context.config.version() == Version::Two {
2141+
if arg_str.len() != 0 || !no_args_and_over_max_width {
2142+
result.push(' ');
2143+
}
2144+
} else {
21342145
result.push(' ');
21352146
}
2147+
21362148
Indent::new(indent.block_indent, last_line_width(&result))
21372149
};
21382150

tests/source/issue-3278.rs

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// rustfmt-version: One
2+
3+
pub fn parse_conditional<'a, I: 'a>(
4+
) -> impl Parser<Input = I, Output = Expr, PartialState = ()> + 'a
5+
where
6+
I: Stream<Item = char>,
7+
{
8+
}

tests/target/issue-3278.rs renamed to tests/source/issue-3278/version_two.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// rustfmt-version: Two
2+
13
pub fn parse_conditional<'a, I: 'a>()
24
-> impl Parser<Input = I, Output = Expr, PartialState = ()> + 'a
35
where

tests/source/long-fn-1.rs renamed to tests/source/long-fn-1/version_one.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// rustfmt-version: One
12
// Tests that a function which is almost short enough, but not quite, gets
23
// formatted correctly.
34

tests/source/long-fn-1/version_two.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// rustfmt-version: Two
2+
// Tests that a function which is almost short enough, but not quite, gets
3+
// formatted correctly.
4+
5+
impl Foo {
6+
fn some_input(&mut self, input: Input, input_path: Option<PathBuf>, ) -> (Input, Option<PathBuf>) {}
7+
8+
fn some_inpu(&mut self, input: Input, input_path: Option<PathBuf>) -> (Input, Option<PathBuf>) {}
9+
}
10+
11+
// #1843
12+
#[allow(non_snake_case)]
13+
pub extern "C" fn Java_com_exonum_binding_storage_indices_ValueSetIndexProxy_nativeContainsByHash() -> bool {
14+
false
15+
}
16+
17+
// #3009
18+
impl Something {
19+
fn my_function_name_is_way_to_long_but_used_as_a_case_study_or_an_example_its_fine(
20+
) -> Result< (), String > {}
21+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// rustfmt-version: One
2+
3+
pub fn parse_conditional<'a, I: 'a>(
4+
) -> impl Parser<Input = I, Output = Expr, PartialState = ()> + 'a
5+
where
6+
I: Stream<Item = char>,
7+
{
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// rustfmt-version: Two
2+
3+
pub fn parse_conditional<'a, I: 'a>()
4+
-> impl Parser<Input = I, Output = Expr, PartialState = ()> + 'a
5+
where
6+
I: Stream<Item = char>,
7+
{
8+
}

tests/target/long-fn-1/version_one.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// rustfmt-version: One
2+
// Tests that a function which is almost short enough, but not quite, gets
3+
// formatted correctly.
4+
5+
impl Foo {
6+
fn some_input(
7+
&mut self,
8+
input: Input,
9+
input_path: Option<PathBuf>,
10+
) -> (Input, Option<PathBuf>) {
11+
}
12+
13+
fn some_inpu(&mut self, input: Input, input_path: Option<PathBuf>) -> (Input, Option<PathBuf>) {
14+
}
15+
}
16+
17+
// #1843
18+
#[allow(non_snake_case)]
19+
pub extern "C" fn Java_com_exonum_binding_storage_indices_ValueSetIndexProxy_nativeContainsByHash(
20+
) -> bool {
21+
false
22+
}
23+
24+
// #3009
25+
impl Something {
26+
fn my_function_name_is_way_to_long_but_used_as_a_case_study_or_an_example_its_fine(
27+
) -> Result<(), String> {
28+
}
29+
}

tests/target/long-fn-1.rs renamed to tests/target/long-fn-1/version_two.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// rustfmt-version: Two
12
// Tests that a function which is almost short enough, but not quite, gets
23
// formatted correctly.
34

0 commit comments

Comments
 (0)