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

Unnecessarily deep indent on arguments following some paren-heavy code #1306

Closed
nabijaczleweli opened this issue Feb 10, 2017 · 5 comments · Fixed by #5436
Closed

Unnecessarily deep indent on arguments following some paren-heavy code #1306

nabijaczleweli opened this issue Feb 10, 2017 · 5 comments · Fixed by #5436
Labels
only-with-option requires a non-default option value to reproduce poor-formatting

Comments

@nabijaczleweli
Copy link

Given this config, rustfmt insists, that this is the best way to format this code chunk:

for elem in try!(gen_epub_book::ops::parse_descriptor_file(&mut try!(File::open(&opts.source_file.1).map_err(|_| {
    gen_epub_book::Error::Io {
        desc: "input file",
        op: "open",
        more: None,
    }
})),
                                                           "input file")) {
    println!("{}", elem);
}

When I'd expect it to do something like this:

for elem in try!(gen_epub_book::ops::parse_descriptor_file(&mut try!(File::open(&opts.source_file.1).map_err(|_| {
    gen_epub_book::Error::Io {
        desc: "input file",
        op: "open",
        more: None,
    }
})), "input file")) {
    println!("{}", elem);
}
@nabijaczleweli
Copy link
Author

Also happens here:

fn write_content() {
    io::copy(try!(File::open(in_f).map_err(|_| {
        Error::Io {
            desc: "Content",
            op: "open",
            more: None,
        }
    })),
             w);
}

@topecongiro
Copy link
Contributor

You could consider using fn_call_style = "Block". With your other settings, output will be like the following:

fn foo() {
    for elem in try!(gen_epub_book::ops::parse_descriptor_file(
        &mut try!(File::open(&opts.source_file.1).map_err(|_| {
                gen_epub_book::Error::Io {
                    desc: "input file",
                    op: "open",
                    more: None,
                }
            })),
        "input file"
    )) {
        println!("{}", elem);
    }
}
fn write_content() {
    io::copy(
        try!(File::open(in_f).map_err(|_| {
                Error::Io {
                    desc: "Content",
                    op: "open",
                    more: None,
                }
            })),
        w,
    );
}

@nabijaczleweli
Copy link
Author

That's ugly though

@nrc nrc added the only-with-option requires a non-default option value to reproduce label Nov 2, 2017
@kadiwa4
Copy link
Contributor

kadiwa4 commented Jun 21, 2022

This no longer applies.

@ytmimi
Copy link
Contributor

ytmimi commented Jul 9, 2022

@kadiwa4 thanks for looking into this. I can confirm that when I use the default rustfmt configs I can't reproduce this issue. Here are the configs orginally listed:

max_width             = 160
ideal_width           = 128
fn_call_width         = 96
fn_args_paren_newline = false
fn_args_density       = "Compressed"
struct_trailing_comma = "Always"
wrap_comments         = true

Not all of them exist anymore. I don't think we have substitutes for ideal_width, and fn_args_paren_newline so lets not worry about those options anymore. In release 1.3.0 fn_args_density was renamed to fn_args_layout. struct_trailing_comma doesn't exist but trailing_comma does. So an updated config for the current rustfmt would be:

max_width      = 160
fn_call_width  = 96
fn_args_layout = "Compressed"
trailing_comma = "Always"
wrap_comments  = true

given this input:

fn foo() {
    for elem in try!(gen_epub_book::ops::parse_descriptor_file(&mut try!(File::open(&opts.source_file.1).map_err(|_| {
        gen_epub_book::Error::Io {
            desc: "input file",
            op: "open",
            more: None,
        }
    })),
                                                               "input file")) {
        println!("{}", elem);
    }
}

fn write_content() {
    io::copy(try!(File::open(in_f).map_err(|_| {
        Error::Io {
            desc: "Content",
            op: "open",
            more: None,
        }
    })),
             w);
}
fn foo() {
    for elem in try!(gen_epub_book::ops::parse_descriptor_file(
        &mut try!(File::open(&opts.source_file.1).map_err(|_| {
            gen_epub_book::Error::Io {
                desc: "input file",
                op: "open",
                more: None,
            }
        })),
        "input file"
    )) {
        println!("{}", elem);
    }
}

fn write_content() {
    io::copy(
        try!(File::open(in_f).map_err(|_| {
            Error::Io {
                desc: "Content",
                op: "open",
                more: None,
            }
        })),
        w,
    );
}

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

Successfully merging a pull request may close this issue.

5 participants