Skip to content

Commit 2e63026

Browse files
committed
Auto merge of rust-lang#125443 - nnethercote:rustfmt-use-decls, r=lcnr,cuviper,GuillaumeGomez
rustfmt `use` declarations This PR implements rust-lang/compiler-team#750, which changes how `use` declarations are formatted by adding these options to `rustfmt.toml`: ``` group_imports = "StdExternalCrate" imports_granularity = "Module" ``` r? `@ghost`
2 parents 2cbbe8b + 84ac80f commit 2e63026

File tree

1,867 files changed

+8167
-8995
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,867 files changed

+8167
-8995
lines changed

compiler/rustc_abi/src/layout.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use std::borrow::{Borrow, Cow};
2-
use std::cmp;
32
use std::fmt::{self, Write};
4-
use std::iter;
5-
use std::ops::Bound;
6-
use std::ops::Deref;
3+
use std::ops::{Bound, Deref};
4+
use std::{cmp, iter};
75

86
use rustc_index::Idx;
97
use tracing::debug;
@@ -982,7 +980,8 @@ fn univariant<
982980
if repr.can_randomize_type_layout() && cfg!(feature = "randomize") {
983981
#[cfg(feature = "randomize")]
984982
{
985-
use rand::{seq::SliceRandom, SeedableRng};
983+
use rand::seq::SliceRandom;
984+
use rand::SeedableRng;
986985
// `ReprOptions.field_shuffle_seed` is a deterministic seed we can use to randomize field
987986
// ordering.
988987
let mut rng =

compiler/rustc_abi/src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,20 @@
66
// tidy-alphabetical-end
77

88
use std::fmt;
9+
#[cfg(feature = "nightly")]
10+
use std::iter::Step;
911
use std::num::{NonZeroUsize, ParseIntError};
1012
use std::ops::{Add, AddAssign, Mul, RangeInclusive, Sub};
1113
use std::str::FromStr;
1214

1315
use bitflags::bitflags;
14-
use rustc_index::{Idx, IndexSlice, IndexVec};
15-
1616
#[cfg(feature = "nightly")]
1717
use rustc_data_structures::stable_hasher::StableOrd;
18+
use rustc_index::{Idx, IndexSlice, IndexVec};
1819
#[cfg(feature = "nightly")]
1920
use rustc_macros::HashStable_Generic;
2021
#[cfg(feature = "nightly")]
2122
use rustc_macros::{Decodable_Generic, Encodable_Generic};
22-
#[cfg(feature = "nightly")]
23-
use std::iter::Step;
2423

2524
mod layout;
2625
#[cfg(test)]

compiler/rustc_arena/src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,14 @@
2727
#![feature(strict_provenance)]
2828
// tidy-alphabetical-end
2929

30-
use smallvec::SmallVec;
31-
3230
use std::alloc::Layout;
3331
use std::cell::{Cell, RefCell};
3432
use std::marker::PhantomData;
3533
use std::mem::{self, MaybeUninit};
3634
use std::ptr::{self, NonNull};
37-
use std::slice;
38-
use std::{cmp, intrinsics};
35+
use std::{cmp, intrinsics, slice};
36+
37+
use smallvec::SmallVec;
3938

4039
/// This calls the passed function while ensuring it won't be inlined into the caller.
4140
#[inline(never)]

compiler/rustc_arena/src/tests.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
extern crate test;
2-
use super::TypedArena;
32
use std::cell::Cell;
3+
44
use test::Bencher;
55

6+
use super::TypedArena;
7+
68
#[allow(dead_code)]
79
#[derive(Debug, Eq, PartialEq)]
810
struct Point {

compiler/rustc_ast/src/ast.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,9 @@
1818
//! - [`Attribute`]: Metadata associated with item.
1919
//! - [`UnOp`], [`BinOp`], and [`BinOpKind`]: Unary and binary operators.
2020
21-
pub use crate::format::*;
22-
pub use crate::util::parser::ExprPrecedence;
23-
pub use rustc_span::AttrId;
24-
pub use GenericArgs::*;
25-
pub use UnsafeSource::*;
21+
use std::borrow::Cow;
22+
use std::{cmp, fmt, mem};
2623

27-
use crate::ptr::P;
28-
use crate::token::{self, CommentKind, Delimiter};
29-
use crate::tokenstream::{DelimSpan, LazyAttrTokenStream, TokenStream};
3024
pub use rustc_ast_ir::{Movability, Mutability};
3125
use rustc_data_structures::packed::Pu128;
3226
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -35,12 +29,17 @@ use rustc_data_structures::sync::Lrc;
3529
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
3630
use rustc_span::source_map::{respan, Spanned};
3731
use rustc_span::symbol::{kw, sym, Ident, Symbol};
32+
pub use rustc_span::AttrId;
3833
use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP};
39-
use std::borrow::Cow;
40-
use std::cmp;
41-
use std::fmt;
42-
use std::mem;
4334
use thin_vec::{thin_vec, ThinVec};
35+
pub use GenericArgs::*;
36+
pub use UnsafeSource::*;
37+
38+
pub use crate::format::*;
39+
use crate::ptr::P;
40+
use crate::token::{self, CommentKind, Delimiter};
41+
use crate::tokenstream::{DelimSpan, LazyAttrTokenStream, TokenStream};
42+
pub use crate::util::parser::ExprPrecedence;
4443

4544
/// A "Label" is an identifier of some point in sources,
4645
/// e.g. in the following code:
@@ -3491,8 +3490,9 @@ pub type ForeignItem = Item<ForeignItemKind>;
34913490
// Some nodes are used a lot. Make sure they don't unintentionally get bigger.
34923491
#[cfg(target_pointer_width = "64")]
34933492
mod size_asserts {
3494-
use super::*;
34953493
use rustc_data_structures::static_assert_size;
3494+
3495+
use super::*;
34963496
// tidy-alphabetical-start
34973497
static_assert_size!(AssocItem, 88);
34983498
static_assert_size!(AssocItemKind, 16);

compiler/rustc_ast/src/ast_traits.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
//! typically those used in AST fragments during macro expansion.
33
//! The traits are not implemented exhaustively, only when actually necessary.
44
5+
use std::fmt;
6+
use std::marker::PhantomData;
7+
58
use crate::ptr::P;
69
use crate::token::Nonterminal;
710
use crate::tokenstream::LazyAttrTokenStream;
8-
use crate::{Arm, Crate, ExprField, FieldDef, GenericParam, Param, PatField, Variant};
9-
use crate::{AssocItem, Expr, ForeignItem, Item, NodeId};
10-
use crate::{AttrItem, AttrKind, Block, Pat, Path, Ty, Visibility};
11-
use crate::{AttrVec, Attribute, Stmt, StmtKind};
12-
13-
use std::fmt;
14-
use std::marker::PhantomData;
11+
use crate::{
12+
Arm, AssocItem, AttrItem, AttrKind, AttrVec, Attribute, Block, Crate, Expr, ExprField,
13+
FieldDef, ForeignItem, GenericParam, Item, NodeId, Param, Pat, PatField, Path, Stmt, StmtKind,
14+
Ty, Variant, Visibility,
15+
};
1516

1617
/// A utility trait to reduce boilerplate.
1718
/// Standard `Deref(Mut)` cannot be reused due to coherence.

compiler/rustc_ast/src/attr/mod.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
//! Functions dealing with attributes and meta items.
22
3+
use std::iter;
4+
use std::sync::atomic::{AtomicU32, Ordering};
5+
6+
use rustc_index::bit_set::GrowableBitSet;
7+
use rustc_span::symbol::{sym, Ident, Symbol};
8+
use rustc_span::Span;
9+
use smallvec::{smallvec, SmallVec};
10+
use thin_vec::{thin_vec, ThinVec};
11+
312
use crate::ast::{
4-
AttrArgs, AttrArgsEq, AttrId, AttrItem, AttrKind, AttrStyle, AttrVec, Attribute, Safety,
13+
AttrArgs, AttrArgsEq, AttrId, AttrItem, AttrKind, AttrStyle, AttrVec, Attribute, DelimArgs,
14+
Expr, ExprKind, LitKind, MetaItem, MetaItemKind, MetaItemLit, NestedMetaItem, NormalAttr, Path,
15+
PathSegment, Safety, DUMMY_NODE_ID,
516
};
6-
use crate::ast::{DelimArgs, Expr, ExprKind, LitKind, MetaItemLit};
7-
use crate::ast::{MetaItem, MetaItemKind, NestedMetaItem, NormalAttr};
8-
use crate::ast::{Path, PathSegment, DUMMY_NODE_ID};
917
use crate::ptr::P;
1018
use crate::token::{self, CommentKind, Delimiter, Token};
11-
use crate::tokenstream::{DelimSpan, Spacing, TokenTree};
12-
use crate::tokenstream::{LazyAttrTokenStream, TokenStream};
19+
use crate::tokenstream::{DelimSpan, LazyAttrTokenStream, Spacing, TokenStream, TokenTree};
1320
use crate::util::comments;
1421
use crate::util::literal::escape_string_symbol;
15-
use rustc_index::bit_set::GrowableBitSet;
16-
use rustc_span::symbol::{sym, Ident, Symbol};
17-
use rustc_span::Span;
18-
use smallvec::{smallvec, SmallVec};
19-
use std::iter;
20-
use std::sync::atomic::{AtomicU32, Ordering};
21-
use thin_vec::{thin_vec, ThinVec};
2222

2323
pub struct MarkedAttrs(GrowableBitSet<AttrId>);
2424

compiler/rustc_ast/src/entry.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use crate::{attr, Attribute};
21
use rustc_span::symbol::sym;
32
use rustc_span::Symbol;
43

4+
use crate::{attr, Attribute};
5+
56
#[derive(Debug)]
67
pub enum EntryPointType {
78
/// This function is not an entrypoint.

compiler/rustc_ast/src/expand/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//! Definitions shared by macros / syntax extensions and e.g. `rustc_middle`.
22
33
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
4-
use rustc_span::{def_id::DefId, symbol::Ident};
4+
use rustc_span::def_id::DefId;
5+
use rustc_span::symbol::Ident;
56

67
use crate::MetaItem;
78

compiler/rustc_ast/src/format.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
use crate::ptr::P;
2-
use crate::Expr;
31
use rustc_data_structures::fx::FxHashMap;
42
use rustc_macros::{Decodable, Encodable};
53
use rustc_span::symbol::{Ident, Symbol};
64
use rustc_span::Span;
75

6+
use crate::ptr::P;
7+
use crate::Expr;
8+
89
// Definitions:
910
//
1011
// format_args!("hello {abc:.xyz$}!!", abc="world");

compiler/rustc_ast/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ pub mod token;
4343
pub mod tokenstream;
4444
pub mod visit;
4545

46+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
47+
4648
pub use self::ast::*;
4749
pub use self::ast_traits::{AstDeref, AstNodeWrapper, HasAttrs, HasNodeId, HasTokens};
4850

49-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
50-
5151
/// Requirements for a `StableHashingContext` to be used in this crate.
5252
/// This is a hack to allow using the `HashStable_Generic` derive macro
5353
/// instead of implementing everything in `rustc_middle`.

compiler/rustc_ast/src/mut_visit.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@
77
//! a `MutVisitor` renaming item names in a module will miss all of those
88
//! that are created by the expansion of a macro.
99
10-
use crate::ast::*;
11-
use crate::ptr::P;
12-
use crate::token::{self, Token};
13-
use crate::tokenstream::*;
14-
use crate::visit::{AssocCtxt, BoundKind};
10+
use std::ops::DerefMut;
11+
use std::panic;
1512

1613
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
1714
use rustc_data_structures::stack::ensure_sufficient_stack;
@@ -20,10 +17,14 @@ use rustc_span::source_map::Spanned;
2017
use rustc_span::symbol::Ident;
2118
use rustc_span::Span;
2219
use smallvec::{smallvec, Array, SmallVec};
23-
use std::ops::DerefMut;
24-
use std::panic;
2520
use thin_vec::ThinVec;
2621

22+
use crate::ast::*;
23+
use crate::ptr::P;
24+
use crate::token::{self, Token};
25+
use crate::tokenstream::*;
26+
use crate::visit::{AssocCtxt, BoundKind};
27+
2728
pub trait ExpectOne<A: Array> {
2829
fn expect_one(self, err: &'static str) -> A::Item;
2930
}

compiler/rustc_ast/src/node_id.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use rustc_span::LocalExpnId;
21
use std::fmt;
32

3+
use rustc_span::LocalExpnId;
4+
45
rustc_index::newtype_index! {
56
/// Identifies an AST node.
67
///

compiler/rustc_ast/src/ptr.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ use std::fmt::{self, Debug, Display};
2121
use std::ops::{Deref, DerefMut};
2222
use std::{slice, vec};
2323

24-
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
25-
2624
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
25+
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
2726
/// An owned smart pointer.
2827
///
2928
/// See the [module level documentation][crate::ptr] for details.

compiler/rustc_ast/src/token.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
use std::borrow::Cow;
2+
use std::fmt;
3+
4+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
5+
use rustc_data_structures::sync::Lrc;
6+
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
7+
use rustc_span::edition::Edition;
8+
use rustc_span::symbol::{kw, sym};
9+
#[allow(clippy::useless_attribute)] // FIXME: following use of `hidden_glob_reexports` incorrectly triggers `useless_attribute` lint.
10+
#[allow(hidden_glob_reexports)]
11+
use rustc_span::symbol::{Ident, Symbol};
12+
use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP};
113
pub use BinOpToken::*;
214
pub use LitKind::*;
315
pub use Nonterminal::*;
@@ -9,17 +21,6 @@ use crate::ast;
921
use crate::ptr::P;
1022
use crate::util::case::Case;
1123

12-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
13-
use rustc_data_structures::sync::Lrc;
14-
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
15-
use rustc_span::symbol::{kw, sym};
16-
#[allow(clippy::useless_attribute)] // FIXME: following use of `hidden_glob_reexports` incorrectly triggers `useless_attribute` lint.
17-
#[allow(hidden_glob_reexports)]
18-
use rustc_span::symbol::{Ident, Symbol};
19-
use rustc_span::{edition::Edition, ErrorGuaranteed, Span, DUMMY_SP};
20-
use std::borrow::Cow;
21-
use std::fmt;
22-
2324
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
2425
pub enum CommentKind {
2526
Line,
@@ -1062,8 +1063,9 @@ where
10621063
// Some types are used a lot. Make sure they don't unintentionally get bigger.
10631064
#[cfg(target_pointer_width = "64")]
10641065
mod size_asserts {
1065-
use super::*;
10661066
use rustc_data_structures::static_assert_size;
1067+
1068+
use super::*;
10671069
// tidy-alphabetical-start
10681070
static_assert_size!(Lit, 12);
10691071
static_assert_size!(LitKind, 2);

compiler/rustc_ast/src/tokenstream.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@
1313
//! and a borrowed `TokenStream` is sufficient to build an owned `TokenStream` without taking
1414
//! ownership of the original.
1515
16-
use crate::ast::{AttrStyle, StmtKind};
17-
use crate::ast_traits::{HasAttrs, HasTokens};
18-
use crate::token::{self, Delimiter, Nonterminal, Token, TokenKind};
19-
use crate::{AttrVec, Attribute};
16+
use std::borrow::Cow;
17+
use std::{cmp, fmt, iter};
2018

2119
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
2220
use rustc_data_structures::sync::{self, Lrc};
2321
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
2422
use rustc_serialize::{Decodable, Encodable};
2523
use rustc_span::{sym, Span, SpanDecoder, SpanEncoder, Symbol, DUMMY_SP};
2624

27-
use std::borrow::Cow;
28-
use std::{cmp, fmt, iter};
25+
use crate::ast::{AttrStyle, StmtKind};
26+
use crate::ast_traits::{HasAttrs, HasTokens};
27+
use crate::token::{self, Delimiter, Nonterminal, Token, TokenKind};
28+
use crate::{AttrVec, Attribute};
2929

3030
/// Part of a `TokenStream`.
3131
#[derive(Debug, Clone, PartialEq, Encodable, Decodable, HashStable_Generic)]
@@ -767,8 +767,9 @@ impl DelimSpacing {
767767
// Some types are used a lot. Make sure they don't unintentionally get bigger.
768768
#[cfg(target_pointer_width = "64")]
769769
mod size_asserts {
770-
use super::*;
771770
use rustc_data_structures::static_assert_size;
771+
772+
use super::*;
772773
// tidy-alphabetical-start
773774
static_assert_size!(AttrTokenStream, 8);
774775
static_assert_size!(AttrTokenTree, 32);

compiler/rustc_ast/src/util/comments.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use crate::token::CommentKind;
21
use rustc_span::{BytePos, Symbol};
32

3+
use crate::token::CommentKind;
4+
45
#[cfg(test)]
56
mod tests;
67

compiler/rustc_ast/src/util/comments/tests.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use super::*;
21
use rustc_span::create_default_session_globals_then;
32

3+
use super::*;
4+
45
#[test]
56
fn test_block_doc_comment_1() {
67
create_default_session_globals_then(|| {

0 commit comments

Comments
 (0)