@@ -801,11 +801,11 @@ E.g., `&&Some(foo)` matches, `Foo(4, Bar)` does not.
801
801
802
802
## Combinable expressions
803
803
804
- Where a function call has a single argument, and that argument is formatted
805
- across multiple-lines, format the outer call as if it were a single-line call,
804
+ When the last argument in a function call is formatted across
805
+ multiple-lines, format the outer call as if it were a single-line call,
806
806
if the result fits. Apply the same combining behaviour to any similar
807
807
expressions which have multi-line, block-indented lists of sub-expressions
808
- delimited by parentheses (e.g., macros or tuple struct literals) . E.g.,
808
+ delimited by parentheses, brackets, or braces . E.g.,
809
809
810
810
``` rust
811
811
foo (bar (
@@ -831,20 +831,61 @@ let arr = [combinable(
831
831
an_expr ,
832
832
another_expr ,
833
833
)];
834
+
835
+ let x = Thing (an_expr , another_expr , match cond {
836
+ A => 1 ,
837
+ B => 2 ,
838
+ });
839
+
840
+ let x = format! (" Stuff: {}" , [
841
+ an_expr ,
842
+ another_expr ,
843
+ ]);
844
+
845
+ let x = func (an_expr , another_expr , SomeStruct {
846
+ field : this_is_long ,
847
+ another_field : 123 ,
848
+ });
834
849
```
835
850
836
851
Apply this behavior recursively.
837
852
838
- For a function with multiple arguments, if the last argument is a multi-line
839
- closure with an explicit block, there are no other closure arguments, and all
840
- the arguments and the first line of the closure fit on the first line, use the
841
- same combining behavior:
853
+ If the last argument is a multi-line closure with an explicit block,
854
+ only apply the combining behavior if there are no other closure arguments.
842
855
843
856
``` rust
857
+ // Combinable
844
858
foo (first_arg , x , | param | {
845
859
action ();
846
860
foo (param )
847
861
})
862
+ // Not combinable, because the closure is not the last argument
863
+ foo (
864
+ first_arg ,
865
+ | param | {
866
+ action ();
867
+ foo (param )
868
+ },
869
+ whatever ,
870
+ )
871
+ // Not combinable, because the first line of the closure does not fit
872
+ foo (
873
+ first_arg ,
874
+ x ,
875
+ move | very_long_param_causing_line_to_overflow | -> Bar {
876
+ action ();
877
+ foo (param )
878
+ },
879
+ )
880
+ // Not combinable, because there is more than one closure argument
881
+ foo (
882
+ first_arg ,
883
+ | x | x . bar (),
884
+ | param | {
885
+ action ();
886
+ foo (param )
887
+ },
888
+ )
848
889
```
849
890
850
891
## Ranges
0 commit comments