use super::project;
use super::project::{normalize_with_depth, Normalized, ProjectionCacheKey};
use super::util;
+use super::util::{closure_trait_ref_and_return_type, predicate_for_trait_def};
+use super::wf;
use super::DerivedObligationCause;
use super::Selection;
use super::SelectionResult;
impl IntercrateAmbiguityCause {
/// Emits notes when the overlap is caused by complex intercrate ambiguities.
/// See #23980 for details.
- pub fn add_intercrate_ambiguity_hint(&self, err: &mut errors::DiagnosticBuilder<'_>) {
+ pub fn add_intercrate_ambiguity_hint(&self, err: &mut rustc_errors::DiagnosticBuilder<'_>) {
err.note(&self.intercrate_ambiguity_hint());
}
}
}
- ty::Predicate::WellFormed(ty) => match ty::wf::obligations(
+ ty::Predicate::WellFormed(ty) => match wf::obligations(
self.infcx,
obligation.param_env,
obligation.cause.body_id,
ty::Predicate::ConstEvaluatable(def_id, substs) => {
if !(obligation.param_env, substs).has_local_value() {
- match self.tcx().const_eval_resolve(obligation.param_env, def_id, substs, None)
- {
+ match self.tcx().const_eval_resolve(
+ obligation.param_env,
+ def_id,
+ substs,
+ None,
+ None,
+ ) {
Ok(_) => Ok(EvaluatedToOk),
Err(_) => Ok(EvaluatedToErr),
}
/// to have a *lower* recursion_depth than the obligation used to create it.
/// Projection sub-obligations may be returned from the projection cache,
/// which results in obligations with an 'old' `recursion_depth`.
- /// Additionally, methods like `ty::wf::obligations` and
+ /// Additionally, methods like `wf::obligations` and
/// `InferCtxt.subtype_predicate` produce subobligations without
/// taking in a 'parent' depth, causing the generated subobligations
/// to have a `recursion_depth` of `0`.
recursion_depth,
&skol_ty,
);
- let skol_obligation = self.tcx().predicate_for_trait_def(
+ let skol_obligation = predicate_for_trait_def(
+ self.tcx(),
param_env,
cause.clone(),
trait_def_id,
// we pass over, we sum up the set of number of vtable
// entries, so that we can compute the offset for the selected
// trait.
- vtable_base = nonmatching.map(|t| tcx.count_own_vtable_entries(t)).sum();
+ vtable_base = nonmatching.map(|t| super::util::count_own_vtable_entries(tcx, t)).sum();
}
VtableObjectData { upcast_trait_ref: upcast_trait_ref.unwrap(), vtable_base, nested }
// Okay to skip binder; it is reintroduced below.
let self_ty = self.infcx.shallow_resolve(*obligation.self_ty().skip_binder());
let sig = self_ty.fn_sig(self.tcx());
- let trait_ref = self
- .tcx()
- .closure_trait_ref_and_return_type(
- obligation.predicate.def_id(),
- self_ty,
- sig,
- util::TupleArgumentsFlag::Yes,
- )
- .map_bound(|(trait_ref, _)| trait_ref);
+ let trait_ref = closure_trait_ref_and_return_type(
+ self.tcx(),
+ obligation.predicate.def_id(),
+ self_ty,
+ sig,
+ util::TupleArgumentsFlag::Yes,
+ )
+ .map_bound(|(trait_ref, _)| trait_ref);
let Normalized { value: trait_ref, obligations } = project::normalize_with_depth(
self,
nested.extend(obligations);
// Construct the nested `Field<T>: Unsize<Field<U>>` predicate.
- nested.push(tcx.predicate_for_trait_def(
+ nested.push(predicate_for_trait_def(
+ tcx,
obligation.param_env,
obligation.cause.clone(),
obligation.predicate.def_id(),
nested.extend(obligations);
// Construct the nested `T: Unsize<U>` predicate.
- nested.push(tcx.predicate_for_trait_def(
+ nested.push(predicate_for_trait_def(
+ tcx,
obligation.param_env,
obligation.cause.clone(),
obligation.predicate.def_id(),
// in fact unparameterized (or at least does not reference any
// regions bound in the obligation). Still probably some
// refactoring could make this nicer.
- self.tcx()
- .closure_trait_ref_and_return_type(
- obligation.predicate.def_id(),
- obligation.predicate.skip_binder().self_ty(), // (1)
- closure_type,
- util::TupleArgumentsFlag::No,
- )
- .map_bound(|(trait_ref, _)| trait_ref)
+ closure_trait_ref_and_return_type(
+ self.tcx(),
+ obligation.predicate.def_id(),
+ obligation.predicate.skip_binder().self_ty(), // (1)
+ closure_type,
+ util::TupleArgumentsFlag::No,
+ )
+ .map_bound(|(trait_ref, _)| trait_ref)
}
fn generator_trait_ref_unnormalized(
// regions bound in the obligation). Still probably some
// refactoring could make this nicer.
- self.tcx()
- .generator_trait_ref_and_outputs(
- obligation.predicate.def_id(),
- obligation.predicate.skip_binder().self_ty(), // (1)
- gen_sig,
- )
- .map_bound(|(trait_ref, ..)| trait_ref)
+ super::util::generator_trait_ref_and_outputs(
+ self.tcx(),
+ obligation.predicate.def_id(),
+ obligation.predicate.skip_binder().self_ty(), // (1)
+ gen_sig,
+ )
+ .map_bound(|(trait_ref, ..)| trait_ref)
}
/// Returns the obligations that are implied by instantiating an
// NOTE(flaper87): As of now, it keeps track of the whole error
// chain. Ideally, we should have a way to configure this either
// by using -Z verbose or just a CLI argument.
- if obligation.recursion_depth >= 0 {
- let derived_cause = DerivedObligationCause {
- parent_trait_ref: obligation.predicate.to_poly_trait_ref(),
- parent_code: Rc::new(obligation.cause.code.clone()),
- };
- let derived_code = variant(derived_cause);
- ObligationCause::new(obligation.cause.span, obligation.cause.body_id, derived_code)
- } else {
- obligation.cause.clone()
- }
+ let derived_cause = DerivedObligationCause {
+ parent_trait_ref: obligation.predicate.to_poly_trait_ref(),
+ parent_code: Rc::new(obligation.cause.code.clone()),
+ };
+ let derived_code = variant(derived_cause);
+ ObligationCause::new(obligation.cause.span, obligation.cause.body_id, derived_code)
}
}