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_borrowck/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_borrowck/src')
45 files changed, 273 insertions, 312 deletions
diff --git a/compiler/rustc_borrowck/src/borrow_set.rs b/compiler/rustc_borrowck/src/borrow_set.rs index 0bae1bd07a2..51b420c441a 100644 --- a/compiler/rustc_borrowck/src/borrow_set.rs +++ b/compiler/rustc_borrowck/src/borrow_set.rs @@ -1,16 +1,17 @@ -use crate::path_utils::allow_two_phase_borrow; -use crate::place_ext::PlaceExt; -use crate::BorrowIndex; +use std::fmt; +use std::ops::Index; + use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_index::bit_set::BitSet; -use rustc_middle::mir::traversal; use rustc_middle::mir::visit::{MutatingUseContext, NonUseContext, PlaceContext, Visitor}; -use rustc_middle::mir::{self, Body, Local, Location}; +use rustc_middle::mir::{self, traversal, Body, Local, Location}; use rustc_middle::span_bug; use rustc_middle::ty::{RegionVid, TyCtxt}; use rustc_mir_dataflow::move_paths::MoveData; -use std::fmt; -use std::ops::Index; + +use crate::path_utils::allow_two_phase_borrow; +use crate::place_ext::PlaceExt; +use crate::BorrowIndex; pub struct BorrowSet<'tcx> { /// The fundamental map relating bitvector indexes to the borrows diff --git a/compiler/rustc_borrowck/src/borrowck_errors.rs b/compiler/rustc_borrowck/src/borrowck_errors.rs index 80deea14685..76e39fe94af 100644 --- a/compiler/rustc_borrowck/src/borrowck_errors.rs +++ b/compiler/rustc_borrowck/src/borrowck_errors.rs @@ -1,8 +1,8 @@ #![allow(rustc::diagnostic_outside_of_impl)] #![allow(rustc::untranslatable_diagnostic)] -use rustc_errors::Applicability; -use rustc_errors::{codes::*, struct_span_code_err, Diag, DiagCtxtHandle}; +use rustc_errors::codes::*; +use rustc_errors::{struct_span_code_err, Applicability, Diag, DiagCtxtHandle}; use rustc_hir as hir; use rustc_middle::span_bug; use rustc_middle::ty::{self, Ty, TyCtxt}; diff --git a/compiler/rustc_borrowck/src/constraints/graph.rs b/compiler/rustc_borrowck/src/constraints/graph.rs index 540b466560c..0ae837898b9 100644 --- a/compiler/rustc_borrowck/src/constraints/graph.rs +++ b/compiler/rustc_borrowck/src/constraints/graph.rs @@ -4,11 +4,8 @@ use rustc_middle::mir::ConstraintCategory; use rustc_middle::ty::{RegionVid, VarianceDiagInfo}; use rustc_span::DUMMY_SP; -use crate::{ - constraints::OutlivesConstraintIndex, - constraints::{OutlivesConstraint, OutlivesConstraintSet}, - type_check::Locations, -}; +use crate::constraints::{OutlivesConstraint, OutlivesConstraintIndex, OutlivesConstraintSet}; +use crate::type_check::Locations; /// The construct graph organizes the constraints by their end-points. /// It can be used to view a `R1: R2` constraint as either an edge `R1 diff --git a/compiler/rustc_borrowck/src/constraints/mod.rs b/compiler/rustc_borrowck/src/constraints/mod.rs index bb2fc3b67e9..7062632de66 100644 --- a/compiler/rustc_borrowck/src/constraints/mod.rs +++ b/compiler/rustc_borrowck/src/constraints/mod.rs @@ -1,12 +1,14 @@ -use crate::region_infer::{ConstraintSccs, RegionDefinition, RegionTracker}; -use crate::type_check::Locations; -use crate::universal_regions::UniversalRegions; +use std::fmt; +use std::ops::Index; + use rustc_index::{IndexSlice, IndexVec}; use rustc_middle::mir::ConstraintCategory; use rustc_middle::ty::{RegionVid, TyCtxt, VarianceDiagInfo}; use rustc_span::Span; -use std::fmt; -use std::ops::Index; + +use crate::region_infer::{ConstraintSccs, RegionDefinition, RegionTracker}; +use crate::type_check::Locations; +use crate::universal_regions::UniversalRegions; pub(crate) mod graph; diff --git a/compiler/rustc_borrowck/src/consumers.rs b/compiler/rustc_borrowck/src/consumers.rs index b9fa46ea883..8f560635cb3 100644 --- a/compiler/rustc_borrowck/src/consumers.rs +++ b/compiler/rustc_borrowck/src/consumers.rs @@ -1,24 +1,22 @@ //! This file provides API for compiler consumers. +use std::rc::Rc; + use rustc_hir::def_id::LocalDefId; use rustc_index::{IndexSlice, IndexVec}; use rustc_middle::mir::{Body, Promoted}; use rustc_middle::ty::TyCtxt; -use std::rc::Rc; +pub use super::constraints::OutlivesConstraint; +pub use super::dataflow::{calculate_borrows_out_of_scope_at_location, BorrowIndex, Borrows}; +pub use super::facts::{AllFacts as PoloniusInput, RustcFacts}; +pub use super::location::{LocationTable, RichLocation}; +pub use super::nll::PoloniusOutput; +pub use super::place_ext::PlaceExt; +pub use super::places_conflict::{places_conflict, PlaceConflictBias}; +pub use super::region_infer::RegionInferenceContext; use crate::borrow_set::BorrowSet; -pub use super::{ - constraints::OutlivesConstraint, - dataflow::{calculate_borrows_out_of_scope_at_location, BorrowIndex, Borrows}, - facts::{AllFacts as PoloniusInput, RustcFacts}, - location::{LocationTable, RichLocation}, - nll::PoloniusOutput, - place_ext::PlaceExt, - places_conflict::{places_conflict, PlaceConflictBias}, - region_infer::RegionInferenceContext, -}; - /// Options determining the output behavior of [`get_body_with_borrowck_facts`]. /// /// If executing under `-Z polonius` the choice here has no effect, and everything as if diff --git a/compiler/rustc_borrowck/src/dataflow.rs b/compiler/rustc_borrowck/src/dataflow.rs index 59b3c6916cb..77794a8525f 100644 --- a/compiler/rustc_borrowck/src/dataflow.rs +++ b/compiler/rustc_borrowck/src/dataflow.rs @@ -1,16 +1,15 @@ +use std::fmt; + use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::graph; use rustc_index::bit_set::BitSet; use rustc_middle::mir::{ self, BasicBlock, Body, CallReturnPlaces, Location, Place, TerminatorEdges, }; -use rustc_middle::ty::RegionVid; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{RegionVid, TyCtxt}; +use rustc_mir_dataflow::fmt::DebugWithContext; use rustc_mir_dataflow::impls::{EverInitializedPlaces, MaybeUninitializedPlaces}; -use rustc_mir_dataflow::ResultsVisitable; -use rustc_mir_dataflow::{fmt::DebugWithContext, GenKill}; -use rustc_mir_dataflow::{Analysis, AnalysisDomain, Results}; -use std::fmt; +use rustc_mir_dataflow::{Analysis, AnalysisDomain, GenKill, Results, ResultsVisitable}; use crate::{places_conflict, BorrowSet, PlaceConflictBias, PlaceExt, RegionInferenceContext}; diff --git a/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs index cbee01f2e2d..52eda721773 100644 --- a/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs @@ -1,17 +1,18 @@ +use std::fmt; +use std::rc::Rc; + use rustc_errors::Diag; use rustc_hir::def_id::LocalDefId; use rustc_infer::infer::canonical::Canonical; -use rustc_infer::infer::region_constraints::Constraint; -use rustc_infer::infer::region_constraints::RegionConstraintData; -use rustc_infer::infer::RegionVariableOrigin; -use rustc_infer::infer::{InferCtxt, RegionResolutionError, SubregionOrigin, TyCtxtInferExt as _}; +use rustc_infer::infer::region_constraints::{Constraint, RegionConstraintData}; +use rustc_infer::infer::{ + InferCtxt, RegionResolutionError, RegionVariableOrigin, SubregionOrigin, TyCtxtInferExt as _, +}; use rustc_infer::traits::ObligationCause; use rustc_middle::ty::error::TypeError; -use rustc_middle::ty::RePlaceholder; -use rustc_middle::ty::Region; -use rustc_middle::ty::RegionVid; -use rustc_middle::ty::UniverseIndex; -use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable}; +use rustc_middle::ty::{ + self, RePlaceholder, Region, RegionVid, Ty, TyCtxt, TypeFoldable, UniverseIndex, +}; use rustc_span::Span; use rustc_trait_selection::error_reporting::infer::nice_region_error::NiceRegionError; use rustc_trait_selection::error_reporting::InferCtxtErrorExt; @@ -19,13 +20,10 @@ use rustc_trait_selection::traits::query::type_op; use rustc_trait_selection::traits::ObligationCtxt; use rustc_traits::{type_op_ascribe_user_type_with_span, type_op_prove_predicate_with_cause}; -use std::fmt; -use std::rc::Rc; - use crate::region_infer::values::RegionElement; -use crate::session_diagnostics::HigherRankedErrorCause; -use crate::session_diagnostics::HigherRankedLifetimeError; -use crate::session_diagnostics::HigherRankedSubtypeError; +use crate::session_diagnostics::{ + HigherRankedErrorCause, HigherRankedLifetimeError, HigherRankedSubtypeError, +}; use crate::MirBorrowckCtxt; #[derive(Clone)] diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 6fe50ad0d96..5c5b1239fea 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -3,25 +3,27 @@ #![allow(rustc::diagnostic_outside_of_impl)] #![allow(rustc::untranslatable_diagnostic)] +use std::iter; +use std::ops::ControlFlow; + use either::Either; use hir::{ClosureKind, Path}; use rustc_data_structures::captures::Captures; use rustc_data_structures::fx::FxIndexSet; -use rustc_errors::{codes::*, struct_span_code_err, Applicability, Diag, MultiSpan}; +use rustc_errors::codes::*; +use rustc_errors::{struct_span_code_err, Applicability, Diag, MultiSpan}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::intravisit::{walk_block, walk_expr, Map, Visitor}; -use rustc_hir::{CoroutineDesugaring, PatField}; -use rustc_hir::{CoroutineKind, CoroutineSource, LangItem}; +use rustc_hir::{CoroutineDesugaring, CoroutineKind, CoroutineSource, LangItem, PatField}; use rustc_middle::bug; use rustc_middle::hir::nested_filter::OnlyBodies; use rustc_middle::mir::tcx::PlaceTy; -use rustc_middle::mir::VarDebugInfoContents; use rustc_middle::mir::{ self, AggregateKind, BindingForm, BorrowKind, CallSource, ClearCrossCrate, ConstraintCategory, FakeBorrowKind, FakeReadCause, LocalDecl, LocalInfo, LocalKind, Location, MutBorrowKind, Operand, Place, PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind, Terminator, - TerminatorKind, VarBindingForm, + TerminatorKind, VarBindingForm, VarDebugInfoContents, }; use rustc_middle::ty::print::PrintTraitRefExt as _; use rustc_middle::ty::{ @@ -30,8 +32,7 @@ use rustc_middle::ty::{ }; use rustc_middle::util::CallKind; use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex}; -use rustc_span::def_id::DefId; -use rustc_span::def_id::LocalDefId; +use rustc_span::def_id::{DefId, LocalDefId}; use rustc_span::hygiene::DesugaringKind; use rustc_span::symbol::{kw, sym, Ident}; use rustc_span::{BytePos, Span, Symbol}; @@ -39,22 +40,14 @@ use rustc_trait_selection::error_reporting::traits::FindExprBySpan; use rustc_trait_selection::error_reporting::InferCtxtErrorExt; use rustc_trait_selection::infer::InferCtxtExt; use rustc_trait_selection::traits::{Obligation, ObligationCause, ObligationCtxt}; -use std::iter; -use std::ops::ControlFlow; -use crate::borrow_set::TwoPhaseActivation; -use crate::borrowck_errors; +use super::explain_borrow::{BorrowExplanation, LaterUseKind}; +use super::{DescribePlaceOpt, RegionName, RegionNameSource, UseSpans}; +use crate::borrow_set::{BorrowData, TwoPhaseActivation}; use crate::diagnostics::conflict_errors::StorageDeadOrDrop::LocalStorageDead; -use crate::diagnostics::{find_all_local_uses, CapturedMessageOpt}; -use crate::{ - borrow_set::BorrowData, diagnostics::Instance, prefixes::IsPrefixOf, - InitializationRequiringAction, MirBorrowckCtxt, WriteKind, -}; - -use super::{ - explain_borrow::{BorrowExplanation, LaterUseKind}, - DescribePlaceOpt, RegionName, RegionNameSource, UseSpans, -}; +use crate::diagnostics::{find_all_local_uses, CapturedMessageOpt, Instance}; +use crate::prefixes::IsPrefixOf; +use crate::{borrowck_errors, InitializationRequiringAction, MirBorrowckCtxt, WriteKind}; #[derive(Debug)] struct MoveSite { diff --git a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs index ffe52f939dd..3590e12274c 100644 --- a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs +++ b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs @@ -19,13 +19,11 @@ use rustc_span::symbol::{kw, Symbol}; use rustc_span::{sym, DesugaringKind, Span}; use rustc_trait_selection::error_reporting::traits::FindExprBySpan; -use crate::region_infer::{BlameConstraint, ExtraConstraintInfo}; -use crate::{ - borrow_set::BorrowData, nll::ConstraintDescription, region_infer::Cause, MirBorrowckCtxt, - WriteKind, -}; - use super::{find_use, RegionName, UseSpans}; +use crate::borrow_set::BorrowData; +use crate::nll::ConstraintDescription; +use crate::region_infer::{BlameConstraint, Cause, ExtraConstraintInfo}; +use crate::{MirBorrowckCtxt, WriteKind}; #[derive(Debug)] pub(crate) enum BorrowExplanation<'tcx> { diff --git a/compiler/rustc_borrowck/src/diagnostics/find_use.rs b/compiler/rustc_borrowck/src/diagnostics/find_use.rs index 94b17e0a2f9..bea8d3bfdfb 100644 --- a/compiler/rustc_borrowck/src/diagnostics/find_use.rs +++ b/compiler/rustc_borrowck/src/diagnostics/find_use.rs @@ -1,15 +1,14 @@ use std::collections::VecDeque; use std::rc::Rc; -use crate::{ - def_use::{self, DefUse}, - region_infer::{Cause, RegionInferenceContext}, -}; use rustc_data_structures::fx::FxIndexSet; use rustc_middle::mir::visit::{MirVisitable, PlaceContext, Visitor}; use rustc_middle::mir::{self, Body, Local, Location}; use rustc_middle::ty::{RegionVid, TyCtxt}; +use crate::def_use::{self, DefUse}; +use crate::region_infer::{Cause, RegionInferenceContext}; + pub(crate) fn find<'tcx>( body: &Body<'tcx>, regioncx: &Rc<RegionInferenceContext<'tcx>>, diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs index d505d9c004e..a2e5c7b8514 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mod.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs @@ -1,14 +1,8 @@ //! Borrow checker diagnostics. -use crate::session_diagnostics::{ - CaptureArgLabel, CaptureReasonLabel, CaptureReasonNote, CaptureReasonSuggest, CaptureVarCause, - CaptureVarKind, CaptureVarPathUseCause, OnClosureNote, -}; -use rustc_errors::MultiSpan; -use rustc_errors::{Applicability, Diag}; +use rustc_errors::{Applicability, Diag, MultiSpan}; use rustc_hir::def::{CtorKind, Namespace}; -use rustc_hir::CoroutineKind; -use rustc_hir::{self as hir, LangItem}; +use rustc_hir::{self as hir, CoroutineKind, LangItem}; use rustc_index::IndexSlice; use rustc_infer::infer::BoundRegionConversionTime; use rustc_infer::traits::SelectionError; @@ -25,7 +19,8 @@ use rustc_middle::util::{call_kind, CallDesugaringKind}; use rustc_mir_dataflow::move_paths::{InitLocation, LookupResult}; use rustc_span::def_id::LocalDefId; use rustc_span::source_map::Spanned; -use rustc_span::{symbol::sym, Span, Symbol, DUMMY_SP}; +use rustc_span::symbol::sym; +use rustc_span::{Span, Symbol, DUMMY_SP}; use rustc_target::abi::{FieldIdx, VariantIdx}; use rustc_trait_selection::error_reporting::InferCtxtErrorExt; use rustc_trait_selection::infer::InferCtxtExt; @@ -33,10 +28,13 @@ use rustc_trait_selection::traits::{ type_known_to_meet_bound_modulo_regions, FulfillmentErrorCode, }; -use crate::fluent_generated as fluent; - use super::borrow_set::BorrowData; use super::MirBorrowckCtxt; +use crate::fluent_generated as fluent; +use crate::session_diagnostics::{ + CaptureArgLabel, CaptureReasonLabel, CaptureReasonNote, CaptureReasonSuggest, CaptureVarCause, + CaptureVarKind, CaptureVarPathUseCause, OnClosureNote, +}; mod find_all_local_uses; mod find_use; @@ -599,8 +597,9 @@ impl UseSpans<'_> { err: &mut Diag<'_>, action: crate::InitializationRequiringAction, ) { - use crate::InitializationRequiringAction::*; use CaptureVarPathUseCause::*; + + use crate::InitializationRequiringAction::*; if let UseSpans::ClosureUse { closure_kind, path_span, .. } = self { match closure_kind { hir::ClosureKind::Coroutine(_) => { diff --git a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs index fcf23aa4785..636ae7b6268 100644 --- a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs @@ -11,8 +11,7 @@ use rustc_mir_dataflow::move_paths::{LookupResult, MovePathIndex}; use rustc_span::{BytePos, ExpnKind, MacroKind, Span}; use rustc_trait_selection::error_reporting::traits::FindExprBySpan; -use crate::diagnostics::CapturedMessageOpt; -use crate::diagnostics::{DescribePlaceOpt, UseSpans}; +use crate::diagnostics::{CapturedMessageOpt, DescribePlaceOpt, UseSpans}; use crate::prefixes::PrefixSet; use crate::MirBorrowckCtxt; diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index a7bf6d636c1..0303b80cace 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -2,17 +2,18 @@ #![allow(rustc::untranslatable_diagnostic)] use core::ops::ControlFlow; + use hir::{ExprKind, Param}; use rustc_errors::{Applicability, Diag}; use rustc_hir::intravisit::Visitor; use rustc_hir::{self as hir, BindingMode, ByRef, Node}; use rustc_middle::bug; -use rustc_middle::mir::{Mutability, Place, PlaceRef, ProjectionElem}; -use rustc_middle::ty::{self, InstanceKind, Ty, TyCtxt, Upcast}; -use rustc_middle::{ - hir::place::PlaceBase, - mir::{self, BindingForm, Local, LocalDecl, LocalInfo, LocalKind, Location}, +use rustc_middle::hir::place::PlaceBase; +use rustc_middle::mir::{ + self, BindingForm, Local, LocalDecl, LocalInfo, LocalKind, Location, Mutability, Place, + PlaceRef, ProjectionElem, }; +use rustc_middle::ty::{self, InstanceKind, Ty, TyCtxt, Upcast}; use rustc_span::symbol::{kw, Symbol}; use rustc_span::{sym, BytePos, DesugaringKind, Span}; use rustc_target::abi::FieldIdx; @@ -847,10 +848,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { // Attempt to search similar mutable associated items for suggestion. // In the future, attempt in all path but initially for RHS of for_loop fn suggest_similar_mut_method_for_for_loop(&self, err: &mut Diag<'_>, span: Span) { - use hir::{ - BorrowKind, Expr, - ExprKind::{AddrOf, Block, Call, MethodCall}, - }; + use hir::ExprKind::{AddrOf, Block, Call, MethodCall}; + use hir::{BorrowKind, Expr}; let hir_map = self.infcx.tcx.hir(); struct Finder { diff --git a/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs b/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs index 082111a642c..9356c24d018 100644 --- a/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs +++ b/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs @@ -4,15 +4,15 @@ #![allow(rustc::diagnostic_outside_of_impl)] #![allow(rustc::untranslatable_diagnostic)] +use std::collections::BTreeMap; + use rustc_data_structures::fx::FxIndexSet; use rustc_errors::Diag; use rustc_middle::ty::RegionVid; use smallvec::SmallVec; -use std::collections::BTreeMap; - -use crate::MirBorrowckCtxt; use super::{ErrorConstraintInfo, RegionName, RegionNameSource}; +use crate::MirBorrowckCtxt; /// The different things we could suggest. enum SuggestedConstraint { diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index 6b7bd7dc0d8..82df9760d8e 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -14,10 +14,7 @@ use rustc_infer::infer::{NllRegionVariableOrigin, RelateParamBound}; use rustc_middle::bug; use rustc_middle::hir::place::PlaceBase; use rustc_middle::mir::{ConstraintCategory, ReturnConstraint}; -use rustc_middle::ty::GenericArgs; -use rustc_middle::ty::TypeVisitor; -use rustc_middle::ty::{self, RegionVid, Ty}; -use rustc_middle::ty::{Region, TyCtxt}; +use rustc_middle::ty::{self, GenericArgs, Region, RegionVid, Ty, TyCtxt, TypeVisitor}; use rustc_span::symbol::{kw, Ident}; use rustc_span::Span; use rustc_trait_selection::error_reporting::infer::nice_region_error::{ @@ -29,20 +26,16 @@ use rustc_trait_selection::error_reporting::InferCtxtErrorExt; use rustc_trait_selection::infer::InferCtxtExt; use rustc_trait_selection::traits::{Obligation, ObligationCtxt}; -use crate::borrowck_errors; +use super::{OutlivesSuggestionBuilder, RegionName, RegionNameSource}; +use crate::nll::ConstraintDescription; +use crate::region_infer::values::RegionElement; +use crate::region_infer::{BlameConstraint, ExtraConstraintInfo, TypeTest}; use crate::session_diagnostics::{ FnMutError, FnMutReturnTypeErr, GenericDoesNotLiveLongEnough, LifetimeOutliveErr, LifetimeReturnCategoryErr, RequireStaticErr, VarHereDenote, }; - -use super::{OutlivesSuggestionBuilder, RegionName, RegionNameSource}; -use crate::region_infer::{BlameConstraint, ExtraConstraintInfo}; -use crate::{ - nll::ConstraintDescription, - region_infer::{values::RegionElement, TypeTest}, - universal_regions::DefiningTy, - MirBorrowckCtxt, -}; +use crate::universal_regions::DefiningTy; +use crate::{borrowck_errors, MirBorrowckCtxt}; impl<'tcx> ConstraintDescription for ConstraintCategory<'tcx> { fn description(&self) -> &'static str { diff --git a/compiler/rustc_borrowck/src/diagnostics/region_name.rs b/compiler/rustc_borrowck/src/diagnostics/region_name.rs index 6443c5e92e8..12aedf6fe08 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_name.rs @@ -9,14 +9,14 @@ use rustc_errors::Diag; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_middle::ty::print::RegionHighlightMode; -use rustc_middle::ty::{self, RegionVid, Ty}; -use rustc_middle::ty::{GenericArgKind, GenericArgsRef}; +use rustc_middle::ty::{self, GenericArgKind, GenericArgsRef, RegionVid, Ty}; use rustc_middle::{bug, span_bug}; use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::{Span, DUMMY_SP}; use rustc_trait_selection::error_reporting::InferCtxtErrorExt; -use crate::{universal_regions::DefiningTy, MirBorrowckCtxt}; +use crate::universal_regions::DefiningTy; +use crate::MirBorrowckCtxt; /// A name for a particular region used in emitting diagnostics. This name could be a generated /// name like `'1`, a name used by the user like `'a`, or a name like `'static`. diff --git a/compiler/rustc_borrowck/src/diagnostics/var_name.rs b/compiler/rustc_borrowck/src/diagnostics/var_name.rs index 0479cd8af35..3e9f975b66b 100644 --- a/compiler/rustc_borrowck/src/diagnostics/var_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/var_name.rs @@ -1,10 +1,11 @@ -use crate::region_infer::RegionInferenceContext; use rustc_index::IndexSlice; use rustc_middle::mir::{Body, Local}; use rustc_middle::ty::{self, RegionVid, TyCtxt}; use rustc_span::symbol::Symbol; use rustc_span::Span; +use crate::region_infer::RegionInferenceContext; + impl<'tcx> RegionInferenceContext<'tcx> { pub(crate) fn get_var_name_and_span_for_region( &self, diff --git a/compiler/rustc_borrowck/src/facts.rs b/compiler/rustc_borrowck/src/facts.rs index af96f115385..94b50448576 100644 --- a/compiler/rustc_borrowck/src/facts.rs +++ b/compiler/rustc_borrowck/src/facts.rs @@ -1,17 +1,18 @@ -use crate::location::{LocationIndex, LocationTable}; -use crate::BorrowIndex; -use polonius_engine::AllFacts as PoloniusFacts; -use polonius_engine::Atom; -use rustc_macros::extension; -use rustc_middle::mir::Local; -use rustc_middle::ty::{RegionVid, TyCtxt}; -use rustc_mir_dataflow::move_paths::MovePathIndex; use std::error::Error; use std::fmt::Debug; use std::fs::{self, File}; use std::io::{BufWriter, Write}; use std::path::Path; +use polonius_engine::{AllFacts as PoloniusFacts, Atom}; +use rustc_macros::extension; +use rustc_middle::mir::Local; +use rustc_middle::ty::{RegionVid, TyCtxt}; +use rustc_mir_dataflow::move_paths::MovePathIndex; + +use crate::location::{LocationIndex, LocationTable}; +use crate::BorrowIndex; + #[derive(Copy, Clone, Debug)] pub struct RustcFacts; diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index 9ad941dabbe..74d9f9d8f81 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -17,6 +17,13 @@ #[macro_use] extern crate tracing; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::marker::PhantomData; +use std::ops::Deref; +use std::rc::Rc; + +use consumers::{BodyWithBorrowckFacts, ConsumerOptions}; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_data_structures::graph::dominators::Dominators; use rustc_errors::Diag; @@ -24,40 +31,31 @@ use rustc_hir as hir; use rustc_hir::def_id::LocalDefId; use rustc_index::bit_set::{BitSet, ChunkedBitSet}; use rustc_index::{IndexSlice, IndexVec}; -use rustc_infer::infer::TyCtxtInferExt; -use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin}; +use rustc_infer::infer::{ + InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin, TyCtxtInferExt, +}; use rustc_middle::mir::tcx::PlaceTy; use rustc_middle::mir::*; use rustc_middle::query::Providers; use rustc_middle::ty::{self, ParamEnv, RegionVid, TyCtxt}; use rustc_middle::{bug, span_bug}; +use rustc_mir_dataflow::impls::{ + EverInitializedPlaces, MaybeInitializedPlaces, MaybeUninitializedPlaces, +}; +use rustc_mir_dataflow::move_paths::{ + InitIndex, InitLocation, LookupResult, MoveData, MoveOutIndex, MovePathIndex, +}; +use rustc_mir_dataflow::{Analysis, MoveDataParamEnv}; use rustc_session::lint::builtin::UNUSED_MUT; use rustc_span::{Span, Symbol}; use rustc_target::abi::FieldIdx; - use smallvec::SmallVec; -use std::cell::RefCell; -use std::collections::BTreeMap; -use std::marker::PhantomData; -use std::ops::Deref; -use std::rc::Rc; - -use rustc_mir_dataflow::impls::{ - EverInitializedPlaces, MaybeInitializedPlaces, MaybeUninitializedPlaces, -}; -use rustc_mir_dataflow::move_paths::{InitIndex, MoveOutIndex, MovePathIndex}; -use rustc_mir_dataflow::move_paths::{InitLocation, LookupResult, MoveData}; -use rustc_mir_dataflow::Analysis; -use rustc_mir_dataflow::MoveDataParamEnv; - -use crate::session_diagnostics::VarNeedNotMut; use self::diagnostics::{AccessKind, IllegalMoveOriginKind, MoveError, RegionName}; use self::location::LocationTable; -use self::prefixes::PrefixSet; -use consumers::{BodyWithBorrowckFacts, ConsumerOptions}; - use self::path_utils::*; +use self::prefixes::PrefixSet; +use crate::session_diagnostics::VarNeedNotMut; pub mod borrow_set; mod borrowck_errors; diff --git a/compiler/rustc_borrowck/src/member_constraints.rs b/compiler/rustc_borrowck/src/member_constraints.rs index 5129b32d492..499c32396d0 100644 --- a/compiler/rustc_borrowck/src/member_constraints.rs +++ b/compiler/rustc_borrowck/src/member_constraints.rs @@ -1,11 +1,12 @@ +use std::hash::Hash; +use std::ops::Index; + use rustc_data_structures::captures::Captures; use rustc_data_structures::fx::FxIndexMap; use rustc_index::{IndexSlice, IndexVec}; use rustc_middle::infer::MemberConstraint; use rustc_middle::ty::{self, Ty}; use rustc_span::Span; -use std::hash::Hash; -use std::ops::Index; /// Compactly stores a set of `R0 member of [R1...Rn]` constraints, /// indexed by the region `R0`. diff --git a/compiler/rustc_borrowck/src/nll.rs b/compiler/rustc_borrowck/src/nll.rs index 2ffa9ba5b4d..af37c028879 100644 --- a/compiler/rustc_borrowck/src/nll.rs +++ b/compiler/rustc_borrowck/src/nll.rs @@ -1,11 +1,18 @@ //! The entry point of the NLL borrow checker. +use std::path::PathBuf; +use std::rc::Rc; +use std::str::FromStr; +use std::{env, io}; + use polonius_engine::{Algorithm, Output}; use rustc_data_structures::fx::FxIndexMap; use rustc_hir::def_id::LocalDefId; use rustc_index::IndexSlice; -use rustc_middle::mir::{create_dump_file, dump_enabled, dump_mir, PassWhere}; -use rustc_middle::mir::{Body, ClosureOutlivesSubject, ClosureRegionRequirements, Promoted}; +use rustc_middle::mir::{ + create_dump_file, dump_enabled, dump_mir, Body, ClosureOutlivesSubject, + ClosureRegionRequirements, PassWhere, Promoted, +}; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::{self, OpaqueHiddenType, TyCtxt}; use rustc_mir_dataflow::impls::MaybeInitializedPlaces; @@ -13,25 +20,16 @@ use rustc_mir_dataflow::move_paths::MoveData; use rustc_mir_dataflow::points::DenseLocationMap; use rustc_mir_dataflow::ResultsCursor; use rustc_span::symbol::sym; -use std::env; -use std::io; -use std::path::PathBuf; -use std::rc::Rc; -use std::str::FromStr; -use crate::{ - borrow_set::BorrowSet, - consumers::ConsumerOptions, - diagnostics::RegionErrors, - facts::{AllFacts, AllFactsExt, RustcFacts}, - location::LocationTable, - polonius, - region_infer::RegionInferenceContext, - renumber, - type_check::{self, MirTypeckRegionConstraints, MirTypeckResults}, - universal_regions::UniversalRegions, - BorrowckInferCtxt, -}; +use crate::borrow_set::BorrowSet; +use crate::consumers::ConsumerOptions; +use crate::diagnostics::RegionErrors; +use crate::facts::{AllFacts, AllFactsExt, RustcFacts}; +use crate::location::LocationTable; +use crate::region_infer::RegionInferenceContext; +use crate::type_check::{self, MirTypeckRegionConstraints, MirTypeckResults}; +use crate::universal_regions::UniversalRegions; +use crate::{polonius, renumber, BorrowckInferCtxt}; pub type PoloniusOutput = Output<RustcFacts>; diff --git a/compiler/rustc_borrowck/src/path_utils.rs b/compiler/rustc_borrowck/src/path_utils.rs index 88b20bba9fb..4afb41be18f 100644 --- a/compiler/rustc_borrowck/src/path_utils.rs +++ b/compiler/rustc_borrowck/src/path_utils.rs @@ -1,13 +1,11 @@ -use crate::borrow_set::{BorrowData, BorrowSet, TwoPhaseActivation}; -use crate::places_conflict; -use crate::AccessDepth; -use crate::BorrowIndex; use rustc_data_structures::graph::dominators::Dominators; -use rustc_middle::mir::BorrowKind; -use rustc_middle::mir::{BasicBlock, Body, Location, Place, PlaceRef, ProjectionElem}; +use rustc_middle::mir::{BasicBlock, Body, BorrowKind, Location, Place, PlaceRef, ProjectionElem}; use rustc_middle::ty::TyCtxt; use rustc_target::abi::FieldIdx; +use crate::borrow_set::{BorrowData, BorrowSet, TwoPhaseActivation}; +use crate::{places_conflict, AccessDepth, BorrowIndex}; + /// Returns `true` if the borrow represented by `kind` is /// allowed to be split into separate Reservation and /// Activation phases. diff --git a/compiler/rustc_borrowck/src/place_ext.rs b/compiler/rustc_borrowck/src/place_ext.rs index 0f806df9da1..ce63d51682e 100644 --- a/compiler/rustc_borrowck/src/place_ext.rs +++ b/compiler/rustc_borrowck/src/place_ext.rs @@ -1,10 +1,10 @@ -use crate::borrow_set::LocalsStateAtExit; use rustc_hir as hir; use rustc_macros::extension; -use rustc_middle::mir::ProjectionElem; -use rustc_middle::mir::{Body, Mutability, Place}; +use rustc_middle::mir::{Body, Mutability, Place, ProjectionElem}; use rustc_middle::ty::{self, TyCtxt}; +use crate::borrow_set::LocalsStateAtExit; + #[extension(pub trait PlaceExt<'tcx>)] impl<'tcx> Place<'tcx> { /// Returns `true` if we can safely ignore borrows of this place. diff --git a/compiler/rustc_borrowck/src/places_conflict.rs b/compiler/rustc_borrowck/src/places_conflict.rs index ad3c3e6d079..42d0c2038f8 100644 --- a/compiler/rustc_borrowck/src/places_conflict.rs +++ b/compiler/rustc_borrowck/src/places_conflict.rs @@ -50,17 +50,17 @@ //! and either equal or disjoint. //! - If we did run out of access, the borrow can access a part of it. -use crate::ArtificialField; -use crate::Overlap; -use crate::{AccessDepth, Deep, Shallow}; +use std::cmp::max; +use std::iter; + use rustc_hir as hir; use rustc_middle::bug; use rustc_middle::mir::{ Body, BorrowKind, FakeBorrowKind, MutBorrowKind, Place, PlaceElem, PlaceRef, ProjectionElem, }; use rustc_middle::ty::{self, TyCtxt}; -use std::cmp::max; -use std::iter; + +use crate::{AccessDepth, ArtificialField, Deep, Overlap, Shallow}; /// When checking if a place conflicts with another place, this enum is used to influence decisions /// where a place might be equal or disjoint with another place, such as if `a[i] == a[j]`. diff --git a/compiler/rustc_borrowck/src/polonius/loan_invalidations.rs b/compiler/rustc_borrowck/src/polonius/loan_invalidations.rs index 30dfc4c21b0..f090da031a0 100644 --- a/compiler/rustc_borrowck/src/polonius/loan_invalidations.rs +++ b/compiler/rustc_borrowck/src/polonius/loan_invalidations.rs @@ -2,17 +2,19 @@ use rustc_data_structures::graph::dominators::Dominators; use rustc_middle::bug; use rustc_middle::mir::visit::Visitor; use rustc_middle::mir::{ - self, BasicBlock, Body, FakeBorrowKind, Location, NonDivergingIntrinsic, Place, Rvalue, + self, BasicBlock, Body, BorrowKind, FakeBorrowKind, InlineAsmOperand, Location, Mutability, + NonDivergingIntrinsic, Operand, Place, Rvalue, Statement, StatementKind, Terminator, + TerminatorKind, }; -use rustc_middle::mir::{BorrowKind, Mutability, Operand}; -use rustc_middle::mir::{InlineAsmOperand, Terminator, TerminatorKind}; -use rustc_middle::mir::{Statement, StatementKind}; use rustc_middle::ty::TyCtxt; +use crate::borrow_set::BorrowSet; +use crate::facts::AllFacts; +use crate::location::LocationTable; +use crate::path_utils::*; use crate::{ - borrow_set::BorrowSet, facts::AllFacts, location::LocationTable, path_utils::*, AccessDepth, - Activation, ArtificialField, BorrowIndex, Deep, LocalMutationIsAllowed, Read, ReadKind, - ReadOrWrite, Reservation, Shallow, Write, WriteKind, + AccessDepth, Activation, ArtificialField, BorrowIndex, Deep, LocalMutationIsAllowed, Read, + ReadKind, ReadOrWrite, Reservation, Shallow, Write, WriteKind, }; /// Emit `loan_invalidated_at` facts. diff --git a/compiler/rustc_borrowck/src/polonius/loan_kills.rs b/compiler/rustc_borrowck/src/polonius/loan_kills.rs index 53adad5561e..d85c2175bed 100644 --- a/compiler/rustc_borrowck/src/polonius/loan_kills.rs +++ b/compiler/rustc_borrowck/src/polonius/loan_kills.rs @@ -5,7 +5,10 @@ use rustc_middle::mir::{ }; use rustc_middle::ty::TyCtxt; -use crate::{borrow_set::BorrowSet, facts::AllFacts, location::LocationTable, places_conflict}; +use crate::borrow_set::BorrowSet; +use crate::facts::AllFacts; +use crate::location::LocationTable; +use crate::places_conflict; /// Emit `loan_killed_at` and `cfg_edge` facts at the same time. pub(super) fn emit_loan_kills<'tcx>( diff --git a/compiler/rustc_borrowck/src/prefixes.rs b/compiler/rustc_borrowck/src/prefixes.rs index 5d3ac1c409a..d3bfd1c418f 100644 --- a/compiler/rustc_borrowck/src/prefixes.rs +++ b/compiler/rustc_borrowck/src/prefixes.rs @@ -4,10 +4,10 @@ //! is borrowed. But: writing `a` is legal if `*a` is borrowed, //! whether or not `a` is a shared or mutable reference. [...] " -use super::MirBorrowckCtxt; - use rustc_middle::mir::{PlaceRef, ProjectionElem}; +use super::MirBorrowckCtxt; + pub trait IsPrefixOf<'tcx> { fn is_prefix_of(&self, other: PlaceRef<'tcx>) -> bool; } diff --git a/compiler/rustc_borrowck/src/region_infer/dump_mir.rs b/compiler/rustc_borrowck/src/region_infer/dump_mir.rs index 53541b33c41..6b8dd1a49e7 100644 --- a/compiler/rustc_borrowck/src/region_infer/dump_mir.rs +++ b/compiler/rustc_borrowck/src/region_infer/dump_mir.rs @@ -3,11 +3,13 @@ //! state of region inference. This code handles emitting the region //! context internal state. -use super::{OutlivesConstraint, RegionInferenceContext}; -use crate::type_check::Locations; +use std::io::{self, Write}; + use rustc_infer::infer::NllRegionVariableOrigin; use rustc_middle::ty::TyCtxt; -use std::io::{self, Write}; + +use super::{OutlivesConstraint, RegionInferenceContext}; +use crate::type_check::Locations; // Room for "'_#NNNNr" before things get misaligned. // Easy enough to fix if this ever doesn't seem like diff --git a/compiler/rustc_borrowck/src/region_infer/graphviz.rs b/compiler/rustc_borrowck/src/region_infer/graphviz.rs index f145d30fe38..743864dd535 100644 --- a/compiler/rustc_borrowck/src/region_infer/graphviz.rs +++ b/compiler/rustc_borrowck/src/region_infer/graphviz.rs @@ -5,11 +5,12 @@ use std::borrow::Cow; use std::io::{self, Write}; -use super::*; use itertools::Itertools; use rustc_graphviz as dot; use rustc_middle::ty::UniverseIndex; +use super::*; + fn render_outlives_constraint(constraint: &OutlivesConstraint<'_>) -> String { match constraint.locations { Locations::All(_) => "All(...)".to_string(), diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs index 44a84fb9d7f..c8dc012de4a 100644 --- a/compiler/rustc_borrowck/src/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -17,27 +17,25 @@ use rustc_middle::mir::{ ClosureRegionRequirements, ConstraintCategory, Local, Location, ReturnConstraint, TerminatorKind, }; -use rustc_middle::traits::ObligationCause; -use rustc_middle::traits::ObligationCauseCode; +use rustc_middle::traits::{ObligationCause, ObligationCauseCode}; use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt, TypeFoldable, UniverseIndex}; use rustc_mir_dataflow::points::DenseLocationMap; use rustc_span::Span; use crate::constraints::graph::{self, NormalConstraintGraph, RegionGraph}; +use crate::constraints::{ConstraintSccIndex, OutlivesConstraint, OutlivesConstraintSet}; use crate::dataflow::BorrowIndex; -use crate::{ - constraints::{ConstraintSccIndex, OutlivesConstraint, OutlivesConstraintSet}, - diagnostics::{RegionErrorKind, RegionErrors, UniverseInfo}, - member_constraints::{MemberConstraintSet, NllMemberConstraintIndex}, - nll::PoloniusOutput, - region_infer::reverse_sccs::ReverseSccGraph, - region_infer::values::{ - LivenessValues, PlaceholderIndices, RegionElement, RegionValues, ToElementIndex, - }, - type_check::{free_region_relations::UniversalRegionRelations, Locations}, - universal_regions::UniversalRegions, - BorrowckInferCtxt, +use crate::diagnostics::{RegionErrorKind, RegionErrors, UniverseInfo}; +use crate::member_constraints::{MemberConstraintSet, NllMemberConstraintIndex}; +use crate::nll::PoloniusOutput; +use crate::region_infer::reverse_sccs::ReverseSccGraph; +use crate::region_infer::values::{ + LivenessValues, PlaceholderIndices, RegionElement, RegionValues, ToElementIndex, }; +use crate::type_check::free_region_relations::UniversalRegionRelations; +use crate::type_check::Locations; +use crate::universal_regions::UniversalRegions; +use crate::BorrowckInferCtxt; mod dump_mir; mod graphviz; diff --git a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs index cf28ba224d6..8c9de5210cd 100644 --- a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs +++ b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs @@ -3,22 +3,20 @@ use rustc_errors::ErrorGuaranteed; use rustc_hir::def::DefKind; use rustc_hir::def_id::LocalDefId; use rustc_hir::OpaqueTyOrigin; -use rustc_infer::infer::TyCtxtInferExt as _; -use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin}; +use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin, TyCtxtInferExt as _}; use rustc_infer::traits::{Obligation, ObligationCause}; use rustc_macros::extension; use rustc_middle::ty::visit::TypeVisitableExt; -use rustc_middle::ty::{self, OpaqueHiddenType, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable}; -use rustc_middle::ty::{GenericArgKind, GenericArgs}; +use rustc_middle::ty::{ + self, GenericArgKind, GenericArgs, OpaqueHiddenType, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable, +}; use rustc_span::Span; use rustc_trait_selection::error_reporting::InferCtxtErrorExt; use rustc_trait_selection::traits::ObligationCtxt; -use crate::session_diagnostics::LifetimeMismatchOpaqueParam; -use crate::session_diagnostics::NonGenericOpaqueTypeParam; -use crate::universal_regions::RegionClassification; - use super::RegionInferenceContext; +use crate::session_diagnostics::{LifetimeMismatchOpaqueParam, NonGenericOpaqueTypeParam}; +use crate::universal_regions::RegionClassification; impl<'tcx> RegionInferenceContext<'tcx> { /// Resolve any opaque types that were encountered while borrow checking diff --git a/compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs b/compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs index 97ddc45ee47..3cc5fa4404e 100644 --- a/compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs +++ b/compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs @@ -1,10 +1,12 @@ -use crate::constraints::ConstraintSccIndex; -use crate::RegionInferenceContext; +use std::ops::Range; + use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_data_structures::graph; use rustc_data_structures::graph::vec_graph::VecGraph; use rustc_middle::ty::RegionVid; -use std::ops::Range; + +use crate::constraints::ConstraintSccIndex; +use crate::RegionInferenceContext; pub(crate) struct ReverseSccGraph { graph: VecGraph<ConstraintSccIndex>, diff --git a/compiler/rustc_borrowck/src/region_infer/values.rs b/compiler/rustc_borrowck/src/region_infer/values.rs index b1caaa63881..1e91130bdc5 100644 --- a/compiler/rustc_borrowck/src/region_infer/values.rs +++ b/compiler/rustc_borrowck/src/region_infer/values.rs @@ -1,14 +1,13 @@ -use rustc_data_structures::fx::FxHashSet; -use rustc_data_structures::fx::FxIndexSet; +use std::fmt::Debug; +use std::rc::Rc; + +use rustc_data_structures::fx::{FxHashSet, FxIndexSet}; use rustc_index::bit_set::SparseBitMatrix; -use rustc_index::interval::IntervalSet; -use rustc_index::interval::SparseIntervalMatrix; +use rustc_index::interval::{IntervalSet, SparseIntervalMatrix}; use rustc_index::Idx; use rustc_middle::mir::{BasicBlock, Location}; use rustc_middle::ty::{self, RegionVid}; use rustc_mir_dataflow::points::{DenseLocationMap, PointIndex}; -use std::fmt::Debug; -use std::rc::Rc; use crate::BorrowIndex; diff --git a/compiler/rustc_borrowck/src/renumber.rs b/compiler/rustc_borrowck/src/renumber.rs index 2858a407e09..2a3b51532e5 100644 --- a/compiler/rustc_borrowck/src/renumber.rs +++ b/compiler/rustc_borrowck/src/renumber.rs @@ -1,12 +1,12 @@ -use crate::BorrowckInferCtxt; use rustc_index::IndexSlice; use rustc_infer::infer::NllRegionVariableOrigin; use rustc_middle::mir::visit::{MutVisitor, TyContext}; use rustc_middle::mir::{Body, ConstOperand, Location, Promoted}; -use rustc_middle::ty::GenericArgsRef; -use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable}; +use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, TypeFoldable}; use rustc_span::Symbol; +use crate::BorrowckInferCtxt; + /// Replaces all free regions appearing in the MIR with fresh /// inference variables, returning the number of variables created. #[instrument(skip(infcx, body, promoted), level = "debug")] diff --git a/compiler/rustc_borrowck/src/session_diagnostics.rs b/compiler/rustc_borrowck/src/session_diagnostics.rs index 40c2ef1c91e..4a50b0f0704 100644 --- a/compiler/rustc_borrowck/src/session_diagnostics.rs +++ b/compiler/rustc_borrowck/src/session_diagnostics.rs @@ -1,4 +1,5 @@ -use rustc_errors::{codes::*, MultiSpan}; +use rustc_errors::codes::*; +use rustc_errors::MultiSpan; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; use rustc_middle::ty::{GenericArg, Ty}; use rustc_span::Span; diff --git a/compiler/rustc_borrowck/src/type_check/canonical.rs b/compiler/rustc_borrowck/src/type_check/canonical.rs index 2dc2568cd47..86cd8b918fc 100644 --- a/compiler/rustc_borrowck/src/type_check/canonical.rs +++ b/compiler/rustc_borrowck/src/type_check/canonical.rs @@ -10,9 +10,8 @@ use rustc_span::Span; use rustc_trait_selection::traits::query::type_op::{self, TypeOpOutput}; use rustc_trait_selection::traits::ObligationCause; -use crate::diagnostics::ToUniverseInfo; - use super::{Locations, NormalizeLocation, TypeChecker}; +use crate::diagnostics::ToUniverseInfo; impl<'a, 'tcx> TypeChecker<'a, 'tcx> { /// Given some operation `op` that manipulates types, proves diff --git a/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs b/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs index 0cb4b15b127..9876f44c002 100644 --- a/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs +++ b/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs @@ -14,12 +14,10 @@ use rustc_trait_selection::traits::query::type_op::custom::CustomTypeOp; use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput}; use rustc_trait_selection::traits::ScrubbedTraitError; -use crate::{ - constraints::OutlivesConstraint, - region_infer::TypeTest, - type_check::{Locations, MirTypeckRegionConstraints}, - universal_regions::UniversalRegions, -}; +use crate::constraints::OutlivesConstraint; +use crate::region_infer::TypeTest; +use crate::type_check::{Locations, MirTypeckRegionConstraints}; +use crate::universal_regions::UniversalRegions; pub(crate) struct ConstraintConversion<'a, 'tcx> { infcx: &'a InferCtxt<'tcx>, diff --git a/compiler/rustc_borrowck/src/type_check/free_region_relations.rs b/compiler/rustc_borrowck/src/type_check/free_region_relations.rs index e4c2e0fced7..b7fb9964ce7 100644 --- a/compiler/rustc_borrowck/src/type_check/free_region_relations.rs +++ b/compiler/rustc_borrowck/src/type_check/free_region_relations.rs @@ -1,11 +1,12 @@ +use std::rc::Rc; + use rustc_data_structures::frozen::Frozen; use rustc_data_structures::transitive_relation::{TransitiveRelation, TransitiveRelationBuilder}; use rustc_hir::def::DefKind; use rustc_infer::infer::canonical::QueryRegionConstraints; -use rustc_infer::infer::outlives; use rustc_infer::infer::outlives::env::RegionBoundPairs; use rustc_infer::infer::region_constraints::GenericKind; -use rustc_infer::infer::InferCtxt; +use rustc_infer::infer::{outlives, InferCtxt}; use rustc_middle::mir::ConstraintCategory; use rustc_middle::traits::query::OutlivesBound; use rustc_middle::traits::ObligationCause; @@ -14,14 +15,10 @@ use rustc_span::{ErrorGuaranteed, Span}; use rustc_trait_selection::error_reporting::InferCtxtErrorExt; use rustc_trait_selection::solve::deeply_normalize; use rustc_trait_selection::traits::query::type_op::{self, TypeOp}; -use std::rc::Rc; use type_op::TypeOpOutput; -use crate::{ - type_check::constraint_conversion, - type_check::{Locations, MirTypeckRegionConstraints}, - universal_regions::UniversalRegions, -}; +use crate::type_check::{constraint_conversion, Locations, MirTypeckRegionConstraints}; +use crate::universal_regions::UniversalRegions; #[derive(Debug)] pub(crate) struct UniversalRegionRelations<'tcx> { diff --git a/compiler/rustc_borrowck/src/type_check/input_output.rs b/compiler/rustc_borrowck/src/type_check/input_output.rs index 741ec05dc9a..ba6030bdff7 100644 --- a/compiler/rustc_borrowck/src/type_check/input_output.rs +++ b/compiler/rustc_borrowck/src/type_check/input_output.rs @@ -16,11 +16,10 @@ use rustc_middle::mir::*; use rustc_middle::ty::{self, Ty}; use rustc_span::Span; +use super::{Locations, TypeChecker}; use crate::renumber::RegionCtxt; use crate::universal_regions::{DefiningTy, UniversalRegions}; -use super::{Locations, TypeChecker}; - impl<'a, 'tcx> TypeChecker<'a, 'tcx> { /// Check explicit closure signature annotation, /// e.g., `|x: FxIndexMap<_, &'static u32>| ...`. diff --git a/compiler/rustc_borrowck/src/type_check/liveness/mod.rs b/compiler/rustc_borrowck/src/type_check/liveness/mod.rs index 6d6425b5f19..a320add0636 100644 --- a/compiler/rustc_borrowck/src/type_check/liveness/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/liveness/mod.rs @@ -1,3 +1,5 @@ +use std::rc::Rc; + use itertools::{Either, Itertools}; use rustc_data_structures::fx::FxHashSet; use rustc_middle::mir::visit::{TyContext, Visitor}; @@ -9,14 +11,11 @@ use rustc_mir_dataflow::impls::MaybeInitializedPlaces; use rustc_mir_dataflow::move_paths::MoveData; use rustc_mir_dataflow::points::DenseLocationMap; use rustc_mir_dataflow::ResultsCursor; -use std::rc::Rc; - -use crate::{ - constraints::OutlivesConstraintSet, region_infer::values::LivenessValues, - universal_regions::UniversalRegions, -}; use super::TypeChecker; +use crate::constraints::OutlivesConstraintSet; +use crate::region_infer::values::LivenessValues; +use crate::universal_regions::UniversalRegions; mod local_use_map; mod polonius; diff --git a/compiler/rustc_borrowck/src/type_check/liveness/polonius.rs b/compiler/rustc_borrowck/src/type_check/liveness/polonius.rs index a009e28a0dd..8c13b166c05 100644 --- a/compiler/rustc_borrowck/src/type_check/liveness/polonius.rs +++ b/compiler/rustc_borrowck/src/type_check/liveness/polonius.rs @@ -1,11 +1,11 @@ -use crate::def_use::{self, DefUse}; -use crate::location::{LocationIndex, LocationTable}; use rustc_middle::mir::visit::{MutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::{Body, Local, Location, Place}; use rustc_middle::ty::GenericArg; use rustc_mir_dataflow::move_paths::{LookupResult, MoveData, MovePathIndex}; use super::TypeChecker; +use crate::def_use::{self, DefUse}; +use crate::location::{LocationIndex, LocationTable}; type VarPointRelation = Vec<(Local, LocationIndex)>; type PathPointRelation = Vec<(MovePathIndex, LocationIndex)>; diff --git a/compiler/rustc_borrowck/src/type_check/liveness/trace.rs b/compiler/rustc_borrowck/src/type_check/liveness/trace.rs index eb86c8d06f1..f0c521cdcfc 100644 --- a/compiler/rustc_borrowck/src/type_check/liveness/trace.rs +++ b/compiler/rustc_borrowck/src/type_check/liveness/trace.rs @@ -1,3 +1,5 @@ +use std::rc::Rc; + use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_index::bit_set::BitSet; use rustc_index::interval::IntervalSet; @@ -6,24 +8,19 @@ use rustc_infer::infer::outlives::for_liveness; use rustc_middle::mir::{BasicBlock, Body, ConstraintCategory, Local, Location}; use rustc_middle::traits::query::DropckOutlivesResult; use rustc_middle::ty::{Ty, TyCtxt, TypeVisitable, TypeVisitableExt}; +use rustc_mir_dataflow::impls::MaybeInitializedPlaces; +use rustc_mir_dataflow::move_paths::{HasMoveData, MoveData, MovePathIndex}; use rustc_mir_dataflow::points::{DenseLocationMap, PointIndex}; +use rustc_mir_dataflow::ResultsCursor; use rustc_span::DUMMY_SP; use rustc_trait_selection::traits::query::type_op::outlives::DropckOutlives; use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput}; -use std::rc::Rc; - -use rustc_mir_dataflow::impls::MaybeInitializedPlaces; -use rustc_mir_dataflow::move_paths::{HasMoveData, MoveData, MovePathIndex}; -use rustc_mir_dataflow::ResultsCursor; use crate::location::RichLocation; -use crate::{ - region_infer::values::{self, LiveLoans}, - type_check::liveness::local_use_map::LocalUseMap, - type_check::liveness::polonius, - type_check::NormalizeLocation, - type_check::TypeChecker, -}; +use crate::region_infer::values::{self, LiveLoans}; +use crate::type_check::liveness::local_use_map::LocalUseMap; +use crate::type_check::liveness::polonius; +use crate::type_check::{NormalizeLocation, TypeChecker}; /// This is the heart of the liveness computation. For each variable X /// that requires a liveness computation, it walks over all the uses diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index db4b5209145..bbb5daccfd6 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -4,7 +4,6 @@ use std::rc::Rc; use std::{fmt, iter, mem}; use either::Either; - use rustc_data_structures::frozen::Frozen; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_errors::ErrorGuaranteed; @@ -28,44 +27,38 @@ use rustc_middle::ty::cast::CastTy; use rustc_middle::ty::visit::TypeVisitableExt; use rustc_middle::ty::{ self, Binder, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, CoroutineArgsExt, - Dynamic, OpaqueHiddenType, OpaqueTypeKey, RegionVid, Ty, TyCtxt, UserType, - UserTypeAnnotationIndex, + Dynamic, GenericArgsRef, OpaqueHiddenType, OpaqueTypeKey, RegionVid, Ty, TyCtxt, UserArgs, + UserType, UserTypeAnnotationIndex, }; -use rustc_middle::ty::{GenericArgsRef, UserArgs}; use rustc_middle::{bug, span_bug}; +use rustc_mir_dataflow::impls::MaybeInitializedPlaces; +use rustc_mir_dataflow::move_paths::MoveData; use rustc_mir_dataflow::points::DenseLocationMap; +use rustc_mir_dataflow::ResultsCursor; use rustc_span::def_id::CRATE_DEF_ID; use rustc_span::source_map::Spanned; use rustc_span::symbol::sym; -use rustc_span::Span; -use rustc_span::DUMMY_SP; +use rustc_span::{Span, DUMMY_SP}; use rustc_target::abi::{FieldIdx, FIRST_VARIANT}; -use rustc_trait_selection::traits::query::type_op::custom::scrape_region_constraints; -use rustc_trait_selection::traits::query::type_op::custom::CustomTypeOp; +use rustc_trait_selection::traits::query::type_op::custom::{ + scrape_region_constraints, CustomTypeOp, +}; use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput}; - use rustc_trait_selection::traits::PredicateObligation; -use rustc_mir_dataflow::impls::MaybeInitializedPlaces; -use rustc_mir_dataflow::move_paths::MoveData; -use rustc_mir_dataflow::ResultsCursor; - +use crate::borrow_set::BorrowSet; +use crate::constraints::{OutlivesConstraint, OutlivesConstraintSet}; +use crate::diagnostics::UniverseInfo; +use crate::facts::AllFacts; +use crate::location::LocationTable; +use crate::member_constraints::MemberConstraintSet; +use crate::region_infer::values::{LivenessValues, PlaceholderIndex, PlaceholderIndices}; +use crate::region_infer::TypeTest; use crate::renumber::RegionCtxt; use crate::session_diagnostics::{MoveUnsized, SimdIntrinsicArgConst}; -use crate::{ - borrow_set::BorrowSet, - constraints::{OutlivesConstraint, OutlivesConstraintSet}, - diagnostics::UniverseInfo, - facts::AllFacts, - location::LocationTable, - member_constraints::MemberConstraintSet, - path_utils, - region_infer::values::{LivenessValues, PlaceholderIndex, PlaceholderIndices}, - region_infer::TypeTest, - type_check::free_region_relations::{CreateResult, UniversalRegionRelations}, - universal_regions::{DefiningTy, UniversalRegions}, - BorrowckInferCtxt, -}; +use crate::type_check::free_region_relations::{CreateResult, UniversalRegionRelations}; +use crate::universal_regions::{DefiningTy, UniversalRegions}; +use crate::{path_utils, BorrowckInferCtxt}; macro_rules! span_mirbug { ($context:expr, $elem:expr, $($message:tt)*) => ({ diff --git a/compiler/rustc_borrowck/src/universal_regions.rs b/compiler/rustc_borrowck/src/universal_regions.rs index 9f5fb59e46c..1ad80cb122a 100644 --- a/compiler/rustc_borrowck/src/universal_regions.rs +++ b/compiler/rustc_borrowck/src/universal_regions.rs @@ -15,6 +15,9 @@ #![allow(rustc::diagnostic_outside_of_impl)] #![allow(rustc::untranslatable_diagnostic)] +use std::cell::Cell; +use std::iter; + use rustc_data_structures::fx::FxIndexMap; use rustc_errors::Diag; use rustc_hir::def_id::{DefId, LocalDefId}; @@ -25,13 +28,12 @@ use rustc_infer::infer::NllRegionVariableOrigin; use rustc_macros::extension; use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::print::with_no_trimmed_paths; -use rustc_middle::ty::{self, InlineConstArgs, InlineConstArgsParts, RegionVid, Ty, TyCtxt}; -use rustc_middle::ty::{GenericArgs, GenericArgsRef}; +use rustc_middle::ty::{ + self, GenericArgs, GenericArgsRef, InlineConstArgs, InlineConstArgsParts, RegionVid, Ty, TyCtxt, +}; use rustc_middle::{bug, span_bug}; use rustc_span::symbol::{kw, sym}; use rustc_span::{ErrorGuaranteed, Symbol}; -use std::cell::Cell; -use std::iter; use crate::renumber::RegionCtxt; use crate::BorrowckInferCtxt; diff --git a/compiler/rustc_borrowck/src/util/collect_writes.rs b/compiler/rustc_borrowck/src/util/collect_writes.rs index 8d92bb35938..93c7810b545 100644 --- a/compiler/rustc_borrowck/src/util/collect_writes.rs +++ b/compiler/rustc_borrowck/src/util/collect_writes.rs @@ -1,5 +1,4 @@ -use rustc_middle::mir::visit::PlaceContext; -use rustc_middle::mir::visit::Visitor; +use rustc_middle::mir::visit::{PlaceContext, Visitor}; use rustc_middle::mir::{Body, Local, Location}; pub trait FindAssignments { |
