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_trait_selection/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_trait_selection/src')
53 files changed, 412 insertions, 452 deletions
diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs index daabdec8f9e..8ccb2a8483a 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs @@ -60,12 +60,11 @@ use rustc_hir::{self as hir}; use rustc_macros::extension; use rustc_middle::bug; use rustc_middle::dep_graph::DepContext; -use rustc_middle::ty::error::ExpectedFound; -use rustc_middle::ty::error::TypeErrorToStringExt; +use rustc_middle::ty::error::{ExpectedFound, TypeError, TypeErrorToStringExt}; use rustc_middle::ty::print::{with_forced_trimmed_paths, PrintError, PrintTraitRefExt as _}; use rustc_middle::ty::{ - self, error::TypeError, List, Region, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable, - TypeVisitable, TypeVisitableExt, + self, List, Region, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable, TypeVisitable, + TypeVisitableExt, }; use rustc_span::{sym, BytePos, DesugaringKind, Pos, Span}; use rustc_target::spec::abi; diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs index 56ea70bcf1d..f667e4c80fd 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs @@ -1,13 +1,11 @@ -use crate::error_reporting::TypeErrCtxt; -use crate::errors::{ - AmbiguousImpl, AmbiguousReturn, AnnotationRequired, InferenceBadError, - SourceKindMultiSuggestion, SourceKindSubdiag, -}; -use crate::infer::InferCtxt; -use rustc_errors::{codes::*, Diag, IntoDiagArg}; +use std::borrow::Cow; +use std::iter; +use std::path::PathBuf; + +use rustc_errors::codes::*; +use rustc_errors::{Diag, IntoDiagArg}; use rustc_hir as hir; -use rustc_hir::def::Res; -use rustc_hir::def::{CtorOf, DefKind, Namespace}; +use rustc_hir::def::{CtorOf, DefKind, Namespace, Res}; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::{Body, Closure, Expr, ExprKind, FnRetTy, HirId, LetStmt, LocalSource}; @@ -21,9 +19,13 @@ use rustc_middle::ty::{ }; use rustc_span::symbol::{sym, Ident}; use rustc_span::{BytePos, Span, DUMMY_SP}; -use std::borrow::Cow; -use std::iter; -use std::path::PathBuf; + +use crate::error_reporting::TypeErrCtxt; +use crate::errors::{ + AmbiguousImpl, AmbiguousReturn, AnnotationRequired, InferenceBadError, + SourceKindMultiSuggestion, SourceKindSubdiag, +}; +use crate::infer::InferCtxt; pub enum TypeAnnotationNeeded { /// ```compile_fail,E0282 diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/different_lifetimes.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/different_lifetimes.rs index 74dcde03639..8f84d771216 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/different_lifetimes.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/different_lifetimes.rs @@ -1,21 +1,17 @@ //! Error Reporting for Anonymous Region Lifetime Errors //! where both the regions are anonymous. -use crate::error_reporting::infer::nice_region_error::find_anon_type::find_anon_type; -use crate::error_reporting::infer::nice_region_error::util::AnonymousParamInfo; -use crate::error_reporting::infer::nice_region_error::NiceRegionError; -use crate::errors::AddLifetimeParamsSuggestion; -use crate::errors::LifetimeMismatch; -use crate::errors::LifetimeMismatchLabels; -use crate::infer::RegionResolutionError; -use crate::infer::SubregionOrigin; - -use rustc_errors::Subdiagnostic; -use rustc_errors::{Diag, ErrorGuaranteed}; +use rustc_errors::{Diag, ErrorGuaranteed, Subdiagnostic}; use rustc_hir::def_id::LocalDefId; use rustc_hir::Ty; use rustc_middle::ty::{Region, TyCtxt}; +use crate::error_reporting::infer::nice_region_error::find_anon_type::find_anon_type; +use crate::error_reporting::infer::nice_region_error::util::AnonymousParamInfo; +use crate::error_reporting::infer::nice_region_error::NiceRegionError; +use crate::errors::{AddLifetimeParamsSuggestion, LifetimeMismatch, LifetimeMismatchLabels}; +use crate::infer::{RegionResolutionError, SubregionOrigin}; + impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { /// Print the error message for lifetime errors when both the concerned regions are anonymous. /// diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/find_anon_type.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/find_anon_type.rs index a892ce58861..3f35391be13 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/find_anon_type.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/find_anon_type.rs @@ -1,4 +1,5 @@ use core::ops::ControlFlow; + use rustc_hir as hir; use rustc_hir::def_id::LocalDefId; use rustc_hir::intravisit::{self, Visitor}; diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/mismatched_static_lifetime.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/mismatched_static_lifetime.rs index 550cc455e01..221f6675d22 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/mismatched_static_lifetime.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/mismatched_static_lifetime.rs @@ -1,14 +1,6 @@ //! Error Reporting for when the lifetime for a type doesn't match the `impl` selected for a predicate //! to hold. -use crate::error_reporting::infer::nice_region_error::NiceRegionError; -use crate::errors::{note_and_explain, IntroducesStaticBecauseUnmetLifetimeReq}; -use crate::errors::{ - DoesNotOutliveStaticFromImpl, ImplicitStaticLifetimeSubdiag, MismatchedStaticLifetime, -}; -use crate::infer::RegionResolutionError; -use crate::infer::{SubregionOrigin, TypeTrace}; -use crate::traits::ObligationCauseCode; use rustc_data_structures::fx::FxIndexSet; use rustc_errors::{ErrorGuaranteed, MultiSpan}; use rustc_hir as hir; @@ -16,6 +8,14 @@ use rustc_hir::intravisit::Visitor; use rustc_middle::bug; use rustc_middle::ty::TypeVisitor; +use crate::error_reporting::infer::nice_region_error::NiceRegionError; +use crate::errors::{ + note_and_explain, DoesNotOutliveStaticFromImpl, ImplicitStaticLifetimeSubdiag, + IntroducesStaticBecauseUnmetLifetimeReq, MismatchedStaticLifetime, +}; +use crate::infer::{RegionResolutionError, SubregionOrigin, TypeTrace}; +use crate::traits::ObligationCauseCode; + impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { pub(super) fn try_report_mismatched_static_lifetime(&self) -> Option<ErrorGuaranteed> { let error = self.error.as_ref()?; diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/mod.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/mod.rs index b83ecd8320c..79a770ac9b3 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/mod.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/mod.rs @@ -1,11 +1,12 @@ -use crate::error_reporting::TypeErrCtxt; -use crate::infer::RegionResolutionError; -use crate::infer::RegionResolutionError::*; use rustc_errors::{Diag, ErrorGuaranteed}; use rustc_hir::def_id::LocalDefId; use rustc_middle::ty::{self, TyCtxt}; use rustc_span::Span; +use crate::error_reporting::TypeErrCtxt; +use crate::infer::RegionResolutionError; +use crate::infer::RegionResolutionError::*; + mod different_lifetimes; pub mod find_anon_type; mod mismatched_static_lifetime; diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/named_anon_conflict.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/named_anon_conflict.rs index d1802d2f5ee..f91a81f76f4 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/named_anon_conflict.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/named_anon_conflict.rs @@ -1,13 +1,14 @@ //! Error Reporting for Anonymous Region Lifetime Errors //! where one region is named and the other is anonymous. -use crate::error_reporting::infer::nice_region_error::find_anon_type::find_anon_type; -use crate::error_reporting::infer::nice_region_error::NiceRegionError; -use crate::errors::ExplicitLifetimeRequired; use rustc_errors::Diag; use rustc_middle::ty; use rustc_span::symbol::kw; +use crate::error_reporting::infer::nice_region_error::find_anon_type::find_anon_type; +use crate::error_reporting::infer::nice_region_error::NiceRegionError; +use crate::errors::ExplicitLifetimeRequired; + impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { /// When given a `ConcreteFailure` for a function with parameters containing a named region and /// an anonymous region, emit an descriptive diagnostic error. diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/placeholder_error.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/placeholder_error.rs index 476ac3f1720..8da0edbeb02 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/placeholder_error.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/placeholder_error.rs @@ -1,12 +1,5 @@ -use crate::error_reporting::infer::nice_region_error::NiceRegionError; -use crate::errors::{ - ActualImplExpectedKind, ActualImplExpectedLifetimeKind, ActualImplExplNotes, - TraitPlaceholderMismatch, TyOrSig, -}; -use crate::infer::RegionResolutionError; -use crate::infer::ValuePairs; -use crate::infer::{SubregionOrigin, TypeTrace}; -use crate::traits::{ObligationCause, ObligationCauseCode}; +use std::fmt; + use rustc_data_structures::intern::Interned; use rustc_errors::{Diag, IntoDiagArg}; use rustc_hir::def::Namespace; @@ -14,10 +7,15 @@ use rustc_hir::def_id::{DefId, CRATE_DEF_ID}; use rustc_middle::bug; use rustc_middle::ty::error::ExpectedFound; use rustc_middle::ty::print::{FmtPrinter, Print, PrintTraitRefExt as _, RegionHighlightMode}; -use rustc_middle::ty::GenericArgsRef; -use rustc_middle::ty::{self, RePlaceholder, Region, TyCtxt}; +use rustc_middle::ty::{self, GenericArgsRef, RePlaceholder, Region, TyCtxt}; -use std::fmt; +use crate::error_reporting::infer::nice_region_error::NiceRegionError; +use crate::errors::{ + ActualImplExpectedKind, ActualImplExpectedLifetimeKind, ActualImplExplNotes, + TraitPlaceholderMismatch, TyOrSig, +}; +use crate::infer::{RegionResolutionError, SubregionOrigin, TypeTrace, ValuePairs}; +use crate::traits::{ObligationCause, ObligationCauseCode}; // HACK(eddyb) maybe move this in a more central location. #[derive(Copy, Clone)] diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/placeholder_relation.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/placeholder_relation.rs index e9f17a3e3e2..9c772f42cca 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/placeholder_relation.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/placeholder_relation.rs @@ -1,10 +1,11 @@ -use crate::error_reporting::infer::nice_region_error::NiceRegionError; -use crate::errors::PlaceholderRelationLfNotSatisfied; -use crate::infer::{RegionResolutionError, SubregionOrigin}; use rustc_data_structures::intern::Interned; use rustc_errors::Diag; use rustc_middle::ty::{self, RePlaceholder, Region}; +use crate::error_reporting::infer::nice_region_error::NiceRegionError; +use crate::errors::PlaceholderRelationLfNotSatisfied; +use crate::infer::{RegionResolutionError, SubregionOrigin}; + impl<'tcx> NiceRegionError<'_, 'tcx> { /// Emitted wwhen given a `ConcreteFailure` when relating two placeholders. pub(super) fn try_report_placeholder_relation(&self) -> Option<Diag<'tcx>> { diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/static_impl_trait.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/static_impl_trait.rs index e5d97976534..dc775b824da 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/static_impl_trait.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/static_impl_trait.rs @@ -1,13 +1,5 @@ //! Error Reporting for static impl Traits. -use crate::error_reporting::infer::nice_region_error::NiceRegionError; -use crate::errors::{ - ButCallingIntroduces, ButNeedsToSatisfy, DynTraitConstraintSuggestion, MoreTargeted, - ReqIntroducedLocations, -}; -use crate::infer::RegionResolutionError; -use crate::infer::{SubregionOrigin, TypeTrace}; -use crate::traits::{ObligationCauseCode, UnifyReceiverContext}; use rustc_data_structures::fx::FxIndexSet; use rustc_errors::{Applicability, Diag, ErrorGuaranteed, MultiSpan, Subdiagnostic}; use rustc_hir::def_id::DefId; @@ -19,10 +11,17 @@ use rustc_hir::{ use rustc_middle::ty::{ self, AssocItemContainer, StaticLifetimeVisitor, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor, }; +use rustc_span::def_id::LocalDefId; use rustc_span::symbol::Ident; use rustc_span::Span; -use rustc_span::def_id::LocalDefId; +use crate::error_reporting::infer::nice_region_error::NiceRegionError; +use crate::errors::{ + ButCallingIntroduces, ButNeedsToSatisfy, DynTraitConstraintSuggestion, MoreTargeted, + ReqIntroducedLocations, +}; +use crate::infer::{RegionResolutionError, SubregionOrigin, TypeTrace}; +use crate::traits::{ObligationCauseCode, UnifyReceiverContext}; impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { /// Print the error message for lifetime errors when the return type is a static `impl Trait`, diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/trait_impl_difference.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/trait_impl_difference.rs index c58c7e13551..09af00beba7 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/trait_impl_difference.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/trait_impl_difference.rs @@ -1,9 +1,5 @@ //! Error Reporting for `impl` items that do not match the obligations from their `trait`. -use crate::error_reporting::infer::nice_region_error::NiceRegionError; -use crate::errors::{ConsiderBorrowingParamHelp, RelationshipHelp, TraitImplDiff}; -use crate::infer::RegionResolutionError; -use crate::infer::{Subtype, ValuePairs}; use rustc_errors::ErrorGuaranteed; use rustc_hir as hir; use rustc_hir::def::Res; @@ -16,6 +12,10 @@ use rustc_middle::ty::print::RegionHighlightMode; use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitor}; use rustc_span::Span; +use crate::error_reporting::infer::nice_region_error::NiceRegionError; +use crate::errors::{ConsiderBorrowingParamHelp, RelationshipHelp, TraitImplDiff}; +use crate::infer::{RegionResolutionError, Subtype, ValuePairs}; + impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { /// Print the error message for lifetime errors when the `impl` doesn't conform to the `trait`. pub(super) fn try_report_impl_not_conforming_to_trait(&self) -> Option<ErrorGuaranteed> { diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/note.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/note.rs index aeb3049c2ae..04e1be22a4d 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/note.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/note.rs @@ -1,10 +1,3 @@ -use crate::error_reporting::infer::{note_and_explain_region, TypeErrCtxt}; -use crate::errors::{ - note_and_explain, FulfillReqLifetime, LfBoundNotSatisfied, OutlivesBound, OutlivesContent, - RefLongerThanData, RegionOriginNote, WhereClauseSuggestions, -}; -use crate::fluent_generated as fluent; -use crate::infer::{self, SubregionOrigin}; use rustc_errors::{Diag, Subdiagnostic}; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_middle::traits::ObligationCauseCode; @@ -13,6 +6,13 @@ use rustc_middle::ty::{self, IsSuggestable, Region, Ty}; use rustc_span::symbol::kw; use super::ObligationCauseAsDiagArg; +use crate::error_reporting::infer::{note_and_explain_region, TypeErrCtxt}; +use crate::errors::{ + note_and_explain, FulfillReqLifetime, LfBoundNotSatisfied, OutlivesBound, OutlivesContent, + RefLongerThanData, RegionOriginNote, WhereClauseSuggestions, +}; +use crate::fluent_generated as fluent; +use crate::infer::{self, SubregionOrigin}; impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { pub(super) fn note_region_origin(&self, err: &mut Diag<'_>, origin: &SubregionOrigin<'tcx>) { diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs index f9110cfb3b9..864510bb650 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs @@ -2,14 +2,12 @@ use rustc_errors::Applicability::{MachineApplicable, MaybeIncorrect}; use rustc_errors::{pluralize, Diag, MultiSpan}; use rustc_hir as hir; use rustc_hir::def::DefKind; -use rustc_middle::traits::ObligationCauseCode; -use rustc_middle::ty::error::ExpectedFound; -use rustc_middle::ty::print::Printer; -use rustc_middle::{ - traits::ObligationCause, - ty::{self, error::TypeError, print::FmtPrinter, suggest_constraining_type_param, Ty}, -}; -use rustc_span::{def_id::DefId, sym, BytePos, Span, Symbol}; +use rustc_middle::traits::{ObligationCause, ObligationCauseCode}; +use rustc_middle::ty::error::{ExpectedFound, TypeError}; +use rustc_middle::ty::print::{FmtPrinter, Printer}; +use rustc_middle::ty::{self, suggest_constraining_type_param, Ty}; +use rustc_span::def_id::DefId; +use rustc_span::{sym, BytePos, Span, Symbol}; use crate::error_reporting::TypeErrCtxt; use crate::infer::InferCtxtExt; diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs index 1ef32d110b3..ee159aa0b77 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs @@ -1,5 +1,5 @@ -use crate::error_reporting::infer::hir::Path; use core::ops::ControlFlow; + use hir::def::CtorKind; use hir::intravisit::{walk_expr, walk_stmt, Visitor}; use hir::{LetStmt, QPath}; @@ -7,8 +7,7 @@ use rustc_data_structures::fx::FxIndexSet; use rustc_errors::{Applicability, Diag}; use rustc_hir as hir; use rustc_hir::def::Res; -use rustc_hir::MatchSource; -use rustc_hir::Node; +use rustc_hir::{MatchSource, Node}; use rustc_middle::traits::{ IfExpressionCause, MatchExpressionArmCause, ObligationCause, ObligationCauseCode, StatementAsExpression, @@ -17,6 +16,7 @@ use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::{self as ty, GenericArgKind, IsSuggestable, Ty, TypeVisitableExt}; use rustc_span::{sym, Span}; +use crate::error_reporting::infer::hir::Path; use crate::error_reporting::TypeErrCtxt; use crate::errors::{ ConsiderAddingAwait, FnConsiderCasting, FnItemsAreDistinct, FnUniqTypes, diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index a7ea308a818..2ce1b955af5 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -1,31 +1,16 @@ -use super::on_unimplemented::{AppendConstMessage, OnUnimplementedNote}; -use super::suggestions::get_explanation_based_on_obligation; -use crate::error_reporting::infer::TyCategory; -use crate::error_reporting::traits::report_object_safety_error; -use crate::error_reporting::TypeErrCtxt; -use crate::errors::{ - AsyncClosureNotFn, ClosureFnMutLabel, ClosureFnOnceLabel, ClosureKindMismatch, -}; -use crate::infer::InferCtxtExt as _; -use crate::infer::{self, InferCtxt}; -use crate::traits::query::evaluate_obligation::InferCtxtExt as _; -use crate::traits::NormalizeExt; -use crate::traits::{ - elaborate, MismatchedProjectionTypes, Obligation, ObligationCause, ObligationCauseCode, - ObligationCtxt, Overflow, PredicateObligation, SelectionError, SignatureMismatch, - TraitNotObjectSafe, -}; use core::ops::ControlFlow; +use std::borrow::Cow; + use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::unord::UnordSet; use rustc_errors::codes::*; -use rustc_errors::{pluralize, struct_span_code_err, Applicability, StringPart}; -use rustc_errors::{Diag, ErrorGuaranteed, StashKey}; +use rustc_errors::{ + pluralize, struct_span_code_err, Applicability, Diag, ErrorGuaranteed, StashKey, StringPart, +}; use rustc_hir::def::Namespace; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::intravisit::Visitor; -use rustc_hir::Node; -use rustc_hir::{self as hir, LangItem}; +use rustc_hir::{self as hir, LangItem, Node}; use rustc_infer::infer::{InferOk, TypeTrace}; use rustc_middle::traits::select::OverflowError; use rustc_middle::traits::SignatureMismatchData; @@ -42,11 +27,25 @@ use rustc_middle::ty::{ use rustc_middle::{bug, span_bug}; use rustc_span::symbol::sym; use rustc_span::{BytePos, Span, Symbol, DUMMY_SP}; -use std::borrow::Cow; +use super::on_unimplemented::{AppendConstMessage, OnUnimplementedNote}; +use super::suggestions::get_explanation_based_on_obligation; use super::{ ArgKind, CandidateSimilarity, GetSafeTransmuteErrorAndReason, ImplCandidate, UnsatisfiedConst, }; +use crate::error_reporting::infer::TyCategory; +use crate::error_reporting::traits::report_object_safety_error; +use crate::error_reporting::TypeErrCtxt; +use crate::errors::{ + AsyncClosureNotFn, ClosureFnMutLabel, ClosureFnOnceLabel, ClosureKindMismatch, +}; +use crate::infer::{self, InferCtxt, InferCtxtExt as _}; +use crate::traits::query::evaluate_obligation::InferCtxtExt as _; +use crate::traits::{ + elaborate, MismatchedProjectionTypes, NormalizeExt, Obligation, ObligationCause, + ObligationCauseCode, ObligationCtxt, Overflow, PredicateObligation, SelectionError, + SignatureMismatch, TraitNotObjectSafe, +}; impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { /// The `root_obligation` parameter should be the `root_obligation` field diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs index 89ae6f4ccab..40a1c184009 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs @@ -19,11 +19,10 @@ use rustc_middle::ty::print::{with_no_trimmed_paths, PrintTraitRefExt as _}; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_span::{ErrorGuaranteed, ExpnKind, Span}; +pub use self::overflow::*; use crate::error_reporting::TypeErrCtxt; use crate::traits::{FulfillmentError, FulfillmentErrorCode}; -pub use self::overflow::*; - // When outputting impl candidates, prefer showing those that are more similar. // // We also compare candidates after skipping lifetimes, which has a lower diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/on_unimplemented.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/on_unimplemented.rs index f65de590ccf..3a082893c5c 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/on_unimplemented.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/on_unimplemented.rs @@ -1,29 +1,27 @@ -use super::{ObligationCauseCode, PredicateObligation}; -use crate::error_reporting::TypeErrCtxt; -use crate::errors::{ - EmptyOnClauseInOnUnimplemented, InvalidOnClauseInOnUnimplemented, NoValueInOnUnimplemented, -}; -use crate::infer::InferCtxtExt; -use rustc_ast::AttrArgs; -use rustc_ast::AttrArgsEq; -use rustc_ast::AttrKind; -use rustc_ast::{Attribute, MetaItem, NestedMetaItem}; -use rustc_attr as attr; +use std::iter; +use std::path::PathBuf; + +use rustc_ast::{AttrArgs, AttrArgsEq, AttrKind, Attribute, MetaItem, NestedMetaItem}; use rustc_data_structures::fx::FxHashMap; -use rustc_errors::{codes::*, struct_span_code_err, ErrorGuaranteed}; -use rustc_hir as hir; +use rustc_errors::codes::*; +use rustc_errors::{struct_span_code_err, ErrorGuaranteed}; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_macros::LintDiagnostic; use rustc_middle::bug; use rustc_middle::ty::print::PrintTraitRefExt as _; -use rustc_middle::ty::GenericArgsRef; -use rustc_middle::ty::{self, GenericParamDefKind, TyCtxt}; +use rustc_middle::ty::{self, GenericArgsRef, GenericParamDefKind, TyCtxt}; use rustc_parse_format::{ParseMode, Parser, Piece, Position}; use rustc_session::lint::builtin::UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES; use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::Span; -use std::iter; -use std::path::PathBuf; +use {rustc_attr as attr, rustc_hir as hir}; + +use super::{ObligationCauseCode, PredicateObligation}; +use crate::error_reporting::TypeErrCtxt; +use crate::errors::{ + EmptyOnClauseInOnUnimplemented, InvalidOnClauseInOnUnimplemented, NoValueInOnUnimplemented, +}; +use crate::infer::InferCtxtExt; /// The symbols which are always allowed in a format string static ALLOWED_FORMAT_SYMBOLS: &[Symbol] = &[ diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index d1381d24764..0d15ef55e24 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -1,34 +1,33 @@ // ignore-tidy-filelength -use super::{ - DefIdOrName, FindExprBySpan, ImplCandidate, Obligation, ObligationCause, ObligationCauseCode, - PredicateObligation, -}; - -use crate::error_reporting::TypeErrCtxt; -use crate::errors; -use crate::traits::{ImplDerivedCause, NormalizeExt, ObligationCtxt}; +use std::assert_matches::debug_assert_matches; +use std::borrow::Cow; +use std::iter; +use itertools::{EitherOrBoth, Itertools}; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::stack::ensure_sufficient_stack; +use rustc_errors::codes::*; use rustc_errors::{ - codes::*, pluralize, struct_span_code_err, Applicability, Diag, EmissionGuarantee, MultiSpan, - Style, SuggestionStyle, + pluralize, struct_span_code_err, Applicability, Diag, EmissionGuarantee, MultiSpan, Style, + SuggestionStyle, }; use rustc_hir as hir; -use rustc_hir::def::CtorOf; -use rustc_hir::def::{DefKind, Res}; +use rustc_hir::def::{CtorOf, DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::intravisit::Visitor; -use rustc_hir::is_range_literal; use rustc_hir::lang_items::LangItem; -use rustc_hir::{CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, HirId, Node}; -use rustc_infer::infer::InferCtxt; -use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes, InferOk}; +use rustc_hir::{ + is_range_literal, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, HirId, Node, +}; +use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes, InferCtxt, InferOk}; use rustc_middle::hir::map; use rustc_middle::traits::IsConstable; use rustc_middle::ty::error::TypeError; -use rustc_middle::ty::print::PrintPolyTraitRefExt; +use rustc_middle::ty::print::{ + with_forced_trimmed_paths, with_no_trimmed_paths, PrintPolyTraitPredicateExt as _, + PrintPolyTraitRefExt, PrintTraitPredicateExt as _, +}; use rustc_middle::ty::{ self, suggest_arbitrary_trait_bound, suggest_constraining_type_param, AdtKind, GenericArgs, InferTy, IsSuggestable, ToPolyTraitRef, Ty, TyCtxt, TypeFoldable, TypeFolder, @@ -39,19 +38,16 @@ use rustc_span::def_id::LocalDefId; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{BytePos, DesugaringKind, ExpnKind, MacroKind, Span, DUMMY_SP}; use rustc_target::spec::abi; -use std::assert_matches::debug_assert_matches; -use std::borrow::Cow; -use std::iter; +use super::{ + DefIdOrName, FindExprBySpan, ImplCandidate, Obligation, ObligationCause, ObligationCauseCode, + PredicateObligation, +}; +use crate::error_reporting::TypeErrCtxt; +use crate::errors; use crate::infer::InferCtxtExt as _; use crate::traits::query::evaluate_obligation::InferCtxtExt as _; -use rustc_middle::ty::print::{ - with_forced_trimmed_paths, with_no_trimmed_paths, PrintPolyTraitPredicateExt as _, - PrintTraitPredicateExt as _, -}; - -use itertools::EitherOrBoth; -use itertools::Itertools; +use crate::traits::{ImplDerivedCause, NormalizeExt, ObligationCtxt}; #[derive(Debug)] pub enum CoroutineInteriorOrUpvar { diff --git a/compiler/rustc_trait_selection/src/errors.rs b/compiler/rustc_trait_selection/src/errors.rs index 0ee4485a365..02fc37d8798 100644 --- a/compiler/rustc_trait_selection/src/errors.rs +++ b/compiler/rustc_trait_selection/src/errors.rs @@ -1,19 +1,18 @@ +use std::path::PathBuf; + use rustc_data_structures::fx::FxHashSet; +use rustc_errors::codes::*; use rustc_errors::{ - codes::*, Applicability, Diag, DiagCtxtHandle, DiagMessage, DiagStyledString, Diagnostic, + Applicability, Diag, DiagCtxtHandle, DiagMessage, DiagStyledString, Diagnostic, EmissionGuarantee, IntoDiagArg, Level, MultiSpan, SubdiagMessageOp, Subdiagnostic, }; use rustc_hir as hir; use rustc_hir::def_id::LocalDefId; use rustc_hir::intravisit::{walk_ty, Visitor}; -use rustc_hir::FnRetTy; -use rustc_hir::GenericParamKind; +use rustc_hir::{FnRetTy, GenericParamKind}; use rustc_macros::{Diagnostic, Subdiagnostic}; -use rustc_middle::ty::print::TraitRefPrintOnlyTraitPath; -use rustc_middle::ty::{ - self, print::PrintTraitRefExt as _, Binder, ClosureKind, FnSig, PolyTraitRef, Region, Ty, - TyCtxt, -}; +use rustc_middle::ty::print::{PrintTraitRefExt as _, TraitRefPrintOnlyTraitPath}; +use rustc_middle::ty::{self, Binder, ClosureKind, FnSig, PolyTraitRef, Region, Ty, TyCtxt}; use rustc_span::symbol::{kw, Ident, Symbol}; use rustc_span::{BytePos, Span}; @@ -22,8 +21,6 @@ use crate::error_reporting::infer::nice_region_error::placeholder_error::Highlig use crate::error_reporting::infer::ObligationCauseAsDiagArg; use crate::fluent_generated as fluent; -use std::path::PathBuf; - pub mod note_and_explain; #[derive(Diagnostic)] diff --git a/compiler/rustc_trait_selection/src/errors/note_and_explain.rs b/compiler/rustc_trait_selection/src/errors/note_and_explain.rs index 1f18cd8c8d8..b1477763028 100644 --- a/compiler/rustc_trait_selection/src/errors/note_and_explain.rs +++ b/compiler/rustc_trait_selection/src/errors/note_and_explain.rs @@ -1,10 +1,12 @@ -use crate::error_reporting::infer::nice_region_error::find_anon_type; -use crate::fluent_generated as fluent; use rustc_errors::{Diag, EmissionGuarantee, IntoDiagArg, SubdiagMessageOp, Subdiagnostic}; use rustc_hir::def_id::LocalDefId; use rustc_middle::bug; use rustc_middle::ty::{self, TyCtxt}; -use rustc_span::{symbol::kw, Span}; +use rustc_span::symbol::kw; +use rustc_span::Span; + +use crate::error_reporting::infer::nice_region_error::find_anon_type; +use crate::fluent_generated as fluent; struct DescriptionCtx<'a> { span: Option<Span>, diff --git a/compiler/rustc_trait_selection/src/infer.rs b/compiler/rustc_trait_selection/src/infer.rs index ad087620ae0..c22925b73e3 100644 --- a/compiler/rustc_trait_selection/src/infer.rs +++ b/compiler/rustc_trait_selection/src/infer.rs @@ -1,20 +1,18 @@ -use crate::infer::at::ToTrace; -use crate::traits::query::evaluate_obligation::InferCtxtExt as _; -use crate::traits::{self, Obligation, ObligationCause, ObligationCtxt, SelectionContext}; +use std::fmt::Debug; use rustc_hir::def_id::DefId; use rustc_hir::lang_items::LangItem; +pub use rustc_infer::infer::*; use rustc_macros::extension; use rustc_middle::arena::ArenaAllocatable; use rustc_middle::infer::canonical::{Canonical, CanonicalQueryResponse, QueryResponse}; use rustc_middle::traits::query::NoSolution; -use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeVisitableExt}; -use rustc_middle::ty::{GenericArg, Upcast}; +use rustc_middle::ty::{self, GenericArg, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, Upcast}; use rustc_span::DUMMY_SP; -use std::fmt::Debug; - -pub use rustc_infer::infer::*; +use crate::infer::at::ToTrace; +use crate::traits::query::evaluate_obligation::InferCtxtExt as _; +use crate::traits::{self, Obligation, ObligationCause, ObligationCtxt, SelectionContext}; #[extension(pub trait InferCtxtExt<'tcx>)] impl<'tcx> InferCtxt<'tcx> { diff --git a/compiler/rustc_trait_selection/src/regions.rs b/compiler/rustc_trait_selection/src/regions.rs index 5f986e22f51..65762cfcd2e 100644 --- a/compiler/rustc_trait_selection/src/regions.rs +++ b/compiler/rustc_trait_selection/src/regions.rs @@ -1,10 +1,11 @@ -use crate::traits::ScrubbedTraitError; use rustc_infer::infer::outlives::env::OutlivesEnvironment; use rustc_infer::infer::{InferCtxt, RegionResolutionError}; use rustc_macros::extension; use rustc_middle::traits::query::NoSolution; use rustc_middle::traits::ObligationCause; +use crate::traits::ScrubbedTraitError; + #[extension(pub trait InferCtxtRegionExt<'tcx>)] impl<'tcx> InferCtxt<'tcx> { /// Resolve regions, using the deep normalizer to normalize any type-outlives diff --git a/compiler/rustc_trait_selection/src/solve/fulfill.rs b/compiler/rustc_trait_selection/src/solve/fulfill.rs index 76b88aeb0f7..49fa775a0a1 100644 --- a/compiler/rustc_trait_selection/src/solve/fulfill.rs +++ b/compiler/rustc_trait_selection/src/solve/fulfill.rs @@ -15,11 +15,10 @@ use rustc_middle::ty::{self, TyCtxt}; use rustc_next_trait_solver::solve::{GenerateProofTree, SolverDelegateEvalExt as _}; use rustc_span::symbol::sym; -use crate::traits::{FulfillmentError, FulfillmentErrorCode, ScrubbedTraitError}; - use super::delegate::SolverDelegate; use super::inspect::{self, ProofTreeInferCtxtExt, ProofTreeVisitor}; use super::Certainty; +use crate::traits::{FulfillmentError, FulfillmentErrorCode, ScrubbedTraitError}; /// A trait engine using the new trait solver. /// diff --git a/compiler/rustc_trait_selection/src/solve/normalize.rs b/compiler/rustc_trait_selection/src/solve/normalize.rs index ddaef7c159f..419d7e704de 100644 --- a/compiler/rustc_trait_selection/src/solve/normalize.rs +++ b/compiler/rustc_trait_selection/src/solve/normalize.rs @@ -1,20 +1,21 @@ use std::fmt::Debug; use std::marker::PhantomData; -use crate::error_reporting::traits::OverflowCause; -use crate::error_reporting::InferCtxtErrorExt; -use crate::traits::query::evaluate_obligation::InferCtxtExt; -use crate::traits::{BoundVarReplacer, PlaceholderReplacer, ScrubbedTraitError}; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_infer::infer::at::At; use rustc_infer::infer::InferCtxt; use rustc_infer::traits::{FromSolverError, Obligation, TraitEngine}; use rustc_middle::traits::ObligationCause; -use rustc_middle::ty::{self, Ty, TyCtxt, UniverseIndex}; -use rustc_middle::ty::{FallibleTypeFolder, TypeFolder, TypeSuperFoldable}; -use rustc_middle::ty::{TypeFoldable, TypeVisitableExt}; +use rustc_middle::ty::{ + self, FallibleTypeFolder, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, + TypeVisitableExt, UniverseIndex, +}; use super::{FulfillmentCtxt, NextSolverError}; +use crate::error_reporting::traits::OverflowCause; +use crate::error_reporting::InferCtxtErrorExt; +use crate::traits::query::evaluate_obligation::InferCtxtExt; +use crate::traits::{BoundVarReplacer, PlaceholderReplacer, ScrubbedTraitError}; /// Deeply normalize all aliases in `value`. This does not handle inference and expects /// its input to be already fully resolved. diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index 796f7fd5a54..29f78f9d5f0 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -1,11 +1,8 @@ //! Support code for rustdoc and external tools. //! You really don't want to be using this unless you need to. -use super::*; - -use crate::errors::UnableToConstructConstantValue; -use crate::infer::region_constraints::{Constraint, RegionConstraintData}; -use crate::traits::project::ProjectAndUnifyResult; +use std::collections::VecDeque; +use std::iter; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet, IndexEntry}; use rustc_data_structures::unord::UnordSet; @@ -13,8 +10,10 @@ use rustc_infer::infer::DefineOpaqueTypes; use rustc_middle::mir::interpret::ErrorHandled; use rustc_middle::ty::{Region, RegionVid}; -use std::collections::VecDeque; -use std::iter; +use super::*; +use crate::errors::UnableToConstructConstantValue; +use crate::infer::region_constraints::{Constraint, RegionConstraintData}; +use crate::traits::project::ProjectAndUnifyResult; // FIXME(twk): this is obviously not nice to duplicate like that #[derive(Eq, PartialEq, Hash, Copy, Clone, Debug)] diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index 7e996c5c5ef..2d843d8f174 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -4,15 +4,8 @@ //! [trait-resolution]: https://rustc-dev-guide.rust-lang.org/traits/resolution.html //! [trait-specialization]: https://rustc-dev-guide.rust-lang.org/traits/specialization.html -use crate::infer::outlives::env::OutlivesEnvironment; -use crate::infer::InferOk; -use crate::solve::inspect::{InspectGoal, ProofTreeInferCtxtExt, ProofTreeVisitor}; -use crate::solve::{deeply_normalize_for_diagnostics, inspect}; -use crate::traits::select::IntercrateAmbiguityCause; -use crate::traits::NormalizeExt; -use crate::traits::SkipLeakCheck; -use crate::traits::{util, FulfillmentErrorCode}; -use crate::traits::{Obligation, ObligationCause, PredicateObligation, SelectionContext}; +use std::fmt::Debug; + use rustc_data_structures::fx::FxIndexSet; use rustc_errors::{Diag, EmissionGuarantee}; use rustc_hir::def::DefKind; @@ -28,10 +21,18 @@ use rustc_middle::ty::{self, Ty, TyCtxt}; pub use rustc_next_trait_solver::coherence::*; use rustc_span::symbol::sym; use rustc_span::{Span, DUMMY_SP}; -use std::fmt::Debug; use super::ObligationCtxt; use crate::error_reporting::traits::suggest_new_overflow_limit; +use crate::infer::outlives::env::OutlivesEnvironment; +use crate::infer::InferOk; +use crate::solve::inspect::{InspectGoal, ProofTreeInferCtxtExt, ProofTreeVisitor}; +use crate::solve::{deeply_normalize_for_diagnostics, inspect}; +use crate::traits::select::IntercrateAmbiguityCause; +use crate::traits::{ + util, FulfillmentErrorCode, NormalizeExt, Obligation, ObligationCause, PredicateObligation, + SelectionContext, SkipLeakCheck, +}; pub struct OverlapResult<'tcx> { pub impl_header: ty::ImplHeader<'tcx>, diff --git a/compiler/rustc_trait_selection/src/traits/engine.rs b/compiler/rustc_trait_selection/src/traits/engine.rs index 49730b532a3..de1d4ef15ac 100644 --- a/compiler/rustc_trait_selection/src/traits/engine.rs +++ b/compiler/rustc_trait_selection/src/traits/engine.rs @@ -1,16 +1,6 @@ use std::cell::RefCell; use std::fmt::Debug; -use super::{FromSolverError, TraitEngine}; -use super::{FulfillmentContext, ScrubbedTraitError}; -use crate::error_reporting::InferCtxtErrorExt; -use crate::regions::InferCtxtRegionExt; -use crate::solve::FulfillmentCtxt as NextFulfillmentCtxt; -use crate::solve::NextSolverError; -use crate::traits::fulfill::OldSolverError; -use crate::traits::NormalizeExt; -use crate::traits::StructurallyNormalizeExt; -use crate::traits::{FulfillmentError, Obligation, ObligationCause, PredicateObligation}; use rustc_data_structures::fx::FxIndexSet; use rustc_errors::ErrorGuaranteed; use rustc_hir::def_id::{DefId, LocalDefId}; @@ -19,16 +9,22 @@ use rustc_infer::infer::canonical::{ Canonical, CanonicalQueryResponse, CanonicalVarValues, QueryResponse, }; use rustc_infer::infer::outlives::env::OutlivesEnvironment; -use rustc_infer::infer::RegionResolutionError; -use rustc_infer::infer::{DefineOpaqueTypes, InferCtxt, InferOk}; +use rustc_infer::infer::{DefineOpaqueTypes, InferCtxt, InferOk, RegionResolutionError}; use rustc_macros::extension; use rustc_middle::arena::ArenaAllocatable; use rustc_middle::traits::query::NoSolution; use rustc_middle::ty::error::TypeError; -use rustc_middle::ty::TypeFoldable; -use rustc_middle::ty::Upcast; -use rustc_middle::ty::Variance; -use rustc_middle::ty::{self, Ty, TyCtxt}; +use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, Upcast, Variance}; + +use super::{FromSolverError, FulfillmentContext, ScrubbedTraitError, TraitEngine}; +use crate::error_reporting::InferCtxtErrorExt; +use crate::regions::InferCtxtRegionExt; +use crate::solve::{FulfillmentCtxt as NextFulfillmentCtxt, NextSolverError}; +use crate::traits::fulfill::OldSolverError; +use crate::traits::{ + FulfillmentError, NormalizeExt, Obligation, ObligationCause, PredicateObligation, + StructurallyNormalizeExt, +}; #[extension(pub trait TraitEngineExt<'tcx, E>)] impl<'tcx, E> dyn TraitEngine<'tcx, E> diff --git a/compiler/rustc_trait_selection/src/traits/fulfill.rs b/compiler/rustc_trait_selection/src/traits/fulfill.rs index cc0bb7a60b2..a6db22ec15a 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -1,32 +1,29 @@ -use crate::infer::{InferCtxt, TyOrConstInferVar}; -use crate::traits::normalize::normalize_with_depth_to; +use std::marker::PhantomData; + use rustc_data_structures::captures::Captures; -use rustc_data_structures::obligation_forest::ProcessResult; -use rustc_data_structures::obligation_forest::{Error, ForestObligation, Outcome}; -use rustc_data_structures::obligation_forest::{ObligationForest, ObligationProcessor}; +use rustc_data_structures::obligation_forest::{ + Error, ForestObligation, ObligationForest, ObligationProcessor, Outcome, ProcessResult, +}; use rustc_infer::infer::DefineOpaqueTypes; -use rustc_infer::traits::{FromSolverError, ProjectionCacheKey}; -use rustc_infer::traits::{PolyTraitObligation, SelectionError, TraitEngine}; +use rustc_infer::traits::{ + FromSolverError, PolyTraitObligation, ProjectionCacheKey, SelectionError, TraitEngine, +}; use rustc_middle::bug; use rustc_middle::mir::interpret::ErrorHandled; use rustc_middle::ty::abstract_const::NotConstEvaluatable; use rustc_middle::ty::error::{ExpectedFound, TypeError}; -use rustc_middle::ty::GenericArgsRef; -use rustc_middle::ty::{self, Binder, Const, TypeVisitableExt}; -use std::marker::PhantomData; +use rustc_middle::ty::{self, Binder, Const, GenericArgsRef, TypeVisitableExt}; use super::project::{self, ProjectAndUnifyResult}; use super::select::SelectionContext; -use super::wf; -use super::EvaluationResult; -use super::PredicateObligation; -use super::Unimplemented; -use super::{const_evaluatable, ScrubbedTraitError}; -use super::{FulfillmentError, FulfillmentErrorCode}; - +use super::{ + const_evaluatable, wf, EvaluationResult, FulfillmentError, FulfillmentErrorCode, + PredicateObligation, ScrubbedTraitError, Unimplemented, +}; use crate::error_reporting::InferCtxtErrorExt; -use crate::traits::project::PolyProjectionObligation; -use crate::traits::project::ProjectionCacheKeyExt as _; +use crate::infer::{InferCtxt, TyOrConstInferVar}; +use crate::traits::normalize::normalize_with_depth_to; +use crate::traits::project::{PolyProjectionObligation, ProjectionCacheKeyExt as _}; use crate::traits::query::evaluate_obligation::InferCtxtExt; impl<'tcx> ForestObligation for PendingPredicateObligation<'tcx> { diff --git a/compiler/rustc_trait_selection/src/traits/misc.rs b/compiler/rustc_trait_selection/src/traits/misc.rs index d749b686803..9a127e752a6 100644 --- a/compiler/rustc_trait_selection/src/traits/misc.rs +++ b/compiler/rustc_trait_selection/src/traits/misc.rs @@ -1,8 +1,5 @@ //! Miscellaneous type-system utilities that are too small to deserve their own modules. -use crate::regions::InferCtxtRegionExt; -use crate::traits::{self, FulfillmentError, ObligationCause}; - use hir::LangItem; use rustc_ast::Mutability; use rustc_data_structures::fx::FxIndexSet; @@ -12,6 +9,8 @@ use rustc_infer::infer::{RegionResolutionError, TyCtxtInferExt}; use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt, TypeVisitableExt}; use super::outlives_bounds::InferCtxtExt; +use crate::regions::InferCtxtRegionExt; +use crate::traits::{self, FulfillmentError, ObligationCause}; pub enum CopyImplementationError<'tcx> { InfringingFields(Vec<(&'tcx ty::FieldDef, Ty<'tcx>, InfringingFieldsReason<'tcx>)>), diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index c57ca014799..f7b8d99593e 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -22,51 +22,55 @@ mod util; pub mod vtable; pub mod wf; -use crate::error_reporting::InferCtxtErrorExt; -use crate::infer::outlives::env::OutlivesEnvironment; -use crate::infer::{InferCtxt, TyCtxtInferExt}; -use crate::regions::InferCtxtRegionExt; -use crate::traits::query::evaluate_obligation::InferCtxtExt as _; +use std::fmt::Debug; +use std::ops::ControlFlow; + use rustc_errors::ErrorGuaranteed; +pub use rustc_infer::traits::*; use rustc_middle::query::Providers; use rustc_middle::span_bug; use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::visit::{TypeVisitable, TypeVisitableExt}; -use rustc_middle::ty::{self, Ty, TyCtxt, TypeFolder, TypeSuperVisitable, Upcast}; -use rustc_middle::ty::{GenericArgs, GenericArgsRef}; +use rustc_middle::ty::{ + self, GenericArgs, GenericArgsRef, Ty, TyCtxt, TypeFolder, TypeSuperVisitable, Upcast, +}; use rustc_span::def_id::DefId; use rustc_span::Span; -use std::fmt::Debug; -use std::ops::ControlFlow; - -pub use self::coherence::{add_placeholder_note, orphan_check_trait_ref, overlapping_impls}; -pub use self::coherence::{InCrate, IsFirstInputType, UncoveredTyParams}; -pub use self::coherence::{OrphanCheckErr, OrphanCheckMode, OverlapResult}; +pub use self::coherence::{ + add_placeholder_note, orphan_check_trait_ref, overlapping_impls, InCrate, IsFirstInputType, + OrphanCheckErr, OrphanCheckMode, OverlapResult, UncoveredTyParams, +}; pub use self::engine::{ObligationCtxt, TraitEngineExt}; pub use self::fulfill::{FulfillmentContext, OldSolverError, PendingPredicateObligation}; pub use self::normalize::NormalizeExt; -pub use self::object_safety::hir_ty_lowering_object_safety_violations; -pub use self::object_safety::is_vtable_safe_method; -pub use self::object_safety::object_safety_violations_for_assoc_item; -pub use self::object_safety::ObjectSafetyViolation; +pub use self::object_safety::{ + hir_ty_lowering_object_safety_violations, is_vtable_safe_method, + object_safety_violations_for_assoc_item, ObjectSafetyViolation, +}; pub use self::project::{normalize_inherent_projection, normalize_projection_ty}; -pub use self::select::{EvaluationCache, SelectionCache, SelectionContext}; -pub use self::select::{EvaluationResult, IntercrateAmbiguityCause, OverflowError}; -pub use self::specialize::specialization_graph::FutureCompatOverlapError; -pub use self::specialize::specialization_graph::FutureCompatOverlapErrorKind; +pub use self::select::{ + EvaluationCache, EvaluationResult, IntercrateAmbiguityCause, OverflowError, SelectionCache, + SelectionContext, +}; +pub use self::specialize::specialization_graph::{ + FutureCompatOverlapError, FutureCompatOverlapErrorKind, +}; pub use self::specialize::{ specialization_graph, translate_args, translate_args_with_cause, OverlapError, }; pub use self::structural_normalize::StructurallyNormalizeExt; -pub use self::util::elaborate; -pub use self::util::{expand_trait_aliases, TraitAliasExpander, TraitAliasExpansionInfo}; -pub use self::util::{impl_item_is_final, upcast_choices}; -pub use self::util::{supertraits, transitive_bounds, transitive_bounds_that_define_assoc_item}; -pub use self::util::{with_replaced_escaping_bound_vars, BoundVarReplacer, PlaceholderReplacer}; - -pub use rustc_infer::traits::*; +pub use self::util::{ + elaborate, expand_trait_aliases, impl_item_is_final, supertraits, transitive_bounds, + transitive_bounds_that_define_assoc_item, upcast_choices, with_replaced_escaping_bound_vars, + BoundVarReplacer, PlaceholderReplacer, TraitAliasExpander, TraitAliasExpansionInfo, +}; +use crate::error_reporting::InferCtxtErrorExt; +use crate::infer::outlives::env::OutlivesEnvironment; +use crate::infer::{InferCtxt, TyCtxtInferExt}; +use crate::regions::InferCtxtRegionExt; +use crate::traits::query::evaluate_obligation::InferCtxtExt as _; pub struct FulfillmentError<'tcx> { pub obligation: PredicateObligation<'tcx>, diff --git a/compiler/rustc_trait_selection/src/traits/normalize.rs b/compiler/rustc_trait_selection/src/traits/normalize.rs index 26cb9bb5a3d..81f8633ba95 100644 --- a/compiler/rustc_trait_selection/src/traits/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/normalize.rs @@ -1,20 +1,24 @@ //! Deeply normalize types using the old trait solver. -use super::SelectionContext; -use super::{project, with_replaced_escaping_bound_vars, BoundVarReplacer, PlaceholderReplacer}; -use crate::error_reporting::traits::OverflowCause; -use crate::error_reporting::InferCtxtErrorExt; -use crate::solve::NextSolverError; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_infer::infer::at::At; use rustc_infer::infer::InferOk; -use rustc_infer::traits::FromSolverError; -use rustc_infer::traits::PredicateObligation; -use rustc_infer::traits::{Normalized, Obligation, TraitEngine}; +use rustc_infer::traits::{ + FromSolverError, Normalized, Obligation, PredicateObligation, TraitEngine, +}; use rustc_macros::extension; use rustc_middle::traits::{ObligationCause, ObligationCauseCode, Reveal}; -use rustc_middle::ty::{self, Ty, TyCtxt, TypeFolder}; -use rustc_middle::ty::{TypeFoldable, TypeSuperFoldable, TypeVisitable, TypeVisitableExt}; +use rustc_middle::ty::{ + self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitable, TypeVisitableExt, +}; + +use super::{ + project, with_replaced_escaping_bound_vars, BoundVarReplacer, PlaceholderReplacer, + SelectionContext, +}; +use crate::error_reporting::traits::OverflowCause; +use crate::error_reporting::InferCtxtErrorExt; +use crate::solve::NextSolverError; #[extension(pub trait NormalizeExt<'tcx>)] impl<'tcx> At<'_, 'tcx> { diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index ec19cf27668..8e1fc0d7fe6 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -8,11 +8,9 @@ //! - not reference the erased type `Self` except for in this receiver; //! - not have generic type parameters. -use super::elaborate; +use std::iter; +use std::ops::ControlFlow; -use crate::infer::TyCtxtInferExt; -use crate::traits::query::evaluate_obligation::InferCtxtExt; -use crate::traits::{util, Obligation, ObligationCause}; use rustc_errors::FatalError; use rustc_hir as hir; use rustc_hir::def_id::DefId; @@ -27,9 +25,10 @@ use rustc_span::Span; use rustc_target::abi::Abi; use smallvec::SmallVec; -use std::iter; -use std::ops::ControlFlow; - +use super::elaborate; +use crate::infer::TyCtxtInferExt; +use crate::traits::query::evaluate_obligation::InferCtxtExt; +use crate::traits::{util, Obligation, ObligationCause}; pub use crate::traits::{MethodViolationCode, ObjectSafetyViolation}; /// Returns the object safety violations that affect HIR ty lowering. diff --git a/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs b/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs index 1dc2ebfaa7a..0fe75059904 100644 --- a/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs +++ b/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs @@ -1,15 +1,15 @@ -use crate::infer::InferCtxt; -use crate::traits::{ObligationCause, ObligationCtxt}; use rustc_data_structures::fx::FxIndexSet; use rustc_infer::infer::resolve::OpportunisticRegionResolver; use rustc_infer::infer::InferOk; use rustc_macros::extension; use rustc_middle::infer::canonical::{OriginalQueryValues, QueryRegionConstraints}; use rustc_middle::span_bug; +pub use rustc_middle::traits::query::OutlivesBound; use rustc_middle::ty::{self, ParamEnv, Ty, TypeFolder, TypeVisitableExt}; use rustc_span::def_id::LocalDefId; -pub use rustc_middle::traits::query::OutlivesBound; +use crate::infer::InferCtxt; +use crate::traits::{ObligationCause, ObligationCtxt}; pub type BoundsCompat<'a, 'tcx: 'a> = impl Iterator<Item = OutlivesBound<'tcx>> + 'a; pub type Bounds<'a, 'tcx: 'a> = impl Iterator<Item = OutlivesBound<'tcx>> + 'a; diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index b96e0c8a977..4b62a5c59b2 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -2,29 +2,6 @@ use std::ops::ControlFlow; -use super::specialization_graph; -use super::translate_args; -use super::util; -use super::MismatchedProjectionTypes; -use super::Obligation; -use super::ObligationCause; -use super::PredicateObligation; -use super::Selection; -use super::SelectionContext; -use super::SelectionError; -use super::{Normalized, NormalizedTerm, ProjectionCacheEntry, ProjectionCacheKey}; -use rustc_infer::traits::ObligationCauseCode; -use rustc_middle::traits::BuiltinImplSource; -use rustc_middle::traits::ImplSource; -use rustc_middle::traits::ImplSourceUserDefinedData; -use rustc_middle::{bug, span_bug}; - -use crate::errors::InherentProjectionNormalizationOverflow; -use crate::infer::{BoundRegionConversionTime, InferOk}; -use crate::traits::normalize::normalize_with_depth; -use crate::traits::normalize::normalize_with_depth_to; -use crate::traits::query::evaluate_obligation::InferCtxtExt as _; -use crate::traits::select::ProjectionMatchesProjection; use rustc_data_structures::sso::SsoHashSet; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_errors::ErrorGuaranteed; @@ -32,13 +9,26 @@ use rustc_hir::def::DefKind; use rustc_hir::lang_items::LangItem; use rustc_infer::infer::resolve::OpportunisticRegionResolver; use rustc_infer::infer::DefineOpaqueTypes; +use rustc_infer::traits::ObligationCauseCode; use rustc_middle::traits::select::OverflowError; +pub use rustc_middle::traits::Reveal; +use rustc_middle::traits::{BuiltinImplSource, ImplSource, ImplSourceUserDefinedData}; use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::visit::{MaxUniverse, TypeVisitable, TypeVisitableExt}; use rustc_middle::ty::{self, Term, Ty, TyCtxt, Upcast}; +use rustc_middle::{bug, span_bug}; use rustc_span::symbol::sym; -pub use rustc_middle::traits::Reveal; +use super::{ + specialization_graph, translate_args, util, MismatchedProjectionTypes, Normalized, + NormalizedTerm, Obligation, ObligationCause, PredicateObligation, ProjectionCacheEntry, + ProjectionCacheKey, Selection, SelectionContext, SelectionError, +}; +use crate::errors::InherentProjectionNormalizationOverflow; +use crate::infer::{BoundRegionConversionTime, InferOk}; +use crate::traits::normalize::{normalize_with_depth, normalize_with_depth_to}; +use crate::traits::query::evaluate_obligation::InferCtxtExt as _; +use crate::traits::select::ProjectionMatchesProjection; pub type PolyProjectionObligation<'tcx> = Obligation<'tcx, ty::PolyProjectionPredicate<'tcx>>; diff --git a/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs b/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs index 7dc051e6fe9..37a16a43acd 100644 --- a/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs +++ b/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs @@ -1,12 +1,12 @@ -use crate::traits::query::normalize::QueryNormalizeExt; -use crate::traits::query::NoSolution; -use crate::traits::{Normalized, ObligationCause, ObligationCtxt}; - use rustc_data_structures::fx::FxHashSet; use rustc_middle::traits::query::{DropckConstraint, DropckOutlivesResult}; use rustc_middle::ty::{self, EarlyBinder, ParamEnvAnd, Ty, TyCtxt}; use rustc_span::{Span, DUMMY_SP}; +use crate::traits::query::normalize::QueryNormalizeExt; +use crate::traits::query::NoSolution; +use crate::traits::{Normalized, ObligationCause, ObligationCtxt}; + /// This returns true if the type `ty` is "trivial" for /// dropck-outlives -- that is, if it doesn't require any types to /// outlive. This is similar but not *quite* the same as the diff --git a/compiler/rustc_trait_selection/src/traits/query/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/normalize.rs index 75f1af7fcf5..247b6e4823c 100644 --- a/compiler/rustc_trait_selection/src/traits/query/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/normalize.rs @@ -2,26 +2,26 @@ //! which folds deeply, invoking the underlying //! `normalize_canonicalized_projection_ty` query when it encounters projections. -use crate::error_reporting::traits::OverflowCause; -use crate::error_reporting::InferCtxtErrorExt; -use crate::infer::at::At; -use crate::infer::canonical::OriginalQueryValues; -use crate::infer::{InferCtxt, InferOk}; -use crate::traits::normalize::needs_normalization; -use crate::traits::Normalized; -use crate::traits::{BoundVarReplacer, PlaceholderReplacer, ScrubbedTraitError}; -use crate::traits::{ObligationCause, PredicateObligation, Reveal}; use rustc_data_structures::sso::SsoHashMap; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_macros::extension; +pub use rustc_middle::traits::query::NormalizationResult; use rustc_middle::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeSuperFoldable}; use rustc_middle::ty::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitableExt}; use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitor}; use rustc_span::DUMMY_SP; use super::NoSolution; - -pub use rustc_middle::traits::query::NormalizationResult; +use crate::error_reporting::traits::OverflowCause; +use crate::error_reporting::InferCtxtErrorExt; +use crate::infer::at::At; +use crate::infer::canonical::OriginalQueryValues; +use crate::infer::{InferCtxt, InferOk}; +use crate::traits::normalize::needs_normalization; +use crate::traits::{ + BoundVarReplacer, Normalized, ObligationCause, PlaceholderReplacer, PredicateObligation, + Reveal, ScrubbedTraitError, +}; #[extension(pub trait QueryNormalizeExt<'tcx>)] impl<'cx, 'tcx> At<'cx, 'tcx> { diff --git a/compiler/rustc_trait_selection/src/traits/query/type_op/ascribe_user_type.rs b/compiler/rustc_trait_selection/src/traits/query/type_op/ascribe_user_type.rs index aca16950223..5e4de43d04f 100644 --- a/compiler/rustc_trait_selection/src/traits/query/type_op/ascribe_user_type.rs +++ b/compiler/rustc_trait_selection/src/traits/query/type_op/ascribe_user_type.rs @@ -1,14 +1,14 @@ -use crate::infer::canonical::{Canonical, CanonicalQueryResponse}; -use crate::traits::ObligationCtxt; use rustc_hir::def_id::{DefId, CRATE_DEF_ID}; use rustc_infer::traits::Obligation; +pub use rustc_middle::traits::query::type_op::AscribeUserType; use rustc_middle::traits::query::NoSolution; use rustc_middle::traits::{ObligationCause, ObligationCauseCode}; use rustc_middle::ty::{self, ParamEnvAnd, Ty, TyCtxt, UserArgs, UserSelfTy, UserType}; - -pub use rustc_middle::traits::query::type_op::AscribeUserType; use rustc_span::{Span, DUMMY_SP}; +use crate::infer::canonical::{Canonical, CanonicalQueryResponse}; +use crate::traits::ObligationCtxt; + impl<'tcx> super::QueryTypeOp<'tcx> for AscribeUserType<'tcx> { type QueryResponse = (); diff --git a/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs b/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs index d533e69a4fa..34e678e93d1 100644 --- a/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs +++ b/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs @@ -1,14 +1,15 @@ -use crate::infer::canonical::query_response; -use crate::infer::InferCtxt; -use crate::traits::query::type_op::TypeOpOutput; -use crate::traits::ObligationCtxt; +use std::fmt; + use rustc_errors::ErrorGuaranteed; use rustc_infer::infer::region_constraints::RegionConstraintData; use rustc_middle::traits::query::NoSolution; use rustc_middle::ty::{TyCtxt, TypeFoldable}; use rustc_span::Span; -use std::fmt; +use crate::infer::canonical::query_response; +use crate::infer::InferCtxt; +use crate::traits::query::type_op::TypeOpOutput; +use crate::traits::ObligationCtxt; pub struct CustomTypeOp<F> { closure: F, diff --git a/compiler/rustc_trait_selection/src/traits/query/type_op/eq.rs b/compiler/rustc_trait_selection/src/traits/query/type_op/eq.rs index 57e649f3e43..656130cda19 100644 --- a/compiler/rustc_trait_selection/src/traits/query/type_op/eq.rs +++ b/compiler/rustc_trait_selection/src/traits/query/type_op/eq.rs @@ -1,10 +1,10 @@ -use crate::infer::canonical::{Canonical, CanonicalQueryResponse}; -use crate::traits::ObligationCtxt; +pub use rustc_middle::traits::query::type_op::Eq; use rustc_middle::traits::query::NoSolution; use rustc_middle::traits::ObligationCause; use rustc_middle::ty::{ParamEnvAnd, TyCtxt}; -pub use rustc_middle::traits::query::type_op::Eq; +use crate::infer::canonical::{Canonical, CanonicalQueryResponse}; +use crate::traits::ObligationCtxt; impl<'tcx> super::QueryTypeOp<'tcx> for Eq<'tcx> { type QueryResponse = (); diff --git a/compiler/rustc_trait_selection/src/traits/query/type_op/implied_outlives_bounds.rs b/compiler/rustc_trait_selection/src/traits/query/type_op/implied_outlives_bounds.rs index 8525215a3bc..b5b209c1af7 100644 --- a/compiler/rustc_trait_selection/src/traits/query/type_op/implied_outlives_bounds.rs +++ b/compiler/rustc_trait_selection/src/traits/query/type_op/implied_outlives_bounds.rs @@ -1,7 +1,3 @@ -use crate::traits::query::NoSolution; -use crate::traits::wf; -use crate::traits::ObligationCtxt; - use rustc_infer::infer::canonical::Canonical; use rustc_infer::infer::resolve::OpportunisticRegionResolver; use rustc_infer::traits::query::OutlivesBound; @@ -14,6 +10,9 @@ use rustc_span::DUMMY_SP; use rustc_type_ir::outlives::{push_outlives_components, Component}; use smallvec::{smallvec, SmallVec}; +use crate::traits::query::NoSolution; +use crate::traits::{wf, ObligationCtxt}; + #[derive(Copy, Clone, Debug, HashStable, TypeFoldable, TypeVisitable)] pub struct ImpliedOutlivesBounds<'tcx> { pub ty: Ty<'tcx>, diff --git a/compiler/rustc_trait_selection/src/traits/query/type_op/mod.rs b/compiler/rustc_trait_selection/src/traits/query/type_op/mod.rs index c1b1bfd300b..2f64ed963f9 100644 --- a/compiler/rustc_trait_selection/src/traits/query/type_op/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/query/type_op/mod.rs @@ -1,8 +1,5 @@ -use crate::infer::canonical::{ - Canonical, CanonicalQueryResponse, OriginalQueryValues, QueryRegionConstraints, -}; -use crate::infer::{InferCtxt, InferOk}; -use crate::traits::{ObligationCause, ObligationCtxt}; +use std::fmt; + use rustc_errors::ErrorGuaranteed; use rustc_infer::infer::canonical::Certainty; use rustc_infer::traits::PredicateObligation; @@ -10,7 +7,12 @@ use rustc_middle::traits::query::NoSolution; use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::{ParamEnvAnd, TyCtxt}; use rustc_span::Span; -use std::fmt; + +use crate::infer::canonical::{ + Canonical, CanonicalQueryResponse, OriginalQueryValues, QueryRegionConstraints, +}; +use crate::infer::{InferCtxt, InferOk}; +use crate::traits::{ObligationCause, ObligationCtxt}; pub mod ascribe_user_type; pub mod custom; diff --git a/compiler/rustc_trait_selection/src/traits/query/type_op/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/type_op/normalize.rs index e9948bf1f71..41c34f6da29 100644 --- a/compiler/rustc_trait_selection/src/traits/query/type_op/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/type_op/normalize.rs @@ -1,12 +1,13 @@ -use crate::infer::canonical::{Canonical, CanonicalQueryResponse}; -use crate::traits::ObligationCtxt; +use std::fmt; + +pub use rustc_middle::traits::query::type_op::Normalize; use rustc_middle::traits::query::NoSolution; use rustc_middle::traits::ObligationCause; use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::{self, Lift, ParamEnvAnd, Ty, TyCtxt, TypeVisitableExt}; -use std::fmt; -pub use rustc_middle::traits::query::type_op::Normalize; +use crate::infer::canonical::{Canonical, CanonicalQueryResponse}; +use crate::traits::ObligationCtxt; impl<'tcx, T> super::QueryTypeOp<'tcx> for Normalize<T> where diff --git a/compiler/rustc_trait_selection/src/traits/query/type_op/outlives.rs b/compiler/rustc_trait_selection/src/traits/query/type_op/outlives.rs index 3e7aa52dcfe..49d324fa62e 100644 --- a/compiler/rustc_trait_selection/src/traits/query/type_op/outlives.rs +++ b/compiler/rustc_trait_selection/src/traits/query/type_op/outlives.rs @@ -1,11 +1,12 @@ +use rustc_macros::{HashStable, TypeFoldable, TypeVisitable}; +use rustc_middle::traits::query::{DropckOutlivesResult, NoSolution}; +use rustc_middle::ty::{ParamEnvAnd, Ty, TyCtxt}; + use crate::infer::canonical::{Canonical, CanonicalQueryResponse}; use crate::traits::query::dropck_outlives::{ compute_dropck_outlives_inner, trivial_dropck_outlives, }; use crate::traits::ObligationCtxt; -use rustc_macros::{HashStable, TypeFoldable, TypeVisitable}; -use rustc_middle::traits::query::{DropckOutlivesResult, NoSolution}; -use rustc_middle::ty::{ParamEnvAnd, Ty, TyCtxt}; #[derive(Copy, Clone, Debug, HashStable, TypeFoldable, TypeVisitable)] pub struct DropckOutlives<'tcx> { diff --git a/compiler/rustc_trait_selection/src/traits/query/type_op/prove_predicate.rs b/compiler/rustc_trait_selection/src/traits/query/type_op/prove_predicate.rs index 63289746f5e..294c6bfc124 100644 --- a/compiler/rustc_trait_selection/src/traits/query/type_op/prove_predicate.rs +++ b/compiler/rustc_trait_selection/src/traits/query/type_op/prove_predicate.rs @@ -1,11 +1,11 @@ -use crate::infer::canonical::{Canonical, CanonicalQueryResponse}; -use crate::traits::ObligationCtxt; use rustc_infer::traits::Obligation; +pub use rustc_middle::traits::query::type_op::ProvePredicate; use rustc_middle::traits::query::NoSolution; use rustc_middle::traits::ObligationCause; use rustc_middle::ty::{self, ParamEnvAnd, TyCtxt}; -pub use rustc_middle::traits::query::type_op::ProvePredicate; +use crate::infer::canonical::{Canonical, CanonicalQueryResponse}; +use crate::traits::ObligationCtxt; impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> { type QueryResponse = (); diff --git a/compiler/rustc_trait_selection/src/traits/query/type_op/subtype.rs b/compiler/rustc_trait_selection/src/traits/query/type_op/subtype.rs index ae11b0825bd..892c2a1f113 100644 --- a/compiler/rustc_trait_selection/src/traits/query/type_op/subtype.rs +++ b/compiler/rustc_trait_selection/src/traits/query/type_op/subtype.rs @@ -1,10 +1,10 @@ -use crate::infer::canonical::{Canonical, CanonicalQueryResponse}; -use crate::traits::ObligationCtxt; +pub use rustc_middle::traits::query::type_op::Subtype; use rustc_middle::traits::query::NoSolution; use rustc_middle::traits::ObligationCause; use rustc_middle::ty::{ParamEnvAnd, TyCtxt}; -pub use rustc_middle::traits::query::type_op::Subtype; +use crate::infer::canonical::{Canonical, CanonicalQueryResponse}; +use crate::traits::ObligationCtxt; impl<'tcx> super::QueryTypeOp<'tcx> for Subtype<'tcx> { type QueryResponse = (); diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index 06b79ea63ca..2085d3da443 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -12,20 +12,17 @@ use hir::def_id::DefId; use hir::LangItem; use rustc_data_structures::fx::{FxHashSet, FxIndexSet}; use rustc_hir as hir; -use rustc_infer::traits::ObligationCause; -use rustc_infer::traits::{Obligation, PolyTraitObligation, SelectionError}; +use rustc_infer::traits::{Obligation, ObligationCause, PolyTraitObligation, SelectionError}; use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams}; use rustc_middle::ty::{self, ToPolyTraitRef, Ty, TypeVisitableExt}; use rustc_middle::{bug, span_bug}; +use super::SelectionCandidate::*; +use super::{BuiltinImplConditions, SelectionCandidateSet, SelectionContext, TraitObligationStack}; use crate::traits; use crate::traits::query::evaluate_obligation::InferCtxtExt; use crate::traits::util; -use super::BuiltinImplConditions; -use super::SelectionCandidate::*; -use super::{SelectionCandidateSet, SelectionContext, TraitObligationStack}; - impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { #[instrument(skip(self, stack), level = "debug")] pub(super) fn assemble_candidates<'o>( diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 9508a3e8e15..ddd8b970cc8 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -7,11 +7,13 @@ //! [rustc dev guide]: //! https://rustc-dev-guide.rust-lang.org/traits/resolution.html#confirmation +use std::iter; +use std::ops::ControlFlow; + use rustc_ast::Mutability; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_hir::lang_items::LangItem; -use rustc_infer::infer::HigherRankedType; -use rustc_infer::infer::{DefineOpaqueTypes, InferOk}; +use rustc_infer::infer::{DefineOpaqueTypes, HigherRankedType, InferOk}; use rustc_infer::traits::ObligationCauseCode; use rustc_middle::traits::{BuiltinImplSource, SignatureMismatchData}; use rustc_middle::ty::{ @@ -21,6 +23,8 @@ use rustc_middle::ty::{ use rustc_middle::{bug, span_bug}; use rustc_span::def_id::DefId; +use super::SelectionCandidate::{self, *}; +use super::{BuiltinImplConditions, SelectionContext}; use crate::traits::normalize::{normalize_with_depth, normalize_with_depth_to}; use crate::traits::util::{self, closure_trait_ref_and_return_type}; use crate::traits::{ @@ -29,13 +33,6 @@ use crate::traits::{ SignatureMismatch, TraitNotObjectSafe, TraitObligation, Unimplemented, }; -use super::BuiltinImplConditions; -use super::SelectionCandidate::{self, *}; -use super::SelectionContext; - -use std::iter; -use std::ops::ControlFlow; - impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { #[instrument(level = "debug", skip(self))] pub(super) fn confirm_candidate( diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 699c05466bd..cc9174d3aad 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -2,31 +2,11 @@ //! //! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/resolution.html#selection -use self::EvaluationResult::*; -use self::SelectionCandidate::*; - -use super::coherence::{self, Conflict}; -use super::const_evaluatable; -use super::project; -use super::project::ProjectionTermObligation; -use super::util; -use super::util::closure_trait_ref_and_return_type; -use super::wf; -use super::{ - ImplDerivedCause, Normalized, Obligation, ObligationCause, ObligationCauseCode, Overflow, - PolyTraitObligation, PredicateObligation, Selection, SelectionError, SelectionResult, - TraitQueryMode, -}; +use std::cell::{Cell, RefCell}; +use std::fmt::{self, Display}; +use std::ops::ControlFlow; +use std::{cmp, iter}; -use crate::error_reporting::InferCtxtErrorExt; -use crate::infer::{InferCtxt, InferCtxtExt, InferOk, TypeFreshener}; -use crate::solve::InferCtxtSelectExt as _; -use crate::traits::normalize::normalize_with_depth; -use crate::traits::normalize::normalize_with_depth_to; -use crate::traits::project::ProjectAndUnifyResult; -use crate::traits::project::ProjectionCacheKeyExt; -use crate::traits::ProjectionCacheKey; -use crate::traits::Unimplemented; use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet}; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_errors::{Diag, EmissionGuarantee}; @@ -34,31 +14,39 @@ use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_hir::LangItem; use rustc_infer::infer::relate::TypeRelation; -use rustc_infer::infer::BoundRegionConversionTime; use rustc_infer::infer::BoundRegionConversionTime::HigherRankedType; -use rustc_infer::infer::DefineOpaqueTypes; +use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes}; use rustc_infer::traits::TraitObligation; use rustc_middle::bug; -use rustc_middle::dep_graph::dep_kinds; -use rustc_middle::dep_graph::DepNodeIndex; +use rustc_middle::dep_graph::{dep_kinds, DepNodeIndex}; use rustc_middle::mir::interpret::ErrorHandled; +pub use rustc_middle::traits::select::*; use rustc_middle::ty::abstract_const::NotConstEvaluatable; use rustc_middle::ty::error::TypeErrorToStringExt; -use rustc_middle::ty::print::PrintTraitRefExt as _; -use rustc_middle::ty::GenericArgsRef; -use rustc_middle::ty::{self, PolyProjectionPredicate, Upcast}; -use rustc_middle::ty::{Ty, TyCtxt, TypeFoldable, TypeVisitableExt}; +use rustc_middle::ty::print::{with_no_trimmed_paths, PrintTraitRefExt as _}; +use rustc_middle::ty::{ + self, GenericArgsRef, PolyProjectionPredicate, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, + Upcast, +}; use rustc_span::symbol::sym; use rustc_span::Symbol; -use std::cell::{Cell, RefCell}; -use std::cmp; -use std::fmt::{self, Display}; -use std::iter; -use std::ops::ControlFlow; - -pub use rustc_middle::traits::select::*; -use rustc_middle::ty::print::with_no_trimmed_paths; +use self::EvaluationResult::*; +use self::SelectionCandidate::*; +use super::coherence::{self, Conflict}; +use super::project::ProjectionTermObligation; +use super::util::closure_trait_ref_and_return_type; +use super::{ + const_evaluatable, project, util, wf, ImplDerivedCause, Normalized, Obligation, + ObligationCause, ObligationCauseCode, Overflow, PolyTraitObligation, PredicateObligation, + Selection, SelectionError, SelectionResult, TraitQueryMode, +}; +use crate::error_reporting::InferCtxtErrorExt; +use crate::infer::{InferCtxt, InferCtxtExt, InferOk, TypeFreshener}; +use crate::solve::InferCtxtSelectExt as _; +use crate::traits::normalize::{normalize_with_depth, normalize_with_depth_to}; +use crate::traits::project::{ProjectAndUnifyResult, ProjectionCacheKeyExt}; +use crate::traits::{ProjectionCacheKey, Unimplemented}; mod _match; mod candidate_assembly; diff --git a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs index 3c33d13567d..4c8c5a2eb17 100644 --- a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs @@ -10,28 +10,25 @@ //! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/specialization.html pub mod specialization_graph; +use rustc_data_structures::fx::FxIndexSet; +use rustc_errors::codes::*; +use rustc_errors::{Diag, EmissionGuarantee}; +use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_infer::infer::DefineOpaqueTypes; +use rustc_middle::bug; +use rustc_middle::query::LocalCrate; use rustc_middle::ty::print::PrintTraitRefExt as _; +use rustc_middle::ty::{self, GenericArgsRef, ImplSubject, Ty, TyCtxt, TypeVisitableExt}; +use rustc_session::lint::builtin::{COHERENCE_LEAK_CHECK, ORDER_DEPENDENT_TRAIT_OBJECTS}; +use rustc_span::{sym, ErrorGuaranteed, Span, DUMMY_SP}; use specialization_graph::GraphExt; +use super::{util, SelectionContext}; use crate::error_reporting::traits::to_pretty_impl_header; use crate::errors::NegativePositiveConflict; use crate::infer::{InferCtxt, InferOk, TyCtxtInferExt}; use crate::traits::select::IntercrateAmbiguityCause; use crate::traits::{coherence, FutureCompatOverlapErrorKind, ObligationCause, ObligationCtxt}; -use rustc_data_structures::fx::FxIndexSet; -use rustc_errors::{codes::*, Diag, EmissionGuarantee}; -use rustc_hir::def_id::{DefId, LocalDefId}; -use rustc_middle::bug; -use rustc_middle::query::LocalCrate; -use rustc_middle::ty::GenericArgsRef; -use rustc_middle::ty::{self, ImplSubject, Ty, TyCtxt, TypeVisitableExt}; -use rustc_session::lint::builtin::COHERENCE_LEAK_CHECK; -use rustc_session::lint::builtin::ORDER_DEPENDENT_TRAIT_OBJECTS; -use rustc_span::{sym, ErrorGuaranteed, Span, DUMMY_SP}; - -use super::util; -use super::SelectionContext; /// Information pertinent to an overlapping impl error. #[derive(Debug)] diff --git a/compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs b/compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs index 90f2c7ad213..732f1b0a3d7 100644 --- a/compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs +++ b/compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs @@ -1,14 +1,13 @@ -use super::OverlapError; - -use crate::traits; use rustc_errors::ErrorGuaranteed; use rustc_hir::def_id::DefId; use rustc_macros::extension; use rustc_middle::bug; +pub use rustc_middle::traits::specialization_graph::*; use rustc_middle::ty::fast_reject::{self, SimplifiedType, TreatParams}; use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt}; -pub use rustc_middle::traits::specialization_graph::*; +use super::OverlapError; +use crate::traits; #[derive(Copy, Clone, Debug)] pub enum FutureCompatOverlapErrorKind { diff --git a/compiler/rustc_trait_selection/src/traits/util.rs b/compiler/rustc_trait_selection/src/traits/util.rs index 951af4b0920..52f87699b16 100644 --- a/compiler/rustc_trait_selection/src/traits/util.rs +++ b/compiler/rustc_trait_selection/src/traits/util.rs @@ -1,19 +1,19 @@ use std::collections::BTreeMap; -use super::NormalizeExt; -use super::{ObligationCause, PredicateObligation, SelectionContext}; use rustc_data_structures::fx::FxIndexMap; use rustc_errors::Diag; use rustc_hir::def_id::DefId; use rustc_infer::infer::{InferCtxt, InferOk}; +pub use rustc_infer::traits::util::*; use rustc_middle::bug; -use rustc_middle::ty::GenericArgsRef; -use rustc_middle::ty::{self, ImplSubject, Ty, TyCtxt, TypeVisitableExt, Upcast}; -use rustc_middle::ty::{TypeFoldable, TypeFolder, TypeSuperFoldable}; +use rustc_middle::ty::{ + self, GenericArgsRef, ImplSubject, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, + TypeVisitableExt, Upcast, +}; use rustc_span::Span; use smallvec::{smallvec, SmallVec}; -pub use rustc_infer::traits::util::*; +use super::{NormalizeExt, ObligationCause, PredicateObligation, SelectionContext}; /////////////////////////////////////////////////////////////////////////// // `TraitAliasExpander` iterator diff --git a/compiler/rustc_trait_selection/src/traits/vtable.rs b/compiler/rustc_trait_selection/src/traits/vtable.rs index 4645d828461..1729d8d307a 100644 --- a/compiler/rustc_trait_selection/src/traits/vtable.rs +++ b/compiler/rustc_trait_selection/src/traits/vtable.rs @@ -1,16 +1,18 @@ -use crate::errors::DumpVTableEntries; -use crate::traits::{impossible_predicates, is_vtable_safe_method}; +use std::fmt::Debug; +use std::ops::ControlFlow; + use rustc_hir::def_id::DefId; use rustc_infer::traits::util::PredicateSet; use rustc_middle::bug; use rustc_middle::query::Providers; -use rustc_middle::ty::{self, GenericParamDefKind, Ty, TyCtxt, Upcast, VtblEntry}; -use rustc_middle::ty::{GenericArgs, TypeVisitableExt}; +use rustc_middle::ty::{ + self, GenericArgs, GenericParamDefKind, Ty, TyCtxt, TypeVisitableExt, Upcast, VtblEntry, +}; use rustc_span::{sym, Span, DUMMY_SP}; use smallvec::{smallvec, SmallVec}; -use std::fmt::Debug; -use std::ops::ControlFlow; +use crate::errors::DumpVTableEntries; +use crate::traits::{impossible_predicates, is_vtable_safe_method}; #[derive(Clone, Debug)] pub enum VtblSegment<'tcx> { diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index e77a05dd8e6..7e5fe7e3c94 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -1,17 +1,18 @@ -use crate::infer::InferCtxt; -use crate::traits; +use std::iter; + use rustc_hir as hir; use rustc_hir::lang_items::LangItem; use rustc_infer::traits::ObligationCauseCode; use rustc_middle::bug; use rustc_middle::ty::{ - self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, + self, GenericArg, GenericArgKind, GenericArgsRef, Ty, TyCtxt, TypeSuperVisitable, + TypeVisitable, TypeVisitableExt, TypeVisitor, }; -use rustc_middle::ty::{GenericArg, GenericArgKind, GenericArgsRef}; use rustc_span::def_id::{DefId, LocalDefId, CRATE_DEF_ID}; use rustc_span::{Span, DUMMY_SP}; -use std::iter; +use crate::infer::InferCtxt; +use crate::traits; /// Returns the set of obligations needed to make `arg` well-formed. /// If `arg` contains unresolved inference variables, this may include /// further WF obligations. However, if `arg` IS an unresolved |
