Skip to content

Commit c1d5bad

Browse files
committed
Change None -> Preserve for group_imports config
Also reword configuration to be less specific.
1 parent 4f4acf7 commit c1d5bad

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

Configurations.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -2010,20 +2010,15 @@ use sit;
20102010

20112011
## `group_imports`
20122012

2013-
Discard existing import groups, and create three groups for:
2014-
1. `std`, `core` and `alloc`,
2015-
2. external crates,
2016-
3. `self`, `super` and `crate` imports.
2017-
2018-
Within each group, imports are sorted as with `reorder_imports`.
2019-
2020-
This has no effect is `reorder_imports` is `false`.
2013+
Controls the strategy for how imports are grouped together.
20212014

2022-
- **Default value**: `None`
2023-
- **Possible values**: `None`, `StdExternalCrate`
2015+
- **Default value**: `Preserve`
2016+
- **Possible values**: `Preserve`, `StdExternalCrate`
20242017
- **Stable**: No
20252018

2026-
#### `None` (default):
2019+
#### `Preserve` (default):
2020+
2021+
Preserve the source file's import groups.
20272022

20282023
```rust
20292024
use super::update::convert_publish_payload;
@@ -2044,6 +2039,11 @@ use core::f32;
20442039

20452040
#### `StdExternalCrate`:
20462041

2042+
Discard existing import groups, and create three groups for:
2043+
1. `std`, `core` and `alloc`,
2044+
2. external crates,
2045+
3. `self`, `super` and `crate` imports.
2046+
20472047
```rust
20482048
use alloc::alloc::Layout;
20492049
use core::f32;

src/config.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ create_config! {
7878
imports_indent: IndentStyle, IndentStyle::Block, false, "Indent of imports";
7979
imports_layout: ListTactic, ListTactic::Mixed, false, "Item layout inside a import block";
8080
merge_imports: bool, false, false, "Merge imports";
81-
group_imports: GroupImportsTactic, GroupImportsTactic::None, false,
81+
group_imports: GroupImportsTactic, GroupImportsTactic::Preserve, false,
8282
"Reorganize import groups";
8383

8484
// Ordering
@@ -595,7 +595,7 @@ where_single_line = false
595595
imports_indent = "Block"
596596
imports_layout = "Mixed"
597597
merge_imports = false
598-
group_imports = "None"
598+
group_imports = "Preserve"
599599
reorder_imports = true
600600
reorder_modules = true
601601
reorder_impl_items = false

src/config/options.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl Density {
110110
/// Configuration for import groups, i.e. sets of imports separated by newlines.
111111
pub enum GroupImportsTactic {
112112
/// Keep groups as they are.
113-
None,
113+
Preserve,
114114
/// Discard existing groups, and create new groups for
115115
/// 1. `std` / `core` / `alloc` imports
116116
/// 2. other imports

src/formatting/reorder.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,12 @@ fn rewrite_reorderable_or_regroupable_items(
230230
normalized_items = merge_use_trees(normalized_items);
231231
}
232232

233-
let mut regrouped_items = if context.config.group_imports() != GroupImportsTactic::None
234-
{
235-
group_imports(normalized_items)
236-
} else {
237-
vec![normalized_items]
238-
};
233+
let mut regrouped_items =
234+
if context.config.group_imports() != GroupImportsTactic::Preserve {
235+
group_imports(normalized_items)
236+
} else {
237+
vec![normalized_items]
238+
};
239239

240240
if context.config.reorder_imports() {
241241
regrouped_items.iter_mut().for_each(|items| items.sort())
@@ -363,14 +363,14 @@ impl ReorderableItemKind {
363363
ReorderableItemKind::ExternCrate
364364
| ReorderableItemKind::Mod
365365
| ReorderableItemKind::Other => false,
366-
ReorderableItemKind::Use => config.group_imports() != GroupImportsTactic::None,
366+
ReorderableItemKind::Use => config.group_imports() != GroupImportsTactic::Preserve,
367367
}
368368
}
369369

370370
fn in_group(self, config: &Config) -> bool {
371371
match self {
372372
ReorderableItemKind::ExternCrate | ReorderableItemKind::Mod => true,
373-
ReorderableItemKind::Use => config.group_imports() == GroupImportsTactic::None,
373+
ReorderableItemKind::Use => config.group_imports() == GroupImportsTactic::Preserve,
374374
ReorderableItemKind::Other => false,
375375
}
376376
}

0 commit comments

Comments
 (0)