Skip to content

Commit 261238e

Browse files
committed
Change use_small_heuristics to an enum and stabilise
Since it is now an enum, we can be future compatible since we can add variants for different heuristics. Closes #1974
1 parent a1c5c46 commit 261238e

File tree

7 files changed

+21
-11
lines changed

7 files changed

+21
-11
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## [Unreleased]
44

5+
- `use_small_heuristics` changed to be an enum and stabilised. Configuration
6+
options are now ready for 1.0.
7+
58
## [0.4.1] 2018-03-16
69

710
### Added

Configurations.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,11 @@ fn lorem<Ipsum, Dolor, Sit, Amet>() -> T
275275

276276
Whether to use different formatting for items and expressions if they satisfy a heuristic notion of 'small'.
277277

278-
- **Default value**: `true`
279-
- **Possible values**: `true`, `false`
280-
- **Stable**: No
278+
- **Default value**: `Default`
279+
- **Possible values**: `Default`, `Off`
280+
- **Stable**: Yess
281281

282-
#### `true` (default):
282+
#### `Default` (default):
283283

284284
```rust
285285
enum Lorem {
@@ -309,7 +309,7 @@ fn main() {
309309
}
310310
```
311311

312-
#### `false`:
312+
#### `Off`:
313313

314314
```rust
315315
enum Lorem {

src/config/config_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ macro_rules! create_config {
399399
}
400400

401401
fn set_heuristics(&mut self) {
402-
if self.use_small_heuristics.2 {
402+
if self.use_small_heuristics.2 == Heuristics::Default {
403403
let max_width = self.max_width.2;
404404
self.set().width_heuristics(WidthHeuristics::scaled(max_width));
405405
} else {

src/config/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ create_config! {
4141
hard_tabs: bool, false, true, "Use tab characters for indentation, spaces for alignment";
4242
tab_spaces: usize, 4, true, "Number of spaces per tab";
4343
newline_style: NewlineStyle, NewlineStyle::Unix, true, "Unix or Windows line endings";
44-
use_small_heuristics: bool, true, false, "Whether to use different formatting for items and \
45-
expressions if they satisfy a heuristic notion of 'small'.";
44+
use_small_heuristics: Heuristics, Heuristics::Default, true, "Whether to use different \
45+
formatting for items and expressions if they satisfy a heuristic notion of 'small'.";
4646
indent_style: IndentStyle, IndentStyle::Block, false, "How do we indent expressions or items.";
4747

4848
// Comments and strings
@@ -236,7 +236,7 @@ mod test {
236236
create_config! {
237237
// Options that are used by the generated functions
238238
max_width: usize, 100, true, "Maximum width of each line";
239-
use_small_heuristics: bool, true, false,
239+
use_small_heuristics: Heuristics, Heuristics::Default, true,
240240
"Whether to use different formatting for items and \
241241
expressions if they satisfy a heuristic notion of 'small'.";
242242
license_template_path: String, String::default(), false,

src/config/options.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ configuration_option_enum! { TypeDensity:
151151
Wide,
152152
}
153153

154+
configuration_option_enum! { Heuristics:
155+
// Turn off any heuristics
156+
Off,
157+
// Use Rustfmt's defaults
158+
Default,
159+
}
160+
154161
impl Density {
155162
pub fn to_list_tactic(self) -> ListTactic {
156163
match self {

tests/source/chains.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// rustfmt-normalize_comments: true
2-
// rustfmt-use_small_heuristics: false
2+
// rustfmt-use_small_heuristics: Off
33
// Test chain formatting.
44

55
fn main() {

tests/target/chains.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// rustfmt-normalize_comments: true
2-
// rustfmt-use_small_heuristics: false
2+
// rustfmt-use_small_heuristics: Off
33
// Test chain formatting.
44

55
fn main() {

0 commit comments

Comments
 (0)