diff options
Diffstat (limited to '')
17 files changed, 486 insertions, 0 deletions
diff --git a/src/tools/rustfmt/tests/target/imports/import-fencepost-length.rs b/src/tools/rustfmt/tests/target/imports/import-fencepost-length.rs new file mode 100644 index 000000000..fd09d50d7 --- /dev/null +++ b/src/tools/rustfmt/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/src/tools/rustfmt/tests/target/imports/imports-impl-only-use.rs b/src/tools/rustfmt/tests/target/imports/imports-impl-only-use.rs new file mode 100644 index 000000000..d290d8d91 --- /dev/null +++ b/src/tools/rustfmt/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/src/tools/rustfmt/tests/target/imports/imports-reorder-lines-and-items.rs b/src/tools/rustfmt/tests/target/imports/imports-reorder-lines-and-items.rs new file mode 100644 index 000000000..98a5afe43 --- /dev/null +++ b/src/tools/rustfmt/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/src/tools/rustfmt/tests/target/imports/imports-reorder-lines.rs b/src/tools/rustfmt/tests/target/imports/imports-reorder-lines.rs new file mode 100644 index 000000000..5b85503b5 --- /dev/null +++ b/src/tools/rustfmt/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/src/tools/rustfmt/tests/target/imports/imports-reorder.rs b/src/tools/rustfmt/tests/target/imports/imports-reorder.rs new file mode 100644 index 000000000..84e97c022 --- /dev/null +++ b/src/tools/rustfmt/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/src/tools/rustfmt/tests/target/imports/imports.rs b/src/tools/rustfmt/tests/target/imports/imports.rs new file mode 100644 index 000000000..87584d89f --- /dev/null +++ b/src/tools/rustfmt/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/src/tools/rustfmt/tests/target/imports/imports_2021_edition.rs b/src/tools/rustfmt/tests/target/imports/imports_2021_edition.rs new file mode 100644 index 000000000..34dcc866a --- /dev/null +++ b/src/tools/rustfmt/tests/target/imports/imports_2021_edition.rs @@ -0,0 +1,3 @@ +// rustfmt-edition: 2021 + +use ::happy::new::year; diff --git a/src/tools/rustfmt/tests/target/imports/imports_block_indent.rs b/src/tools/rustfmt/tests/target/imports/imports_block_indent.rs new file mode 100644 index 000000000..8c90f7ce2 --- /dev/null +++ b/src/tools/rustfmt/tests/target/imports/imports_block_indent.rs @@ -0,0 +1,4 @@ +// #2569 +use apns2::request::notification::{ + Notificatio, NotificationBuilder, Priority, SilentNotificationBuilder, +}; diff --git a/src/tools/rustfmt/tests/target/imports/imports_granularity_crate.rs b/src/tools/rustfmt/tests/target/imports/imports_granularity_crate.rs new file mode 100644 index 000000000..36e01558f --- /dev/null +++ b/src/tools/rustfmt/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/src/tools/rustfmt/tests/target/imports/imports_granularity_default-with-dups.rs b/src/tools/rustfmt/tests/target/imports/imports_granularity_default-with-dups.rs new file mode 100644 index 000000000..5da6d588e --- /dev/null +++ b/src/tools/rustfmt/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/src/tools/rustfmt/tests/target/imports/imports_granularity_item-with-dups-StdExternalCrate-no-reorder.rs b/src/tools/rustfmt/tests/target/imports/imports_granularity_item-with-dups-StdExternalCrate-no-reorder.rs new file mode 100644 index 000000000..ed4df544d --- /dev/null +++ b/src/tools/rustfmt/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/src/tools/rustfmt/tests/target/imports/imports_granularity_item-with-dups.rs b/src/tools/rustfmt/tests/target/imports/imports_granularity_item-with-dups.rs new file mode 100644 index 000000000..00df37f93 --- /dev/null +++ b/src/tools/rustfmt/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/src/tools/rustfmt/tests/target/imports/imports_granularity_item.rs b/src/tools/rustfmt/tests/target/imports/imports_granularity_item.rs new file mode 100644 index 000000000..d2f5496fd --- /dev/null +++ b/src/tools/rustfmt/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/src/tools/rustfmt/tests/target/imports/imports_granularity_module.rs b/src/tools/rustfmt/tests/target/imports/imports_granularity_module.rs new file mode 100644 index 000000000..14f341016 --- /dev/null +++ b/src/tools/rustfmt/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/src/tools/rustfmt/tests/target/imports_granularity_one.rs b/src/tools/rustfmt/tests/target/imports_granularity_one.rs new file mode 100644 index 000000000..da4c6678d --- /dev/null +++ b/src/tools/rustfmt/tests/target/imports_granularity_one.rs @@ -0,0 +1,109 @@ +// rustfmt-imports_granularity: One + +use { + a::{ + aa::*, + ab, + ac::{aca, acb}, + }, + b, +}; + +use { + a::{self as x, aa, ab}, + b::ba, +}; + +use a::{ + aa::{aaa, *}, + ab::aba as x, +}; + +#[cfg(test)] +use a::{ab, ac::aca}; +#[cfg(test)] +use b::{ + ba, bb, + bc::bca::{bcaa, bcab}, +}; +use { + a::{aa, ad::ada}, + b, +}; + +pub use { + a::{aa, ae}, + b::{bb, bc::bca}, +}; +use { + a::{ab, ac, ad}, + b::ba, +}; + +use { + a::{ + aa::{aaa, *}, + ab, + ac::{aca, acb}, + }, + b::{ + ba, + bb::{self, bba}, + }, +}; + +use { + crate::{a, b::ba}, + c::ca, +}; + +use { + super::{a, b::ba}, + c::ca, +}; + +use { + super::b, + crate::a, + c::{self, ca}, +}; + +use a::{ + // some comment + aa::{aaa, aab}, + ab, + // another comment + ac::aca, +}; +use {a::ad::ada, b as x}; + +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/src/tools/rustfmt/tests/target/imports_raw_identifiers/version_One.rs b/src/tools/rustfmt/tests/target/imports_raw_identifiers/version_One.rs new file mode 100644 index 000000000..bc4b5b135 --- /dev/null +++ b/src/tools/rustfmt/tests/target/imports_raw_identifiers/version_One.rs @@ -0,0 +1,5 @@ +// rustfmt-version:One + +use websocket::client::ClientBuilder; +use websocket::r#async::futures::Stream; +use websocket::result::WebSocketError; diff --git a/src/tools/rustfmt/tests/target/imports_raw_identifiers/version_Two.rs b/src/tools/rustfmt/tests/target/imports_raw_identifiers/version_Two.rs new file mode 100644 index 000000000..22bfe9312 --- /dev/null +++ b/src/tools/rustfmt/tests/target/imports_raw_identifiers/version_Two.rs @@ -0,0 +1,5 @@ +// rustfmt-version:Two + +use websocket::r#async::futures::Stream; +use websocket::client::ClientBuilder; +use websocket::result::WebSocketError; |