1
Fork 0

Rollup merge of #126717 - nnethercote:rustfmt-use-pre-cleanups, r=jieyouxu

Clean up some comments near `use` declarations

#125443 will reformat all `use` declarations in the repository. There are a few edge cases involving comments on `use` declarations that require care. This PR cleans up some clumsy comment cases, taking us a step closer to #125443 being able to merge.

r? ``@lqd``
This commit is contained in:
Matthias Krüger 2024-06-20 14:07:04 +02:00 committed by GitHub
commit ef2e8bfcbf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
75 changed files with 98 additions and 33 deletions

View file

@ -1,6 +1,7 @@
//! The expansion from a test function to the appropriate test struct for libtest
//! Ideally, this code would be in libtest but for efficiency and error messages it lives here.
use crate::errors;
/// The expansion from a test function to the appropriate test struct for libtest
/// Ideally, this code would be in libtest but for efficiency and error messages it lives here.
use crate::util::{check_builtin_macro_attribute, warn_on_duplicate_attribute};
use rustc_ast::ptr::P;
use rustc_ast::{self as ast, attr, GenericParamKind};

View file

@ -1,4 +1,5 @@
//! The common code for `tests/lang_tests_*.rs`
use std::{
env::{self, current_dir},
path::{Path, PathBuf},

View file

@ -1,6 +1,7 @@
//! Locals are in a private module as updating `LocalRef::Operand` has to
//! be careful wrt to subtyping. To deal with this we only allow updates by using
//! `FunctionCx::overwrite_local` which handles it automatically.
use crate::mir::{FunctionCx, LocalRef};
use crate::traits::BuilderMethods;
use rustc_index::IndexVec;

View file

@ -1,5 +1,6 @@
/// Converts unsigned integers into a string representation with some base.
/// Bases up to and including 36 can be used for case-insensitive things.
//! Converts unsigned integers into a string representation with some base.
//! Bases up to and including 36 can be used for case-insensitive things.
use std::ascii;
use std::fmt;

View file

@ -1,6 +1,7 @@
//! A simple markdown parser that can write formatted text to the terminal
//!
//! Entrypoint is `MdStream::parse_str(...)`
use std::io;
use termcolor::{Buffer, BufferWriter, ColorChoice};

View file

@ -104,6 +104,7 @@
//! Kleene operators under which a meta-variable is repeating is the concatenation of the stacks
//! stored when entering a macro definition starting from the state in which the meta-variable is
//! bound.
use crate::errors;
use crate::mbe::{KleeneToken, TokenTree};

View file

@ -1,9 +1,7 @@
// tidy-alphabetical-start
use std::ffi::CString;
use std::fs;
use std::io;
use std::path::{absolute, Path, PathBuf};
// tidy-alphabetical-end
// Unfortunately, on windows, it looks like msvcrt.dll is silently translating
// verbatim paths under the hood to non-verbatim paths! This manifests itself as

View file

@ -1,6 +1,7 @@
// FIXME(@lcnr): Move this module out of `rustc_hir_analysis`.
//
// We don't do any drop checking during hir typeck.
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{codes::*, struct_span_code_err, ErrorGuaranteed};
use rustc_infer::infer::outlives::env::OutlivesEnvironment;

View file

@ -1,4 +1,5 @@
//! Some helper functions for `AutoDeref`
//! Some helper functions for `AutoDeref`.
use super::method::MethodCallee;
use super::{FnCtxt, PlaceOp};

View file

@ -1,4 +1,5 @@
//! Errors emitted by `rustc_hir_typeck`.
use std::borrow::Cow;
use crate::fluent_generated as fluent;

View file

@ -1,4 +1,5 @@
//! A utility module to inspect currently ambiguous obligations in the current context.
use crate::FnCtxt;
use rustc_infer::traits::{self, ObligationCause};
use rustc_middle::traits::solve::Goal;

View file

@ -1,5 +1,6 @@
//! Error Reporting for Anonymous Region Lifetime Errors
//! where one region is named and the other is anonymous.
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
use crate::{
errors::ExplicitLifetimeRequired,

View file

@ -30,6 +30,7 @@
//! solving a set of constraints. In contrast, the type inferencer assigns a value to each type
//! variable only once, and it does so as soon as it can, so it is reasonable to ask what the type
//! inferencer knows "so far".
use super::InferCtxt;
use rustc_data_structures::fx::FxHashMap;
use rustc_middle::bug;

View file

@ -1,4 +1,5 @@
//! Various code related to computing outlives relations.
use self::env::OutlivesEnvironment;
use super::region_constraints::RegionConstraintData;
use super::{InferCtxt, RegionResolutionError, SubregionOrigin};

View file

@ -1,4 +1,3 @@
// tidy-alphabetical-start
pub use self::Level::*;
use rustc_ast::node_id::NodeId;
use rustc_ast::{AttrId, Attribute};
@ -15,7 +14,6 @@ use rustc_span::edition::Edition;
use rustc_span::symbol::MacroRulesNormalizedIdent;
use rustc_span::{sym, symbol::Ident, Span, Symbol};
use rustc_target::spec::abi::Abi;
// tidy-alphabetical-end
use serde::{Deserialize, Serialize};

View file

@ -1,6 +1,7 @@
//! A pass that checks to make sure private fields and methods aren't used
//! outside their scopes. This pass will also generate a set of exported items
//! which are available for use externally when compiled as a library.
use crate::ty::{TyCtxt, Visibility};
use rustc_data_structures::fx::{FxIndexMap, IndexEntry};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};

View file

@ -1,4 +1,5 @@
/// Functionality for statements, operands, places, and things that appear in them.
//! Functionality for statements, operands, places, and things that appear in them.
use super::{interpret::GlobalAlloc, *};
///////////////////////////////////////////////////////////////////////////

View file

@ -1,4 +1,5 @@
/// Functionality for terminators and helper types that appear in terminators.
//! Functionality for terminators and helper types that appear in terminators.
use rustc_hir::LangItem;
use smallvec::{smallvec, SmallVec};

View file

@ -1,4 +1,5 @@
//! A subset of a mir body used for const evaluability checking.
use crate::ty::{
self, Const, EarlyBinder, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable,
TypeVisitableExt,

View file

@ -1,5 +1,6 @@
//! A pass that inserts the `ConstEvalCounter` instruction into any blocks that have a back edge
//! (thus indicating there is a loop in the CFG), or whose terminator is a function call.
use crate::MirPass;
use rustc_data_structures::graph::dominators::Dominators;

View file

@ -1,4 +1,5 @@
//! Inlining pass for MIR functions
//! Inlining pass for MIR functions.
use crate::deref_separator::deref_finder;
use rustc_attr::InlineAttr;
use rustc_hir::def::DefKind;

View file

@ -1,6 +1,7 @@
//! This pass statically detects code which has undefined behaviour or is likely to be erroneous.
//! It can be used to locate problems in MIR building or optimizations. It assumes that all code
//! can be executed, so it has false positives.
use rustc_data_structures::fx::FxHashSet;
use rustc_index::bit_set::BitSet;
use rustc_middle::mir::visit::{PlaceContext, Visitor};

View file

@ -1,4 +1,5 @@
// ignore-tidy-filelength
use super::diagnostics::SnapshotParser;
use super::pat::{CommaRecoveryMode, Expected, RecoverColon, RecoverComma};
use super::ty::{AllowPlus, RecoverQPath, RecoverReturnSign};

View file

@ -1,5 +1,6 @@
//! As explained in [`crate::usefulness`], values and patterns are made from constructors applied to
//! fields. This file defines types that represent patterns in this way.
use std::fmt;
use smallvec::{smallvec, SmallVec};

View file

@ -1,4 +1,5 @@
//! Test the pattern complexity limit.
use common::*;
use rustc_pattern_analysis::{pat::DeconstructedPat, usefulness::PlaceValidity, MatchArm};

View file

@ -1,4 +1,5 @@
//! Test exhaustiveness checking.
use common::*;
use rustc_pattern_analysis::{
pat::{DeconstructedPat, WitnessPat},

View file

@ -1,4 +1,5 @@
//! Test the computation of arm intersections.
use common::*;
use rustc_pattern_analysis::{pat::DeconstructedPat, usefulness::PlaceValidity, MatchArm};

View file

@ -4,6 +4,7 @@
//!
//! For more information about LLVM CFI and cross-language LLVM CFI support for the Rust compiler,
//! see design document in the tracking issue #89653.
use rustc_data_structures::base_n::ToBaseN;
use rustc_data_structures::base_n::ALPHANUMERIC_ONLY;
use rustc_data_structures::base_n::CASE_INSENSITIVE;

View file

@ -3,6 +3,7 @@
//!
//! For more information about LLVM CFI and cross-language LLVM CFI support for the Rust compiler,
//! see design document in the tracking issue #89653.
use rustc_data_structures::fx::FxHashMap;
use rustc_middle::bug;
use rustc_middle::ty::{self, Instance, Ty, TyCtxt, TypeFoldable};

View file

@ -3,6 +3,7 @@
//!
//! For more information about LLVM CFI and cross-language LLVM CFI support for the Rust compiler,
//! see design document in the tracking issue #89653.
use rustc_hir as hir;
use rustc_hir::LangItem;
use rustc_middle::bug;

View file

@ -3,6 +3,7 @@
//!
//! For more information about LLVM CFI and cross-language LLVM CFI support for the Rust compiler,
//! see design document in the tracking issue #89653.
use bitflags::bitflags;
use rustc_middle::ty::{Instance, Ty, TyCtxt};
use rustc_target::abi::call::FnAbi;

View file

@ -3,6 +3,7 @@
//!
//! For more information about LLVM KCFI and cross-language LLVM KCFI support for the Rust compiler,
//! see the tracking issue #123479.
use rustc_middle::ty::{Instance, InstanceKind, ReifyReason, Ty, TyCtxt};
use rustc_target::abi::call::FnAbi;
use std::hash::Hasher;

View file

@ -1,4 +1,5 @@
//! Related to out filenames of compilation (e.g. binaries).
use crate::config::{self, CrateType, Input, OutFileName, OutputFilenames, OutputType};
use crate::errors::{
self, CrateNameDoesNotMatch, CrateNameEmpty, CrateNameInvalid, FileIsNotWriteable,

View file

@ -3,6 +3,7 @@
//! We first retrieve and monomorphize the rustc body representation, i.e., we generate a
//! monomorphic body using internal representation.
//! After that, we convert the internal representation into a stable one.
use crate::rustc_smir::{Stable, Tables};
use rustc_hir::def::DefKind;
use rustc_middle::mir;

View file

@ -1,6 +1,7 @@
//! Handle the conversion of different internal errors into a stable version.
//!
//! Currently we encode everything as [stable_mir::Error], which is represented as a string.
use crate::rustc_smir::{Stable, Tables};
use rustc_middle::mir::interpret::AllocError;
use rustc_middle::ty::layout::LayoutError;

View file

@ -1,5 +1,5 @@
/// A target tuple for OpenWrt MIPS64 targets
///
//! A target tuple for OpenWrt MIPS64 targets.
use crate::abi::Endian;
use crate::spec::{base, Target, TargetOptions};

View file

@ -1,4 +1,5 @@
//! Deeply normalize types using the old trait solver.
use super::error_reporting::OverflowCause;
use super::error_reporting::TypeErrCtxtExt;
use super::SelectionContext;

View file

@ -6,6 +6,7 @@
//!
//! [rustc dev guide]:
//! https://rustc-dev-guide.rust-lang.org/traits/resolution.html#confirmation
use rustc_ast::Mutability;
use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_hir::lang_items::LangItem;

View file

@ -1,4 +1,5 @@
//! This module provides methods to retrieve allocation information, such as static variables.
use crate::mir::mono::{Instance, StaticDef};
use crate::target::{Endian, MachineInfo};
use crate::ty::{Allocation, Binder, ExistentialTraitRef, IndexedVal, Ty};

View file

@ -1,6 +1,7 @@
// Based on
// https://github.com/matthieu-m/rfc2580/blob/b58d1d3cba0d4b5e859d3617ea2d0943aaa31329/examples/thin.rs
// by matthieu-m
//! Based on
//! <https://github.com/matthieu-m/rfc2580/blob/b58d1d3cba0d4b5e859d3617ea2d0943aaa31329/examples/thin.rs>
//! by matthieu-m
use crate::alloc::{self, Layout, LayoutError};
use core::error::Error;
use core::fmt::{self, Debug, Display, Formatter};

View file

@ -154,6 +154,7 @@
//! }
//! vec.truncate(write_idx);
//! ```
use crate::alloc::{handle_alloc_error, Global};
use core::alloc::Allocator;
use core::alloc::Layout;

View file

@ -17,6 +17,7 @@
//! Note: Because the term "leading byte" can sometimes be ambiguous (for
//! example, it could also refer to the first byte of a slice), we'll often use
//! the term "non-continuation byte" to refer to these bytes in the code.
use core::intrinsics::unlikely;
const USIZE_SIZE: usize = core::mem::size_of::<usize>();

View file

@ -3,6 +3,7 @@ use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
#[cfg(not(panic = "abort"))]
mod drop_checks {
//! These tests mainly make sure the elements are correctly dropped.
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering::SeqCst};
#[derive(Debug)]

View file

@ -1,4 +1,5 @@
// FIXME: These tests are all excellent candidates for AFL fuzz testing
use core::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
use core::str::FromStr;

View file

@ -27,6 +27,7 @@
//! standard. That is why they accept wildly diverse inputs or may seem to duplicate other tests.
//! Please consider this carefully when adding, removing, or reorganizing these tests. They are
//! here so that it is clear what tests are required by the standard and what can be changed.
use ::core::str::FromStr;
// IEEE 754 for many tests is applied to specific bit patterns.

View file

@ -1,4 +1,5 @@
// edition:2021
use core::{
marker::PhantomPinned,
mem::{drop as stuff, transmute},

View file

@ -1,4 +1,5 @@
//! Unwinding panics for Miri.
use alloc::boxed::Box;
use core::any::Any;

View file

@ -1,6 +1,5 @@
// Code taken from the `packed_simd` crate
// Run this code with `cargo test --example dot_product`
//use std::iter::zip;
//! Code taken from the `packed_simd` crate.
//! Run this code with `cargo test --example dot_product`.
#![feature(array_chunks)]
#![feature(slice_as_chunks)]

View file

@ -1,4 +1,5 @@
//! Assignment operators
use super::*;
use core::ops::{AddAssign, MulAssign}; // commutative binary op-assignment
use core::ops::{BitAndAssign, BitOrAssign, BitXorAssign}; // commutative bit binary op-assignment

View file

@ -2,6 +2,7 @@
//! Ideally, Rust would take care of this itself,
//! and method calls usually handle the LHS implicitly.
//! But this is not the case with arithmetic ops.
use super::*;
macro_rules! deref_lhs {

View file

@ -6,6 +6,7 @@
//! outside this crate.
//!
//! [`collections`]: crate::collections
#[allow(deprecated)]
use super::{BuildHasher, Hasher, SipHasher13};
use crate::cell::Cell;

View file

@ -1,13 +1,14 @@
///! An encapsulation of `BufReader`'s buffer management logic.
///
/// This module factors out the basic functionality of `BufReader` in order to protect two core
/// invariants:
/// * `filled` bytes of `buf` are always initialized
/// * `pos` is always <= `filled`
/// Since this module encapsulates the buffer management logic, we can ensure that the range
/// `pos..filled` is always a valid index into the initialized region of the buffer. This means
/// that user code which wants to do reads from a `BufReader` via `buffer` + `consume` can do so
/// without encountering any runtime bounds checks.
//! An encapsulation of `BufReader`'s buffer management logic.
//!
//! This module factors out the basic functionality of `BufReader` in order to protect two core
//! invariants:
//! * `filled` bytes of `buf` are always initialized
//! * `pos` is always <= `filled`
//! Since this module encapsulates the buffer management logic, we can ensure that the range
//! `pos..filled` is always a valid index into the initialized region of the buffer. This means
//! that user code which wants to do reads from a `BufReader` via `buffer` + `consume` can do so
//! without encountering any runtime bounds checks.
use crate::cmp;
use crate::io::{self, BorrowedBuf, Read};
use crate::mem::MaybeUninit;

View file

@ -1,5 +1,6 @@
/// The underlying OsString/OsStr implementation on Windows is a
/// wrapper around the "WTF-8" encoding; see the `wtf8` module for more.
//! The underlying OsString/OsStr implementation on Windows is a
//! wrapper around the "WTF-8" encoding; see the `wtf8` module for more.
use crate::borrow::Cow;
use crate::collections::TryReserveError;
use crate::fmt;

View file

@ -1,5 +1,6 @@
//! Thread implementation backed by μITRON tasks. Assumes `acre_tsk` and
//! `exd_tsk` are available.
use super::{
abi,
error::{expect_success, expect_success_aborting, ItronError},

View file

@ -1,4 +1,5 @@
//! `solid_fs.h`
use crate::os::raw::{c_char, c_int, c_uchar};
pub use libc::{
ino_t, off_t, stat, time_t, O_APPEND, O_CREAT, O_EXCL, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY,

View file

@ -1,6 +1,7 @@
//! Emulated wait status for non-Unix #[cfg(unix) platforms
//!
//! Separate module to facilitate testing against a real Unix implementation.
use crate::ffi::c_int;
use crate::fmt;
use crate::num::NonZero;

View file

@ -475,6 +475,7 @@ mod cgroups {
//! * cgroup v2 in non-standard mountpoints
//! * paths containing control characters or spaces, since those would be escaped in procfs
//! output and we don't unescape
use crate::borrow::Cow;
use crate::ffi::OsString;
use crate::fs::{try_exists, File};

View file

@ -1,4 +1,5 @@
//! POSIX conditional variable implementation based on user-space wait queues.
use crate::sys::pal::itron::{
abi, error::expect_success_aborting, spin::SpinMutex, task, time::with_tmos_strong,
};

View file

@ -1,5 +1,6 @@
//! Mutex implementation backed by μITRON mutexes. Assumes `acre_mtx` and
//! `TA_INHERIT` are available.
use crate::sys::pal::itron::{
abi,
error::{expect_success, expect_success_aborting, fail, ItronError},

View file

@ -1,4 +1,5 @@
//! A readers-writer lock implementation backed by the SOLID kernel extension.
use crate::sys::pal::{
abi,
itron::{

View file

@ -2,6 +2,7 @@
//! Note that this test changes the current directory so
//! should not be in the same process as other tests.
use std::env;
use std::fs;
use std::path::{Path, PathBuf};

View file

@ -1,4 +1,5 @@
//! Benchmarking module.
use super::{
event::CompletedTest,
options::BenchMode,

View file

@ -1,5 +1,6 @@
//! Helper module which helps to determine amount of threads to be used
//! during tests execution.
use std::{env, num::NonZero, thread};
pub fn get_concurrency() -> usize {

View file

@ -1,4 +1,5 @@
//! Benchmark metrics.
use std::collections::BTreeMap;
#[derive(Clone, PartialEq, Debug, Copy)]

View file

@ -1,4 +1,5 @@
//! Calculates information used for the --show-coverage flag.
use crate::clean;
use crate::core::DocContext;
use crate::html::markdown::{find_testable_code, ErrorCodes};

View file

@ -1,6 +1,7 @@
//! Collects trait impls for each item in the crate. For example, if a crate
//! defines a struct that implements a trait, this pass will note that the
//! struct implements that trait.
use super::Pass;
use crate::clean::*;
use crate::core::DocContext;

View file

@ -1,4 +1,5 @@
//! Validates syntax inside Rust code blocks (\`\`\`rust).
use rustc_data_structures::sync::{Lock, Lrc};
use rustc_errors::{
emitter::Emitter,

View file

@ -1,4 +1,5 @@
//! Detects invalid HTML (like an unclosed `<span>`) in doc comments.
use crate::clean::*;
use crate::core::DocContext;
use crate::html::markdown::main_body_opts;

View file

@ -1,4 +1,5 @@
//! Propagates [`#[doc(cfg(...))]`](https://github.com/rust-lang/rust/issues/43781) to child items.
use std::sync::Arc;
use crate::clean::cfg::Cfg;

View file

@ -1,5 +1,6 @@
//! Strips all private import statements (use, extern crate) from a
//! crate.
use crate::clean;
use crate::core::DocContext;
use crate::fold::DocFolder;

View file

@ -1,5 +1,6 @@
//! Strip all private items from the output. Additionally implies strip_priv_imports.
//! Basically, the goal is to remove items that are not relevant for public documentation.
use crate::clean::{self, ItemIdSet};
use crate::core::DocContext;
use crate::fold::DocFolder;

View file

@ -1,4 +1,5 @@
//! A collection of utility functions for the `strip_*` passes.
use rustc_hir::def_id::DefId;
use rustc_middle::ty::{TyCtxt, Visibility};
use std::mem;

View file

@ -1,6 +1,7 @@
//! Tidy check to ensure below in UI test directories:
//! - the number of entries in each directory must be less than `ENTRY_LIMIT`
//! - there are no stray `.stderr` files
use ignore::Walk;
use std::collections::{BTreeSet, HashMap};
use std::ffi::OsStr;

View file

@ -3,9 +3,9 @@
//@ compile-flags: -Zmir-enable-passes=-NormalizeArrayLen
// Check that we do not insert StorageDead at each target if StorageDead was never seen
// EMIT_MIR issue_76432.test.SimplifyComparisonIntegral.diff
use std::fmt::Debug;
// EMIT_MIR issue_76432.test.SimplifyComparisonIntegral.diff
fn test<T: Copy + Debug + PartialEq>(x: T) {
let v: &[T] = &[x, x, x];
match v {

View file

@ -6,6 +6,7 @@
// See https://github.com/rust-lang/rust/issues/12459
//@ ignore-cross-compile
use run_make_support::{create_symlink, dynamic_lib_name, fs_wrapper, rustc};
fn main() {