Skip to content

Commit ee577df

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

File tree

4 files changed

+20
-22
lines changed

4 files changed

+20
-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

+6-8
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ fn rewrite_reorderable_item(
195195

196196
/// Rewrite a list of items with reordering and/or regrouping. Every item
197197
/// in `items` must have the same `ast::ItemKind`. Whether reordering, regrouping,
198-
/// or both ore done is determined from the `context`.
198+
/// or both are done is determined from the `context`.
199199
fn rewrite_reorderable_or_regroupable_items(
200200
context: &RewriteContext<'_>,
201201
reorderable_items: &[&ast::Item],
@@ -230,11 +230,9 @@ 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]
233+
let mut regrouped_items = match context.config.group_imports() {
234+
GroupImportsTactic::Preserve => vec![normalized_items],
235+
GroupImportsTactic::StdExternalCrate => group_imports(normalized_items),
238236
};
239237

240238
if context.config.reorder_imports() {
@@ -363,14 +361,14 @@ impl ReorderableItemKind {
363361
ReorderableItemKind::ExternCrate
364362
| ReorderableItemKind::Mod
365363
| ReorderableItemKind::Other => false,
366-
ReorderableItemKind::Use => config.group_imports() != GroupImportsTactic::None,
364+
ReorderableItemKind::Use => config.group_imports() != GroupImportsTactic::Preserve,
367365
}
368366
}
369367

370368
fn in_group(self, config: &Config) -> bool {
371369
match self {
372370
ReorderableItemKind::ExternCrate | ReorderableItemKind::Mod => true,
373-
ReorderableItemKind::Use => config.group_imports() == GroupImportsTactic::None,
371+
ReorderableItemKind::Use => config.group_imports() == GroupImportsTactic::Preserve,
374372
ReorderableItemKind::Other => false,
375373
}
376374
}

0 commit comments

Comments
 (0)