1
Fork 0

Auto merge of #99501 - lcnr:check-regions-infcx, r=oli-obk

move `considering_regions` to the infcx

it seems weird to prove some obligations which constrain inference vars while ignoring regions  in a context which considers regions. This is especially weird because even for a fulfillment context with ignored regions, we still added region outlives bounds when directly relating regions.

tbh our handling of regions is still very weird, but at least this is a step in the right direction imo.

r? rust-lang/types
This commit is contained in:
bors 2022-07-21 19:43:21 +00:00
commit 62b272d25c
16 changed files with 82 additions and 122 deletions

View file

@ -86,7 +86,10 @@ impl<'tcx> Inherited<'_, 'tcx> {
let hir_owner = tcx.hir().local_def_id_to_hir_id(def_id).owner;
InheritedBuilder {
infcx: tcx.infer_ctxt().with_fresh_in_progress_typeck_results(hir_owner),
infcx: tcx
.infer_ctxt()
.ignoring_regions()
.with_fresh_in_progress_typeck_results(hir_owner),
def_id,
}
}
@ -113,7 +116,7 @@ impl<'a, 'tcx> Inherited<'a, 'tcx> {
maybe_typeck_results: infcx.in_progress_typeck_results,
},
infcx,
fulfillment_cx: RefCell::new(<dyn TraitEngine<'_>>::new_ignoring_regions(tcx)),
fulfillment_cx: RefCell::new(<dyn TraitEngine<'_>>::new(tcx)),
locals: RefCell::new(Default::default()),
deferred_sized_obligations: RefCell::new(Vec::new()),
deferred_call_resolutions: RefCell::new(Default::default()),

View file

@ -87,10 +87,10 @@ mod op;
mod pat;
mod place_op;
mod region;
mod regionck;
pub mod regionck;
pub mod rvalue_scopes;
mod upvar;
mod wfcheck;
pub mod wfcheck;
pub mod writeback;
use check::{check_abi, check_fn, check_mod_item_types};

View file

@ -1913,7 +1913,7 @@ impl<'a, 'tcx> WfCheckingCtxt<'a, 'tcx> {
}
}
pub(super) fn impl_implied_bounds<'tcx>(
pub fn impl_implied_bounds<'tcx>(
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
impl_def_id: LocalDefId,

View file

@ -116,8 +116,8 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
// why this field does not implement Copy. This is useful because sometimes
// it is not immediately clear why Copy is not implemented for a field, since
// all we point at is the field itself.
tcx.infer_ctxt().enter(|infcx| {
let mut fulfill_cx = traits::FulfillmentContext::new_ignoring_regions();
tcx.infer_ctxt().ignoring_regions().enter(|infcx| {
let mut fulfill_cx = traits::FulfillmentContext::new();
fulfill_cx.register_bound(
&infcx,
param_env,

View file

@ -65,6 +65,8 @@
//! cause use after frees with purely safe code in the same way as specializing
//! on traits with methods can.
use crate::check::regionck::OutlivesEnvironmentExt;
use crate::check::wfcheck::impl_implied_bounds;
use crate::constrained_generic_params as cgp;
use crate::errors::SubstsOnOverriddenImpl;
@ -148,8 +150,15 @@ fn get_impl_substs<'tcx>(
let impl2_substs =
translate_substs(infcx, param_env, impl1_def_id.to_def_id(), impl1_substs, impl2_node);
// Conservatively use an empty `ParamEnv`.
let outlives_env = OutlivesEnvironment::new(ty::ParamEnv::empty());
let mut outlives_env = OutlivesEnvironment::new(param_env);
let implied_bounds =
impl_implied_bounds(infcx.tcx, param_env, impl1_def_id, tcx.def_span(impl1_def_id));
outlives_env.add_implied_bounds(
infcx,
implied_bounds,
tcx.hir().local_def_id_to_hir_id(impl1_def_id),
);
infcx.process_registered_region_obligations(outlives_env.region_bound_pairs(), param_env);
infcx.resolve_regions_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);