mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Put param_env
into infcx
.
Because they get passed around together a lot.
This commit is contained in:
parent
c9283f8fa9
commit
af50fe407e
@ -60,7 +60,7 @@ impl<'tcx> UniverseInfo<'tcx> {
|
|||||||
UniverseInfo::RelateTys { expected, found } => {
|
UniverseInfo::RelateTys { expected, found } => {
|
||||||
let err = mbcx.infcx.err_ctxt().report_mismatched_types(
|
let err = mbcx.infcx.err_ctxt().report_mismatched_types(
|
||||||
&cause,
|
&cause,
|
||||||
mbcx.param_env,
|
mbcx.infcx.param_env,
|
||||||
expected,
|
expected,
|
||||||
found,
|
found,
|
||||||
TypeError::RegionsPlaceholderMismatch,
|
TypeError::RegionsPlaceholderMismatch,
|
||||||
|
@ -266,7 +266,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.param_env.caller_bounds().iter().any(|c| {
|
if self.infcx.param_env.caller_bounds().iter().any(|c| {
|
||||||
c.as_trait_clause().is_some_and(|pred| {
|
c.as_trait_clause().is_some_and(|pred| {
|
||||||
pred.skip_binder().self_ty() == ty && self.infcx.tcx.is_fn_trait(pred.def_id())
|
pred.skip_binder().self_ty() == ty && self.infcx.tcx.is_fn_trait(pred.def_id())
|
||||||
})
|
})
|
||||||
@ -682,13 +682,13 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
// Normalize before comparing to see through type aliases and projections.
|
// Normalize before comparing to see through type aliases and projections.
|
||||||
let old_ty = ty::EarlyBinder::bind(ty).instantiate(tcx, generic_args);
|
let old_ty = ty::EarlyBinder::bind(ty).instantiate(tcx, generic_args);
|
||||||
let new_ty = ty::EarlyBinder::bind(ty).instantiate(tcx, new_args);
|
let new_ty = ty::EarlyBinder::bind(ty).instantiate(tcx, new_args);
|
||||||
if let Ok(old_ty) =
|
if let Ok(old_ty) = tcx.try_normalize_erasing_regions(
|
||||||
tcx.try_normalize_erasing_regions(self.infcx.typing_env(self.param_env), old_ty)
|
self.infcx.typing_env(self.infcx.param_env),
|
||||||
&& let Ok(new_ty) = tcx.try_normalize_erasing_regions(
|
old_ty,
|
||||||
self.infcx.typing_env(self.param_env),
|
) && let Ok(new_ty) = tcx.try_normalize_erasing_regions(
|
||||||
new_ty,
|
self.infcx.typing_env(self.infcx.param_env),
|
||||||
)
|
new_ty,
|
||||||
{
|
) {
|
||||||
old_ty == new_ty
|
old_ty == new_ty
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
@ -707,15 +707,16 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
// Test the callee's predicates, substituting in `ref_ty` for the moved argument type.
|
// Test the callee's predicates, substituting in `ref_ty` for the moved argument type.
|
||||||
clauses.instantiate(tcx, new_args).predicates.iter().all(|&(mut clause)| {
|
clauses.instantiate(tcx, new_args).predicates.iter().all(|&(mut clause)| {
|
||||||
// Normalize before testing to see through type aliases and projections.
|
// Normalize before testing to see through type aliases and projections.
|
||||||
if let Ok(normalized) =
|
if let Ok(normalized) = tcx.try_normalize_erasing_regions(
|
||||||
tcx.try_normalize_erasing_regions(self.infcx.typing_env(self.param_env), clause)
|
self.infcx.typing_env(self.infcx.param_env),
|
||||||
{
|
clause,
|
||||||
|
) {
|
||||||
clause = normalized;
|
clause = normalized;
|
||||||
}
|
}
|
||||||
self.infcx.predicate_must_hold_modulo_regions(&Obligation::new(
|
self.infcx.predicate_must_hold_modulo_regions(&Obligation::new(
|
||||||
tcx,
|
tcx,
|
||||||
ObligationCause::dummy(),
|
ObligationCause::dummy(),
|
||||||
self.param_env,
|
self.infcx.param_env,
|
||||||
clause,
|
clause,
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
@ -904,7 +905,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
let ty = moved_place.ty(self.body, self.infcx.tcx).ty;
|
let ty = moved_place.ty(self.body, self.infcx.tcx).ty;
|
||||||
debug!("ty: {:?}, kind: {:?}", ty, ty.kind());
|
debug!("ty: {:?}, kind: {:?}", ty, ty.kind());
|
||||||
|
|
||||||
let Some(assign_value) = self.infcx.err_ctxt().ty_kind_suggestion(self.param_env, ty)
|
let Some(assign_value) = self.infcx.err_ctxt().ty_kind_suggestion(self.infcx.param_env, ty)
|
||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
@ -1304,7 +1305,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
pub(crate) fn implements_clone(&self, ty: Ty<'tcx>) -> bool {
|
pub(crate) fn implements_clone(&self, ty: Ty<'tcx>) -> bool {
|
||||||
let Some(clone_trait_def) = self.infcx.tcx.lang_items().clone_trait() else { return false };
|
let Some(clone_trait_def) = self.infcx.tcx.lang_items().clone_trait() else { return false };
|
||||||
self.infcx
|
self.infcx
|
||||||
.type_implements_trait(clone_trait_def, [ty], self.param_env)
|
.type_implements_trait(clone_trait_def, [ty], self.infcx.param_env)
|
||||||
.must_apply_modulo_regions()
|
.must_apply_modulo_regions()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1437,7 +1438,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
let ocx = ObligationCtxt::new_with_diagnostics(self.infcx);
|
let ocx = ObligationCtxt::new_with_diagnostics(self.infcx);
|
||||||
let cause = ObligationCause::misc(span, self.mir_def_id());
|
let cause = ObligationCause::misc(span, self.mir_def_id());
|
||||||
|
|
||||||
ocx.register_bound(cause, self.param_env, ty, def_id);
|
ocx.register_bound(cause, self.infcx.param_env, ty, def_id);
|
||||||
let errors = ocx.select_all_or_error();
|
let errors = ocx.select_all_or_error();
|
||||||
|
|
||||||
// Only emit suggestion if all required predicates are on generic
|
// Only emit suggestion if all required predicates are on generic
|
||||||
@ -1957,7 +1958,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
&& let ty::Ref(_, inner, _) = rcvr_ty.kind()
|
&& let ty::Ref(_, inner, _) = rcvr_ty.kind()
|
||||||
&& let inner = inner.peel_refs()
|
&& let inner = inner.peel_refs()
|
||||||
&& (Holds { ty: inner }).visit_ty(local_ty).is_break()
|
&& (Holds { ty: inner }).visit_ty(local_ty).is_break()
|
||||||
&& let None = self.infcx.type_implements_trait_shallow(clone, inner, self.param_env)
|
&& let None =
|
||||||
|
self.infcx.type_implements_trait_shallow(clone, inner, self.infcx.param_env)
|
||||||
{
|
{
|
||||||
err.span_label(
|
err.span_label(
|
||||||
span,
|
span,
|
||||||
@ -1989,7 +1991,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
let obligation = Obligation::new(
|
let obligation = Obligation::new(
|
||||||
self.infcx.tcx,
|
self.infcx.tcx,
|
||||||
ObligationCause::dummy(),
|
ObligationCause::dummy(),
|
||||||
self.param_env,
|
self.infcx.param_env,
|
||||||
trait_ref,
|
trait_ref,
|
||||||
);
|
);
|
||||||
self.infcx.err_ctxt().suggest_derive(
|
self.infcx.err_ctxt().suggest_derive(
|
||||||
@ -3398,7 +3400,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
if let Some(iter_trait) = tcx.get_diagnostic_item(sym::Iterator)
|
if let Some(iter_trait) = tcx.get_diagnostic_item(sym::Iterator)
|
||||||
&& self
|
&& self
|
||||||
.infcx
|
.infcx
|
||||||
.type_implements_trait(iter_trait, [return_ty], self.param_env)
|
.type_implements_trait(iter_trait, [return_ty], self.infcx.param_env)
|
||||||
.must_apply_modulo_regions()
|
.must_apply_modulo_regions()
|
||||||
{
|
{
|
||||||
err.span_suggestion_hidden(
|
err.span_suggestion_hidden(
|
||||||
@ -3839,14 +3841,15 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
tcx.get_diagnostic_item(sym::deref_target).and_then(|deref_target| {
|
tcx.get_diagnostic_item(sym::deref_target).and_then(|deref_target| {
|
||||||
Instance::try_resolve(
|
Instance::try_resolve(
|
||||||
tcx,
|
tcx,
|
||||||
self.infcx.typing_env(self.param_env),
|
self.infcx.typing_env(self.infcx.param_env),
|
||||||
deref_target,
|
deref_target,
|
||||||
method_args,
|
method_args,
|
||||||
)
|
)
|
||||||
.transpose()
|
.transpose()
|
||||||
});
|
});
|
||||||
if let Some(Ok(instance)) = deref_target {
|
if let Some(Ok(instance)) = deref_target {
|
||||||
let deref_target_ty = instance.ty(tcx, self.infcx.typing_env(self.param_env));
|
let deref_target_ty =
|
||||||
|
instance.ty(tcx, self.infcx.typing_env(self.infcx.param_env));
|
||||||
err.note(format!("borrow occurs due to deref coercion to `{deref_target_ty}`"));
|
err.note(format!("borrow occurs due to deref coercion to `{deref_target_ty}`"));
|
||||||
err.span_note(tcx.def_span(instance.def_id()), "deref defined here");
|
err.span_note(tcx.def_span(instance.def_id()), "deref defined here");
|
||||||
}
|
}
|
||||||
|
@ -864,7 +864,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
|
|
||||||
let kind = call_kind(
|
let kind = call_kind(
|
||||||
self.infcx.tcx,
|
self.infcx.tcx,
|
||||||
self.infcx.typing_env(self.param_env),
|
self.infcx.typing_env(self.infcx.param_env),
|
||||||
method_did,
|
method_did,
|
||||||
method_args,
|
method_args,
|
||||||
*fn_span,
|
*fn_span,
|
||||||
@ -1160,7 +1160,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
let suggest = match tcx.get_diagnostic_item(sym::IntoIterator) {
|
let suggest = match tcx.get_diagnostic_item(sym::IntoIterator) {
|
||||||
Some(def_id) => type_known_to_meet_bound_modulo_regions(
|
Some(def_id) => type_known_to_meet_bound_modulo_regions(
|
||||||
self.infcx,
|
self.infcx,
|
||||||
self.param_env,
|
self.infcx.param_env,
|
||||||
Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, ty),
|
Ty::new_imm_ref(tcx, tcx.lifetimes.re_erased, ty),
|
||||||
def_id,
|
def_id,
|
||||||
),
|
),
|
||||||
@ -1224,7 +1224,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
BoundRegionConversionTime::FnCall,
|
BoundRegionConversionTime::FnCall,
|
||||||
tcx.fn_sig(method_did).instantiate(tcx, method_args).input(0),
|
tcx.fn_sig(method_did).instantiate(tcx, method_args).input(0),
|
||||||
)
|
)
|
||||||
&& self.infcx.can_eq(self.param_env, ty, self_ty)
|
&& self.infcx.can_eq(self.infcx.param_env, ty, self_ty)
|
||||||
{
|
{
|
||||||
err.subdiagnostic(CaptureReasonSuggest::FreshReborrow {
|
err.subdiagnostic(CaptureReasonSuggest::FreshReborrow {
|
||||||
span: move_span.shrink_to_hi(),
|
span: move_span.shrink_to_hi(),
|
||||||
@ -1258,7 +1258,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
if let Some(errors) = self.infcx.type_implements_trait_shallow(
|
if let Some(errors) = self.infcx.type_implements_trait_shallow(
|
||||||
clone_trait,
|
clone_trait,
|
||||||
ty,
|
ty,
|
||||||
self.param_env,
|
self.infcx.param_env,
|
||||||
) && !has_sugg
|
) && !has_sugg
|
||||||
{
|
{
|
||||||
let msg = match &errors[..] {
|
let msg = match &errors[..] {
|
||||||
|
@ -305,7 +305,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
let Some(copy_trait_def) = self.infcx.tcx.lang_items().copy_trait() else { return false };
|
let Some(copy_trait_def) = self.infcx.tcx.lang_items().copy_trait() else { return false };
|
||||||
// This is only going to be ambiguous if there are incoherent impls, because otherwise
|
// This is only going to be ambiguous if there are incoherent impls, because otherwise
|
||||||
// ambiguity should never happen in MIR.
|
// ambiguity should never happen in MIR.
|
||||||
self.infcx.type_implements_trait(copy_trait_def, [ty], self.param_env).may_apply()
|
self.infcx.type_implements_trait(copy_trait_def, [ty], self.infcx.param_env).may_apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn report_cannot_move_from_static(&mut self, place: Place<'tcx>, span: Span) -> Diag<'infcx> {
|
fn report_cannot_move_from_static(&mut self, place: Place<'tcx>, span: Span) -> Diag<'infcx> {
|
||||||
|
@ -1242,7 +1242,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
.type_implements_trait_shallow(
|
.type_implements_trait_shallow(
|
||||||
clone_trait,
|
clone_trait,
|
||||||
ty.peel_refs(),
|
ty.peel_refs(),
|
||||||
self.param_env,
|
self.infcx.param_env,
|
||||||
)
|
)
|
||||||
.as_deref()
|
.as_deref()
|
||||||
{
|
{
|
||||||
@ -1279,7 +1279,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
let obligation = traits::Obligation::new(
|
let obligation = traits::Obligation::new(
|
||||||
self.infcx.tcx,
|
self.infcx.tcx,
|
||||||
traits::ObligationCause::dummy(),
|
traits::ObligationCause::dummy(),
|
||||||
self.param_env,
|
self.infcx.param_env,
|
||||||
trait_ref,
|
trait_ref,
|
||||||
);
|
);
|
||||||
self.infcx.err_ctxt().suggest_derive(
|
self.infcx.err_ctxt().suggest_derive(
|
||||||
|
@ -952,7 +952,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
|
|
||||||
if let Ok(Some(instance)) = ty::Instance::try_resolve(
|
if let Ok(Some(instance)) = ty::Instance::try_resolve(
|
||||||
tcx,
|
tcx,
|
||||||
self.infcx.typing_env(self.param_env),
|
self.infcx.typing_env(self.infcx.param_env),
|
||||||
*fn_did,
|
*fn_did,
|
||||||
self.infcx.resolve_vars_if_possible(args),
|
self.infcx.resolve_vars_if_possible(args),
|
||||||
) {
|
) {
|
||||||
@ -1091,7 +1091,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
peeled_ty = ref_ty;
|
peeled_ty = ref_ty;
|
||||||
count += 1;
|
count += 1;
|
||||||
}
|
}
|
||||||
if !self.infcx.type_is_copy_modulo_regions(self.param_env, peeled_ty) {
|
if !self.infcx.type_is_copy_modulo_regions(self.infcx.param_env, peeled_ty) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1160,7 +1160,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||||||
let ocx = ObligationCtxt::new(&self.infcx);
|
let ocx = ObligationCtxt::new(&self.infcx);
|
||||||
ocx.register_obligations(preds.iter().map(|(pred, span)| {
|
ocx.register_obligations(preds.iter().map(|(pred, span)| {
|
||||||
trace!(?pred);
|
trace!(?pred);
|
||||||
Obligation::misc(tcx, span, self.mir_def_id(), self.param_env, pred)
|
Obligation::misc(tcx, span, self.mir_def_id(), self.infcx.param_env, pred)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if ocx.select_all_or_error().is_empty() && count > 0 {
|
if ocx.select_all_or_error().is_empty() && count > 0 {
|
||||||
|
@ -140,7 +140,6 @@ fn do_mir_borrowck<'tcx>(
|
|||||||
) -> (BorrowCheckResult<'tcx>, Option<Box<BodyWithBorrowckFacts<'tcx>>>) {
|
) -> (BorrowCheckResult<'tcx>, Option<Box<BodyWithBorrowckFacts<'tcx>>>) {
|
||||||
let def = input_body.source.def_id().expect_local();
|
let def = input_body.source.def_id().expect_local();
|
||||||
let infcx = BorrowckInferCtxt::new(tcx, def);
|
let infcx = BorrowckInferCtxt::new(tcx, def);
|
||||||
let param_env = tcx.param_env(def);
|
|
||||||
|
|
||||||
let mut local_names = IndexVec::from_elem(None, &input_body.local_decls);
|
let mut local_names = IndexVec::from_elem(None, &input_body.local_decls);
|
||||||
for var_debug_info in &input_body.var_debug_info {
|
for var_debug_info in &input_body.var_debug_info {
|
||||||
@ -175,8 +174,7 @@ fn do_mir_borrowck<'tcx>(
|
|||||||
// will have a lifetime tied to the inference context.
|
// will have a lifetime tied to the inference context.
|
||||||
let mut body_owned = input_body.clone();
|
let mut body_owned = input_body.clone();
|
||||||
let mut promoted = input_promoted.to_owned();
|
let mut promoted = input_promoted.to_owned();
|
||||||
let free_regions =
|
let free_regions = nll::replace_regions_in_mir(&infcx, &mut body_owned, &mut promoted);
|
||||||
nll::replace_regions_in_mir(&infcx, param_env, &mut body_owned, &mut promoted);
|
|
||||||
let body = &body_owned; // no further changes
|
let body = &body_owned; // no further changes
|
||||||
|
|
||||||
// FIXME(-Znext-solver): A bit dubious that we're only registering
|
// FIXME(-Znext-solver): A bit dubious that we're only registering
|
||||||
@ -213,7 +211,6 @@ fn do_mir_borrowck<'tcx>(
|
|||||||
body,
|
body,
|
||||||
&promoted,
|
&promoted,
|
||||||
&location_table,
|
&location_table,
|
||||||
param_env,
|
|
||||||
&mut flow_inits,
|
&mut flow_inits,
|
||||||
&move_data,
|
&move_data,
|
||||||
&borrow_set,
|
&borrow_set,
|
||||||
@ -250,7 +247,6 @@ fn do_mir_borrowck<'tcx>(
|
|||||||
let promoted_body = &promoted[idx];
|
let promoted_body = &promoted[idx];
|
||||||
let mut promoted_mbcx = MirBorrowckCtxt {
|
let mut promoted_mbcx = MirBorrowckCtxt {
|
||||||
infcx: &infcx,
|
infcx: &infcx,
|
||||||
param_env,
|
|
||||||
body: promoted_body,
|
body: promoted_body,
|
||||||
move_data: &move_data,
|
move_data: &move_data,
|
||||||
location_table: &location_table, // no need to create a real one for the promoted, it is not used
|
location_table: &location_table, // no need to create a real one for the promoted, it is not used
|
||||||
@ -290,7 +286,6 @@ fn do_mir_borrowck<'tcx>(
|
|||||||
|
|
||||||
let mut mbcx = MirBorrowckCtxt {
|
let mut mbcx = MirBorrowckCtxt {
|
||||||
infcx: &infcx,
|
infcx: &infcx,
|
||||||
param_env,
|
|
||||||
body,
|
body,
|
||||||
move_data: &move_data,
|
move_data: &move_data,
|
||||||
location_table: &location_table,
|
location_table: &location_table,
|
||||||
@ -447,12 +442,14 @@ fn get_flow_results<'a, 'tcx>(
|
|||||||
pub(crate) struct BorrowckInferCtxt<'tcx> {
|
pub(crate) struct BorrowckInferCtxt<'tcx> {
|
||||||
pub(crate) infcx: InferCtxt<'tcx>,
|
pub(crate) infcx: InferCtxt<'tcx>,
|
||||||
pub(crate) reg_var_to_origin: RefCell<FxIndexMap<ty::RegionVid, RegionCtxt>>,
|
pub(crate) reg_var_to_origin: RefCell<FxIndexMap<ty::RegionVid, RegionCtxt>>,
|
||||||
|
pub(crate) param_env: ParamEnv<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> BorrowckInferCtxt<'tcx> {
|
impl<'tcx> BorrowckInferCtxt<'tcx> {
|
||||||
pub(crate) fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Self {
|
pub(crate) fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Self {
|
||||||
let infcx = tcx.infer_ctxt().build(TypingMode::analysis_in_body(tcx, def_id));
|
let infcx = tcx.infer_ctxt().build(TypingMode::analysis_in_body(tcx, def_id));
|
||||||
BorrowckInferCtxt { infcx, reg_var_to_origin: RefCell::new(Default::default()) }
|
let param_env = tcx.param_env(def_id);
|
||||||
|
BorrowckInferCtxt { infcx, reg_var_to_origin: RefCell::new(Default::default()), param_env }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn next_region_var<F>(
|
pub(crate) fn next_region_var<F>(
|
||||||
@ -531,7 +528,6 @@ impl<'tcx> Deref for BorrowckInferCtxt<'tcx> {
|
|||||||
|
|
||||||
struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
|
struct MirBorrowckCtxt<'a, 'infcx, 'tcx> {
|
||||||
infcx: &'infcx BorrowckInferCtxt<'tcx>,
|
infcx: &'infcx BorrowckInferCtxt<'tcx>,
|
||||||
param_env: ParamEnv<'tcx>,
|
|
||||||
body: &'a Body<'tcx>,
|
body: &'a Body<'tcx>,
|
||||||
move_data: &'a MoveData<'tcx>,
|
move_data: &'a MoveData<'tcx>,
|
||||||
|
|
||||||
|
@ -50,10 +50,9 @@ pub(crate) struct NllOutput<'tcx> {
|
|||||||
/// Rewrites the regions in the MIR to use NLL variables, also scraping out the set of universal
|
/// Rewrites the regions in the MIR to use NLL variables, also scraping out the set of universal
|
||||||
/// regions (e.g., region parameters) declared on the function. That set will need to be given to
|
/// regions (e.g., region parameters) declared on the function. That set will need to be given to
|
||||||
/// `compute_regions`.
|
/// `compute_regions`.
|
||||||
#[instrument(skip(infcx, param_env, body, promoted), level = "debug")]
|
#[instrument(skip(infcx, body, promoted), level = "debug")]
|
||||||
pub(crate) fn replace_regions_in_mir<'tcx>(
|
pub(crate) fn replace_regions_in_mir<'tcx>(
|
||||||
infcx: &BorrowckInferCtxt<'tcx>,
|
infcx: &BorrowckInferCtxt<'tcx>,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
|
||||||
body: &mut Body<'tcx>,
|
body: &mut Body<'tcx>,
|
||||||
promoted: &mut IndexSlice<Promoted, Body<'tcx>>,
|
promoted: &mut IndexSlice<Promoted, Body<'tcx>>,
|
||||||
) -> UniversalRegions<'tcx> {
|
) -> UniversalRegions<'tcx> {
|
||||||
@ -62,7 +61,7 @@ pub(crate) fn replace_regions_in_mir<'tcx>(
|
|||||||
debug!(?def);
|
debug!(?def);
|
||||||
|
|
||||||
// Compute named region information. This also renumbers the inputs/outputs.
|
// Compute named region information. This also renumbers the inputs/outputs.
|
||||||
let universal_regions = UniversalRegions::new(infcx, def, param_env);
|
let universal_regions = UniversalRegions::new(infcx, def);
|
||||||
|
|
||||||
// Replace all remaining regions with fresh inference variables.
|
// Replace all remaining regions with fresh inference variables.
|
||||||
renumber::renumber_mir(infcx, body, promoted);
|
renumber::renumber_mir(infcx, body, promoted);
|
||||||
@ -81,7 +80,6 @@ pub(crate) fn compute_regions<'a, 'tcx>(
|
|||||||
body: &Body<'tcx>,
|
body: &Body<'tcx>,
|
||||||
promoted: &IndexSlice<Promoted, Body<'tcx>>,
|
promoted: &IndexSlice<Promoted, Body<'tcx>>,
|
||||||
location_table: &LocationTable,
|
location_table: &LocationTable,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
|
||||||
flow_inits: &mut ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
|
flow_inits: &mut ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
|
||||||
move_data: &MoveData<'tcx>,
|
move_data: &MoveData<'tcx>,
|
||||||
borrow_set: &BorrowSet<'tcx>,
|
borrow_set: &BorrowSet<'tcx>,
|
||||||
@ -101,7 +99,6 @@ pub(crate) fn compute_regions<'a, 'tcx>(
|
|||||||
let MirTypeckResults { constraints, universal_region_relations, opaque_type_values } =
|
let MirTypeckResults { constraints, universal_region_relations, opaque_type_values } =
|
||||||
type_check::type_check(
|
type_check::type_check(
|
||||||
infcx,
|
infcx,
|
||||||
param_env,
|
|
||||||
body,
|
body,
|
||||||
promoted,
|
promoted,
|
||||||
universal_regions,
|
universal_regions,
|
||||||
|
@ -132,7 +132,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
locations: Locations,
|
locations: Locations,
|
||||||
category: ConstraintCategory<'tcx>,
|
category: ConstraintCategory<'tcx>,
|
||||||
) {
|
) {
|
||||||
let param_env = self.param_env;
|
let param_env = self.infcx.param_env;
|
||||||
let predicate = predicate.upcast(self.tcx());
|
let predicate = predicate.upcast(self.tcx());
|
||||||
let _: Result<_, ErrorGuaranteed> = self.fully_perform_op(
|
let _: Result<_, ErrorGuaranteed> = self.fully_perform_op(
|
||||||
locations,
|
locations,
|
||||||
@ -158,7 +158,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
where
|
where
|
||||||
T: type_op::normalize::Normalizable<'tcx> + fmt::Display + Copy + 'tcx,
|
T: type_op::normalize::Normalizable<'tcx> + fmt::Display + Copy + 'tcx,
|
||||||
{
|
{
|
||||||
let param_env = self.param_env;
|
let param_env = self.infcx.param_env;
|
||||||
let result: Result<_, ErrorGuaranteed> = self.fully_perform_op(
|
let result: Result<_, ErrorGuaranteed> = self.fully_perform_op(
|
||||||
location.to_locations(),
|
location.to_locations(),
|
||||||
category,
|
category,
|
||||||
@ -176,7 +176,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
if self.infcx.next_trait_solver() {
|
if self.infcx.next_trait_solver() {
|
||||||
let body = self.body;
|
let body = self.body;
|
||||||
let param_env = self.param_env;
|
let param_env = self.infcx.param_env;
|
||||||
self.fully_perform_op(
|
self.fully_perform_op(
|
||||||
location.to_locations(),
|
location.to_locations(),
|
||||||
ConstraintCategory::Boring,
|
ConstraintCategory::Boring,
|
||||||
@ -223,7 +223,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
let _: Result<_, ErrorGuaranteed> = self.fully_perform_op(
|
let _: Result<_, ErrorGuaranteed> = self.fully_perform_op(
|
||||||
Locations::All(span),
|
Locations::All(span),
|
||||||
ConstraintCategory::Boring,
|
ConstraintCategory::Boring,
|
||||||
self.param_env.and(type_op::ascribe_user_type::AscribeUserType { mir_ty, user_ty }),
|
self.infcx
|
||||||
|
.param_env
|
||||||
|
.and(type_op::ascribe_user_type::AscribeUserType { mir_ty, user_ty }),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,7 +252,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
let mir_ty = self.normalize(mir_ty, Locations::All(span));
|
let mir_ty = self.normalize(mir_ty, Locations::All(span));
|
||||||
|
|
||||||
let cause = ObligationCause::dummy_with_span(span);
|
let cause = ObligationCause::dummy_with_span(span);
|
||||||
let param_env = self.param_env;
|
let param_env = self.infcx.param_env;
|
||||||
let _: Result<_, ErrorGuaranteed> = self.fully_perform_op(
|
let _: Result<_, ErrorGuaranteed> = self.fully_perform_op(
|
||||||
Locations::All(span),
|
Locations::All(span),
|
||||||
ConstraintCategory::Boring,
|
ConstraintCategory::Boring,
|
||||||
|
@ -234,7 +234,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
|
|||||||
// In the new solver, normalize the type-outlives obligation assumptions.
|
// In the new solver, normalize the type-outlives obligation assumptions.
|
||||||
if self.infcx.next_trait_solver() {
|
if self.infcx.next_trait_solver() {
|
||||||
match deeply_normalize(
|
match deeply_normalize(
|
||||||
self.infcx.at(&ObligationCause::misc(span, defining_ty_def_id), self.param_env),
|
self.infcx.at(&ObligationCause::misc(span, defining_ty_def_id), param_env),
|
||||||
outlives,
|
outlives,
|
||||||
) {
|
) {
|
||||||
Ok(normalized_outlives) => {
|
Ok(normalized_outlives) => {
|
||||||
@ -274,15 +274,15 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
|
|||||||
if let Some(c) = constraints_unnorm {
|
if let Some(c) = constraints_unnorm {
|
||||||
constraints.push(c)
|
constraints.push(c)
|
||||||
}
|
}
|
||||||
let TypeOpOutput { output: norm_ty, constraints: constraints_normalize, .. } = self
|
let TypeOpOutput { output: norm_ty, constraints: constraints_normalize, .. } =
|
||||||
.param_env
|
param_env
|
||||||
.and(type_op::normalize::Normalize { value: ty })
|
.and(type_op::normalize::Normalize { value: ty })
|
||||||
.fully_perform(self.infcx, span)
|
.fully_perform(self.infcx, span)
|
||||||
.unwrap_or_else(|guar| TypeOpOutput {
|
.unwrap_or_else(|guar| TypeOpOutput {
|
||||||
output: Ty::new_error(self.infcx.tcx, guar),
|
output: Ty::new_error(self.infcx.tcx, guar),
|
||||||
constraints: None,
|
constraints: None,
|
||||||
error_info: None,
|
error_info: None,
|
||||||
});
|
});
|
||||||
if let Some(c) = constraints_normalize {
|
if let Some(c) = constraints_normalize {
|
||||||
constraints.push(c)
|
constraints.push(c)
|
||||||
}
|
}
|
||||||
@ -312,8 +312,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
|
|||||||
// Add implied bounds from impl header.
|
// Add implied bounds from impl header.
|
||||||
if matches!(tcx.def_kind(defining_ty_def_id), DefKind::AssocFn | DefKind::AssocConst) {
|
if matches!(tcx.def_kind(defining_ty_def_id), DefKind::AssocFn | DefKind::AssocConst) {
|
||||||
for &(ty, _) in tcx.assumed_wf_types(tcx.local_parent(defining_ty_def_id)) {
|
for &(ty, _) in tcx.assumed_wf_types(tcx.local_parent(defining_ty_def_id)) {
|
||||||
let result: Result<_, ErrorGuaranteed> = self
|
let result: Result<_, ErrorGuaranteed> = param_env
|
||||||
.param_env
|
|
||||||
.and(type_op::normalize::Normalize { value: ty })
|
.and(type_op::normalize::Normalize { value: ty })
|
||||||
.fully_perform(self.infcx, span);
|
.fully_perform(self.infcx, span);
|
||||||
let Ok(TypeOpOutput { output: norm_ty, constraints: c, .. }) = result else {
|
let Ok(TypeOpOutput { output: norm_ty, constraints: c, .. }) = result else {
|
||||||
|
@ -608,7 +608,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
|
|||||||
|
|
||||||
value.visit_with(&mut for_liveness::FreeRegionsVisitor {
|
value.visit_with(&mut for_liveness::FreeRegionsVisitor {
|
||||||
tcx: typeck.tcx(),
|
tcx: typeck.tcx(),
|
||||||
param_env: typeck.param_env,
|
param_env: typeck.infcx.param_env,
|
||||||
op: |r| {
|
op: |r| {
|
||||||
let live_region_vid = typeck.universal_regions.to_region_vid(r);
|
let live_region_vid = typeck.universal_regions.to_region_vid(r);
|
||||||
|
|
||||||
@ -621,6 +621,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
|
|||||||
debug!("compute_drop_data(dropped_ty={:?})", dropped_ty,);
|
debug!("compute_drop_data(dropped_ty={:?})", dropped_ty,);
|
||||||
|
|
||||||
match typeck
|
match typeck
|
||||||
|
.infcx
|
||||||
.param_env
|
.param_env
|
||||||
.and(DropckOutlives { dropped_ty })
|
.and(DropckOutlives { dropped_ty })
|
||||||
.fully_perform(typeck.infcx, DUMMY_SP)
|
.fully_perform(typeck.infcx, DUMMY_SP)
|
||||||
|
@ -118,7 +118,6 @@ mod relate_tys;
|
|||||||
/// - `elements` -- MIR region map
|
/// - `elements` -- MIR region map
|
||||||
pub(crate) fn type_check<'a, 'tcx>(
|
pub(crate) fn type_check<'a, 'tcx>(
|
||||||
infcx: &BorrowckInferCtxt<'tcx>,
|
infcx: &BorrowckInferCtxt<'tcx>,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
|
||||||
body: &Body<'tcx>,
|
body: &Body<'tcx>,
|
||||||
promoted: &IndexSlice<Promoted, Body<'tcx>>,
|
promoted: &IndexSlice<Promoted, Body<'tcx>>,
|
||||||
universal_regions: UniversalRegions<'tcx>,
|
universal_regions: UniversalRegions<'tcx>,
|
||||||
@ -147,7 +146,7 @@ pub(crate) fn type_check<'a, 'tcx>(
|
|||||||
known_type_outlives_obligations,
|
known_type_outlives_obligations,
|
||||||
} = free_region_relations::create(
|
} = free_region_relations::create(
|
||||||
infcx,
|
infcx,
|
||||||
param_env,
|
infcx.param_env,
|
||||||
implicit_region_bound,
|
implicit_region_bound,
|
||||||
universal_regions,
|
universal_regions,
|
||||||
&mut constraints,
|
&mut constraints,
|
||||||
@ -157,7 +156,6 @@ pub(crate) fn type_check<'a, 'tcx>(
|
|||||||
|
|
||||||
let mut checker = TypeChecker {
|
let mut checker = TypeChecker {
|
||||||
infcx,
|
infcx,
|
||||||
param_env,
|
|
||||||
last_span: body.span,
|
last_span: body.span,
|
||||||
body,
|
body,
|
||||||
user_type_annotations: &body.user_type_annotations,
|
user_type_annotations: &body.user_type_annotations,
|
||||||
@ -828,7 +826,6 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
|
|||||||
/// NLL region checking.
|
/// NLL region checking.
|
||||||
struct TypeChecker<'a, 'tcx> {
|
struct TypeChecker<'a, 'tcx> {
|
||||||
infcx: &'a BorrowckInferCtxt<'tcx>,
|
infcx: &'a BorrowckInferCtxt<'tcx>,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
|
||||||
last_span: Span,
|
last_span: Span,
|
||||||
body: &'a Body<'tcx>,
|
body: &'a Body<'tcx>,
|
||||||
/// User type annotations are shared between the main MIR and the MIR of
|
/// User type annotations are shared between the main MIR and the MIR of
|
||||||
@ -1017,7 +1014,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
self.universal_regions,
|
self.universal_regions,
|
||||||
&self.region_bound_pairs,
|
&self.region_bound_pairs,
|
||||||
self.implicit_region_bound,
|
self.implicit_region_bound,
|
||||||
self.param_env,
|
self.infcx.param_env,
|
||||||
&self.known_type_outlives_obligations,
|
&self.known_type_outlives_obligations,
|
||||||
locations,
|
locations,
|
||||||
locations.span(self.body),
|
locations.span(self.body),
|
||||||
@ -1517,9 +1514,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
// The signature in this call can reference region variables,
|
// The signature in this call can reference region variables,
|
||||||
// so erase them before calling a query.
|
// so erase them before calling a query.
|
||||||
let output_ty = self.tcx().erase_regions(sig.output());
|
let output_ty = self.tcx().erase_regions(sig.output());
|
||||||
if !output_ty
|
if !output_ty.is_privately_uninhabited(
|
||||||
.is_privately_uninhabited(self.tcx(), self.infcx.typing_env(self.param_env))
|
self.tcx(),
|
||||||
{
|
self.infcx.typing_env(self.infcx.param_env),
|
||||||
|
) {
|
||||||
span_mirbug!(self, term, "call to converging function {:?} w/o dest", sig);
|
span_mirbug!(self, term, "call to converging function {:?} w/o dest", sig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1729,7 +1727,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
// `Sized` bound in no way depends on precise regions, so this
|
// `Sized` bound in no way depends on precise regions, so this
|
||||||
// shouldn't affect `is_sized`.
|
// shouldn't affect `is_sized`.
|
||||||
let erased_ty = tcx.erase_regions(ty);
|
let erased_ty = tcx.erase_regions(ty);
|
||||||
if !erased_ty.is_sized(tcx, self.param_env) {
|
if !erased_ty.is_sized(tcx, self.infcx.param_env) {
|
||||||
// in current MIR construction, all non-control-flow rvalue
|
// in current MIR construction, all non-control-flow rvalue
|
||||||
// expressions evaluate through `as_temp` or `into` a return
|
// expressions evaluate through `as_temp` or `into` a return
|
||||||
// slot or local, so to find all unsized rvalues it is enough
|
// slot or local, so to find all unsized rvalues it is enough
|
||||||
@ -2781,7 +2779,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
self.universal_regions,
|
self.universal_regions,
|
||||||
&self.region_bound_pairs,
|
&self.region_bound_pairs,
|
||||||
self.implicit_region_bound,
|
self.implicit_region_bound,
|
||||||
self.param_env,
|
self.infcx.param_env,
|
||||||
&self.known_type_outlives_obligations,
|
&self.known_type_outlives_obligations,
|
||||||
locations,
|
locations,
|
||||||
self.body.span, // irrelevant; will be overridden.
|
self.body.span, // irrelevant; will be overridden.
|
||||||
|
@ -522,7 +522,7 @@ impl<'b, 'tcx> PredicateEmittingRelation<InferCtxt<'tcx>> for NllTypeRelating<'_
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn param_env(&self) -> ty::ParamEnv<'tcx> {
|
fn param_env(&self) -> ty::ParamEnv<'tcx> {
|
||||||
self.type_checker.param_env
|
self.type_checker.infcx.param_env
|
||||||
}
|
}
|
||||||
|
|
||||||
fn register_predicates(
|
fn register_predicates(
|
||||||
|
@ -248,12 +248,8 @@ impl<'tcx> UniversalRegions<'tcx> {
|
|||||||
/// MIR -- that is, all the regions that appear in the function's
|
/// MIR -- that is, all the regions that appear in the function's
|
||||||
/// signature. This will also compute the relationships that are
|
/// signature. This will also compute the relationships that are
|
||||||
/// known between those regions.
|
/// known between those regions.
|
||||||
pub(crate) fn new(
|
pub(crate) fn new(infcx: &BorrowckInferCtxt<'tcx>, mir_def: LocalDefId) -> Self {
|
||||||
infcx: &BorrowckInferCtxt<'tcx>,
|
UniversalRegionsBuilder { infcx, mir_def }.build()
|
||||||
mir_def: LocalDefId,
|
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
|
||||||
) -> Self {
|
|
||||||
UniversalRegionsBuilder { infcx, mir_def, param_env }.build()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Given a reference to a closure type, extracts all the values
|
/// Given a reference to a closure type, extracts all the values
|
||||||
@ -426,7 +422,6 @@ impl<'tcx> UniversalRegions<'tcx> {
|
|||||||
struct UniversalRegionsBuilder<'infcx, 'tcx> {
|
struct UniversalRegionsBuilder<'infcx, 'tcx> {
|
||||||
infcx: &'infcx BorrowckInferCtxt<'tcx>,
|
infcx: &'infcx BorrowckInferCtxt<'tcx>,
|
||||||
mir_def: LocalDefId,
|
mir_def: LocalDefId,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const FR: NllRegionVariableOrigin = NllRegionVariableOrigin::FreeRegion;
|
const FR: NllRegionVariableOrigin = NllRegionVariableOrigin::FreeRegion;
|
||||||
@ -435,7 +430,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||||||
fn build(self) -> UniversalRegions<'tcx> {
|
fn build(self) -> UniversalRegions<'tcx> {
|
||||||
debug!("build(mir_def={:?})", self.mir_def);
|
debug!("build(mir_def={:?})", self.mir_def);
|
||||||
|
|
||||||
let param_env = self.param_env;
|
let param_env = self.infcx.param_env;
|
||||||
debug!("build: param_env={:?}", param_env);
|
debug!("build: param_env={:?}", param_env);
|
||||||
|
|
||||||
assert_eq!(FIRST_GLOBAL_INDEX, self.infcx.num_region_vars());
|
assert_eq!(FIRST_GLOBAL_INDEX, self.infcx.num_region_vars());
|
||||||
|
Loading…
Reference in New Issue
Block a user