From bd80077be89b3e8584d8c93af263e38c0e156d5b Mon Sep 17 00:00:00 2001 From: topecongiro Date: Sat, 10 Jun 2017 20:37:34 +0900 Subject: Add format_trait_ref_then_update_result --- tests/source/big-impl-rfc.rs | 114 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 tests/source/big-impl-rfc.rs (limited to 'tests/source') diff --git a/tests/source/big-impl-rfc.rs b/tests/source/big-impl-rfc.rs new file mode 100644 index 00000000000..167f654cc43 --- /dev/null +++ b/tests/source/big-impl-rfc.rs @@ -0,0 +1,114 @@ +// rustfmt-fn_args_layout: Block +// rustfmt-fn_call_style: Block +// rustfmt-generics_indent: Block +// rustfmt-where_style: Rfc + +// #1357 +impl< + 'a, + Select, + From, + Distinct, + Where, + Order, + Limit, + Offset, + Groupby, + DB, +> InternalBoxedDsl<'a, DB> + for SelectStatement< + Select, + From, + Distinct, + Where, + Order, + Limit, + Offset, + GroupBy, + > where + DB: Backend, + Select: QueryFragment + SelectableExpression + 'a, + Distinct: QueryFragment + 'a, + Where: Into + 'a>>>, + Order: QueryFragment + 'a, + Limit: QueryFragment + 'a, + Offset: QueryFragment + 'a, +{ + type Output = BoxedSelectStatement<'a, Select::SqlTypeForSelect, From, DB>; + + fn internal_into_boxed(self) -> Self::Output { + BoxedSelectStatement::new( + Box::new(self.select), + self.from, + Box::new(self.distinct), + self.where_clause.into(), + Box::new(self.order), + Box::new(self.limit), + Box::new(self.offset), + ) + } +} + +// #1369 +impl< + ExcessivelyLongGenericName, + ExcessivelyLongGenericName, + AnotherExcessivelyLongGenericName, +> Foo for Bar { + fn foo() {} +} +impl Foo< + ExcessivelyLongGenericName, + ExcessivelyLongGenericName, + AnotherExcessivelyLongGenericName, +> for Bar { + fn foo() {} +} +impl< + ExcessivelyLongGenericName, + ExcessivelyLongGenericName, + AnotherExcessivelyLongGenericName, +> Foo< + ExcessivelyLongGenericName, + ExcessivelyLongGenericName, + AnotherExcessivelyLongGenericName, +> for Bar { + fn foo() {} +} +impl< + ExcessivelyLongGenericName, + ExcessivelyLongGenericName, + AnotherExcessivelyLongGenericName, +> Foo for Bar< + ExcessivelyLongGenericName, + ExcessivelyLongGenericName, + AnotherExcessivelyLongGenericName, +> { + fn foo() {} +} +impl Foo< + ExcessivelyLongGenericName, + ExcessivelyLongGenericName, + AnotherExcessivelyLongGenericName, +> for Bar< + ExcessivelyLongGenericName, + ExcessivelyLongGenericName, + AnotherExcessivelyLongGenericName, +> { + fn foo() {} +} +impl< + ExcessivelyLongGenericName, + ExcessivelyLongGenericName, + AnotherExcessivelyLongGenericName, +> Foo< + ExcessivelyLongGenericName, + ExcessivelyLongGenericName, + AnotherExcessivelyLongGenericName, +> for Bar< + ExcessivelyLongGenericName, + ExcessivelyLongGenericName, + AnotherExcessivelyLongGenericName, +> { + fn foo() {} +} -- cgit 1.4.1-3-g733a5 From e94fcfcd39c2658812a59f1adc0f6fca5a36a0cf Mon Sep 17 00:00:00 2001 From: topecongiro Date: Sun, 11 Jun 2017 23:27:02 +0900 Subject: Update tests --- tests/source/big-impl.rs | 104 +++++++++++++++++++++++++++++++++++++++++++ tests/source/impls.rs | 17 +++++++ tests/target/big-impl-rfc.rs | 26 ++++++++--- tests/target/big-impl.rs | 62 ++++++++++++++++++++++++++ tests/target/impls.rs | 36 ++++++++++++++- 5 files changed, 236 insertions(+), 9 deletions(-) create mode 100644 tests/source/big-impl.rs create mode 100644 tests/target/big-impl.rs (limited to 'tests/source') diff --git a/tests/source/big-impl.rs b/tests/source/big-impl.rs new file mode 100644 index 00000000000..c36b7e6cadb --- /dev/null +++ b/tests/source/big-impl.rs @@ -0,0 +1,104 @@ +// #1357 +impl< + 'a, + Select, + From, + Distinct, + Where, + Order, + Limit, + Offset, + Groupby, + DB, +> InternalBoxedDsl<'a, DB> + for SelectStatement< + Select, + From, + Distinct, + Where, + Order, + Limit, + Offset, + GroupBy, + > where + DB: Backend, + Select: QueryFragment + SelectableExpression + 'a, + Distinct: QueryFragment + 'a, + Where: Into + 'a>>>, + Order: QueryFragment + 'a, + Limit: QueryFragment + 'a, + Offset: QueryFragment + 'a, +{ + type Output = BoxedSelectStatement<'a, Select::SqlTypeForSelect, From, DB>; + + fn internal_into_boxed(self) -> Self::Output { + BoxedSelectStatement::new( + Box::new(self.select), + self.from, + Box::new(self.distinct), + self.where_clause.into(), + Box::new(self.order), + Box::new(self.limit), + Box::new(self.offset), + ) + } +} + +// #1369 +impl< + ExcessivelyLongGenericName, + ExcessivelyLongGenericName, + AnotherExcessivelyLongGenericName, +> Foo for Bar { + fn foo() {} +} +impl Foo< + ExcessivelyLongGenericName, + ExcessivelyLongGenericName, + AnotherExcessivelyLongGenericName, +> for Bar { + fn foo() {} +} +impl< + ExcessivelyLongGenericName, + ExcessivelyLongGenericName, + AnotherExcessivelyLongGenericName, +> Foo< + ExcessivelyLongGenericName, + ExcessivelyLongGenericName, + AnotherExcessivelyLongGenericName, +> for Bar { + fn foo() {} +} +impl< + ExcessivelyLongGenericName, + ExcessivelyLongGenericName, + AnotherExcessivelyLongGenericName, +> Foo for Bar< + ExcessivelyLongGenericName, + ExcessivelyLongGenericName, + AnotherExcessivelyLongGenericName, +> { + fn foo() {} +} +impl Foo< + ExcessivelyLongGenericName, + ExcessivelyLongGenericName, + AnotherExcessivelyLongGenericName, +> for Bar< + ExcessivelyLongGenericName, + ExcessivelyLongGenericName, + AnotherExcessivelyLongGenericName, +> { + fn foo() {} +} +impl Foo + for Bar { + fn foo() {} +} diff --git a/tests/source/impls.rs b/tests/source/impls.rs index 1c38a2ff284..17588fb9d35 100644 --- a/tests/source/impls.rs +++ b/tests/source/impls.rs @@ -122,3 +122,20 @@ impl Issue1249 Drop for RawTable { fn drop() {} } + +// #1168 +pub trait Number: Copy + Eq + Not + Shl + + Shr + + BitAnd + BitOr + BitAndAssign + BitOrAssign + + + +{ + // test + fn zero() -> Self; +} + +// #1642 +pub trait SomeTrait : Clone + Eq + PartialEq + Ord + PartialOrd + Default + Hash + Debug + Display + Write + Read + FromStr { + // comment +} diff --git a/tests/target/big-impl-rfc.rs b/tests/target/big-impl-rfc.rs index 18fa59cb5a0..108968faaed 100644 --- a/tests/target/big-impl-rfc.rs +++ b/tests/target/big-impl-rfc.rs @@ -5,7 +5,7 @@ // #1357 impl<'a, Select, From, Distinct, Where, Order, Limit, Offset, Groupby, DB> InternalBoxedDsl<'a, DB> -for SelectStatement + for SelectStatement where DB: Backend, Select: QueryFragment + SelectableExpression + 'a, @@ -32,11 +32,11 @@ where // #1369 impl Foo -for Bar { + for Bar { fn foo() {} } impl Foo -for Bar { + for Bar { fn foo() {} } impl< @@ -44,15 +44,23 @@ impl< ExcessivelyLongGenericName, AnotherExcessivelyLongGenericName, > Foo -for Bar { + for Bar { fn foo() {} } impl Foo -for Bar { + for Bar< + ExcessivelyLongGenericName, + ExcessivelyLongGenericName, + AnotherExcessivelyLongGenericName, + > { fn foo() {} } impl Foo -for Bar { + for Bar< + ExcessivelyLongGenericName, + ExcessivelyLongGenericName, + AnotherExcessivelyLongGenericName, + > { fn foo() {} } impl< @@ -60,6 +68,10 @@ impl< ExcessivelyLongGenericName, AnotherExcessivelyLongGenericName, > Foo -for Bar { + for Bar< + ExcessivelyLongGenericName, + ExcessivelyLongGenericName, + AnotherExcessivelyLongGenericName, + > { fn foo() {} } diff --git a/tests/target/big-impl.rs b/tests/target/big-impl.rs new file mode 100644 index 00000000000..afe2571ec68 --- /dev/null +++ b/tests/target/big-impl.rs @@ -0,0 +1,62 @@ +// #1357 +impl<'a, Select, From, Distinct, Where, Order, Limit, Offset, Groupby, DB> InternalBoxedDsl<'a, DB> + for SelectStatement + where DB: Backend, + Select: QueryFragment + SelectableExpression + 'a, + Distinct: QueryFragment + 'a, + Where: Into + 'a>>>, + Order: QueryFragment + 'a, + Limit: QueryFragment + 'a, + Offset: QueryFragment + 'a +{ + type Output = BoxedSelectStatement<'a, Select::SqlTypeForSelect, From, DB>; + + fn internal_into_boxed(self) -> Self::Output { + BoxedSelectStatement::new(Box::new(self.select), + self.from, + Box::new(self.distinct), + self.where_clause.into(), + Box::new(self.order), + Box::new(self.limit), + Box::new(self.offset)) + } +} + +// #1369 +impl Foo + for Bar { + fn foo() {} +} +impl Foo + for Bar { + fn foo() {} +} +impl Foo for Bar { + fn foo() {} +} +impl Foo + for Bar { + fn foo() {} +} +impl Foo + for Bar { + fn foo() {} +} +impl Foo + for Bar { + fn foo() {} +} diff --git a/tests/target/impls.rs b/tests/target/impls.rs index f8b9f43aeb0..654d4be8967 100644 --- a/tests/target/impls.rs +++ b/tests/target/impls.rs @@ -126,8 +126,8 @@ mod m { impl PartialEq for S where T: PartialEq {} } -impl Handle, - HandleType> { +impl + Handle, HandleType> { } impl PartialEq @@ -154,3 +154,35 @@ impl impl<#[may_dangle] K, #[may_dangle] V> Drop for RawTable { fn drop() {} } + +// #1168 +pub trait Number + : Copy + + Eq + + Not + + Shl + + Shr + + BitAnd + + BitOr + + BitAndAssign + + BitOrAssign { + // test + fn zero() -> Self; +} + +// #1642 +pub trait SomeTrait + : Clone + + Eq + + PartialEq + + Ord + + PartialOrd + + Default + + Hash + + Debug + + Display + + Write + + Read + + FromStr { + // comment +} -- cgit 1.4.1-3-g733a5 From 9ad499786d1eb8008423d9d9810b47c4124e8d47 Mon Sep 17 00:00:00 2001 From: topecongiro Date: Mon, 12 Jun 2017 15:58:27 +0900 Subject: Use block indent for args if single line args exceeds max width --- src/expr.rs | 18 +++++++++++++++--- tests/source/configs-fn_call_style-block.rs | 6 ++++++ .../configs-fn_call_style-block-trailing-comma.rs | 4 +++- tests/target/configs-fn_call_style-block.rs | 7 +++++++ 4 files changed, 31 insertions(+), 4 deletions(-) (limited to 'tests/source') diff --git a/src/expr.rs b/src/expr.rs index aa5913e5f0f..b47bf391ac1 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1734,9 +1734,12 @@ fn rewrite_call_inner(context: &RewriteContext, force_trailing_comma); } + let args_shape = shape + .sub_width(last_line_width(&callee_str)) + .ok_or(Ordering::Less)?; Ok(format!("{}{}", callee_str, - wrap_args_with_parens(context, &list_str, extendable, shape, nested_shape))) + wrap_args_with_parens(context, &list_str, extendable, args_shape, nested_shape))) } fn need_block_indent(s: &str, shape: Shape) -> bool { @@ -1906,14 +1909,23 @@ fn can_be_overflowed_expr(context: &RewriteContext, expr: &ast::Expr, args_len: } } +fn paren_overhead(context: &RewriteContext) -> usize { + if context.config.spaces_within_parens() { + 4 + } else { + 2 + } +} + fn wrap_args_with_parens(context: &RewriteContext, args_str: &str, is_extendable: bool, shape: Shape, nested_shape: Shape) -> String { - if !context.use_block_indent() || (context.inside_macro && !args_str.contains('\n')) || - is_extendable { + if !context.use_block_indent() || + (context.inside_macro && !args_str.contains('\n') && + args_str.len() + paren_overhead(context) <= shape.width) || is_extendable { if context.config.spaces_within_parens() && args_str.len() > 0 { format!("( {} )", args_str) } else { diff --git a/tests/source/configs-fn_call_style-block.rs b/tests/source/configs-fn_call_style-block.rs index 2068216d18e..ee6178c1902 100644 --- a/tests/source/configs-fn_call_style-block.rs +++ b/tests/source/configs-fn_call_style-block.rs @@ -125,3 +125,9 @@ fn issue1581() { }, ); } + +fn issue1651() { + { + let type_list: Vec<_> = try_opt!(types.iter().map(|ty| ty.rewrite(context, shape)).collect()); + } +} diff --git a/tests/target/configs-fn_call_style-block-trailing-comma.rs b/tests/target/configs-fn_call_style-block-trailing-comma.rs index ebdf41d0e3b..b6eb94eb677 100644 --- a/tests/target/configs-fn_call_style-block-trailing-comma.rs +++ b/tests/target/configs-fn_call_style-block-trailing-comma.rs @@ -3,7 +3,9 @@ // rustfmt should not add trailing comma when rewriting macro. See #1528. fn a() { - panic!("this is a long string that goes past the maximum line length causing rustfmt to insert a comma here:"); + panic!( + "this is a long string that goes past the maximum line length causing rustfmt to insert a comma here:" + ); foo( oooptoptoptoptptooptoptoptoptptooptoptoptoptptoptoptoptoptpt(), ); diff --git a/tests/target/configs-fn_call_style-block.rs b/tests/target/configs-fn_call_style-block.rs index ddead8ce5a8..dfc8daef6d9 100644 --- a/tests/target/configs-fn_call_style-block.rs +++ b/tests/target/configs-fn_call_style-block.rs @@ -145,3 +145,10 @@ fn issue1581() { } }); } + +fn issue1651() { + { + let type_list: Vec<_> = + try_opt!(types.iter().map(|ty| ty.rewrite(context, shape)).collect()); + } +} -- cgit 1.4.1-3-g733a5 From d269189f19f62de61564d9225cef18d9482bb55c Mon Sep 17 00:00:00 2001 From: topecongiro Date: Mon, 12 Jun 2017 16:23:10 +0900 Subject: Use correct indent for return type when it goes multi line --- src/items.rs | 2 +- tests/source/configs-fn_args_layout-block.rs | 4 ++++ tests/target/configs-fn_args_layout-block.rs | 11 +++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) (limited to 'tests/source') diff --git a/src/items.rs b/src/items.rs index ac2f36ad76a..43101d9187b 100644 --- a/src/items.rs +++ b/src/items.rs @@ -1798,7 +1798,7 @@ fn rewrite_fn_base(context: &RewriteContext, indent } else { result.push(' '); - Indent::new(indent.width(), result.len()) + Indent::new(indent.block_indent, last_line_width(&result)) }; if multi_line_ret_str || ret_should_indent { diff --git a/tests/source/configs-fn_args_layout-block.rs b/tests/source/configs-fn_args_layout-block.rs index 55b38101abc..28d1dffe6b3 100644 --- a/tests/source/configs-fn_args_layout-block.rs +++ b/tests/source/configs-fn_args_layout-block.rs @@ -20,3 +20,7 @@ extern "C" { second_parameter: SecondParameterType, ...); } + +// #1652 +fn deconstruct(foo: Bar) -> (SocketAddr, Header, Method, RequestUri, HttpVersion, AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA) { +} diff --git a/tests/target/configs-fn_args_layout-block.rs b/tests/target/configs-fn_args_layout-block.rs index 04a4d631ca4..f93b84f2d4a 100644 --- a/tests/target/configs-fn_args_layout-block.rs +++ b/tests/target/configs-fn_args_layout-block.rs @@ -32,3 +32,14 @@ extern "C" { ... ); } + +// #1652 +fn deconstruct( + foo: Bar, +) -> (SocketAddr, + Header, + Method, + RequestUri, + HttpVersion, + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA) { +} -- cgit 1.4.1-3-g733a5