diff --git a/Configurations.md b/Configurations.md index ca804b2f7f25..8ace886a98f7 100644 --- a/Configurations.md +++ b/Configurations.md @@ -6,7 +6,7 @@ A possible content of `rustfmt.toml` or `.rustfmt.toml` might look like this: ```toml indent_style = "Block" -reorder_imported_names = true +reorder_imports = false ``` Each configuration option is either stable or unstable. @@ -1240,31 +1240,10 @@ fn dolor() -> usize {} fn adipiscing() -> usize {} ``` -## `reorder_imported_names` - -Reorder lists of names in import statements alphabetically - -- **Default value**: `false` -- **Possible values**: `true`, `false` -- **Stable**: No - -#### `false` (default): - -```rust -use super::{lorem, ipsum, dolor, sit}; -``` - -#### `true`: - -```rust -use super::{dolor, ipsum, lorem, sit}; -``` - -See also [`reorder_imports`](#reorder_imports). ## `reorder_imports` -Reorder import statements alphabetically +Reorder import and extern crate statements alphabetically - **Default value**: `false` - **Possible values**: `true`, `false` @@ -1288,98 +1267,6 @@ use lorem; use sit; ``` -See also [`reorder_imported_names`](#reorder_imported_names), [`reorder_imports_in_group`](#reorder_imports_in_group). - -## `reorder_imports_in_group` - -Reorder import statements in group - -- **Default value**: `false` -- **Possible values**: `true`, `false` -- **Stable**: No - -**Note:** This option takes effect only when [`reorder_imports`](#reorder_imports) is set to `true`. - -#### `true` (default): - -```rust -use std::io; -use std::mem; - -use dolor; -use ipsum; -use lorem; -use sit; -``` - -#### `false`: - - -```rust -use dolor; -use ipsum; -use lorem; -use sit; -use std::io; -use std::mem; -``` - -See also [`reorder_imports`](#reorder_imports). - -## `reorder_extern_crates` - -Reorder `extern crate` statements alphabetically - -- **Default value**: `true` -- **Possible values**: `true`, `false` -- **Stable**: No - -#### `true` (default): - -```rust -extern crate dolor; -extern crate ipsum; -extern crate lorem; -extern crate sit; -``` - -#### `false`: - -```rust -extern crate lorem; -extern crate ipsum; - -extern crate dolor; -extern crate sit; -``` - -See also [`reorder_extern_crates_in_group`](#reorder_extern_crates_in_group). - -## `reorder_extern_crates_in_group` - -Reorder `extern crate` statements in group - -- **Default value**: `true` -- **Possible values**: `true`, `false` -- **Stable**: No - -#### `false` (default): - -This value has no influence beyond the effect of the [`reorder_extern_crates`](#reorder_extern_crates) option. Set [`reorder_extern_crates`](#reorder_extern_crates) to `false` if you do not want `extern crate` groups to be collapsed and ordered. - -#### `true`: - -**Note:** This only takes effect when [`reorder_extern_crates`](#reorder_extern_crates) is set to `true`. - -```rust -extern crate a; -extern crate b; - -extern crate dolor; -extern crate ipsum; -extern crate lorem; -extern crate sit; -``` ## `reorder_modules` diff --git a/src/config/mod.rs b/src/config/mod.rs index 3676aed4ba97..63a75f880b62 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -68,14 +68,9 @@ create_config! { imports_layout: ListTactic, ListTactic::Mixed, false, "Item layout inside a import block"; // Ordering - reorder_extern_crates: bool, true, false, "Reorder extern crate statements alphabetically"; - reorder_extern_crates_in_group: bool, true, false, "Reorder extern crate statements in group"; - reorder_imports: bool, true, false, "Reorder import statements alphabetically"; - reorder_imports_in_group: bool, true, false, "Reorder import statements in group"; - reorder_imported_names: bool, true, false, - "Reorder lists of names in import statements alphabetically"; - reorder_modules: bool, true, false, "Reorder module statemtents alphabetically in group"; reorder_impl_items: bool, false, false, "Reorder impl items"; + reorder_imports: bool, true, false, "Reorder import and extern crate statements alphabetically"; + reorder_modules: bool, true, false, "Reorder module statements alphabetically in group"; // Spaces around punctuation type_punctuation_density: TypeDensity, TypeDensity::Wide, false, diff --git a/src/imports.rs b/src/imports.rs index 9a02ee64fb7d..62273a865964 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -485,6 +485,7 @@ fn rewrite_nested_use_tree( ); (tactic, remaining_width) }; + let ends_with_newline = context.config.imports_indent() == IndentStyle::Block && tactic != DefinitiveListTactic::Horizontal; let fmt = ListFormatting { diff --git a/src/lib.rs b/src/lib.rs index 9a7d0d2f8817..61eeb9332a6a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,8 +42,8 @@ use std::time::Duration; use syntax::ast; pub use syntax::codemap::FileName; use syntax::codemap::{CodeMap, FilePathMapping}; -use syntax::errors::emitter::{ColorConfig, EmitterWriter}; use syntax::errors::{DiagnosticBuilder, Handler}; +use syntax::errors::emitter::{ColorConfig, EmitterWriter}; use syntax::parse::{self, ParseSess}; use checkstyle::{output_footer, output_header}; diff --git a/src/reorder.rs b/src/reorder.rs index 15191995d024..273f20c92543 100644 --- a/src/reorder.rs +++ b/src/reorder.rs @@ -198,18 +198,18 @@ impl ReorderableItemKind { pub fn is_reorderable(&self, config: &Config) -> bool { match *self { - ReorderableItemKind::ExternCrate => config.reorder_extern_crates(), + ReorderableItemKind::ExternCrate => config.reorder_imports(), ReorderableItemKind::Mod => config.reorder_modules(), ReorderableItemKind::Use => config.reorder_imports(), ReorderableItemKind::Other => false, } } - pub fn in_group(&self, config: &Config) -> bool { + pub fn in_group(&self) -> bool { match *self { - ReorderableItemKind::ExternCrate => config.reorder_extern_crates_in_group(), - ReorderableItemKind::Mod => config.reorder_modules(), - ReorderableItemKind::Use => config.reorder_imports_in_group(), + ReorderableItemKind::ExternCrate => false, + ReorderableItemKind::Mod => true, + ReorderableItemKind::Use => true, ReorderableItemKind::Other => false, } } @@ -268,7 +268,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { let item_kind = ReorderableItemKind::from(items[0]); if item_kind.is_reorderable(self.config) { let visited_items_num = - self.walk_reorderable_items(items, item_kind, item_kind.in_group(self.config)); + self.walk_reorderable_items(items, item_kind, item_kind.in_group()); let (_, rest) = items.split_at(visited_items_num); items = rest; } else { diff --git a/tests/target/extern.rs b/tests/target/extern.rs index b0aa51127d54..61989cace75d 100644 --- a/tests/target/extern.rs +++ b/tests/target/extern.rs @@ -1,17 +1,14 @@ // rustfmt-normalize_comments: true -extern crate foo; -extern crate foo as bar; - +extern crate bar; extern crate chrono; extern crate dotenv; -extern crate futures; - -extern crate bar; extern crate foo; - -// #2315 +extern crate foo; +extern crate foo as bar; +extern crate futures; extern crate proc_macro; +// #2315 extern crate proc_macro2; extern "C" { diff --git a/tests/target/import-fencepost-length.rs b/tests/target/import-fencepost-length.rs index e4f885c09b1f..9d247aaf6dff 100644 --- a/tests/target/import-fencepost-length.rs +++ b/tests/target/import-fencepost-length.rs @@ -1,4 +1,4 @@ -use aaaaaaaaaaaaaaa::bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; use aaaaaaaaaaaaaaa::{bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccccccc, dddddddd}; use aaaaaaaaaaaaaaa::{bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccccccc, ddddddddd}; +use aaaaaaaaaaaaaaa::bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; diff --git a/tests/target/imports.rs b/tests/target/imports.rs index 236fee95e82b..b6d939fc125f 100644 --- a/tests/target/imports.rs +++ b/tests/target/imports.rs @@ -54,9 +54,9 @@ use foo::{baz, qux as bar}; // With absolute paths use foo; +use Foo; use foo::Bar; use foo::{Bar, Baz}; -use Foo; use {Bar, Baz}; // Root globs