diff options
| author | Michael Goulet <michael@errs.io> | 2024-05-09 20:05:59 -0400 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2024-05-10 10:42:56 -0400 |
| commit | 4bde8a8f4b039c44baae49dea2f728a28d152122 (patch) | |
| tree | 9449a2c31786b9b8713cd5edf36e1a2bae8f2b72 /compiler/rustc_trait_selection/src | |
| parent | 04c049498d8c24b890bc22f8ee2d541d5e4ee2f6 (diff) | |
| download | rust-4bde8a8f4b039c44baae49dea2f728a28d152122.tar.gz rust-4bde8a8f4b039c44baae49dea2f728a28d152122.zip | |
Remove glob imports for ObligationCauseCode
Diffstat (limited to 'compiler/rustc_trait_selection/src')
5 files changed, 59 insertions, 52 deletions
diff --git a/compiler/rustc_trait_selection/src/solve/fulfill.rs b/compiler/rustc_trait_selection/src/solve/fulfill.rs index f92b1eb88cd..893a6428a5e 100644 --- a/compiler/rustc_trait_selection/src/solve/fulfill.rs +++ b/compiler/rustc_trait_selection/src/solve/fulfill.rs @@ -7,7 +7,7 @@ use rustc_infer::traits::solve::inspect::ProbeKind; use rustc_infer::traits::solve::{CandidateSource, GoalSource, MaybeCause}; use rustc_infer::traits::{ self, FulfillmentError, FulfillmentErrorCode, MismatchedProjectionTypes, Obligation, - ObligationCause, PredicateObligation, SelectionError, TraitEngine, + ObligationCause, ObligationCauseCode, PredicateObligation, SelectionError, TraitEngine, }; use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::{self, TyCtxt}; @@ -425,17 +425,20 @@ fn derive_cause<'tcx>( tcx.predicates_of(impl_def_id).instantiate_identity(tcx).iter().nth(idx) { cause = cause.derived_cause(parent_trait_pred, |derived| { - traits::ImplDerivedObligation(Box::new(traits::ImplDerivedObligationCause { - derived, - impl_or_alias_def_id: impl_def_id, - impl_def_predicate_index: Some(idx), - span, - })) + ObligationCauseCode::ImplDerivedObligation(Box::new( + traits::ImplDerivedObligationCause { + derived, + impl_or_alias_def_id: impl_def_id, + impl_def_predicate_index: Some(idx), + span, + }, + )) }) } } ProbeKind::TraitCandidate { source: CandidateSource::BuiltinImpl(..), result: _ } => { - cause = cause.derived_cause(parent_trait_pred, traits::BuiltinDerivedObligation); + cause = cause + .derived_cause(parent_trait_pred, ObligationCauseCode::BuiltinDerivedObligation); } _ => {} }; diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index 587f2f72207..0ef007e30f1 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -13,6 +13,7 @@ use super::Selection; use super::SelectionContext; use super::SelectionError; use super::{Normalized, NormalizedTy, ProjectionCacheEntry, ProjectionCacheKey}; +use rustc_infer::traits::ObligationCauseCode; use rustc_middle::traits::BuiltinImplSource; use rustc_middle::traits::ImplSource; use rustc_middle::traits::ImplSourceUserDefinedData; @@ -573,9 +574,9 @@ pub fn normalize_inherent_projection<'a, 'b, 'tcx>( // diagnostics which is not ideal. // Consider creating separate cause codes for this specific situation. if span.is_dummy() { - super::ItemObligation(alias_ty.def_id) + ObligationCauseCode::ItemObligation(alias_ty.def_id) } else { - super::BindingObligation(alias_ty.def_id, span) + ObligationCauseCode::BindingObligation(alias_ty.def_id, span) }, ); @@ -2113,22 +2114,22 @@ fn assoc_ty_own_obligations<'cx, 'tcx>( let nested_cause = if matches!( obligation.cause.code(), - super::CompareImplItemObligation { .. } - | super::CheckAssociatedTypeBounds { .. } - | super::AscribeUserTypeProvePredicate(..) + ObligationCauseCode::CompareImplItemObligation { .. } + | ObligationCauseCode::CheckAssociatedTypeBounds { .. } + | ObligationCauseCode::AscribeUserTypeProvePredicate(..) ) { obligation.cause.clone() } else if span.is_dummy() { ObligationCause::new( obligation.cause.span, obligation.cause.body_id, - super::ItemObligation(obligation.predicate.def_id), + ObligationCauseCode::ItemObligation(obligation.predicate.def_id), ) } else { ObligationCause::new( obligation.cause.span, obligation.cause.body_id, - super::BindingObligation(obligation.predicate.def_id, span), + ObligationCauseCode::BindingObligation(obligation.predicate.def_id, span), ) }; nested.push(Obligation::with_depth( diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 22e0ee38344..3746e56b7c9 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -11,6 +11,7 @@ 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::traits::ObligationCauseCode; use rustc_middle::traits::{BuiltinImplSource, SignatureMismatchData}; use rustc_middle::ty::{ self, GenericArgs, GenericArgsRef, GenericParamDefKind, ToPolyTraitRef, ToPredicate, @@ -25,10 +26,9 @@ use crate::traits::vtable::{ VtblSegment, }; use crate::traits::{ - BuiltinDerivedObligation, ImplDerivedObligation, ImplDerivedObligationCause, ImplSource, - ImplSourceUserDefinedData, Normalized, Obligation, ObligationCause, PolyTraitObligation, - PredicateObligation, Selection, SelectionError, SignatureMismatch, TraitNotObjectSafe, - TraitObligation, Unimplemented, + ImplDerivedObligationCause, ImplSource, ImplSourceUserDefinedData, Normalized, Obligation, + ObligationCause, PolyTraitObligation, PredicateObligation, Selection, SelectionError, + SignatureMismatch, TraitNotObjectSafe, TraitObligation, Unimplemented, }; use super::BuiltinImplConditions; @@ -275,7 +275,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { bug!("obligation {:?} had matched a builtin impl but now doesn't", obligation); }; - let cause = obligation.derived_cause(BuiltinDerivedObligation); + let cause = obligation.derived_cause(ObligationCauseCode::BuiltinDerivedObligation); self.collect_predicates_for_types( obligation.param_env, cause, @@ -435,7 +435,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ) -> Vec<PredicateObligation<'tcx>> { debug!(?nested, "vtable_auto_impl"); ensure_sufficient_stack(|| { - let cause = obligation.derived_cause(BuiltinDerivedObligation); + let cause = obligation.derived_cause(ObligationCauseCode::BuiltinDerivedObligation); let poly_trait_ref = obligation.predicate.to_poly_trait_ref(); let trait_ref = self.infcx.enter_forall_and_leak_universe(poly_trait_ref); @@ -723,7 +723,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let mut nested = self.equate_trait_refs(obligation.with(tcx, placeholder_predicate), trait_ref)?; - let cause = obligation.derived_cause(BuiltinDerivedObligation); + let cause = obligation.derived_cause(ObligationCauseCode::BuiltinDerivedObligation); // Confirm the `type Output: Sized;` bound that is present on `FnOnce` let output_ty = self.infcx.enter_forall_and_leak_universe(sig.output()); @@ -1381,7 +1381,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let self_ty = obligation.self_ty().map_bound(|ty| self.infcx.shallow_resolve(ty)); let mut nested = vec![]; - let cause = obligation.derived_cause(BuiltinDerivedObligation); + let cause = obligation.derived_cause(ObligationCauseCode::BuiltinDerivedObligation); // If we have a custom `impl const Drop`, then // first check it like a regular impl candidate. @@ -1396,7 +1396,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { debug!(?args, "impl args"); let cause = obligation.derived_cause(|derived| { - ImplDerivedObligation(Box::new(ImplDerivedObligationCause { + ObligationCauseCode::ImplDerivedObligation(Box::new(ImplDerivedObligationCause { derived, impl_or_alias_def_id: impl_def_id, impl_def_predicate_index: None, diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index dc005982695..f9246d22bfe 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -13,9 +13,9 @@ use super::util; use super::util::closure_trait_ref_and_return_type; use super::wf; use super::{ - ImplDerivedObligation, ImplDerivedObligationCause, Normalized, Obligation, ObligationCause, - ObligationCauseCode, Overflow, PolyTraitObligation, PredicateObligation, Selection, - SelectionError, SelectionResult, TraitQueryMode, + ImplDerivedObligationCause, Normalized, Obligation, ObligationCause, ObligationCauseCode, + Overflow, PolyTraitObligation, PredicateObligation, Selection, SelectionError, SelectionResult, + TraitQueryMode, }; use crate::infer::{InferCtxt, InferOk, TypeFreshener}; @@ -2771,12 +2771,14 @@ impl<'tcx> SelectionContext<'_, 'tcx> { cause.clone() } else { cause.clone().derived_cause(parent_trait_pred, |derived| { - ImplDerivedObligation(Box::new(ImplDerivedObligationCause { - derived, - impl_or_alias_def_id: def_id, - impl_def_predicate_index: Some(index), - span, - })) + ObligationCauseCode::ImplDerivedObligation(Box::new( + ImplDerivedObligationCause { + derived, + impl_or_alias_def_id: def_id, + impl_def_predicate_index: Some(index), + span, + }, + )) }) }; let clause = normalize_with_depth_to( diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index 28ee76f7145..44c70f2be00 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -2,6 +2,7 @@ use crate::infer::InferCtxt; use crate::traits; use rustc_hir as hir; use rustc_hir::lang_items::LangItem; +use rustc_infer::traits::ObligationCauseCode; use rustc_middle::ty::{ self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, }; @@ -333,7 +334,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { return self.out; } - let cause = self.cause(traits::WellFormed(None)); + let cause = self.cause(ObligationCauseCode::WellFormed(None)); let param_env = self.param_env; let mut obligations = Vec::with_capacity(self.out.len()); for mut obligation in self.out { @@ -485,7 +486,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { &mut traits::SelectionContext::new(self.infcx), self.param_env, data, - self.cause(traits::WellFormed(None)), + self.cause(ObligationCauseCode::WellFormed(None)), self.recursion_depth, &mut self.out, ); @@ -498,7 +499,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { fn compute_projection_args(&mut self, args: GenericArgsRef<'tcx>) { let tcx = self.tcx(); - let cause = self.cause(traits::WellFormed(None)); + let cause = self.cause(ObligationCauseCode::WellFormed(None)); let param_env = self.param_env; let depth = self.recursion_depth; @@ -565,9 +566,9 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { iter::zip(predicates, origins.into_iter().rev()) .map(|((pred, span), origin_def_id)| { let code = if span.is_dummy() { - traits::ItemObligation(origin_def_id) + ObligationCauseCode::ItemObligation(origin_def_id) } else { - traits::BindingObligation(origin_def_id, span) + ObligationCauseCode::BindingObligation(origin_def_id, span) }; let cause = self.cause(code); traits::Obligation::with_depth( @@ -626,7 +627,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { self.out.reserve(implicit_bounds.len()); for implicit_bound in implicit_bounds { - let cause = self.cause(traits::ObjectTypeBound(ty, explicit_bound)); + let cause = self.cause(ObligationCauseCode::ObjectTypeBound(ty, explicit_bound)); let outlives = ty::Binder::dummy(ty::OutlivesPredicate(explicit_bound, implicit_bound)); self.out.push(traits::Obligation::with_depth( @@ -644,7 +645,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> { type Result = (); - fn visit_ty(&mut self, t: <TyCtxt<'tcx> as ty::Interner>::Ty) -> Self::Result { + fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result { debug!("wf bounds for t={:?} t.kind={:#?}", t, t.kind()); let tcx = self.tcx(); @@ -673,22 +674,22 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> { ty::Infer(ty::FloatVar(_)) => {} ty::Slice(subty) => { - self.require_sized(subty, traits::SliceOrArrayElem); + self.require_sized(subty, ObligationCauseCode::SliceOrArrayElem); } ty::Array(subty, _) => { - self.require_sized(subty, traits::SliceOrArrayElem); + self.require_sized(subty, ObligationCauseCode::SliceOrArrayElem); // Note that we handle the len is implicitly checked while walking `arg`. } ty::Pat(subty, _) => { - self.require_sized(subty, traits::MiscObligation); + self.require_sized(subty, ObligationCauseCode::MiscObligation); } ty::Tuple(tys) => { if let Some((_last, rest)) = tys.split_last() { for &elem in rest { - self.require_sized(elem, traits::TupleElem); + self.require_sized(elem, ObligationCauseCode::TupleElem); } } } @@ -728,7 +729,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> { ty::Ref(r, rty, _) => { // WfReference if !r.has_escaping_bound_vars() && !rty.has_escaping_bound_vars() { - let cause = self.cause(traits::ReferenceOutlivesReferent(t)); + let cause = self.cause(ObligationCauseCode::ReferenceOutlivesReferent(t)); self.out.push(traits::Obligation::with_depth( tcx, cause, @@ -825,7 +826,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> { if let Some(principal) = data.principal_def_id() { self.out.push(traits::Obligation::with_depth( tcx, - self.cause(traits::WellFormed(None)), + self.cause(ObligationCauseCode::WellFormed(None)), self.recursion_depth, self.param_env, ty::Binder::dummy(ty::PredicateKind::ObjectSafe(principal)), @@ -847,7 +848,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> { // See also the comment on `fn obligations`, describing "livelock" // prevention, which happens before this can be reached. ty::Infer(_) => { - let cause = self.cause(traits::WellFormed(None)); + let cause = self.cause(ObligationCauseCode::WellFormed(None)); self.out.push(traits::Obligation::with_depth( tcx, cause, @@ -863,7 +864,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> { t.super_visit_with(self) } - fn visit_const(&mut self, c: <TyCtxt<'tcx> as ty::Interner>::Const) -> Self::Result { + fn visit_const(&mut self, c: ty::Const<'tcx>) -> Self::Result { let tcx = self.tcx(); match c.kind() { @@ -875,7 +876,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> { let predicate = ty::Binder::dummy(ty::PredicateKind::Clause( ty::ClauseKind::ConstEvaluatable(c), )); - let cause = self.cause(traits::WellFormed(None)); + let cause = self.cause(ObligationCauseCode::WellFormed(None)); self.out.push(traits::Obligation::with_depth( tcx, cause, @@ -886,7 +887,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> { } } ty::ConstKind::Infer(_) => { - let cause = self.cause(traits::WellFormed(None)); + let cause = self.cause(ObligationCauseCode::WellFormed(None)); self.out.push(traits::Obligation::with_depth( tcx, @@ -909,7 +910,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> { let predicate = ty::Binder::dummy(ty::PredicateKind::Clause( ty::ClauseKind::ConstEvaluatable(c), )); - let cause = self.cause(traits::WellFormed(None)); + let cause = self.cause(ObligationCauseCode::WellFormed(None)); self.out.push(traits::Obligation::with_depth( tcx, cause, @@ -933,7 +934,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> { c.super_visit_with(self) } - fn visit_predicate(&mut self, _p: <TyCtxt<'tcx> as ty::Interner>::Predicate) -> Self::Result { + fn visit_predicate(&mut self, _p: ty::Predicate<'tcx>) -> Self::Result { bug!("predicate should not be checked for well-formedness"); } } |
