From ee577df551ee086ba26b445945421da0648cbb75 Mon Sep 17 00:00:00 2001 From: Matthieu Felix Date: Sun, 4 Oct 2020 10:50:31 -0400 Subject: [PATCH] Change None -> Preserve for group_imports config Also reword configuration to be less specific. --- Configurations.md | 22 +++++++++++----------- src/config.rs | 4 ++-- src/config/options.rs | 2 +- src/formatting/reorder.rs | 14 ++++++-------- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/Configurations.md b/Configurations.md index 137d9d786e9..f7b0017604a 100644 --- a/Configurations.md +++ b/Configurations.md @@ -2010,20 +2010,15 @@ use sit; ## `group_imports` -Discard existing import groups, and create three groups for: -1. `std`, `core` and `alloc`, -2. external crates, -3. `self`, `super` and `crate` imports. - -Within each group, imports are sorted as with `reorder_imports`. - -This has no effect is `reorder_imports` is `false`. +Controls the strategy for how imports are grouped together. -- **Default value**: `None` -- **Possible values**: `None`, `StdExternalCrate` +- **Default value**: `Preserve` +- **Possible values**: `Preserve`, `StdExternalCrate` - **Stable**: No -#### `None` (default): +#### `Preserve` (default): + +Preserve the source file's import groups. ```rust use super::update::convert_publish_payload; @@ -2044,6 +2039,11 @@ use core::f32; #### `StdExternalCrate`: +Discard existing import groups, and create three groups for: +1. `std`, `core` and `alloc`, +2. external crates, +3. `self`, `super` and `crate` imports. + ```rust use alloc::alloc::Layout; use core::f32; diff --git a/src/config.rs b/src/config.rs index 6b16f15c6e2..b28fe3d9e36 100644 --- a/src/config.rs +++ b/src/config.rs @@ -78,7 +78,7 @@ create_config! { imports_indent: IndentStyle, IndentStyle::Block, false, "Indent of imports"; imports_layout: ListTactic, ListTactic::Mixed, false, "Item layout inside a import block"; merge_imports: bool, false, false, "Merge imports"; - group_imports: GroupImportsTactic, GroupImportsTactic::None, false, + group_imports: GroupImportsTactic, GroupImportsTactic::Preserve, false, "Reorganize import groups"; // Ordering @@ -595,7 +595,7 @@ where_single_line = false imports_indent = "Block" imports_layout = "Mixed" merge_imports = false -group_imports = "None" +group_imports = "Preserve" reorder_imports = true reorder_modules = true reorder_impl_items = false diff --git a/src/config/options.rs b/src/config/options.rs index 46eadbb56a7..aea67749a45 100644 --- a/src/config/options.rs +++ b/src/config/options.rs @@ -110,7 +110,7 @@ impl Density { /// Configuration for import groups, i.e. sets of imports separated by newlines. pub enum GroupImportsTactic { /// Keep groups as they are. - None, + Preserve, /// Discard existing groups, and create new groups for /// 1. `std` / `core` / `alloc` imports /// 2. other imports diff --git a/src/formatting/reorder.rs b/src/formatting/reorder.rs index c0418afea0e..f43cd10f45d 100644 --- a/src/formatting/reorder.rs +++ b/src/formatting/reorder.rs @@ -195,7 +195,7 @@ fn rewrite_reorderable_item( /// Rewrite a list of items with reordering and/or regrouping. Every item /// in `items` must have the same `ast::ItemKind`. Whether reordering, regrouping, -/// or both ore done is determined from the `context`. +/// or both are done is determined from the `context`. fn rewrite_reorderable_or_regroupable_items( context: &RewriteContext<'_>, reorderable_items: &[&ast::Item], @@ -230,11 +230,9 @@ fn rewrite_reorderable_or_regroupable_items( normalized_items = merge_use_trees(normalized_items); } - let mut regrouped_items = if context.config.group_imports() != GroupImportsTactic::None - { - group_imports(normalized_items) - } else { - vec![normalized_items] + let mut regrouped_items = match context.config.group_imports() { + GroupImportsTactic::Preserve => vec![normalized_items], + GroupImportsTactic::StdExternalCrate => group_imports(normalized_items), }; if context.config.reorder_imports() { @@ -363,14 +361,14 @@ impl ReorderableItemKind { ReorderableItemKind::ExternCrate | ReorderableItemKind::Mod | ReorderableItemKind::Other => false, - ReorderableItemKind::Use => config.group_imports() != GroupImportsTactic::None, + ReorderableItemKind::Use => config.group_imports() != GroupImportsTactic::Preserve, } } fn in_group(self, config: &Config) -> bool { match self { ReorderableItemKind::ExternCrate | ReorderableItemKind::Mod => true, - ReorderableItemKind::Use => config.group_imports() == GroupImportsTactic::None, + ReorderableItemKind::Use => config.group_imports() == GroupImportsTactic::Preserve, ReorderableItemKind::Other => false, } }