diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-07-29 08:13:50 +1000 | 
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-07-29 08:26:52 +1000 | 
| commit | 84ac80f1921afc243d71fd0caaa4f2838c294102 (patch) | |
| tree | 29006db815bf547dfd0129910b23b8c54675bd98 /compiler/rustc_const_eval/src | |
| parent | 118f9350c5b902e462a6dcc4325670f3da701600 (diff) | |
| download | rust-84ac80f1921afc243d71fd0caaa4f2838c294102.tar.gz rust-84ac80f1921afc243d71fd0caaa4f2838c294102.zip | |
Reformat `use` declarations.
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
Diffstat (limited to 'compiler/rustc_const_eval/src')
33 files changed, 130 insertions, 177 deletions
| diff --git a/compiler/rustc_const_eval/src/check_consts/check.rs b/compiler/rustc_const_eval/src/check_consts/check.rs index 8700ec4c210..ffdf790da7a 100644 --- a/compiler/rustc_const_eval/src/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/check_consts/check.rs @@ -1,5 +1,8 @@ //! The `Visitor` responsible for actually checking a `mir::Body` for invalid operations. +use std::mem; +use std::ops::Deref; + use rustc_errors::{Diag, ErrorGuaranteed}; use rustc_hir::def_id::DefId; use rustc_hir::{self as hir, LangItem}; @@ -9,17 +12,13 @@ use rustc_infer::traits::ObligationCause; use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::*; use rustc_middle::span_bug; -use rustc_middle::ty::{self, adjustment::PointerCoercion, Ty, TyCtxt}; -use rustc_middle::ty::{Instance, InstanceKind, TypeVisitableExt}; +use rustc_middle::ty::adjustment::PointerCoercion; +use rustc_middle::ty::{self, Instance, InstanceKind, Ty, TyCtxt, TypeVisitableExt}; use rustc_mir_dataflow::Analysis; use rustc_span::{sym, Span, Symbol, DUMMY_SP}; use rustc_trait_selection::error_reporting::InferCtxtErrorExt; use rustc_trait_selection::traits::{self, ObligationCauseCode, ObligationCtxt}; use rustc_type_ir::visit::{TypeSuperVisitable, TypeVisitor}; - -use std::mem; -use std::ops::Deref; - use tracing::{debug, instrument, trace}; use super::ops::{self, NonConstOp, Status}; diff --git a/compiler/rustc_const_eval/src/check_consts/mod.rs b/compiler/rustc_const_eval/src/check_consts/mod.rs index ac8f0d842ee..15ac4cedcc3 100644 --- a/compiler/rustc_const_eval/src/check_consts/mod.rs +++ b/compiler/rustc_const_eval/src/check_consts/mod.rs @@ -4,14 +4,12 @@ //! has interior mutability or needs to be dropped, as well as the visitor that emits errors when //! it finds operations that are invalid in a certain context. -use rustc_attr as attr; use rustc_errors::DiagCtxtHandle; -use rustc_hir as hir; use rustc_hir::def_id::{DefId, LocalDefId}; -use rustc_middle::bug; -use rustc_middle::mir; use rustc_middle::ty::{self, PolyFnSig, TyCtxt}; +use rustc_middle::{bug, mir}; use rustc_span::Symbol; +use {rustc_attr as attr, rustc_hir as hir}; pub use self::qualifs::Qualif; diff --git a/compiler/rustc_const_eval/src/check_consts/ops.rs b/compiler/rustc_const_eval/src/check_consts/ops.rs index 55432e63ef9..f47a2ec8f75 100644 --- a/compiler/rustc_const_eval/src/check_consts/ops.rs +++ b/compiler/rustc_const_eval/src/check_consts/ops.rs @@ -2,7 +2,8 @@ use hir::def_id::LocalDefId; use hir::{ConstContext, LangItem}; -use rustc_errors::{codes::*, Diag}; +use rustc_errors::codes::*; +use rustc_errors::Diag; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_infer::infer::TyCtxtInferExt; diff --git a/compiler/rustc_const_eval/src/check_consts/post_drop_elaboration.rs b/compiler/rustc_const_eval/src/check_consts/post_drop_elaboration.rs index f5e745454ab..c4f06e5af0b 100644 --- a/compiler/rustc_const_eval/src/check_consts/post_drop_elaboration.rs +++ b/compiler/rustc_const_eval/src/check_consts/post_drop_elaboration.rs @@ -1,7 +1,8 @@ use rustc_middle::mir::visit::Visitor; use rustc_middle::mir::{self, BasicBlock, Location}; use rustc_middle::ty::{Ty, TyCtxt}; -use rustc_span::{symbol::sym, Span}; +use rustc_span::symbol::sym; +use rustc_span::Span; use tracing::trace; use super::check::Qualifs; diff --git a/compiler/rustc_const_eval/src/check_consts/qualifs.rs b/compiler/rustc_const_eval/src/check_consts/qualifs.rs index d5d3f7767b1..c0f2d113c7e 100644 --- a/compiler/rustc_const_eval/src/check_consts/qualifs.rs +++ b/compiler/rustc_const_eval/src/check_consts/qualifs.rs @@ -5,11 +5,10 @@ use rustc_errors::ErrorGuaranteed; use rustc_hir::LangItem; use rustc_infer::infer::TyCtxtInferExt; -use rustc_middle::bug; -use rustc_middle::mir; use rustc_middle::mir::*; use rustc_middle::traits::BuiltinImplSource; use rustc_middle::ty::{self, AdtDef, GenericArgsRef, Ty}; +use rustc_middle::{bug, mir}; use rustc_trait_selection::traits::{ ImplSource, Obligation, ObligationCause, ObligationCtxt, SelectionContext, }; diff --git a/compiler/rustc_const_eval/src/check_consts/resolver.rs b/compiler/rustc_const_eval/src/check_consts/resolver.rs index 011341472b4..ea3a5264357 100644 --- a/compiler/rustc_const_eval/src/check_consts/resolver.rs +++ b/compiler/rustc_const_eval/src/check_consts/resolver.rs @@ -2,17 +2,16 @@ //! //! This contains the dataflow analysis used to track `Qualif`s on complex control-flow graphs. +use std::fmt; +use std::marker::PhantomData; + use rustc_index::bit_set::BitSet; use rustc_middle::mir::visit::Visitor; use rustc_middle::mir::{ self, BasicBlock, CallReturnPlaces, Local, Location, Statement, StatementKind, TerminatorEdges, }; use rustc_mir_dataflow::fmt::DebugWithContext; -use rustc_mir_dataflow::JoinSemiLattice; -use rustc_mir_dataflow::{Analysis, AnalysisDomain}; - -use std::fmt; -use std::marker::PhantomData; +use rustc_mir_dataflow::{Analysis, AnalysisDomain, JoinSemiLattice}; use super::{qualifs, ConstCx, Qualif}; diff --git a/compiler/rustc_const_eval/src/const_eval/dummy_machine.rs b/compiler/rustc_const_eval/src/const_eval/dummy_machine.rs index 9a98677a844..aa7449e8ad2 100644 --- a/compiler/rustc_const_eval/src/const_eval/dummy_machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/dummy_machine.rs @@ -1,14 +1,14 @@ -use crate::interpret::{ - self, throw_machine_stop, HasStaticRootDefId, ImmTy, Immediate, InterpCx, PointerArithmetic, -}; use rustc_middle::mir::interpret::{AllocId, ConstAllocation, InterpResult}; use rustc_middle::mir::*; use rustc_middle::query::TyCtxtAt; -use rustc_middle::ty; use rustc_middle::ty::layout::TyAndLayout; -use rustc_middle::{bug, span_bug}; +use rustc_middle::{bug, span_bug, ty}; use rustc_span::def_id::DefId; +use crate::interpret::{ + self, throw_machine_stop, HasStaticRootDefId, ImmTy, Immediate, InterpCx, PointerArithmetic, +}; + /// Macro for machine-specific `InterpError` without allocation. /// (These will never be shown to the user, but they help diagnose ICEs.) pub macro throw_machine_stop_str($($tt:tt)*) {{ diff --git a/compiler/rustc_const_eval/src/const_eval/error.rs b/compiler/rustc_const_eval/src/const_eval/error.rs index b17dc7f3ddd..00bbd9337f7 100644 --- a/compiler/rustc_const_eval/src/const_eval/error.rs +++ b/compiler/rustc_const_eval/src/const_eval/error.rs @@ -4,14 +4,15 @@ use rustc_errors::{DiagArgName, DiagArgValue, DiagMessage, Diagnostic, IntoDiagA use rustc_middle::mir::interpret::{Provenance, ReportedErrorInfo}; use rustc_middle::mir::AssertKind; use rustc_middle::query::TyCtxtAt; -use rustc_middle::ty::TyCtxt; -use rustc_middle::ty::{layout::LayoutError, ConstInt}; +use rustc_middle::ty::layout::LayoutError; +use rustc_middle::ty::{ConstInt, TyCtxt}; use rustc_span::{Span, Symbol}; use super::CompileTimeMachine; use crate::errors::{self, FrameNote, ReportErrorExt}; -use crate::interpret::{err_inval, err_machine_stop}; -use crate::interpret::{ErrorHandled, Frame, InterpError, InterpErrorInfo, MachineStopType}; +use crate::interpret::{ + err_inval, err_machine_stop, ErrorHandled, Frame, InterpError, InterpErrorInfo, MachineStopType, +}; /// The CTFE machine has some custom error kinds. #[derive(Clone, Debug)] @@ -25,8 +26,9 @@ pub enum ConstEvalErrKind { impl MachineStopType for ConstEvalErrKind { fn diagnostic_message(&self) -> DiagMessage { - use crate::fluent_generated::*; use ConstEvalErrKind::*; + + use crate::fluent_generated::*; match self { ConstAccessesMutGlobal => const_eval_const_accesses_mut_global, ModifiedGlobal => const_eval_modified_global, diff --git a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs index d8efaa66415..ba4b80d1026 100644 --- a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs +++ b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs @@ -1,8 +1,6 @@ use std::sync::atomic::Ordering::Relaxed; use either::{Left, Right}; -use tracing::{debug, instrument, trace}; - use rustc_hir::def::DefKind; use rustc_middle::bug; use rustc_middle::mir::interpret::{AllocId, ErrorHandled, InterpErrorInfo}; @@ -16,17 +14,16 @@ use rustc_session::lint; use rustc_span::def_id::LocalDefId; use rustc_span::{Span, DUMMY_SP}; use rustc_target::abi::{self, Abi}; +use tracing::{debug, instrument, trace}; use super::{CanAccessMutGlobal, CompileTimeInterpCx, CompileTimeMachine}; use crate::const_eval::CheckAlignment; -use crate::errors::ConstEvalError; -use crate::errors::{self, DanglingPtrInFinal}; +use crate::errors::{self, ConstEvalError, DanglingPtrInFinal}; use crate::interpret::{ - create_static_alloc, intern_const_alloc_recursive, CtfeValidationMode, GlobalId, Immediate, - InternKind, InterpCx, InterpError, InterpResult, MPlaceTy, MemoryKind, OpTy, RefTracking, - StackPopCleanup, + create_static_alloc, eval_nullary_intrinsic, intern_const_alloc_recursive, throw_exhaust, + CtfeValidationMode, GlobalId, Immediate, InternKind, InternResult, InterpCx, InterpError, + InterpResult, MPlaceTy, MemoryKind, OpTy, RefTracking, StackPopCleanup, }; -use crate::interpret::{eval_nullary_intrinsic, throw_exhaust, InternResult}; use crate::CTRL_C_RECEIVED; // Returns a pointer to where the result lives diff --git a/compiler/rustc_const_eval/src/const_eval/fn_queries.rs b/compiler/rustc_const_eval/src/const_eval/fn_queries.rs index 7acd08e0cce..ca0993f0580 100644 --- a/compiler/rustc_const_eval/src/const_eval/fn_queries.rs +++ b/compiler/rustc_const_eval/src/const_eval/fn_queries.rs @@ -1,10 +1,9 @@ -use rustc_attr as attr; -use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_middle::query::Providers; use rustc_middle::ty::TyCtxt; use rustc_span::symbol::Symbol; +use {rustc_attr as attr, rustc_hir as hir}; /// Whether the `def_id` is an unstable const fn and what feature gate(s) are necessary to enable /// it. diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index 17e1d8566c2..65cbeab24ec 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -4,18 +4,14 @@ use std::hash::Hash; use std::ops::ControlFlow; use rustc_ast::Mutability; -use rustc_data_structures::fx::FxIndexMap; -use rustc_data_structures::fx::IndexEntry; -use rustc_hir::def_id::DefId; -use rustc_hir::def_id::LocalDefId; -use rustc_hir::LangItem; -use rustc_hir::{self as hir, CRATE_HIR_ID}; -use rustc_middle::bug; -use rustc_middle::mir; +use rustc_data_structures::fx::{FxIndexMap, IndexEntry}; +use rustc_hir::def_id::{DefId, LocalDefId}; +use rustc_hir::{self as hir, LangItem, CRATE_HIR_ID}; use rustc_middle::mir::AssertMessage; use rustc_middle::query::TyCtxtAt; use rustc_middle::ty::layout::{FnAbiOf, TyAndLayout}; use rustc_middle::ty::{self, TyCtxt}; +use rustc_middle::{bug, mir}; use rustc_session::lint::builtin::WRITES_THROUGH_IMMUTABLE_POINTER; use rustc_span::symbol::{sym, Symbol}; use rustc_span::Span; @@ -23,6 +19,7 @@ use rustc_target::abi::{Align, Size}; use rustc_target::spec::abi::Abi as CallAbi; use tracing::debug; +use super::error::*; use crate::errors::{LongRunning, LongRunningWarn}; use crate::fluent_generated as fluent; use crate::interpret::{ @@ -31,8 +28,6 @@ use crate::interpret::{ GlobalAlloc, ImmTy, InterpCx, InterpResult, MPlaceTy, OpTy, Pointer, PointerArithmetic, Scalar, }; -use super::error::*; - /// When hitting this many interpreted terminators we emit a deny by default lint /// that notfies the user that their constant takes a long time to evaluate. If that's /// what they intended, they can just allow the lint. @@ -201,7 +196,8 @@ impl<'tcx> CompileTimeInterpCx<'tcx> { let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span); let caller = self.tcx.sess.source_map().lookup_char_pos(topmost.lo()); - use rustc_session::{config::RemapPathScopeComponents, RemapFileNameExt}; + use rustc_session::config::RemapPathScopeComponents; + use rustc_session::RemapFileNameExt; ( Symbol::intern( &caller diff --git a/compiler/rustc_const_eval/src/const_eval/mod.rs b/compiler/rustc_const_eval/src/const_eval/mod.rs index 3a6dc81eff1..8add23ed22f 100644 --- a/compiler/rustc_const_eval/src/const_eval/mod.rs +++ b/compiler/rustc_const_eval/src/const_eval/mod.rs @@ -1,10 +1,9 @@ // Not in interpret to make sure we do not use private implementation details -use rustc_middle::bug; -use rustc_middle::mir; use rustc_middle::mir::interpret::InterpErrorInfo; use rustc_middle::query::{Key, TyCtxtAt}; use rustc_middle::ty::{self, Ty, TyCtxt}; +use rustc_middle::{bug, mir}; use rustc_target::abi::VariantIdx; use tracing::instrument; diff --git a/compiler/rustc_const_eval/src/const_eval/valtrees.rs b/compiler/rustc_const_eval/src/const_eval/valtrees.rs index 3bc01510730..8227c045948 100644 --- a/compiler/rustc_const_eval/src/const_eval/valtrees.rs +++ b/compiler/rustc_const_eval/src/const_eval/valtrees.rs @@ -1,9 +1,8 @@ use rustc_data_structures::stack::ensure_sufficient_stack; -use rustc_middle::bug; -use rustc_middle::mir; use rustc_middle::mir::interpret::{EvalToValTreeResult, GlobalId}; use rustc_middle::ty::layout::{LayoutCx, LayoutOf, TyAndLayout}; use rustc_middle::ty::{self, ScalarInt, Ty, TyCtxt}; +use rustc_middle::{bug, mir}; use rustc_span::DUMMY_SP; use rustc_target::abi::{Abi, VariantIdx}; use tracing::{debug, instrument, trace}; @@ -13,10 +12,9 @@ use super::machine::CompileTimeInterpCx; use super::{ValTreeCreationError, ValTreeCreationResult, VALTREE_MAX_NODES}; use crate::const_eval::CanAccessMutGlobal; use crate::errors::MaxNumNodesInConstErr; -use crate::interpret::MPlaceTy; use crate::interpret::{ - intern_const_alloc_recursive, ImmTy, Immediate, InternKind, MemPlaceMeta, MemoryKind, PlaceTy, - Projectable, Scalar, + intern_const_alloc_recursive, ImmTy, Immediate, InternKind, MPlaceTy, MemPlaceMeta, MemoryKind, + PlaceTy, Projectable, Scalar, }; #[instrument(skip(ecx), level = "debug")] diff --git a/compiler/rustc_const_eval/src/errors.rs b/compiler/rustc_const_eval/src/errors.rs index 292d6ba9d08..8096ed6d8d0 100644 --- a/compiler/rustc_const_eval/src/errors.rs +++ b/compiler/rustc_const_eval/src/errors.rs @@ -1,8 +1,9 @@ use std::borrow::Cow; use either::Either; +use rustc_errors::codes::*; use rustc_errors::{ - codes::*, Diag, DiagArgValue, DiagCtxtHandle, DiagMessage, Diagnostic, EmissionGuarantee, Level, + Diag, DiagArgValue, DiagCtxtHandle, DiagMessage, Diagnostic, EmissionGuarantee, Level, }; use rustc_hir::ConstContext; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; @@ -468,8 +469,9 @@ fn bad_pointer_message(msg: CheckInAllocMsg, dcx: DiagCtxtHandle<'_>) -> String impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> { fn diagnostic_message(&self) -> DiagMessage { - use crate::fluent_generated::*; use UndefinedBehaviorInfo::*; + + use crate::fluent_generated::*; match self { Ub(msg) => msg.clone().into(), Custom(x) => (x.msg)(), @@ -630,8 +632,9 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> { impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> { fn diagnostic_message(&self) -> DiagMessage { - use crate::fluent_generated::*; use rustc_middle::mir::interpret::ValidationErrorKind::*; + + use crate::fluent_generated::*; match self.kind { PtrToUninhabited { ptr_kind: PointerKind::Box, .. } => { const_eval_validation_box_to_uninhabited @@ -702,9 +705,10 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> { } fn add_args<G: EmissionGuarantee>(self, err: &mut Diag<'_, G>) { - use crate::fluent_generated as fluent; use rustc_middle::mir::interpret::ValidationErrorKind::*; + use crate::fluent_generated as fluent; + if let PointerAsInt { .. } | PartialPointer = self.kind { err.help(fluent::const_eval_ptr_as_bytes_1); err.help(fluent::const_eval_ptr_as_bytes_2); @@ -835,9 +839,9 @@ impl ReportErrorExt for UnsupportedOpInfo { } } fn add_args<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) { - use crate::fluent_generated::*; - use UnsupportedOpInfo::*; + + use crate::fluent_generated::*; if let ReadPointerAsInt(_) | OverwritePartialPointer(_) | ReadPartialPointer(_) = self { diag.help(const_eval_ptr_as_bytes_1); diag.help(const_eval_ptr_as_bytes_2); diff --git a/compiler/rustc_const_eval/src/interpret/cast.rs b/compiler/rustc_const_eval/src/interpret/cast.rs index bd2a5812cfa..b2f07de0ac4 100644 --- a/compiler/rustc_const_eval/src/interpret/cast.rs +++ b/compiler/rustc_const_eval/src/interpret/cast.rs @@ -12,11 +12,10 @@ use rustc_target::abi::Integer; use rustc_type_ir::TyKind::*; use tracing::trace; +use super::util::ensure_monomorphic_enough; use super::{ - err_inval, throw_ub, throw_ub_custom, util::ensure_monomorphic_enough, FnVal, ImmTy, Immediate, - InterpCx, Machine, OpTy, PlaceTy, + err_inval, throw_ub, throw_ub_custom, FnVal, ImmTy, Immediate, InterpCx, Machine, OpTy, PlaceTy, }; - use crate::fluent_generated as fluent; impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { diff --git a/compiler/rustc_const_eval/src/interpret/discriminant.rs b/compiler/rustc_const_eval/src/interpret/discriminant.rs index 181c7115386..0008a15722b 100644 --- a/compiler/rustc_const_eval/src/interpret/discriminant.rs +++ b/compiler/rustc_const_eval/src/interpret/discriminant.rs @@ -1,11 +1,9 @@ //! Functions for reading and writing discriminants of multi-variant layouts (enums and coroutines). -use rustc_middle::mir; -use rustc_middle::span_bug; use rustc_middle::ty::layout::{LayoutOf, PrimitiveExt}; use rustc_middle::ty::{self, CoroutineArgsExt, ScalarInt, Ty}; -use rustc_target::abi::{self, TagEncoding}; -use rustc_target::abi::{VariantIdx, Variants}; +use rustc_middle::{mir, span_bug}; +use rustc_target::abi::{self, TagEncoding, VariantIdx, Variants}; use tracing::{instrument, trace}; use super::{ diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index 9fddeec2973..85f9b2341d9 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -2,16 +2,14 @@ use std::cell::Cell; use std::{fmt, mem}; use either::{Either, Left, Right}; -use rustc_infer::infer::at::ToTrace; -use rustc_infer::traits::ObligationCause; -use rustc_trait_selection::traits::ObligationCtxt; -use tracing::{debug, info, info_span, instrument, trace}; - use rustc_errors::DiagCtxtHandle; -use rustc_hir::{self as hir, def_id::DefId, definitions::DefPathData}; +use rustc_hir::def_id::DefId; +use rustc_hir::definitions::DefPathData; +use rustc_hir::{self as hir}; use rustc_index::IndexVec; +use rustc_infer::infer::at::ToTrace; use rustc_infer::infer::TyCtxtInferExt; -use rustc_middle::mir; +use rustc_infer::traits::ObligationCause; use rustc_middle::mir::interpret::{ CtfeProvenance, ErrorHandled, InvalidMetaKind, ReportedErrorInfo, }; @@ -21,11 +19,14 @@ use rustc_middle::ty::layout::{ TyAndLayout, }; use rustc_middle::ty::{self, GenericArgsRef, ParamEnv, Ty, TyCtxt, TypeFoldable, Variance}; -use rustc_middle::{bug, span_bug}; +use rustc_middle::{bug, mir, span_bug}; use rustc_mir_dataflow::storage::always_storage_live_locals; use rustc_session::Limit; use rustc_span::Span; -use rustc_target::abi::{call::FnAbi, Align, HasDataLayout, Size, TargetDataLayout}; +use rustc_target::abi::call::FnAbi; +use rustc_target::abi::{Align, HasDataLayout, Size, TargetDataLayout}; +use rustc_trait_selection::traits::ObligationCtxt; +use tracing::{debug, info, info_span, instrument, trace}; use super::{ err_inval, throw_inval, throw_ub, throw_ub_custom, throw_unsup, GlobalId, Immediate, @@ -33,9 +34,7 @@ use super::{ OpTy, Operand, Place, PlaceTy, Pointer, PointerArithmetic, Projectable, Provenance, ReturnAction, Scalar, }; -use crate::errors; -use crate::util; -use crate::{fluent_generated as fluent, ReportErrorExt}; +use crate::{errors, fluent_generated as fluent, util, ReportErrorExt}; pub struct InterpCx<'tcx, M: Machine<'tcx>> { /// Stores the `Machine` instance. diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index b227565f8f9..c305a57e85a 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -3,26 +3,21 @@ //! and miri. use rustc_hir::def_id::DefId; -use rustc_middle::ty; -use rustc_middle::ty::layout::{LayoutOf as _, ValidityRequirement}; -use rustc_middle::ty::GenericArgsRef; -use rustc_middle::ty::{Ty, TyCtxt}; -use rustc_middle::{ - bug, - mir::{self, BinOp, ConstValue, NonDivergingIntrinsic}, - ty::layout::TyAndLayout, -}; +use rustc_middle::mir::{self, BinOp, ConstValue, NonDivergingIntrinsic}; +use rustc_middle::ty::layout::{LayoutOf as _, TyAndLayout, ValidityRequirement}; +use rustc_middle::ty::{GenericArgsRef, Ty, TyCtxt}; +use rustc_middle::{bug, ty}; use rustc_span::symbol::{sym, Symbol}; use rustc_target::abi::Size; use tracing::trace; +use super::memory::MemoryKind; +use super::util::ensure_monomorphic_enough; use super::{ - err_inval, err_ub_custom, err_unsup_format, memory::MemoryKind, throw_inval, throw_ub_custom, - throw_ub_format, util::ensure_monomorphic_enough, Allocation, CheckInAllocMsg, ConstAllocation, - GlobalId, ImmTy, InterpCx, InterpResult, MPlaceTy, Machine, OpTy, Pointer, PointerArithmetic, - Provenance, Scalar, + err_inval, err_ub_custom, err_unsup_format, throw_inval, throw_ub_custom, throw_ub_format, + Allocation, CheckInAllocMsg, ConstAllocation, GlobalId, ImmTy, InterpCx, InterpResult, + MPlaceTy, Machine, OpTy, Pointer, PointerArithmetic, Provenance, Scalar, }; - use crate::fluent_generated as fluent; /// Directly returns an `Allocation` containing an absolute path representation of the given type. diff --git a/compiler/rustc_const_eval/src/interpret/machine.rs b/compiler/rustc_const_eval/src/interpret/machine.rs index 7f2e9ce06a5..a82209514ec 100644 --- a/compiler/rustc_const_eval/src/interpret/machine.rs +++ b/compiler/rustc_const_eval/src/interpret/machine.rs @@ -8,10 +8,9 @@ use std::hash::Hash; use rustc_apfloat::{Float, FloatConvert}; use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece}; -use rustc_middle::mir; use rustc_middle::query::TyCtxtAt; -use rustc_middle::ty; use rustc_middle::ty::layout::TyAndLayout; +use rustc_middle::{mir, ty}; use rustc_span::def_id::DefId; use rustc_span::Span; use rustc_target::abi::{Align, Size}; diff --git a/compiler/rustc_const_eval/src/interpret/memory.rs b/compiler/rustc_const_eval/src/interpret/memory.rs index 36fe8dfdd29..092174a3079 100644 --- a/compiler/rustc_const_eval/src/interpret/memory.rs +++ b/compiler/rustc_const_eval/src/interpret/memory.rs @@ -10,8 +10,7 @@ use std::assert_matches::assert_matches; use std::borrow::Cow; use std::cell::Cell; use std::collections::VecDeque; -use std::fmt; -use std::ptr; +use std::{fmt, ptr}; use rustc_ast::Mutability; use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; @@ -20,17 +19,15 @@ use rustc_middle::bug; use rustc_middle::mir::display_allocation; use rustc_middle::ty::{self, Instance, ParamEnv, Ty, TyCtxt}; use rustc_target::abi::{Align, HasDataLayout, Size}; - use tracing::{debug, instrument, trace}; -use crate::fluent_generated as fluent; - use super::{ alloc_range, err_ub, err_ub_custom, throw_ub, throw_ub_custom, throw_unsup, throw_unsup_format, AllocBytes, AllocId, AllocMap, AllocRange, Allocation, CheckAlignMsg, CheckInAllocMsg, CtfeProvenance, GlobalAlloc, InterpCx, InterpResult, Machine, MayLeak, Misalignment, Pointer, PointerArithmetic, Provenance, Scalar, }; +use crate::fluent_generated as fluent; #[derive(Debug, PartialEq, Copy, Clone)] pub enum MemoryKind<T> { diff --git a/compiler/rustc_const_eval/src/interpret/mod.rs b/compiler/rustc_const_eval/src/interpret/mod.rs index f703c6fbe3e..afa2303e387 100644 --- a/compiler/rustc_const_eval/src/interpret/mod.rs +++ b/compiler/rustc_const_eval/src/interpret/mod.rs @@ -18,6 +18,7 @@ mod util; mod validity; mod visitor; +use eval_context::{from_known_layout, mir_assign_valid_types}; #[doc(no_inline)] pub use rustc_middle::mir::interpret::*; // have all the `interpret` symbols in one place: here @@ -26,20 +27,15 @@ pub use self::intern::{ intern_const_alloc_for_constprop, intern_const_alloc_recursive, HasStaticRootDefId, InternKind, InternResult, }; +pub(crate) use self::intrinsics::eval_nullary_intrinsic; pub use self::machine::{compile_time_machine, AllocMap, Machine, MayLeak, ReturnAction}; pub use self::memory::{AllocKind, AllocRef, AllocRefMut, FnVal, Memory, MemoryKind}; +use self::operand::Operand; pub use self::operand::{ImmTy, Immediate, OpTy, Readable}; pub use self::place::{MPlaceTy, MemPlaceMeta, PlaceTy, Writeable}; +use self::place::{MemPlace, Place}; pub use self::projection::{OffsetMode, Projectable}; pub use self::terminator::FnArg; +pub(crate) use self::util::create_static_alloc; pub use self::validity::{CtfeValidationMode, RefTracking}; pub use self::visitor::ValueVisitor; - -use self::{ - operand::Operand, - place::{MemPlace, Place}, -}; - -pub(crate) use self::intrinsics::eval_nullary_intrinsic; -pub(crate) use self::util::create_static_alloc; -use eval_context::{from_known_layout, mir_assign_valid_types}; diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs index 0a7e9853763..d4559e1e8c6 100644 --- a/compiler/rustc_const_eval/src/interpret/operand.rs +++ b/compiler/rustc_const_eval/src/interpret/operand.rs @@ -4,16 +4,14 @@ use std::assert_matches::assert_matches; use either::{Either, Left, Right}; -use tracing::trace; - use rustc_hir::def::Namespace; use rustc_middle::mir::interpret::ScalarSizeMismatch; use rustc_middle::ty::layout::{HasParamEnv, HasTyCtxt, LayoutOf, TyAndLayout}; use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter}; use rustc_middle::ty::{ConstInt, ScalarInt, Ty, TyCtxt}; -use rustc_middle::{bug, span_bug}; -use rustc_middle::{mir, ty}; +use rustc_middle::{bug, mir, span_bug, ty}; use rustc_target::abi::{self, Abi, HasDataLayout, Size}; +use tracing::trace; use super::{ alloc_range, err_ub, from_known_layout, mir_assign_valid_types, throw_ub, CtfeProvenance, @@ -835,8 +833,9 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { // Some nodes are used a lot. Make sure they don't unintentionally get bigger. #[cfg(target_pointer_width = "64")] mod size_asserts { - use super::*; use rustc_data_structures::static_assert_size; + + use super::*; // tidy-alphabetical-start static_assert_size!(Immediate, 48); static_assert_size!(ImmTy<'_>, 64); diff --git a/compiler/rustc_const_eval/src/interpret/operator.rs b/compiler/rustc_const_eval/src/interpret/operator.rs index 2723507397e..684c98f6061 100644 --- a/compiler/rustc_const_eval/src/interpret/operator.rs +++ b/compiler/rustc_const_eval/src/interpret/operator.rs @@ -1,11 +1,9 @@ use either::Either; - use rustc_apfloat::{Float, FloatConvert}; -use rustc_middle::mir; use rustc_middle::mir::interpret::{InterpResult, Scalar}; use rustc_middle::ty::layout::{LayoutOf, TyAndLayout}; use rustc_middle::ty::{self, FloatTy, ScalarInt}; -use rustc_middle::{bug, span_bug}; +use rustc_middle::{bug, mir, span_bug}; use rustc_span::symbol::sym; use tracing::trace; diff --git a/compiler/rustc_const_eval/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs index 33c25b746cc..9f79f4c55be 100644 --- a/compiler/rustc_const_eval/src/interpret/place.rs +++ b/compiler/rustc_const_eval/src/interpret/place.rs @@ -5,14 +5,12 @@ use std::assert_matches::assert_matches; use either::{Either, Left, Right}; -use tracing::{instrument, trace}; - use rustc_ast::Mutability; -use rustc_middle::mir; use rustc_middle::ty::layout::{LayoutOf, TyAndLayout}; use rustc_middle::ty::Ty; -use rustc_middle::{bug, span_bug}; +use rustc_middle::{bug, mir, span_bug}; use rustc_target::abi::{Abi, Align, HasDataLayout, Size}; +use tracing::{instrument, trace}; use super::{ alloc_range, mir_assign_valid_types, throw_ub, AllocRef, AllocRefMut, CheckAlignMsg, @@ -1034,8 +1032,9 @@ where // Some nodes are used a lot. Make sure they don't unintentionally get bigger. #[cfg(target_pointer_width = "64")] mod size_asserts { - use super::*; use rustc_data_structures::static_assert_size; + + use super::*; // tidy-alphabetical-start static_assert_size!(MemPlace, 48); static_assert_size!(MemPlaceMeta, 24); diff --git a/compiler/rustc_const_eval/src/interpret/projection.rs b/compiler/rustc_const_eval/src/interpret/projection.rs index cfa814c810a..dd8dd21e0e8 100644 --- a/compiler/rustc_const_eval/src/interpret/projection.rs +++ b/compiler/rustc_const_eval/src/interpret/projection.rs @@ -10,14 +10,10 @@ use std::marker::PhantomData; use std::ops::Range; -use rustc_middle::mir; -use rustc_middle::ty; use rustc_middle::ty::layout::{LayoutOf, TyAndLayout}; use rustc_middle::ty::Ty; -use rustc_middle::{bug, span_bug}; -use rustc_target::abi::Size; -use rustc_target::abi::{self, VariantIdx}; - +use rustc_middle::{bug, mir, span_bug, ty}; +use rustc_target::abi::{self, Size, VariantIdx}; use tracing::{debug, instrument}; use super::{ diff --git a/compiler/rustc_const_eval/src/interpret/step.rs b/compiler/rustc_const_eval/src/interpret/step.rs index b3124dfdfbc..48433d95c51 100644 --- a/compiler/rustc_const_eval/src/interpret/step.rs +++ b/compiler/rustc_const_eval/src/interpret/step.rs @@ -3,13 +3,11 @@ //! The main entry point is the `step` method. use either::Either; -use tracing::{info, instrument, trace}; - use rustc_index::IndexSlice; -use rustc_middle::mir; use rustc_middle::ty::layout::LayoutOf; -use rustc_middle::{bug, span_bug}; +use rustc_middle::{bug, mir, span_bug}; use rustc_target::abi::{FieldIdx, FIRST_VARIANT}; +use tracing::{info, instrument, trace}; use super::{ ImmTy, Immediate, InterpCx, InterpResult, Machine, MemPlaceMeta, PlaceTy, Projectable, Scalar, diff --git a/compiler/rustc_const_eval/src/interpret/terminator.rs b/compiler/rustc_const_eval/src/interpret/terminator.rs index 56d3dc94104..5de42ab9608 100644 --- a/compiler/rustc_const_eval/src/interpret/terminator.rs +++ b/compiler/rustc_const_eval/src/interpret/terminator.rs @@ -1,33 +1,24 @@ use std::borrow::Cow; use either::Either; -use tracing::trace; - -use rustc_middle::{ - bug, mir, span_bug, - ty::{ - self, - layout::{FnAbiOf, IntegerExt, LayoutOf, TyAndLayout}, - AdtDef, Instance, Ty, - }, -}; -use rustc_span::{source_map::Spanned, sym}; -use rustc_target::abi::{self, FieldIdx}; -use rustc_target::abi::{ - call::{ArgAbi, FnAbi, PassMode}, - Integer, -}; +use rustc_middle::ty::layout::{FnAbiOf, IntegerExt, LayoutOf, TyAndLayout}; +use rustc_middle::ty::{self, AdtDef, Instance, Ty}; +use rustc_middle::{bug, mir, span_bug}; +use rustc_span::source_map::Spanned; +use rustc_span::sym; +use rustc_target::abi::call::{ArgAbi, FnAbi, PassMode}; +use rustc_target::abi::{self, FieldIdx, Integer}; use rustc_target::spec::abi::Abi; +use tracing::trace; use super::{ throw_ub, throw_ub_custom, throw_unsup_format, CtfeProvenance, FnVal, ImmTy, InterpCx, InterpResult, MPlaceTy, Machine, OpTy, PlaceTy, Projectable, Provenance, Scalar, StackPopCleanup, }; -use crate::{ - fluent_generated as fluent, - interpret::{eval_context::StackPopInfo, ReturnAction}, -}; +use crate::fluent_generated as fluent; +use crate::interpret::eval_context::StackPopInfo; +use crate::interpret::ReturnAction; /// An argment passed to a function. #[derive(Clone, Debug)] diff --git a/compiler/rustc_const_eval/src/interpret/util.rs b/compiler/rustc_const_eval/src/interpret/util.rs index bbe5e5fe3ed..6f5bcebbbb6 100644 --- a/compiler/rustc_const_eval/src/interpret/util.rs +++ b/compiler/rustc_const_eval/src/interpret/util.rs @@ -1,4 +1,5 @@ -use crate::const_eval::{CompileTimeInterpCx, CompileTimeMachine, InterpretationResult}; +use std::ops::ControlFlow; + use rustc_hir::def_id::LocalDefId; use rustc_middle::mir; use rustc_middle::mir::interpret::{Allocation, InterpResult, Pointer}; @@ -6,10 +7,10 @@ use rustc_middle::ty::layout::TyAndLayout; use rustc_middle::ty::{ self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, }; -use std::ops::ControlFlow; use tracing::debug; use super::{throw_inval, InterpCx, MPlaceTy, MemPlaceMeta, MemoryKind}; +use crate::const_eval::{CompileTimeInterpCx, CompileTimeMachine, InterpretationResult}; /// Checks whether a type contains generic parameters which must be instantiated. /// diff --git a/compiler/rustc_const_eval/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs index 3dc3e6c8833..3171a888151 100644 --- a/compiler/rustc_const_eval/src/interpret/validity.rs +++ b/compiler/rustc_const_eval/src/interpret/validity.rs @@ -9,17 +9,15 @@ use std::hash::Hash; use std::num::NonZero; use either::{Left, Right}; -use tracing::trace; - use hir::def::DefKind; use rustc_ast::Mutability; use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; use rustc_middle::bug; +use rustc_middle::mir::interpret::ValidationErrorKind::{self, *}; use rustc_middle::mir::interpret::{ ExpectedKind, InterpError, InvalidMetaKind, Misalignment, PointerKind, Provenance, UnsupportedOpInfo, ValidationErrorInfo, - ValidationErrorKind::{self, *}, }; use rustc_middle::ty::layout::{LayoutOf, TyAndLayout}; use rustc_middle::ty::{self, Ty}; @@ -27,11 +25,13 @@ use rustc_span::symbol::{sym, Symbol}; use rustc_target::abi::{ Abi, FieldIdx, Scalar as ScalarAbi, Size, VariantIdx, Variants, WrappingRange, }; +use tracing::trace; +use super::machine::AllocMap; use super::{ - err_ub, format_interp_error, machine::AllocMap, throw_ub, AllocId, AllocKind, CheckInAllocMsg, - GlobalAlloc, ImmTy, Immediate, InterpCx, InterpResult, MPlaceTy, Machine, MemPlaceMeta, OpTy, - Pointer, Projectable, Scalar, ValueVisitor, + err_ub, format_interp_error, throw_ub, AllocId, AllocKind, CheckInAllocMsg, GlobalAlloc, ImmTy, + Immediate, InterpCx, InterpResult, MPlaceTy, Machine, MemPlaceMeta, OpTy, Pointer, Projectable, + Scalar, ValueVisitor, }; // for the validation errors diff --git a/compiler/rustc_const_eval/src/interpret/visitor.rs b/compiler/rustc_const_eval/src/interpret/visitor.rs index 71c057e549b..fd649d608c6 100644 --- a/compiler/rustc_const_eval/src/interpret/visitor.rs +++ b/compiler/rustc_const_eval/src/interpret/visitor.rs @@ -1,15 +1,14 @@ //! Visitor for a run-time value with a given layout: Traverse enums, structs and other compound //! types until we arrive at the leaves, with custom handling for primitive types. +use std::num::NonZero; + use rustc_index::IndexVec; use rustc_middle::mir::interpret::InterpResult; use rustc_middle::ty::{self, Ty}; -use rustc_target::abi::FieldIdx; -use rustc_target::abi::{FieldsShape, VariantIdx, Variants}; +use rustc_target::abi::{FieldIdx, FieldsShape, VariantIdx, Variants}; use tracing::trace; -use std::num::NonZero; - use super::{throw_inval, InterpCx, MPlaceTy, Machine, Projectable}; /// How to traverse a value and what to do when we are at the leaves. diff --git a/compiler/rustc_const_eval/src/lib.rs b/compiler/rustc_const_eval/src/lib.rs index 50a4d0612cc..780404212c3 100644 --- a/compiler/rustc_const_eval/src/lib.rs +++ b/compiler/rustc_const_eval/src/lib.rs @@ -26,8 +26,8 @@ pub mod util; use std::sync::atomic::AtomicBool; pub use errors::ReportErrorExt; - -use rustc_middle::{ty, util::Providers}; +use rustc_middle::ty; +use rustc_middle::util::Providers; rustc_fluent_macro::fluent_messages! { "../messages.ftl" } diff --git a/compiler/rustc_const_eval/src/util/caller_location.rs b/compiler/rustc_const_eval/src/util/caller_location.rs index 3b07bee2d9c..eb185bee5c0 100644 --- a/compiler/rustc_const_eval/src/util/caller_location.rs +++ b/compiler/rustc_const_eval/src/util/caller_location.rs @@ -1,9 +1,8 @@ use rustc_hir::LangItem; -use rustc_middle::bug; -use rustc_middle::mir; use rustc_middle::query::TyCtxtAt; use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::{self, Mutability}; +use rustc_middle::{bug, mir}; use rustc_span::symbol::Symbol; use tracing::trace; diff --git a/compiler/rustc_const_eval/src/util/type_name.rs b/compiler/rustc_const_eval/src/util/type_name.rs index 01e517250f7..3aa3b3b74e0 100644 --- a/compiler/rustc_const_eval/src/util/type_name.rs +++ b/compiler/rustc_const_eval/src/util/type_name.rs @@ -1,13 +1,11 @@ +use std::fmt::Write; + use rustc_data_structures::intern::Interned; use rustc_hir::def_id::CrateNum; use rustc_hir::definitions::DisambiguatedDefPathData; use rustc_middle::bug; -use rustc_middle::ty::{ - self, - print::{PrettyPrinter, Print, PrintError, Printer}, - GenericArg, GenericArgKind, Ty, TyCtxt, -}; -use std::fmt::Write; +use rustc_middle::ty::print::{PrettyPrinter, Print, PrintError, Printer}; +use rustc_middle::ty::{self, GenericArg, GenericArgKind, Ty, TyCtxt}; struct AbsolutePathPrinter<'tcx> { tcx: TyCtxt<'tcx>, | 
