Remove glob imports for ObligationCauseCode
This commit is contained in:
parent
04c049498d
commit
4bde8a8f4b
24 changed files with 279 additions and 178 deletions
|
@ -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);
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue