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

Consider increasing single_line_if_else_max_width #1181

Closed
nivekuil opened this issue Oct 1, 2016 · 2 comments
Closed

Consider increasing single_line_if_else_max_width #1181

nivekuil opened this issue Oct 1, 2016 · 2 comments

Comments

@nivekuil
Copy link

nivekuil commented Oct 1, 2016

The default 50 column limit on single-line if-else statements feels like it creates too much whitespace for simple logic. For example:

let dest: PathBuf = {
    let grave = graveyard.join(path.strip_prefix("/").unwrap());
    if grave.exists() { rename_grave(grave) } else { grave }
};

becomes

let dest: PathBuf = {
    let grave = graveyard.join(path.strip_prefix("/").unwrap());
    if grave.exists() {
        rename_grave(grave)
    } else {
        grave
    }
};

I understand the rationale behind discouraging complex one-liners, but it seems like a length restriction just encourages shorter variable names.

@nrc
Copy link
Member

nrc commented Oct 1, 2016

Yeah, I mostly agree and also get frustrated when we don't quite hit the length limit. However, rather than just extend the limit, I'd rather do something a little smarter, like look at the expressions in the arms (I think we already require a single expression) and allow a one-liner if there is a 'small' expression, for some definition of that.

@nrc
Copy link
Member

nrc commented Jun 23, 2017

Discussed at rust-lang/style-team#47

@nrc nrc closed this as completed Jun 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants