Auto merge of #125443 - nnethercote:rustfmt-use-decls, r=lcnr,cuviper… · rust-lang/rust@2e63026 (original) (raw)

1,867 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
1 1 use std::borrow::{Borrow, Cow};
2 -use std::cmp;
3 2 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};
7 5
8 6 use rustc_index::Idx;
9 7 use tracing::debug;
@@ -982,7 +980,8 @@ fn univariant<
982 980 if repr.can_randomize_type_layout() && cfg!(feature = "randomize") {
983 981 #[cfg(feature = "randomize")]
984 982 {
985 -use rand::{seq::SliceRandom, SeedableRng};
983 +use rand::seq::SliceRandom;
984 +use rand::SeedableRng;
986 985 // `ReprOptions.field_shuffle_seed` is a deterministic seed we can use to randomize field
987 986 // ordering.
988 987 let mut rng =
Original file line number Diff line number Diff line change
@@ -6,21 +6,20 @@
6 6 // tidy-alphabetical-end
7 7
8 8 use std::fmt;
9 +#[cfg(feature = "nightly")]
10 +use std::iter::Step;
9 11 use std::num::{NonZeroUsize, ParseIntError};
10 12 use std::ops::{Add, AddAssign, Mul, RangeInclusive, Sub};
11 13 use std::str::FromStr;
12 14
13 15 use bitflags::bitflags;
14 -use rustc_index::{Idx, IndexSlice, IndexVec};
15 -
16 16 #[cfg(feature = "nightly")]
17 17 use rustc_data_structures::stable_hasher::StableOrd;
18 +use rustc_index::{Idx, IndexSlice, IndexVec};
18 19 #[cfg(feature = "nightly")]
19 20 use rustc_macros::HashStable_Generic;
20 21 #[cfg(feature = "nightly")]
21 22 use rustc_macros::{Decodable_Generic, Encodable_Generic};
22 -#[cfg(feature = "nightly")]
23 -use std::iter::Step;
24 23
25 24 mod layout;
26 25 #[cfg(test)]
Original file line number Diff line number Diff line change
@@ -27,15 +27,14 @@
27 27 #![feature(strict_provenance)]
28 28 // tidy-alphabetical-end
29 29
30 -use smallvec::SmallVec;
31 -
32 30 use std::alloc::Layout;
33 31 use std::cell::{Cell, RefCell};
34 32 use std:📑:PhantomData;
35 33 use std::mem::{self, MaybeUninit};
36 34 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;
39 38
40 39 /// This calls the passed function while ensuring it won't be inlined into the caller.
41 40 #[inline(never)]
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
1 1 extern crate test;
2 -use super::TypedArena;
3 2 use std::cell::Cell;
3 +
4 4 use test::Bencher;
5 5
6 +use super::TypedArena;
7 +
6 8 #[allow(dead_code)]
7 9 #[derive(Debug, Eq, PartialEq)]
8 10 struct Point {
Original file line number Diff line number Diff line change
@@ -18,15 +18,9 @@
18 18 //! - [`Attribute`]: Metadata associated with item.
19 19 //! - [`UnOp`], [`BinOp`], and [`BinOpKind`]: Unary and binary operators.
20 20
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};
26 23
27 -use crate::ptr::P;
28 -use crate::token::{self, CommentKind, Delimiter};
29 -use crate::tokenstream::{DelimSpan, LazyAttrTokenStream, TokenStream};
30 24 pub use rustc_ast_ir::{Movability, Mutability};
31 25 use rustc_data_structures::packed::Pu128;
32 26 use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -35,12 +29,17 @@ use rustc_data_structures::sync::Lrc;
35 29 use rustc_macros::{Decodable, Encodable, HashStable_Generic};
36 30 use rustc_span::source_map::{respan, Spanned};
37 31 use rustc_span::symbol::{kw, sym, Ident, Symbol};
32 +pub use rustc_span::AttrId;
38 33 use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP};
39 -use std::borrow::Cow;
40 -use std::cmp;
41 -use std::fmt;
42 -use std::mem;
43 34 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;
44 43
45 44 /// A "Label" is an identifier of some point in sources,
46 45 /// e.g. in the following code:
@@ -3491,8 +3490,9 @@ pub type ForeignItem = Item;
3491 3490 // Some nodes are used a lot. Make sure they don't unintentionally get bigger.
3492 3491 #[cfg(target_pointer_width = "64")]
3493 3492 mod size_asserts {
3494 -use super::*;
3495 3493 use rustc_data_structures::static_assert_size;
3494 +
3495 +use super::*;
3496 3496 // tidy-alphabetical-start
3497 3497 static_assert_size!(AssocItem, 88);
3498 3498 static_assert_size!(AssocItemKind, 16);
Original file line number Diff line number Diff line change
@@ -2,16 +2,17 @@
2 2 //! typically those used in AST fragments during macro expansion.
3 3 //! The traits are not implemented exhaustively, only when actually necessary.
4 4
5 +use std::fmt;
6 +use std:📑:PhantomData;
7 +
5 8 use crate::ptr::P;
6 9 use crate::token::Nonterminal;
7 10 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:📑: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 +};
15 16
16 17 /// A utility trait to reduce boilerplate.
17 18 /// Standard `Deref(Mut)` cannot be reused due to coherence.
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
1 1 //! Functions dealing with attributes and meta items.
2 2
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 +
3 12 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,
5 16 };
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};
9 17 use crate::ptr::P;
10 18 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};
13 20 use crate::util::comments;
14 21 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};
22 22
23 23 pub struct MarkedAttrs(GrowableBitSet<AttrId>);
24 24
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
1 -use crate::{attr, Attribute};
2 1 use rustc_span::symbol::sym;
3 2 use rustc_span::Symbol;
4 3
4 +use crate::{attr, Attribute};
5 +
5 6 #[derive(Debug)]
6 7 pub enum EntryPointType {
7 8 /// This function is not an entrypoint.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
1 1 //! Definitions shared by macros / syntax extensions and e.g. `rustc_middle`.
2 2
3 3 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;
5 6
6 7 use crate::MetaItem;
7 8
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
1 -use crate::ptr::P;
2 -use crate::Expr;
3 1 use rustc_data_structures::fx::FxHashMap;
4 2 use rustc_macros::{Decodable, Encodable};
5 3 use rustc_span::symbol::{Ident, Symbol};
6 4 use rustc_span::Span;
7 5
6 +use crate::ptr::P;
7 +use crate::Expr;
8 +
8 9 // Definitions:
9 10 //
10 11 // format_args!("hello {abc:.xyz$}!!", abc="world");
Original file line number Diff line number Diff line change
@@ -43,11 +43,11 @@ pub mod token;
43 43 pub mod tokenstream;
44 44 pub mod visit;
45 45
46 +use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
47 +
46 48 pub use self::ast::*;
47 49 pub use self::ast_traits::{AstDeref, AstNodeWrapper, HasAttrs, HasNodeId, HasTokens};
48 50
49 -use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
50 -
51 51 /// Requirements for a `StableHashingContext` to be used in this crate.
52 52 /// This is a hack to allow using the `HashStable_Generic` derive macro
53 53 /// instead of implementing everything in `rustc_middle`.
Original file line number Diff line number Diff line change
@@ -7,11 +7,8 @@
7 7 //! a `MutVisitor` renaming item names in a module will miss all of those
8 8 //! that are created by the expansion of a macro.
9 9
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;
15 12
16 13 use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
17 14 use rustc_data_structures::stack::ensure_sufficient_stack;
@@ -20,10 +17,14 @@ use rustc_span::source_map::Spanned;
20 17 use rustc_span::symbol::Ident;
21 18 use rustc_span::Span;
22 19 use smallvec::{smallvec, Array, SmallVec};
23 -use std::ops::DerefMut;
24 -use std::panic;
25 20 use thin_vec::ThinVec;
26 21
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 +
27 28 pub trait ExpectOne<A: Array> {
28 29 fn expect_one(self, err: &'static str) -> A::Item;
29 30 }
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
1 -use rustc_span::LocalExpnId;
2 1 use std::fmt;
3 2
3 +use rustc_span::LocalExpnId;
4 +
4 5 rustc_index::newtype_index! {
5 6 /// Identifies an AST node.
6 7 ///
Original file line number Diff line number Diff line change
@@ -21,9 +21,8 @@ use std::fmt::{self, Debug, Display};
21 21 use std::ops::{Deref, DerefMut};
22 22 use std::{slice, vec};
23 23
24 -use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
25 -
26 24 use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
25 +use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
27 26 /// An owned smart pointer.
28 27 ///
29 28 /// See the [module level documentation][crate::ptr] for details.
Original file line number Diff line number Diff 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};
1 13 pub use BinOpToken::*;
2 14 pub use LitKind::*;
3 15 pub use Nonterminal::*;
@@ -9,17 +21,6 @@ use crate::ast;
9 21 use crate::ptr::P;
10 22 use crate::util::case::Case;
11 23
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 -
23 24 #[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
24 25 pub enum CommentKind {
25 26 Line,
@@ -1062,8 +1063,9 @@ where
1062 1063 // Some types are used a lot. Make sure they don't unintentionally get bigger.
1063 1064 #[cfg(target_pointer_width = "64")]
1064 1065 mod size_asserts {
1065 -use super::*;
1066 1066 use rustc_data_structures::static_assert_size;
1067 +
1068 +use super::*;
1067 1069 // tidy-alphabetical-start
1068 1070 static_assert_size!(Lit, 12);
1069 1071 static_assert_size!(LitKind, 2);
Original file line number Diff line number Diff line change
@@ -13,19 +13,19 @@
13 13 //! and a borrowed `TokenStream` is sufficient to build an owned `TokenStream` without taking
14 14 //! ownership of the original.
15 15
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};
20 18
21 19 use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
22 20 use rustc_data_structures::sync::{self, Lrc};
23 21 use rustc_macros::{Decodable, Encodable, HashStable_Generic};
24 22 use rustc_serialize::{Decodable, Encodable};
25 23 use rustc_span::{sym, Span, SpanDecoder, SpanEncoder, Symbol, DUMMY_SP};
26 24
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};
29 29
30 30 /// Part of a `TokenStream`.
31 31 #[derive(Debug, Clone, PartialEq, Encodable, Decodable, HashStable_Generic)]
@@ -767,8 +767,9 @@ impl DelimSpacing {
767 767 // Some types are used a lot. Make sure they don't unintentionally get bigger.
768 768 #[cfg(target_pointer_width = "64")]
769 769 mod size_asserts {
770 -use super::*;
771 770 use rustc_data_structures::static_assert_size;
771 +
772 +use super::*;
772 773 // tidy-alphabetical-start
773 774 static_assert_size!(AttrTokenStream, 8);
774 775 static_assert_size!(AttrTokenTree, 32);
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
1 -use crate::token::CommentKind;
2 1 use rustc_span::{BytePos, Symbol};
3 2
3 +use crate::token::CommentKind;
4 +
4 5 #[cfg(test)]
5 6 mod tests;
6 7
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
1 -use super::*;
2 1 use rustc_span::create_default_session_globals_then;
3 2
3 +use super::*;
4 +
4 5 #[test]
5 6 fn test_block_doc_comment_1() {
6 7 create_default_session_globals_then(|