Skip to content
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

inconsistent indents on function calls with closure arguments #6108

Open
kawaemon opened this issue Mar 10, 2024 · 0 comments
Open

inconsistent indents on function calls with closure arguments #6108

kawaemon opened this issue Mar 10, 2024 · 0 comments

Comments

@kawaemon
Copy link

kawaemon commented Mar 10, 2024

Edit (simplified):

Output of rustfmt on nightly-2024-03-08:

fn main() {
    app.with_state()
        .layer(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(
        |foo: &Xxxxxxxxx| macroxxxx!(??xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx),
    ));
}

Expected:

fn main() {
    app.with_state()
        .layer(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(|foo: &Xxxxxxxxx| {
            macroxxxx!(??xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)
        }));
}
original report

This code:

fn main() {
    let app = app
        .with_state(build_schema().await)
        .layer(TraceLayer::new_for_http().make_span_with(
            |req: &Request<_>| info_span!("req", method=?req.method(), path=req.uri().to_string()),
        ));
}

formats to:

❮ rustfmt +nightly-2024-03-08 b.rs --emit stdout
/tmp/ktmp/SgB/b.rs:

fn main() {
    let app =
        app.with_state(build_schema().await)
            .layer(TraceLayer::new_for_http().make_span_with(
            |req: &Request<_>| info_span!("req", method=?req.method(), path=req.uri().to_string()),
        ));
}

I think leaving the original code is fine. Or maybe It's ideal to indent the argument one more block like this:

fn main() {
    let app =
        app.with_state(build_schema().await)
            .layer(TraceLayer::new_for_http().make_span_with(
                |req: &Request<_>| info_span!("req", method=?req.method(), path=req.uri().to_string()),
            ));
}

because rustfmt emits like so if the argument was normal function call. For example:

❯ rustfmt +nightly-2024-03-08 a.rs --emit stdout
/tmp/ktmp/SgB/a.rs:

fn main() {
    let app =
        app.with_state(build_schema().await)
            .layer(TraceLayer::new_for_http().make_span_with(
                sooooooooooooooooooooooooooooooooooooooo_long_function_call_here(foo, bar, baz),
            ));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants