Skip to content

Weird closure formatting with indent_style = "Visual" #2921

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

Closed
YaLTeR opened this issue Aug 16, 2018 · 1 comment
Closed

Weird closure formatting with indent_style = "Visual" #2921

YaLTeR opened this issue Aug 16, 2018 · 1 comment
Labels
only-with-option requires a non-default option value to reproduce poor-formatting

Comments

@YaLTeR
Copy link
Contributor

YaLTeR commented Aug 16, 2018

I ran rustfmt 0.99.2-nightly (5c9a2b6 2018-08-07) through my indent_style = "Visual" codebase and it resulted in this weird formatting in a couple of places:

        let pro_que = context.and_then(|ctx| {
                                 ocl::ProQue::builder()
                .context(ctx)
                .prog_bldr(ocl::Program::builder()
                               .src(include_str!("../../cl_src/color_conversion.cl"))
                               .src(include_str!("../../cl_src/sampling.cl")))
                .build()
                .chain_err(|| "error building ocl::ProQue")
                             })
                             .map(|pro_que| Box::into_raw(Box::new(pro_que)))
                             .map_err(report_opencl_error)
                             .ok();

More minimal reproduction case (the only option required is indent_style = "Visual"):

fn main() {
    let pro_que = context.and_then(|ctx| {
                             ocl::ProQue::builder()
            .context(ctx)
            .prog_bldr(
                ocl::Program::builder()
                .src(include_str!("../../cl_src/color_conversion.cl"))
                .src(include_str!("../../cl_src/sampling.cl")),
                ).build()
            .chain_err(|| "error building ocl::ProQue")
                         })
                         .map(|pro_que| Box::into_raw(Box::new(pro_que)))
                         .map_err(report_opencl_error)
                         .ok();
}

Actually, it seems that sometimes rustfmt just gives up and preserves the whatever formatting the closure had originally. Joining all of these lines into one and running rustfmt results in this (without any errors or warnings in the output):

fn main() {
    let pro_que = context .and_then(|ctx| { ocl::ProQue::builder() .context(ctx) .prog_bldr( ocl::Program::builder() .src(include_str!("../../cl_src/color_conversion.cl")) .src(include_str!("../../cl_src/sampling.cl")),).build() .chain_err(|| "error building ocl::ProQue") }).map(|pro_que| Box::into_raw(Box::new(pro_que))) .map_err(report_opencl_error) .ok();
}

Default settings (indent_style = "Block") handles all of this correctly (with Block formatting obviously).

I expect rustfmt to at least format things properly even if overflowing max_width rather than just do nothing in this case.

@topecongiro topecongiro added poor-formatting only-with-option requires a non-default option value to reproduce labels Aug 16, 2018
@YaLTeR
Copy link
Contributor Author

YaLTeR commented Sep 11, 2018

I think this is effectively a direct consequence of #2970 and can be closed in favor of that?

@nrc nrc closed this as completed Sep 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
only-with-option requires a non-default option value to reproduce poor-formatting
Projects
None yet
Development

No branches or pull requests

3 participants