Skip to content

Do not scale WidthHeuristics when max_width less than 100 #2667

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 3 commits into from
May 3, 2018

Conversation

tspiteri
Copy link
Contributor

Fixes #2644.

Copy link
Member

@nrc nrc left a comment

Choose a reason for hiding this comment

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

Looks good other than the small change. Could you also add a couple of tests please?

let mut max_width_ratio: f32 = max_width as f32 / 100.0; // 100 is the default width -> default ratio is 1
max_width_ratio = (max_width_ratio * 10.0).round() / 10.0; // round to the closest 0.1
// 100 is the default width -> default ratio is 1
let max_width_ratio = if max_width > 100 {
Copy link
Member

Choose a reason for hiding this comment

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

COuld we pull the default max width out into a const?

@tspiteri tspiteri force-pushed the width-heuristics branch 2 times, most recently from 5a0997a to 3f6c816 Compare May 2, 2018 09:21
@tspiteri
Copy link
Contributor Author

tspiteri commented May 2, 2018

I added the DEFAULT_MAX_WIDTH constant in the function, added a test for the issue in commit 2, and added a test to check that width heuristics work for larger widths in commit 3. In commit 3 I also had to touch config_type.rs to make sure self.set_heuristics() is called if max_width changes, otherwise WidthHeuristics are not updated properly for the test's rustfmt-max_width.

@tspiteri tspiteri force-pushed the width-heuristics branch from 3f6c816 to 48df8f8 Compare May 2, 2018 09:38
@nrc nrc merged commit 4a57e79 into rust-lang:master May 3, 2018
@nrc
Copy link
Member

nrc commented May 3, 2018

Thank you, looks great!

@tspiteri tspiteri deleted the width-heuristics branch May 4, 2018 08:43
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