Skip to content

Format if expressions & loops #147

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

Merged
merged 5 commits into from
Jul 24, 2015
Merged

Format if expressions & loops #147

merged 5 commits into from
Jul 24, 2015

Conversation

marcusklaas
Copy link
Contributor

Since a lot of code is inside these expressions, this should significantly increase coverage!

Blocked by rust-lang/rust#27065.

Single line if-else expressions are not implemented yet.

Closes https://github.com/nrc/rustfmt/issues/102.

@nrc
Copy link
Member

nrc commented Jul 20, 2015

I wonder if we should ever try to format the label on to the previous line? For example:

'a_long_label:
while a < b {
}

// rather than 
'a_long_label: while a <
                   b {
}

(assuming a and b are actually really long, or whatever).

I guess in practice labels are usually quite short, but it does prevent rightward drift a little bit.

Anyway, just a random thought, don't need to change anything with the PR.

@nrc
Copy link
Member

nrc commented Jul 20, 2015

This is awesome, thanks!

@marcusklaas
Copy link
Contributor Author

Good thing you mentioned tests for ranges, because their bad spans still break this :-(

It seems we're blocked on rust-lang/rust#27162 now.

@marcusklaas
Copy link
Contributor Author

How should we format if-else block inside functions? I'm tempted to format things as follows:

Some(if cond {
    ...
} else {
    ...
})

but that's not really consistent with how we format them within struct literals. OTOH,

Some(if cond {
         ...

     } else {

        ...

     })

just looks weird to me...

What to do? Maybe we could take a hint from the user here?

@nrc
Copy link
Member

nrc commented Jul 21, 2015

I would add options for this: block indent, block indent + tab, visual indent.

@nrc
Copy link
Member

nrc commented Jul 21, 2015

I'm not sure what the default should be, perhaps block + tab?

@marcusklaas
Copy link
Contributor Author

I'll play around with a bit and see what looks good (enough), but that sounds sensible to me.

@marcusklaas
Copy link
Contributor Author

The bad span for ranges should be fixed now, I hope nightly is updated in time!

This should also close https://github.com/nrc/rustfmt/issues/155.

@marcusklaas
Copy link
Contributor Author

Guess not :-(

@marcusklaas
Copy link
Contributor Author

This builds now!

nrc added a commit that referenced this pull request Jul 24, 2015
@nrc nrc merged commit 8461e8a into rust-lang:master Jul 24, 2015
@marcusklaas marcusklaas deleted the even-more-expr branch September 11, 2015 09:23
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

Successfully merging this pull request may close these issues.

2 participants