From 7d34cfaf2c31dc90f6dc8fc1cdc001fcbd7ebbfa Mon Sep 17 00:00:00 2001 From: David Bar-On <61089727+davidBar-On@users.noreply.github.com> Date: Tue, 16 Mar 2021 03:57:04 +0200 Subject: Dedup `imports_granularity = "Item"` (#4737) * Fix for issue 4725 - dedup Item imports_granularity (2nd version) * Use unique() instead of unique_by() --- src/imports.rs | 15 ++- tests/source/imports-impl-only-use.rs | 4 - tests/source/imports-reorder-lines-and-items.rs | 7 -- tests/source/imports-reorder-lines.rs | 32 ----- tests/source/imports-reorder.rs | 5 - tests/source/imports.rs | 107 ----------------- tests/source/imports/imports-impl-only-use.rs | 4 + .../imports/imports-reorder-lines-and-items.rs | 7 ++ tests/source/imports/imports-reorder-lines.rs | 32 +++++ tests/source/imports/imports-reorder.rs | 5 + tests/source/imports/imports.rs | 107 +++++++++++++++++ tests/source/imports/imports_block_indent.rs | 2 + tests/source/imports/imports_granularity_crate.rs | 65 +++++++++++ .../imports_granularity_default-with-dups.rs | 6 + ...y_item-with-dups-StdExternalCrate-no-reorder.rs | 13 +++ .../imports/imports_granularity_item-with-dups.rs | 11 ++ tests/source/imports/imports_granularity_item.rs | 34 ++++++ tests/source/imports/imports_granularity_module.rs | 47 ++++++++ tests/source/imports_block_indent.rs | 2 - tests/source/imports_granularity_crate.rs | 65 ----------- tests/source/imports_granularity_item.rs | 34 ------ tests/source/imports_granularity_module.rs | 47 -------- tests/target/import-fencepost-length.rs | 7 -- tests/target/imports-impl-only-use.rs | 4 - tests/target/imports-reorder-lines-and-items.rs | 7 -- tests/target/imports-reorder-lines.rs | 31 ----- tests/target/imports-reorder.rs | 5 - tests/target/imports.rs | 129 --------------------- tests/target/imports/import-fencepost-length.rs | 7 ++ tests/target/imports/imports-impl-only-use.rs | 4 + .../imports/imports-reorder-lines-and-items.rs | 7 ++ tests/target/imports/imports-reorder-lines.rs | 31 +++++ tests/target/imports/imports-reorder.rs | 5 + tests/target/imports/imports.rs | 129 +++++++++++++++++++++ tests/target/imports/imports_2021_edition.rs | 3 + tests/target/imports/imports_block_indent.rs | 4 + tests/target/imports/imports_granularity_crate.rs | 59 ++++++++++ .../imports_granularity_default-with-dups.rs | 6 + ...y_item-with-dups-StdExternalCrate-no-reorder.rs | 7 ++ .../imports/imports_granularity_item-with-dups.rs | 5 + tests/target/imports/imports_granularity_item.rs | 45 +++++++ tests/target/imports/imports_granularity_module.rs | 55 +++++++++ tests/target/imports_2021_edition.rs | 3 - tests/target/imports_block_indent.rs | 4 - tests/target/imports_granularity_crate.rs | 59 ---------- tests/target/imports_granularity_item.rs | 45 ------- tests/target/imports_granularity_module.rs | 55 --------- 47 files changed, 714 insertions(+), 653 deletions(-) delete mode 100644 tests/source/imports-impl-only-use.rs delete mode 100644 tests/source/imports-reorder-lines-and-items.rs delete mode 100644 tests/source/imports-reorder-lines.rs delete mode 100644 tests/source/imports-reorder.rs delete mode 100644 tests/source/imports.rs create mode 100644 tests/source/imports/imports-impl-only-use.rs create mode 100644 tests/source/imports/imports-reorder-lines-and-items.rs create mode 100644 tests/source/imports/imports-reorder-lines.rs create mode 100644 tests/source/imports/imports-reorder.rs create mode 100644 tests/source/imports/imports.rs create mode 100644 tests/source/imports/imports_block_indent.rs create mode 100644 tests/source/imports/imports_granularity_crate.rs create mode 100644 tests/source/imports/imports_granularity_default-with-dups.rs create mode 100644 tests/source/imports/imports_granularity_item-with-dups-StdExternalCrate-no-reorder.rs create mode 100644 tests/source/imports/imports_granularity_item-with-dups.rs create mode 100644 tests/source/imports/imports_granularity_item.rs create mode 100644 tests/source/imports/imports_granularity_module.rs delete mode 100644 tests/source/imports_block_indent.rs delete mode 100644 tests/source/imports_granularity_crate.rs delete mode 100644 tests/source/imports_granularity_item.rs delete mode 100644 tests/source/imports_granularity_module.rs delete mode 100644 tests/target/import-fencepost-length.rs delete mode 100644 tests/target/imports-impl-only-use.rs delete mode 100644 tests/target/imports-reorder-lines-and-items.rs delete mode 100644 tests/target/imports-reorder-lines.rs delete mode 100644 tests/target/imports-reorder.rs delete mode 100644 tests/target/imports.rs create mode 100644 tests/target/imports/import-fencepost-length.rs create mode 100644 tests/target/imports/imports-impl-only-use.rs create mode 100644 tests/target/imports/imports-reorder-lines-and-items.rs create mode 100644 tests/target/imports/imports-reorder-lines.rs create mode 100644 tests/target/imports/imports-reorder.rs create mode 100644 tests/target/imports/imports.rs create mode 100644 tests/target/imports/imports_2021_edition.rs create mode 100644 tests/target/imports/imports_block_indent.rs create mode 100644 tests/target/imports/imports_granularity_crate.rs create mode 100644 tests/target/imports/imports_granularity_default-with-dups.rs create mode 100644 tests/target/imports/imports_granularity_item-with-dups-StdExternalCrate-no-reorder.rs create mode 100644 tests/target/imports/imports_granularity_item-with-dups.rs create mode 100644 tests/target/imports/imports_granularity_item.rs create mode 100644 tests/target/imports/imports_granularity_module.rs delete mode 100644 tests/target/imports_2021_edition.rs delete mode 100644 tests/target/imports_block_indent.rs delete mode 100644 tests/target/imports_granularity_crate.rs delete mode 100644 tests/target/imports_granularity_item.rs delete mode 100644 tests/target/imports_granularity_module.rs diff --git a/src/imports.rs b/src/imports.rs index 962f2126c66..559ed3917db 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -2,6 +2,10 @@ use std::borrow::Cow; use std::cmp::Ordering; use std::fmt; +use core::hash::{Hash, Hasher}; + +use itertools::Itertools; + use rustc_ast::ast::{self, UseTreeKind}; use rustc_span::{ symbol::{self, sym}, @@ -87,7 +91,7 @@ impl<'a> FmtVisitor<'a> { // sorting. // FIXME we do a lot of allocation to make our own representation. -#[derive(Clone, Eq, PartialEq)] +#[derive(Clone, Eq, Hash, PartialEq)] pub(crate) enum UseSegment { Ident(String, Option), Slf(Option), @@ -232,10 +236,13 @@ fn flatten_use_trees( use_trees: Vec, import_granularity: ImportGranularity, ) -> Vec { + // Return non-sorted single occurance of the use-trees text string; + // order is by first occurance of the use-tree. use_trees .into_iter() .flat_map(|tree| tree.flatten(import_granularity)) .map(UseTree::nest_trailing_self) + .unique() .collect() } @@ -780,6 +787,12 @@ fn merge_use_trees_inner(trees: &mut Vec, use_tree: UseTree, merge_by: trees.sort(); } +impl Hash for UseTree { + fn hash(&self, state: &mut H) { + self.path.hash(state); + } +} + impl PartialOrd for UseSegment { fn partial_cmp(&self, other: &UseSegment) -> Option { Some(self.cmp(other)) diff --git a/tests/source/imports-impl-only-use.rs b/tests/source/imports-impl-only-use.rs deleted file mode 100644 index d290d8d9185..00000000000 --- a/tests/source/imports-impl-only-use.rs +++ /dev/null @@ -1,4 +0,0 @@ -#![feature(underscore_imports)] - -use attr; -use std::iter::Iterator as _; diff --git a/tests/source/imports-reorder-lines-and-items.rs b/tests/source/imports-reorder-lines-and-items.rs deleted file mode 100644 index b6380f31c61..00000000000 --- a/tests/source/imports-reorder-lines-and-items.rs +++ /dev/null @@ -1,7 +0,0 @@ -/// This comment should stay with `use std::str;` -use std::str; -use std::cmp::{d, c, b, a}; -use std::ddd::aaa; -use std::ddd::{d as p, c as g, b, a}; -// This comment should stay with `use std::ddd:bbb;` -use std::ddd::bbb; diff --git a/tests/source/imports-reorder-lines.rs b/tests/source/imports-reorder-lines.rs deleted file mode 100644 index 2b018544eae..00000000000 --- a/tests/source/imports-reorder-lines.rs +++ /dev/null @@ -1,32 +0,0 @@ -use std::str; -use std::cmp::{d, c, b, a}; -use std::cmp::{b, e, g, f}; -use std::ddd::aaa; -// This comment should stay with `use std::ddd;` -use std::ddd; -use std::ddd::bbb; - -mod test { -} - -use aaa::bbb; -use aaa; -use aaa::*; - -mod test {} -// If item names are equal, order by rename - -use test::{a as bb, b}; -use test::{a as aa, c}; - -mod test {} -// If item names are equal, order by rename - no rename comes before a rename - -use test::{a as bb, b}; -use test::{a, c}; - -mod test {} -// `self` always comes first - -use test::{a as aa, c}; -use test::{self as bb, b}; diff --git a/tests/source/imports-reorder.rs b/tests/source/imports-reorder.rs deleted file mode 100644 index cbe9d6ca78a..00000000000 --- a/tests/source/imports-reorder.rs +++ /dev/null @@ -1,5 +0,0 @@ -// rustfmt-normalize_comments: true - -use path::{C,/*A*/ A, B /* B */, self /* self */}; - -use {ab, ac, aa, Z, b}; diff --git a/tests/source/imports.rs b/tests/source/imports.rs deleted file mode 100644 index 4dfc6ed94e3..00000000000 --- a/tests/source/imports.rs +++ /dev/null @@ -1,107 +0,0 @@ -// rustfmt-normalize_comments: true - -// Imports. - -// Long import. -use rustc_ast::ast::{ItemForeignMod, ItemImpl, ItemMac, ItemMod, ItemStatic, ItemDefaultImpl}; -use exceedingly::looooooooooooooooooooooooooooooooooooooooooooooooooooooooooong::import::path::{ItemA, ItemB}; -use exceedingly::loooooooooooooooooooooooooooooooooooooooooooooooooooooooong::import::path::{ItemA, ItemB}; - -use list::{ - // Some item - SomeItem /* Comment */, /* Another item */ AnotherItem /* Another Comment */, // Last Item - LastItem -}; - -use test::{ Other /* C */ , /* A */ self /* B */ }; - -use rustc_ast::{self}; -use {/* Pre-comment! */ - Foo, Bar /* comment */}; -use Foo::{Bar, Baz}; -pub use rustc_ast::ast::{Expr_, Expr, ExprAssign, ExprCall, ExprMethodCall, ExprPath}; - -use rustc_ast::some::{}; - -use self; -use std::io::{self}; -use std::io::self; - -mod Foo { - pub use rustc_ast::ast::{ - ItemForeignMod, - ItemImpl, - ItemMac, - ItemMod, - ItemStatic, - ItemDefaultImpl - }; - - mod Foo2 { - pub use rustc_ast::ast::{ItemForeignMod, ItemImpl, ItemMac, ItemMod, ItemStatic, self, ItemDefaultImpl}; - } -} - -fn test() { -use Baz::*; - use Qux; -} - -// Simple imports -use foo::bar::baz as baz ; -use bar::quux as kaas; -use foo; - -// With aliases. -use foo::{self as bar, baz}; -use foo::{self as bar}; -use foo::{qux as bar}; -use foo::{baz, qux as bar}; - -// With absolute paths -use ::foo; -use ::foo::{Bar}; -use ::foo::{Bar, Baz}; -use ::{Foo}; -use ::{Bar, Baz}; - -// Root globs -use *; -use ::*; - -// spaces used to cause glob imports to disappear (#1356) -use super:: * ; -use foo::issue_1356:: * ; - -// We shouldn't remove imports which have attributes attached (#1858) -#[cfg(unix)] -use self::unix::{}; - -// nested imports -use foo::{a, bar::{baz, qux, xxxxxxxxxxx, yyyyyyyyyyyyy, zzzzzzzzzzzzzzzz, foo::{a, b, cxxxxxxxxxxxxx, yyyyyyyyyyyyyy, zzzzzzzzzzzzzzzz}}, b, boo, c,}; - -use fooo::{baar::{foobar::{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz}}, z, bar, bar::*, x, y}; - -use exonum::{api::{Api, ApiError}, blockchain::{self, BlockProof, Blockchain, Transaction, TransactionSet}, crypto::{Hash, PublicKey}, helpers::Height, node::TransactionSend, storage::{ListProof, MapProof}}; - -// nested imports with a single sub-tree. -use a::{b::{c::*}}; -use a::{b::{c::{}}}; -use a::{b::{c::d}}; -use a::{b::{c::{xxx, yyy, zzz}}}; - -// #2645 -/// This line is not affected. -// This line is deleted. -use c; - -// #2670 -#[macro_use] -use imports_with_attr; - -// #2888 -use std::f64::consts::{SQRT_2, E, PI}; - -// #3273 -#[rustfmt::skip] -use std::fmt::{self, {Display, Formatter}}; diff --git a/tests/source/imports/imports-impl-only-use.rs b/tests/source/imports/imports-impl-only-use.rs new file mode 100644 index 00000000000..d290d8d9185 --- /dev/null +++ b/tests/source/imports/imports-impl-only-use.rs @@ -0,0 +1,4 @@ +#![feature(underscore_imports)] + +use attr; +use std::iter::Iterator as _; diff --git a/tests/source/imports/imports-reorder-lines-and-items.rs b/tests/source/imports/imports-reorder-lines-and-items.rs new file mode 100644 index 00000000000..b6380f31c61 --- /dev/null +++ b/tests/source/imports/imports-reorder-lines-and-items.rs @@ -0,0 +1,7 @@ +/// This comment should stay with `use std::str;` +use std::str; +use std::cmp::{d, c, b, a}; +use std::ddd::aaa; +use std::ddd::{d as p, c as g, b, a}; +// This comment should stay with `use std::ddd:bbb;` +use std::ddd::bbb; diff --git a/tests/source/imports/imports-reorder-lines.rs b/tests/source/imports/imports-reorder-lines.rs new file mode 100644 index 00000000000..2b018544eae --- /dev/null +++ b/tests/source/imports/imports-reorder-lines.rs @@ -0,0 +1,32 @@ +use std::str; +use std::cmp::{d, c, b, a}; +use std::cmp::{b, e, g, f}; +use std::ddd::aaa; +// This comment should stay with `use std::ddd;` +use std::ddd; +use std::ddd::bbb; + +mod test { +} + +use aaa::bbb; +use aaa; +use aaa::*; + +mod test {} +// If item names are equal, order by rename + +use test::{a as bb, b}; +use test::{a as aa, c}; + +mod test {} +// If item names are equal, order by rename - no rename comes before a rename + +use test::{a as bb, b}; +use test::{a, c}; + +mod test {} +// `self` always comes first + +use test::{a as aa, c}; +use test::{self as bb, b}; diff --git a/tests/source/imports/imports-reorder.rs b/tests/source/imports/imports-reorder.rs new file mode 100644 index 00000000000..cbe9d6ca78a --- /dev/null +++ b/tests/source/imports/imports-reorder.rs @@ -0,0 +1,5 @@ +// rustfmt-normalize_comments: true + +use path::{C,/*A*/ A, B /* B */, self /* self */}; + +use {ab, ac, aa, Z, b}; diff --git a/tests/source/imports/imports.rs b/tests/source/imports/imports.rs new file mode 100644 index 00000000000..4dfc6ed94e3 --- /dev/null +++ b/tests/source/imports/imports.rs @@ -0,0 +1,107 @@ +// rustfmt-normalize_comments: true + +// Imports. + +// Long import. +use rustc_ast::ast::{ItemForeignMod, ItemImpl, ItemMac, ItemMod, ItemStatic, ItemDefaultImpl}; +use exceedingly::looooooooooooooooooooooooooooooooooooooooooooooooooooooooooong::import::path::{ItemA, ItemB}; +use exceedingly::loooooooooooooooooooooooooooooooooooooooooooooooooooooooong::import::path::{ItemA, ItemB}; + +use list::{ + // Some item + SomeItem /* Comment */, /* Another item */ AnotherItem /* Another Comment */, // Last Item + LastItem +}; + +use test::{ Other /* C */ , /* A */ self /* B */ }; + +use rustc_ast::{self}; +use {/* Pre-comment! */ + Foo, Bar /* comment */}; +use Foo::{Bar, Baz}; +pub use rustc_ast::ast::{Expr_, Expr, ExprAssign, ExprCall, ExprMethodCall, ExprPath}; + +use rustc_ast::some::{}; + +use self; +use std::io::{self}; +use std::io::self; + +mod Foo { + pub use rustc_ast::ast::{ + ItemForeignMod, + ItemImpl, + ItemMac, + ItemMod, + ItemStatic, + ItemDefaultImpl + }; + + mod Foo2 { + pub use rustc_ast::ast::{ItemForeignMod, ItemImpl, ItemMac, ItemMod, ItemStatic, self, ItemDefaultImpl}; + } +} + +fn test() { +use Baz::*; + use Qux; +} + +// Simple imports +use foo::bar::baz as baz ; +use bar::quux as kaas; +use foo; + +// With aliases. +use foo::{self as bar, baz}; +use foo::{self as bar}; +use foo::{qux as bar}; +use foo::{baz, qux as bar}; + +// With absolute paths +use ::foo; +use ::foo::{Bar}; +use ::foo::{Bar, Baz}; +use ::{Foo}; +use ::{Bar, Baz}; + +// Root globs +use *; +use ::*; + +// spaces used to cause glob imports to disappear (#1356) +use super:: * ; +use foo::issue_1356:: * ; + +// We shouldn't remove imports which have attributes attached (#1858) +#[cfg(unix)] +use self::unix::{}; + +// nested imports +use foo::{a, bar::{baz, qux, xxxxxxxxxxx, yyyyyyyyyyyyy, zzzzzzzzzzzzzzzz, foo::{a, b, cxxxxxxxxxxxxx, yyyyyyyyyyyyyy, zzzzzzzzzzzzzzzz}}, b, boo, c,}; + +use fooo::{baar::{foobar::{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz}}, z, bar, bar::*, x, y}; + +use exonum::{api::{Api, ApiError}, blockchain::{self, BlockProof, Blockchain, Transaction, TransactionSet}, crypto::{Hash, PublicKey}, helpers::Height, node::TransactionSend, storage::{ListProof, MapProof}}; + +// nested imports with a single sub-tree. +use a::{b::{c::*}}; +use a::{b::{c::{}}}; +use a::{b::{c::d}}; +use a::{b::{c::{xxx, yyy, zzz}}}; + +// #2645 +/// This line is not affected. +// This line is deleted. +use c; + +// #2670 +#[macro_use] +use imports_with_attr; + +// #2888 +use std::f64::consts::{SQRT_2, E, PI}; + +// #3273 +#[rustfmt::skip] +use std::fmt::{self, {Display, Formatter}}; diff --git a/tests/source/imports/imports_block_indent.rs b/tests/source/imports/imports_block_indent.rs new file mode 100644 index 00000000000..016deefe58c --- /dev/null +++ b/tests/source/imports/imports_block_indent.rs @@ -0,0 +1,2 @@ +// #2569 +use apns2::request::notification::{Notificatio, NotificationBuilder, Priority, SilentNotificationBuilder}; diff --git a/tests/source/imports/imports_granularity_crate.rs b/tests/source/imports/imports_granularity_crate.rs new file mode 100644 index 00000000000..f6f7761e82e --- /dev/null +++ b/tests/source/imports/imports_granularity_crate.rs @@ -0,0 +1,65 @@ +// rustfmt-imports_granularity: Crate + +use a::{c,d,b}; +use a::{d, e, b, a, f}; +use a::{f, g, c}; + +#[doc(hidden)] +use a::b; +use a::c; +use a::d; + +use a::{c, d, e}; +#[doc(hidden)] +use a::b; +use a::d; + +pub use foo::bar; +use foo::{a, b, c}; +pub use foo::foobar; + +use a::{b::{c::*}}; +use a::{b::{c::{}}}; +use a::{b::{c::d}}; +use a::{b::{c::{xxx, yyy, zzz}}}; + +// https://github.com/rust-lang/rustfmt/issues/3808 +use d::{self}; +use e::{self as foo}; +use f::{self, b}; +use g::a; +use g::{self, b}; +use h::{a}; +use i::a::{self}; +use j::{a::{self}}; + +use {k::{a, b}, l::{a, b}}; +use {k::{c, d}, l::{c, d}}; + +use b::{f::g, h::{i, j} /* After b::h group */}; +use b::e; +use b::{/* Before b::l group */ l::{self, m, n::o, p::*}, q}; +use b::d; +use b::r; // After b::r +use b::q::{self /* After b::q::self */}; +use b::u::{ + a, + b, +}; +use b::t::{ + // Before b::t::a + a, + b, +}; +use b::s::{ + a, + b, // After b::s::b +}; +use b::v::{ + // Before b::v::a + a, + // Before b::v::b + b, +}; +use b::t::{/* Before b::t::self */ self}; +use b::c; diff --git a/tests/source/imports/imports_granularity_default-with-dups.rs b/tests/source/imports/imports_granularity_default-with-dups.rs new file mode 100644 index 00000000000..cbb21a9f1b3 --- /dev/null +++ b/tests/source/imports/imports_granularity_default-with-dups.rs @@ -0,0 +1,6 @@ +use crate::lexer; +use crate::lexer::tokens::TokenData; +use crate::lexer::{tokens::TokenData}; +use crate::lexer::self; +use crate::lexer::{self}; +use crate::lexer::{self, tokens::TokenData}; diff --git a/tests/source/imports/imports_granularity_item-with-dups-StdExternalCrate-no-reorder.rs b/tests/source/imports/imports_granularity_item-with-dups-StdExternalCrate-no-reorder.rs new file mode 100644 index 00000000000..e23705a884f --- /dev/null +++ b/tests/source/imports/imports_granularity_item-with-dups-StdExternalCrate-no-reorder.rs @@ -0,0 +1,13 @@ +// rustfmt-imports_granularity: Item +// rustfmt-reorder_imports: false +// rustfmt-group_imports: StdExternalCrate + +use crate::lexer; +use crate::lexer; +use crate::lexer::tokens::TokenData; +use crate::lexer::{tokens::TokenData}; +use crate::lexer::self; +use crate::lexer; +use crate::lexer; +use crate::lexer::{self}; +use crate::lexer::{self, tokens::TokenData}; diff --git a/tests/source/imports/imports_granularity_item-with-dups.rs b/tests/source/imports/imports_granularity_item-with-dups.rs new file mode 100644 index 00000000000..3e9589c299f --- /dev/null +++ b/tests/source/imports/imports_granularity_item-with-dups.rs @@ -0,0 +1,11 @@ +// rustfmt-imports_granularity: Item + +use crate::lexer; +use crate::lexer; +use crate::lexer::tokens::TokenData; +use crate::lexer::{tokens::TokenData}; +use crate::lexer::self; +use crate::lexer; +use crate::lexer; +use crate::lexer::{self}; +use crate::lexer::{self, tokens::TokenData}; diff --git a/tests/source/imports/imports_granularity_item.rs b/tests/source/imports/imports_granularity_item.rs new file mode 100644 index 00000000000..b82c0d33caf --- /dev/null +++ b/tests/source/imports/imports_granularity_item.rs @@ -0,0 +1,34 @@ +// rustfmt-imports_granularity: Item + +use a::{b, c, d}; +use a::{f::g, h::{i, j}}; +use a::{l::{self, m, n::o, p::*}}; +use a::q::{self}; + +use b::{f::g, h::{i, j} /* After b::h group */}; +use b::e; +use b::{/* Before b::l group */ l::{self, m, n::o, p::*}, q}; +use b::d; +use b::r; // After b::r +use b::q::{self /* After b::q::self */}; +use b::u::{ + a, + b, +}; +use b::t::{ + // Before b::t::a + a, + b, +}; +use b::s::{ + a, + b, // After b::s::b +}; +use b::v::{ + // Before b::v::a + a, + // Before b::v::b + b, +}; +use b::t::{/* Before b::t::self */ self}; +use b::c; diff --git a/tests/source/imports/imports_granularity_module.rs b/tests/source/imports/imports_granularity_module.rs new file mode 100644 index 00000000000..c7f68cea6d4 --- /dev/null +++ b/tests/source/imports/imports_granularity_module.rs @@ -0,0 +1,47 @@ +// rustfmt-imports_granularity: Module + +use a::{b::c, d::e}; +use a::{f, g::{h, i}}; +use a::{j::{self, k::{self, l}, m}, n::{o::p, q}}; +pub use a::{r::s, t}; +use b::{c::d, self}; + +#[cfg(test)] +use foo::{a::b, c::d}; +use foo::e; + +use bar::{ + // comment + a::b, + // more comment + c::d, + e::f, +}; + +use b::{f::g, h::{i, j} /* After b::h group */}; +use b::e; +use b::{/* Before b::l group */ l::{self, m, n::o, p::*}, q}; +use b::d; +use b::r; // After b::r +use b::q::{self /* After b::q::self */}; +use b::u::{ + a, + b, +}; +use b::t::{ + // Before b::t::a + a, + b, +}; +use b::s::{ + a, + b, // After b::s::b +}; +use b::v::{ + // Before b::v::a + a, + // Before b::v::b + b, +}; +use b::t::{/* Before b::t::self */ self}; +use b::c; diff --git a/tests/source/imports_block_indent.rs b/tests/source/imports_block_indent.rs deleted file mode 100644 index 016deefe58c..00000000000 --- a/tests/source/imports_block_indent.rs +++ /dev/null @@ -1,2 +0,0 @@ -// #2569 -use apns2::request::notification::{Notificatio, NotificationBuilder, Priority, SilentNotificationBuilder}; diff --git a/tests/source/imports_granularity_crate.rs b/tests/source/imports_granularity_crate.rs deleted file mode 100644 index f6f7761e82e..00000000000 --- a/tests/source/imports_granularity_crate.rs +++ /dev/null @@ -1,65 +0,0 @@ -// rustfmt-imports_granularity: Crate - -use a::{c,d,b}; -use a::{d, e, b, a, f}; -use a::{f, g, c}; - -#[doc(hidden)] -use a::b; -use a::c; -use a::d; - -use a::{c, d, e}; -#[doc(hidden)] -use a::b; -use a::d; - -pub use foo::bar; -use foo::{a, b, c}; -pub use foo::foobar; - -use a::{b::{c::*}}; -use a::{b::{c::{}}}; -use a::{b::{c::d}}; -use a::{b::{c::{xxx, yyy, zzz}}}; - -// https://github.com/rust-lang/rustfmt/issues/3808 -use d::{self}; -use e::{self as foo}; -use f::{self, b}; -use g::a; -use g::{self, b}; -use h::{a}; -use i::a::{self}; -use j::{a::{self}}; - -use {k::{a, b}, l::{a, b}}; -use {k::{c, d}, l::{c, d}}; - -use b::{f::g, h::{i, j} /* After b::h group */}; -use b::e; -use b::{/* Before b::l group */ l::{self, m, n::o, p::*}, q}; -use b::d; -use b::r; // After b::r -use b::q::{self /* After b::q::self */}; -use b::u::{ - a, - b, -}; -use b::t::{ - // Before b::t::a - a, - b, -}; -use b::s::{ - a, - b, // After b::s::b -}; -use b::v::{ - // Before b::v::a - a, - // Before b::v::b - b, -}; -use b::t::{/* Before b::t::self */ self}; -use b::c; diff --git a/tests/source/imports_granularity_item.rs b/tests/source/imports_granularity_item.rs deleted file mode 100644 index b82c0d33caf..00000000000 --- a/tests/source/imports_granularity_item.rs +++ /dev/null @@ -1,34 +0,0 @@ -// rustfmt-imports_granularity: Item - -use a::{b, c, d}; -use a::{f::g, h::{i, j}}; -use a::{l::{self, m, n::o, p::*}}; -use a::q::{self}; - -use b::{f::g, h::{i, j} /* After b::h group */}; -use b::e; -use b::{/* Before b::l group */ l::{self, m, n::o, p::*}, q}; -use b::d; -use b::r; // After b::r -use b::q::{self /* After b::q::self */}; -use b::u::{ - a, - b, -}; -use b::t::{ - // Before b::t::a - a, - b, -}; -use b::s::{ - a, - b, // After b::s::b -}; -use b::v::{ - // Before b::v::a - a, - // Before b::v::b - b, -}; -use b::t::{/* Before b::t::self */ self}; -use b::c; diff --git a/tests/source/imports_granularity_module.rs b/tests/source/imports_granularity_module.rs deleted file mode 100644 index c7f68cea6d4..00000000000 --- a/tests/source/imports_granularity_module.rs +++ /dev/null @@ -1,47 +0,0 @@ -// rustfmt-imports_granularity: Module - -use a::{b::c, d::e}; -use a::{f, g::{h, i}}; -use a::{j::{self, k::{self, l}, m}, n::{o::p, q}}; -pub use a::{r::s, t}; -use b::{c::d, self}; - -#[cfg(test)] -use foo::{a::b, c::d}; -use foo::e; - -use bar::{ - // comment - a::b, - // more comment - c::d, - e::f, -}; - -use b::{f::g, h::{i, j} /* After b::h group */}; -use b::e; -use b::{/* Before b::l group */ l::{self, m, n::o, p::*}, q}; -use b::d; -use b::r; // After b::r -use b::q::{self /* After b::q::self */}; -use b::u::{ - a, - b, -}; -use b::t::{ - // Before b::t::a - a, - b, -}; -use b::s::{ - a, - b, // After b::s::b -}; -use b::v::{ - // Before b::v::a - a, - // Before b::v::b - b, -}; -use b::t::{/* Before b::t::self */ self}; -use b::c; diff --git a/tests/target/import-fencepost-length.rs b/tests/target/import-fencepost-length.rs deleted file mode 100644 index fd09d50d72d..00000000000 --- a/tests/target/import-fencepost-length.rs +++ /dev/null @@ -1,7 +0,0 @@ -use aaaaaaaaaaaaaaa::bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; -use aaaaaaaaaaaaaaa::{ - bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccccccc, dddddddd, -}; -use aaaaaaaaaaaaaaa::{ - bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccccccc, ddddddddd, -}; diff --git a/tests/target/imports-impl-only-use.rs b/tests/target/imports-impl-only-use.rs deleted file mode 100644 index d290d8d9185..00000000000 --- a/tests/target/imports-impl-only-use.rs +++ /dev/null @@ -1,4 +0,0 @@ -#![feature(underscore_imports)] - -use attr; -use std::iter::Iterator as _; diff --git a/tests/target/imports-reorder-lines-and-items.rs b/tests/target/imports-reorder-lines-and-items.rs deleted file mode 100644 index 98a5afe4348..00000000000 --- a/tests/target/imports-reorder-lines-and-items.rs +++ /dev/null @@ -1,7 +0,0 @@ -use std::cmp::{a, b, c, d}; -use std::ddd::aaa; -use std::ddd::{a, b, c as g, d as p}; -/// This comment should stay with `use std::str;` -use std::str; -// This comment should stay with `use std::ddd:bbb;` -use std::ddd::bbb; diff --git a/tests/target/imports-reorder-lines.rs b/tests/target/imports-reorder-lines.rs deleted file mode 100644 index 5b85503b55d..00000000000 --- a/tests/target/imports-reorder-lines.rs +++ /dev/null @@ -1,31 +0,0 @@ -use std::cmp::{a, b, c, d}; -use std::cmp::{b, e, f, g}; -use std::ddd::aaa; -use std::str; -// This comment should stay with `use std::ddd;` -use std::ddd; -use std::ddd::bbb; - -mod test {} - -use aaa; -use aaa::bbb; -use aaa::*; - -mod test {} -// If item names are equal, order by rename - -use test::{a as bb, b}; -use test::{a as aa, c}; - -mod test {} -// If item names are equal, order by rename - no rename comes before a rename - -use test::{a as bb, b}; -use test::{a, c}; - -mod test {} -// `self` always comes first - -use test::{self as bb, b}; -use test::{a as aa, c}; diff --git a/tests/target/imports-reorder.rs b/tests/target/imports-reorder.rs deleted file mode 100644 index 84e97c0224f..00000000000 --- a/tests/target/imports-reorder.rs +++ /dev/null @@ -1,5 +0,0 @@ -// rustfmt-normalize_comments: true - -use path::{self /* self */, /* A */ A, B /* B */, C}; - -use {aa, ab, ac, b, Z}; diff --git a/tests/target/imports.rs b/tests/target/imports.rs deleted file mode 100644 index 87584d89f66..00000000000 --- a/tests/target/imports.rs +++ /dev/null @@ -1,129 +0,0 @@ -// rustfmt-normalize_comments: true - -// Imports. - -// Long import. -use exceedingly::loooooooooooooooooooooooooooooooooooooooooooooooooooooooong::import::path::{ - ItemA, ItemB, -}; -use exceedingly::looooooooooooooooooooooooooooooooooooooooooooooooooooooooooong::import::path::{ - ItemA, ItemB, -}; -use rustc_ast::ast::{ItemDefaultImpl, ItemForeignMod, ItemImpl, ItemMac, ItemMod, ItemStatic}; - -use list::{ - // Another item - AnotherItem, // Another Comment - // Last Item - LastItem, - // Some item - SomeItem, // Comment -}; - -use test::{/* A */ self /* B */, Other /* C */}; - -pub use rustc_ast::ast::{Expr, ExprAssign, ExprCall, ExprMethodCall, ExprPath, Expr_}; -use rustc_ast::{self}; -use Foo::{Bar, Baz}; -use {Bar /* comment */, /* Pre-comment! */ Foo}; - -use std::io; -use std::io::{self}; - -mod Foo { - pub use rustc_ast::ast::{ - ItemDefaultImpl, ItemForeignMod, ItemImpl, ItemMac, ItemMod, ItemStatic, - }; - - mod Foo2 { - pub use rustc_ast::ast::{ - self, ItemDefaultImpl, ItemForeignMod, ItemImpl, ItemMac, ItemMod, ItemStatic, - }; - } -} - -fn test() { - use Baz::*; - use Qux; -} - -// Simple imports -use bar::quux as kaas; -use foo; -use foo::bar::baz; - -// With aliases. -use foo::qux as bar; -use foo::{self as bar}; -use foo::{self as bar, baz}; -use foo::{baz, qux as bar}; - -// With absolute paths -use foo; -use foo::Bar; -use foo::{Bar, Baz}; -use Foo; -use {Bar, Baz}; - -// Root globs -use *; -use *; - -// spaces used to cause glob imports to disappear (#1356) -use super::*; -use foo::issue_1356::*; - -// We shouldn't remove imports which have attributes attached (#1858) -#[cfg(unix)] -use self::unix::{}; - -// nested imports -use foo::{ - a, b, - bar::{ - baz, - foo::{a, b, cxxxxxxxxxxxxx, yyyyyyyyyyyyyy, zzzzzzzzzzzzzzzz}, - qux, xxxxxxxxxxx, yyyyyyyyyyyyy, zzzzzzzzzzzzzzzz, - }, - boo, c, -}; - -use fooo::{ - baar::foobar::{ - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy, - zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz, - }, - bar, - bar::*, - x, y, z, -}; - -use exonum::{ - api::{Api, ApiError}, - blockchain::{self, BlockProof, Blockchain, Transaction, TransactionSet}, - crypto::{Hash, PublicKey}, - helpers::Height, - node::TransactionSend, - storage::{ListProof, MapProof}, -}; - -// nested imports with a single sub-tree. -use a::b::c::d; -use a::b::c::*; -use a::b::c::{xxx, yyy, zzz}; - -// #2645 -/// This line is not affected. -// This line is deleted. -use c; - -// #2670 -#[macro_use] -use imports_with_attr; - -// #2888 -use std::f64::consts::{E, PI, SQRT_2}; - -// #3273 -#[rustfmt::skip] -use std::fmt::{self, {Display, Formatter}}; diff --git a/tests/target/imports/import-fencepost-length.rs b/tests/target/imports/import-fencepost-length.rs new file mode 100644 index 00000000000..fd09d50d72d --- /dev/null +++ b/tests/target/imports/import-fencepost-length.rs @@ -0,0 +1,7 @@ +use aaaaaaaaaaaaaaa::bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; +use aaaaaaaaaaaaaaa::{ + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccccccc, dddddddd, +}; +use aaaaaaaaaaaaaaa::{ + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccccccc, ddddddddd, +}; diff --git a/tests/target/imports/imports-impl-only-use.rs b/tests/target/imports/imports-impl-only-use.rs new file mode 100644 index 00000000000..d290d8d9185 --- /dev/null +++ b/tests/target/imports/imports-impl-only-use.rs @@ -0,0 +1,4 @@ +#![feature(underscore_imports)] + +use attr; +use std::iter::Iterator as _; diff --git a/tests/target/imports/imports-reorder-lines-and-items.rs b/tests/target/imports/imports-reorder-lines-and-items.rs new file mode 100644 index 00000000000..98a5afe4348 --- /dev/null +++ b/tests/target/imports/imports-reorder-lines-and-items.rs @@ -0,0 +1,7 @@ +use std::cmp::{a, b, c, d}; +use std::ddd::aaa; +use std::ddd::{a, b, c as g, d as p}; +/// This comment should stay with `use std::str;` +use std::str; +// This comment should stay with `use std::ddd:bbb;` +use std::ddd::bbb; diff --git a/tests/target/imports/imports-reorder-lines.rs b/tests/target/imports/imports-reorder-lines.rs new file mode 100644 index 00000000000..5b85503b55d --- /dev/null +++ b/tests/target/imports/imports-reorder-lines.rs @@ -0,0 +1,31 @@ +use std::cmp::{a, b, c, d}; +use std::cmp::{b, e, f, g}; +use std::ddd::aaa; +use std::str; +// This comment should stay with `use std::ddd;` +use std::ddd; +use std::ddd::bbb; + +mod test {} + +use aaa; +use aaa::bbb; +use aaa::*; + +mod test {} +// If item names are equal, order by rename + +use test::{a as bb, b}; +use test::{a as aa, c}; + +mod test {} +// If item names are equal, order by rename - no rename comes before a rename + +use test::{a as bb, b}; +use test::{a, c}; + +mod test {} +// `self` always comes first + +use test::{self as bb, b}; +use test::{a as aa, c}; diff --git a/tests/target/imports/imports-reorder.rs b/tests/target/imports/imports-reorder.rs new file mode 100644 index 00000000000..84e97c0224f --- /dev/null +++ b/tests/target/imports/imports-reorder.rs @@ -0,0 +1,5 @@ +// rustfmt-normalize_comments: true + +use path::{self /* self */, /* A */ A, B /* B */, C}; + +use {aa, ab, ac, b, Z}; diff --git a/tests/target/imports/imports.rs b/tests/target/imports/imports.rs new file mode 100644 index 00000000000..87584d89f66 --- /dev/null +++ b/tests/target/imports/imports.rs @@ -0,0 +1,129 @@ +// rustfmt-normalize_comments: true + +// Imports. + +// Long import. +use exceedingly::loooooooooooooooooooooooooooooooooooooooooooooooooooooooong::import::path::{ + ItemA, ItemB, +}; +use exceedingly::looooooooooooooooooooooooooooooooooooooooooooooooooooooooooong::import::path::{ + ItemA, ItemB, +}; +use rustc_ast::ast::{ItemDefaultImpl, ItemForeignMod, ItemImpl, ItemMac, ItemMod, ItemStatic}; + +use list::{ + // Another item + AnotherItem, // Another Comment + // Last Item + LastItem, + // Some item + SomeItem, // Comment +}; + +use test::{/* A */ self /* B */, Other /* C */}; + +pub use rustc_ast::ast::{Expr, ExprAssign, ExprCall, ExprMethodCall, ExprPath, Expr_}; +use rustc_ast::{self}; +use Foo::{Bar, Baz}; +use {Bar /* comment */, /* Pre-comment! */ Foo}; + +use std::io; +use std::io::{self}; + +mod Foo { + pub use rustc_ast::ast::{ + ItemDefaultImpl, ItemForeignMod, ItemImpl, ItemMac, ItemMod, ItemStatic, + }; + + mod Foo2 { + pub use rustc_ast::ast::{ + self, ItemDefaultImpl, ItemForeignMod, ItemImpl, ItemMac, ItemMod, ItemStatic, + }; + } +} + +fn test() { + use Baz::*; + use Qux; +} + +// Simple imports +use bar::quux as kaas; +use foo; +use foo::bar::baz; + +// With aliases. +use foo::qux as bar; +use foo::{self as bar}; +use foo::{self as bar, baz}; +use foo::{baz, qux as bar}; + +// With absolute paths +use foo; +use foo::Bar; +use foo::{Bar, Baz}; +use Foo; +use {Bar, Baz}; + +// Root globs +use *; +use *; + +// spaces used to cause glob imports to disappear (#1356) +use super::*; +use foo::issue_1356::*; + +// We shouldn't remove imports which have attributes attached (#1858) +#[cfg(unix)] +use self::unix::{}; + +// nested imports +use foo::{ + a, b, + bar::{ + baz, + foo::{a, b, cxxxxxxxxxxxxx, yyyyyyyyyyyyyy, zzzzzzzzzzzzzzzz}, + qux, xxxxxxxxxxx, yyyyyyyyyyyyy, zzzzzzzzzzzzzzzz, + }, + boo, c, +}; + +use fooo::{ + baar::foobar::{ + xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy, + zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz, + }, + bar, + bar::*, + x, y, z, +}; + +use exonum::{ + api::{Api, ApiError}, + blockchain::{self, BlockProof, Blockchain, Transaction, TransactionSet}, + crypto::{Hash, PublicKey}, + helpers::Height, + node::TransactionSend, + storage::{ListProof, MapProof}, +}; + +// nested imports with a single sub-tree. +use a::b::c::d; +use a::b::c::*; +use a::b::c::{xxx, yyy, zzz}; + +// #2645 +/// This line is not affected. +// This line is deleted. +use c; + +// #2670 +#[macro_use] +use imports_with_attr; + +// #2888 +use std::f64::consts::{E, PI, SQRT_2}; + +// #3273 +#[rustfmt::skip] +use std::fmt::{self, {Display, Formatter}}; diff --git a/tests/target/imports/imports_2021_edition.rs b/tests/target/imports/imports_2021_edition.rs new file mode 100644 index 00000000000..34dcc866a0b --- /dev/null +++ b/tests/target/imports/imports_2021_edition.rs @@ -0,0 +1,3 @@ +// rustfmt-edition: 2021 + +use ::happy::new::year; diff --git a/tests/target/imports/imports_block_indent.rs b/tests/target/imports/imports_block_indent.rs new file mode 100644 index 00000000000..8c90f7ce29c --- /dev/null +++ b/tests/target/imports/imports_block_indent.rs @@ -0,0 +1,4 @@ +// #2569 +use apns2::request::notification::{ + Notificatio, NotificationBuilder, Priority, SilentNotificationBuilder, +}; diff --git a/tests/target/imports/imports_granularity_crate.rs b/tests/target/imports/imports_granularity_crate.rs new file mode 100644 index 00000000000..36e01558ff0 --- /dev/null +++ b/tests/target/imports/imports_granularity_crate.rs @@ -0,0 +1,59 @@ +// rustfmt-imports_granularity: Crate + +use a::{a, b, c, d, e, f, g}; + +#[doc(hidden)] +use a::b; +use a::{c, d}; + +#[doc(hidden)] +use a::b; +use a::{c, d, e}; + +use foo::{a, b, c}; +pub use foo::{bar, foobar}; + +use a::b::c::{d, xxx, yyy, zzz, *}; + +// https://github.com/rust-lang/rustfmt/issues/3808 +use d::{self}; +use e::{self as foo}; +use f::{self, b}; +use g::{self, a, b}; +use h::a; +use i::a::{self}; +use j::a::{self}; + +use k::{a, b, c, d}; +use l::{a, b, c, d}; + +use b::q::{self /* After b::q::self */}; +use b::r; // After b::r +use b::s::{ + a, + b, // After b::s::b +}; +use b::t::{/* Before b::t::self */ self}; +use b::t::{ + // Before b::t::a + a, + b, +}; +use b::v::{ + // Before b::v::a + a, + // Before b::v::b + b, +}; +use b::{ + c, d, e, + u::{a, b}, +}; +use b::{ + f::g, + h::{i, j}, /* After b::h group */ +}; +use b::{ + /* Before b::l group */ l::{self, m, n::o, p::*}, + q, +}; diff --git a/tests/target/imports/imports_granularity_default-with-dups.rs b/tests/target/imports/imports_granularity_default-with-dups.rs new file mode 100644 index 00000000000..5da6d588e6d --- /dev/null +++ b/tests/target/imports/imports_granularity_default-with-dups.rs @@ -0,0 +1,6 @@ +use crate::lexer; +use crate::lexer; +use crate::lexer::tokens::TokenData; +use crate::lexer::tokens::TokenData; +use crate::lexer::{self}; +use crate::lexer::{self, tokens::TokenData}; diff --git a/tests/target/imports/imports_granularity_item-with-dups-StdExternalCrate-no-reorder.rs b/tests/target/imports/imports_granularity_item-with-dups-StdExternalCrate-no-reorder.rs new file mode 100644 index 00000000000..ed4df544d6f --- /dev/null +++ b/tests/target/imports/imports_granularity_item-with-dups-StdExternalCrate-no-reorder.rs @@ -0,0 +1,7 @@ +// rustfmt-imports_granularity: Item +// rustfmt-reorder_imports: false +// rustfmt-group_imports: StdExternalCrate + +use crate::lexer; +use crate::lexer::tokens::TokenData; +use crate::lexer::{self}; diff --git a/tests/target/imports/imports_granularity_item-with-dups.rs b/tests/target/imports/imports_granularity_item-with-dups.rs new file mode 100644 index 00000000000..00df37f9332 --- /dev/null +++ b/tests/target/imports/imports_granularity_item-with-dups.rs @@ -0,0 +1,5 @@ +// rustfmt-imports_granularity: Item + +use crate::lexer; +use crate::lexer::tokens::TokenData; +use crate::lexer::{self}; diff --git a/tests/target/imports/imports_granularity_item.rs b/tests/target/imports/imports_granularity_item.rs new file mode 100644 index 00000000000..d2f5496fdac --- /dev/null +++ b/tests/target/imports/imports_granularity_item.rs @@ -0,0 +1,45 @@ +// rustfmt-imports_granularity: Item + +use a::b; +use a::c; +use a::d; +use a::f::g; +use a::h::i; +use a::h::j; +use a::l::m; +use a::l::n::o; +use a::l::p::*; +use a::l::{self}; +use a::q::{self}; + +use b::c; +use b::d; +use b::e; +use b::q::{self /* After b::q::self */}; +use b::r; // After b::r +use b::s::{ + a, + b, // After b::s::b +}; +use b::t::{/* Before b::t::self */ self}; +use b::t::{ + // Before b::t::a + a, + b, +}; +use b::u::a; +use b::u::b; +use b::v::{ + // Before b::v::a + a, + // Before b::v::b + b, +}; +use b::{ + f::g, + h::{i, j}, /* After b::h group */ +}; +use b::{ + /* Before b::l group */ l::{self, m, n::o, p::*}, + q, +}; diff --git a/tests/target/imports/imports_granularity_module.rs b/tests/target/imports/imports_granularity_module.rs new file mode 100644 index 00000000000..14f341016ff --- /dev/null +++ b/tests/target/imports/imports_granularity_module.rs @@ -0,0 +1,55 @@ +// rustfmt-imports_granularity: Module + +use a::b::c; +use a::d::e; +use a::f; +use a::g::{h, i}; +use a::j::k::{self, l}; +use a::j::{self, m}; +use a::n::o::p; +use a::n::q; +pub use a::r::s; +pub use a::t; +use b::c::d; +use b::{self}; + +use foo::e; +#[cfg(test)] +use foo::{a::b, c::d}; + +use bar::{ + // comment + a::b, + // more comment + c::d, + e::f, +}; + +use b::q::{self /* After b::q::self */}; +use b::r; // After b::r +use b::s::{ + a, + b, // After b::s::b +}; +use b::t::{/* Before b::t::self */ self}; +use b::t::{ + // Before b::t::a + a, + b, +}; +use b::u::{a, b}; +use b::v::{ + // Before b::v::a + a, + // Before b::v::b + b, +}; +use b::{c, d, e}; +use b::{ + f::g, + h::{i, j}, /* After b::h group */ +}; +use b::{ + /* Before b::l group */ l::{self, m, n::o, p::*}, + q, +}; diff --git a/tests/target/imports_2021_edition.rs b/tests/target/imports_2021_edition.rs deleted file mode 100644 index 34dcc866a0b..00000000000 --- a/tests/target/imports_2021_edition.rs +++ /dev/null @@ -1,3 +0,0 @@ -// rustfmt-edition: 2021 - -use ::happy::new::year; diff --git a/tests/target/imports_block_indent.rs b/tests/target/imports_block_indent.rs deleted file mode 100644 index 8c90f7ce29c..00000000000 --- a/tests/target/imports_block_indent.rs +++ /dev/null @@ -1,4 +0,0 @@ -// #2569 -use apns2::request::notification::{ - Notificatio, NotificationBuilder, Priority, SilentNotificationBuilder, -}; diff --git a/tests/target/imports_granularity_crate.rs b/tests/target/imports_granularity_crate.rs deleted file mode 100644 index 36e01558ff0..00000000000 --- a/tests/target/imports_granularity_crate.rs +++ /dev/null @@ -1,59 +0,0 @@ -// rustfmt-imports_granularity: Crate - -use a::{a, b, c, d, e, f, g}; - -#[doc(hidden)] -use a::b; -use a::{c, d}; - -#[doc(hidden)] -use a::b; -use a::{c, d, e}; - -use foo::{a, b, c}; -pub use foo::{bar, foobar}; - -use a::b::c::{d, xxx, yyy, zzz, *}; - -// https://github.com/rust-lang/rustfmt/issues/3808 -use d::{self}; -use e::{self as foo}; -use f::{self, b}; -use g::{self, a, b}; -use h::a; -use i::a::{self}; -use j::a::{self}; - -use k::{a, b, c, d}; -use l::{a, b, c, d}; - -use b::q::{self /* After b::q::self */}; -use b::r; // After b::r -use b::s::{ - a, - b, // After b::s::b -}; -use b::t::{/* Before b::t::self */ self}; -use b::t::{ - // Before b::t::a - a, - b, -}; -use b::v::{ - // Before b::v::a - a, - // Before b::v::b - b, -}; -use b::{ - c, d, e, - u::{a, b}, -}; -use b::{ - f::g, - h::{i, j}, /* After b::h group */ -}; -use b::{ - /* Before b::l group */ l::{self, m, n::o, p::*}, - q, -}; diff --git a/tests/target/imports_granularity_item.rs b/tests/target/imports_granularity_item.rs deleted file mode 100644 index d2f5496fdac..00000000000 --- a/tests/target/imports_granularity_item.rs +++ /dev/null @@ -1,45 +0,0 @@ -// rustfmt-imports_granularity: Item - -use a::b; -use a::c; -use a::d; -use a::f::g; -use a::h::i; -use a::h::j; -use a::l::m; -use a::l::n::o; -use a::l::p::*; -use a::l::{self}; -use a::q::{self}; - -use b::c; -use b::d; -use b::e; -use b::q::{self /* After b::q::self */}; -use b::r; // After b::r -use b::s::{ - a, - b, // After b::s::b -}; -use b::t::{/* Before b::t::self */ self}; -use b::t::{ - // Before b::t::a - a, - b, -}; -use b::u::a; -use b::u::b; -use b::v::{ - // Before b::v::a - a, - // Before b::v::b - b, -}; -use b::{ - f::g, - h::{i, j}, /* After b::h group */ -}; -use b::{ - /* Before b::l group */ l::{self, m, n::o, p::*}, - q, -}; diff --git a/tests/target/imports_granularity_module.rs b/tests/target/imports_granularity_module.rs deleted file mode 100644 index 14f341016ff..00000000000 --- a/tests/target/imports_granularity_module.rs +++ /dev/null @@ -1,55 +0,0 @@ -// rustfmt-imports_granularity: Module - -use a::b::c; -use a::d::e; -use a::f; -use a::g::{h, i}; -use a::j::k::{self, l}; -use a::j::{self, m}; -use a::n::o::p; -use a::n::q; -pub use a::r::s; -pub use a::t; -use b::c::d; -use b::{self}; - -use foo::e; -#[cfg(test)] -use foo::{a::b, c::d}; - -use bar::{ - // comment - a::b, - // more comment - c::d, - e::f, -}; - -use b::q::{self /* After b::q::self */}; -use b::r; // After b::r -use b::s::{ - a, - b, // After b::s::b -}; -use b::t::{/* Before b::t::self */ self}; -use b::t::{ - // Before b::t::a - a, - b, -}; -use b::u::{a, b}; -use b::v::{ - // Before b::v::a - a, - // Before b::v::b - b, -}; -use b::{c, d, e}; -use b::{ - f::g, - h::{i, j}, /* After b::h group */ -}; -use b::{ - /* Before b::l group */ l::{self, m, n::o, p::*}, - q, -}; -- cgit 1.4.1-3-g733a5