-
Notifications
You must be signed in to change notification settings - Fork 927
Lambda with long argument list should be formatted without indent_style="Visual" #5284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for the report.
I just want to point out that the rules that dictate how rustfmt is meant to work are laid out in the style guide. The relevant section on closures, does seem to indicate that the formatting should be more consistent with functions. |
confirming that on fn main() {
let long_lambda = |
x: &mut usize,
y: &mut usize,
z: &mut usize,
w: &mut usize,
v: &mut usize,
a: &mut usize,
b: &mut usize
| {
println!("{}", x);
println!("{}", y);
println!("{}", z);
println!("{}", w);
println!("{}", a);
println!("{}", b);
};
long_lambda(&mut 1, &mut 2, &mut 3, &mut 4, &mut 5, &mut 6, &mut 7);
} produces this output: fn main() {
let long_lambda = |x: &mut usize,
y: &mut usize,
z: &mut usize,
w: &mut usize,
v: &mut usize,
a: &mut usize,
b: &mut usize| {
println!("{}", x);
println!("{}", y);
println!("{}", z);
println!("{}", w);
println!("{}", a);
println!("{}", b);
};
long_lambda(&mut 1, &mut 2, &mut 3, &mut 4, &mut 5, &mut 6, &mut 7);
} The error_on_line_overflow = true
error_on_unformatted = true
version = "Two" |
Thank you for the report but let's go ahead and close this as a duplicate |
I have a couple of lambdas with parameters with complex types, which take up a lot of space. This means rustfmt splits up the parameters over multiple lines, but it does so as if
indent_style="Visual"
. A simple reproducing example, on1.4.38-nightly (2022-03-19 8d60bf4)
(the current rust playground formatter):This is inconsistent with the rest of rustfmt formatting, and doesn't play well with things like IDE type hints.
I think it would be better if lambda parameters were formatted more like
indent_style="Block"
, which is the default elsewhere, eg. function parameters.The text was updated successfully, but these errors were encountered: