Skip to content

Conversation

topecongiro
Copy link
Contributor

When either one of these two options are set to true, each should take
precedence over the brace_style option.

This commit does not introduce any formatting change to the default
configuration, so no version gate is required.

Closes #2835.

When either one of these two options are set to `true`, each should take
precedence over the brace_style option.

This commit does not introduce any formatting change to the default
configuration, so no version gate is required.
@@ -390,42 +392,37 @@ impl<'a> FmtVisitor<'a> {

if self.config.empty_item_single_line()
&& is_empty_block(block, None, source_map)
&& self.block_indent.width() + fn_str.len() + 2 <= self.config.max_width()
&& self.block_indent.width() + fn_str.len() + 3 <= self.config.max_width()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it a 3 now instead of a 2 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for a space between fn_str and the opening brace.


None
let width = self.block_indent.width() + fn_str.len() + res.len() + 5;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it 5 and before it was 4 ?

Copy link
Contributor Author

@topecongiro topecongiro Feb 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for a space between fn_str and the opening brace.

None
let width = self.block_indent.width() + fn_str.len() + res.len() + 5;
if !res.contains('\n') && width <= self.config.max_width() {
Some(format!("{} {{ {} }}", fn_str, res))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is an extra space right after fn_str, is it on purpose ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

@topecongiro
Copy link
Contributor Author

Previously we added spaces and the opening brace before calling self.single_line() (here), so we could not rewrite a short function in a single line when we had already put the opening brace on the next line. This PR changes it so that spaces and the opening brace are added after calling self.single_line(). As a consequence, inside single_line_fn we need to take into account the space before the opening brace.

@scampi
Copy link
Contributor

scampi commented Feb 1, 2019

thanks @topecongiro for the clarifications!

@topecongiro topecongiro merged commit bfcfaf1 into rust-lang:master Feb 3, 2019
@topecongiro topecongiro deleted the issue-2835 branch February 3, 2019 15:11
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