use super::TraitEngine;
use super::{ChalkFulfillmentContext, FulfillmentContext};
use crate::infer::InferCtxtExt;
-use rustc_hir::def_id::DefId;
+use rustc_data_structures::fx::FxHashSet;
+use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_infer::infer::{InferCtxt, InferOk};
use rustc_infer::traits::{
FulfillmentError, Obligation, ObligationCause, PredicateObligation, TraitEngineExt as _,
use rustc_middle::ty::ToPredicate;
use rustc_middle::ty::TypeFoldable;
use rustc_middle::ty::{self, Ty, TyCtxt};
+use rustc_span::Span;
pub trait TraitEngineExt<'tcx> {
fn new(tcx: TyCtxt<'tcx>) -> Box<Self>;
pub fn select_all_or_error(&self) -> Vec<FulfillmentError<'tcx>> {
self.engine.borrow_mut().select_all_or_error(self.infcx)
}
+
+ pub fn assumed_wf_types(
+ &self,
+ param_env: ty::ParamEnv<'tcx>,
+ span: Span,
+ def_id: LocalDefId,
+ ) -> FxHashSet<Ty<'tcx>> {
+ let tcx = self.infcx.tcx;
+ let assumed_wf_types = tcx.assumed_wf_types(def_id);
+ let mut implied_bounds = FxHashSet::default();
+ let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
+ let cause = ObligationCause::misc(span, hir_id);
+ for ty in assumed_wf_types {
+ implied_bounds.insert(ty);
+ let normalized = self.normalize(cause.clone(), param_env, ty);
+ implied_bounds.insert(normalized);
+ }
+ implied_bounds
+ }
}
tcx.infer_ctxt().enter(move |infcx| {
let ocx = ObligationCtxt::new(&infcx);
- let assumed_wf_types = tcx.assumed_wf_types(impl_ty.def_id);
- let mut implied_bounds = FxHashSet::default();
- let cause = ObligationCause::misc(impl_ty_span, impl_ty_hir_id);
- for ty in assumed_wf_types {
- implied_bounds.insert(ty);
- let normalized = ocx.normalize(cause.clone(), param_env, ty);
- implied_bounds.insert(normalized);
- }
- let implied_bounds = implied_bounds;
+ let assumed_wf_types =
+ ocx.assumed_wf_types(param_env, impl_ty_span, impl_ty.def_id.expect_local());
let mut selcx = traits::SelectionContext::new(&infcx);
let normalize_cause = ObligationCause::new(
// Finally, resolve all regions. This catches wily misuses of
// lifetime parameters.
let mut outlives_environment = OutlivesEnvironment::new(param_env);
- outlives_environment.add_implied_bounds(&infcx, implied_bounds, impl_ty_hir_id);
+ outlives_environment.add_implied_bounds(&infcx, assumed_wf_types, impl_ty_hir_id);
infcx.check_region_obligations_and_report_errors(
impl_ty.def_id.expect_local(),
&outlives_environment,
tcx.infer_ctxt().enter(|ref infcx| {
let ocx = ObligationCtxt::new(infcx);
- let assumed_wf_types = tcx.assumed_wf_types(body_def_id);
- let mut implied_bounds = FxHashSet::default();
- let cause = ObligationCause::misc(span, body_id);
- for ty in assumed_wf_types {
- implied_bounds.insert(ty);
- let normalized = ocx.normalize(cause.clone(), param_env, ty);
- implied_bounds.insert(normalized);
- }
- let implied_bounds = implied_bounds;
+ let assumed_wf_types = ocx.assumed_wf_types(param_env, span, body_def_id);
let mut wfcx = WfCheckingCtxt { ocx, span, body_id, param_env };
}
let mut outlives_environment = OutlivesEnvironment::new(param_env);
- outlives_environment.add_implied_bounds(infcx, implied_bounds, body_id);
+ outlives_environment.add_implied_bounds(infcx, assumed_wf_types, body_id);
infcx.check_region_obligations_and_report_errors(body_def_id, &outlives_environment);
})
}
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
use rustc_infer::infer::TyCtxtInferExt;
use rustc_infer::traits::specialization_graph::Node;
-use rustc_infer::traits::ObligationCause;
use rustc_middle::ty::subst::{GenericArg, InternalSubsts, SubstsRef};
use rustc_middle::ty::trait_def::TraitSpecializationKind;
use rustc_middle::ty::{self, TyCtxt, TypeVisitable};
let param_env = tcx.param_env(impl1_def_id);
let impl1_hir_id = tcx.hir().local_def_id_to_hir_id(impl1_def_id);
- let assumed_wf_types = tcx.assumed_wf_types(impl1_def_id);
- let mut implied_bounds = FxHashSet::default();
- let cause = ObligationCause::misc(tcx.def_span(impl1_def_id), impl1_hir_id);
- for ty in assumed_wf_types {
- implied_bounds.insert(ty);
- let normalized = ocx.normalize(cause.clone(), param_env, ty);
- implied_bounds.insert(normalized);
- }
- let implied_bounds = implied_bounds;
+ let assumed_wf_types =
+ ocx.assumed_wf_types(param_env, tcx.def_span(impl1_def_id), impl1_def_id);
let impl1_substs = InternalSubsts::identity_for_item(tcx, impl1_def_id.to_def_id());
let impl2_substs =
}
let mut outlives_env = OutlivesEnvironment::new(param_env);
- outlives_env.add_implied_bounds(infcx, implied_bounds, impl1_hir_id);
+ outlives_env.add_implied_bounds(infcx, assumed_wf_types, impl1_hir_id);
infcx.check_region_obligations_and_report_errors(impl1_def_id, &outlives_env);
let Ok(impl2_substs) = infcx.fully_resolve(impl2_substs) else {
let span = tcx.def_span(impl1_def_id);