@@ -818,11 +818,11 @@ E.g., `&&Some(foo)` matches, `Foo(4, Bar)` does not.
818
818
819
819
## Combinable expressions
820
820
821
- Where a function call has a single argument, and that argument is formatted
822
- across multiple-lines, format the outer call as if it were a single-line call,
821
+ When the last argument in a function call is formatted across
822
+ multiple-lines, format the outer call as if it were a single-line call,
823
823
if the result fits. Apply the same combining behaviour to any similar
824
824
expressions which have multi-line, block-indented lists of sub-expressions
825
- delimited by parentheses (e.g., macros or tuple struct literals) . E.g.,
825
+ delimited by parentheses, brackets, or braces . E.g.,
826
826
827
827
``` rust
828
828
foo (bar (
@@ -848,20 +848,61 @@ let arr = [combinable(
848
848
an_expr ,
849
849
another_expr ,
850
850
)];
851
+
852
+ let x = Thing (an_expr , another_expr , match cond {
853
+ A => 1 ,
854
+ B => 2 ,
855
+ });
856
+
857
+ let x = format! (" Stuff: {}" , [
858
+ an_expr ,
859
+ another_expr ,
860
+ ]);
861
+
862
+ let x = func (an_expr , another_expr , SomeStruct {
863
+ field : this_is_long ,
864
+ another_field : 123 ,
865
+ });
851
866
```
852
867
853
868
Apply this behavior recursively.
854
869
855
- For a function with multiple arguments, if the last argument is a multi-line
856
- closure with an explicit block, there are no other closure arguments, and all
857
- the arguments and the first line of the closure fit on the first line, use the
858
- same combining behavior:
870
+ If the last argument is a multi-line closure with an explicit block,
871
+ only apply the combining behavior if there are no other closure arguments.
859
872
860
873
``` rust
874
+ // Combinable
861
875
foo (first_arg , x , | param | {
862
876
action ();
863
877
foo (param )
864
878
})
879
+ // Not combinable, because the closure is not the last argument
880
+ foo (
881
+ first_arg ,
882
+ | param | {
883
+ action ();
884
+ foo (param )
885
+ },
886
+ whatever ,
887
+ )
888
+ // Not combinable, because the first line of the closure does not fit
889
+ foo (
890
+ first_arg ,
891
+ x ,
892
+ move | very_long_param_causing_line_to_overflow | -> Bar {
893
+ action ();
894
+ foo (param )
895
+ },
896
+ )
897
+ // Not combinable, because there is more than one closure argument
898
+ foo (
899
+ first_arg ,
900
+ | x | x . bar (),
901
+ | param | {
902
+ action ();
903
+ foo (param )
904
+ },
905
+ )
865
906
```
866
907
867
908
## Ranges
0 commit comments