Rename functions reflect that inline const is also "typeck_child"

This commit is contained in:
Gary Guo 2021-11-06 20:01:35 +00:00
parent d0f59f6d65
commit c4103d438f
18 changed files with 64 additions and 73 deletions

View file

@ -408,7 +408,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let param = generics.type_param(&param_ty, tcx); let param = generics.type_param(&param_ty, tcx);
if let Some(generics) = tcx if let Some(generics) = tcx
.hir() .hir()
.get_generics(tcx.closure_base_def_id(self.mir_def_id().to_def_id())) .get_generics(tcx.typeck_root_def_id(self.mir_def_id().to_def_id()))
{ {
suggest_constraining_type_param( suggest_constraining_type_param(
tcx, tcx,

View file

@ -376,7 +376,7 @@ pub(super) fn dump_annotation<'a, 'tcx>(
errors_buffer: &mut Vec<Diagnostic>, errors_buffer: &mut Vec<Diagnostic>,
) { ) {
let tcx = infcx.tcx; let tcx = infcx.tcx;
let base_def_id = tcx.closure_base_def_id(body.source.def_id()); let base_def_id = tcx.typeck_root_def_id(body.source.def_id());
if !tcx.has_attr(base_def_id, sym::rustc_regions) { if !tcx.has_attr(base_def_id, sym::rustc_regions) {
return; return;
} }

View file

@ -569,8 +569,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
// to store those. Otherwise, we'll pass in `None` to the // to store those. Otherwise, we'll pass in `None` to the
// functions below, which will trigger them to report errors // functions below, which will trigger them to report errors
// eagerly. // eagerly.
let mut outlives_requirements = let mut outlives_requirements = infcx.tcx.is_typeck_child(mir_def_id).then(Vec::new);
infcx.tcx.is_closure_or_inline_const(mir_def_id).then(Vec::new);
self.check_type_tests(infcx, body, outlives_requirements.as_mut(), &mut errors_buffer); self.check_type_tests(infcx, body, outlives_requirements.as_mut(), &mut errors_buffer);
@ -2230,7 +2229,7 @@ impl<'tcx> ClosureRegionRequirementsExt<'tcx> for ClosureRegionRequirements<'tcx
tcx, tcx,
closure_substs, closure_substs,
self.num_external_vids, self.num_external_vids,
tcx.closure_base_def_id(closure_def_id), tcx.typeck_root_def_id(closure_def_id),
); );
debug!("apply_requirements: closure_mapping={:?}", closure_mapping); debug!("apply_requirements: closure_mapping={:?}", closure_mapping);

View file

@ -1344,18 +1344,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// though. // though.
let category = match place.as_local() { let category = match place.as_local() {
Some(RETURN_PLACE) => { Some(RETURN_PLACE) => {
if let BorrowCheckContext { let defining_ty = &self.borrowck_context.universal_regions.defining_ty;
universal_regions: if defining_ty.is_const() {
UniversalRegions { if tcx.is_static(defining_ty.def_id()) {
defining_ty:
DefiningTy::Const(def_id, _)
| DefiningTy::InlineConst(def_id, _),
..
},
..
} = self.borrowck_context
{
if tcx.is_static(*def_id) {
ConstraintCategory::UseAsStatic ConstraintCategory::UseAsStatic
} else { } else {
ConstraintCategory::UseAsConst ConstraintCategory::UseAsConst

View file

@ -247,7 +247,7 @@ impl<'tcx> UniversalRegions<'tcx> {
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
closure_substs: SubstsRef<'tcx>, closure_substs: SubstsRef<'tcx>,
expected_num_vars: usize, expected_num_vars: usize,
closure_base_def_id: DefId, typeck_root_def_id: DefId,
) -> IndexVec<RegionVid, ty::Region<'tcx>> { ) -> IndexVec<RegionVid, ty::Region<'tcx>> {
let mut region_mapping = IndexVec::with_capacity(expected_num_vars); let mut region_mapping = IndexVec::with_capacity(expected_num_vars);
region_mapping.push(tcx.lifetimes.re_static); region_mapping.push(tcx.lifetimes.re_static);
@ -255,7 +255,7 @@ impl<'tcx> UniversalRegions<'tcx> {
region_mapping.push(fr); region_mapping.push(fr);
}); });
for_each_late_bound_region_defined_on(tcx, closure_base_def_id, |r| { for_each_late_bound_region_defined_on(tcx, typeck_root_def_id, |r| {
region_mapping.push(r); region_mapping.push(r);
}); });
@ -349,8 +349,8 @@ impl<'tcx> UniversalRegions<'tcx> {
// tests, and the resulting print-outs include def-ids // tests, and the resulting print-outs include def-ids
// and other things that are not stable across tests! // and other things that are not stable across tests!
// So we just include the region-vid. Annoying. // So we just include the region-vid. Annoying.
let closure_base_def_id = tcx.closure_base_def_id(def_id); let typeck_root_def_id = tcx.typeck_root_def_id(def_id);
for_each_late_bound_region_defined_on(tcx, closure_base_def_id, |r| { for_each_late_bound_region_defined_on(tcx, typeck_root_def_id, |r| {
err.note(&format!("late-bound region is {:?}", self.to_region_vid(r),)); err.note(&format!("late-bound region is {:?}", self.to_region_vid(r),));
}); });
} }
@ -364,8 +364,8 @@ impl<'tcx> UniversalRegions<'tcx> {
// FIXME: As above, we'd like to print out the region // FIXME: As above, we'd like to print out the region
// `r` but doing so is not stable across architectures // `r` but doing so is not stable across architectures
// and so forth. // and so forth.
let closure_base_def_id = tcx.closure_base_def_id(def_id); let typeck_root_def_id = tcx.typeck_root_def_id(def_id);
for_each_late_bound_region_defined_on(tcx, closure_base_def_id, |r| { for_each_late_bound_region_defined_on(tcx, typeck_root_def_id, |r| {
err.note(&format!("late-bound region is {:?}", self.to_region_vid(r),)); err.note(&format!("late-bound region is {:?}", self.to_region_vid(r),));
}); });
} }
@ -422,7 +422,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
let mut indices = self.compute_indices(fr_static, defining_ty); let mut indices = self.compute_indices(fr_static, defining_ty);
debug!("build: indices={:?}", indices); debug!("build: indices={:?}", indices);
let closure_base_def_id = self.infcx.tcx.closure_base_def_id(self.mir_def.did.to_def_id()); let typeck_root_def_id = self.infcx.tcx.typeck_root_def_id(self.mir_def.did.to_def_id());
// If this is a closure or generator, then the late-bound regions from the enclosing // If this is a closure or generator, then the late-bound regions from the enclosing
// function are actually external regions to us. For example, here, 'a is not local // function are actually external regions to us. For example, here, 'a is not local
@ -430,7 +430,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
// fn foo<'a>() { // fn foo<'a>() {
// let c = || { let x: &'a u32 = ...; } // let c = || { let x: &'a u32 = ...; }
// } // }
if self.mir_def.did.to_def_id() != closure_base_def_id { if self.mir_def.did.to_def_id() != typeck_root_def_id {
self.infcx self.infcx
.replace_late_bound_regions_with_nll_infer_vars(self.mir_def.did, &mut indices) .replace_late_bound_regions_with_nll_infer_vars(self.mir_def.did, &mut indices)
} }
@ -448,7 +448,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
); );
// Converse of above, if this is a function then the late-bound regions declared on its // Converse of above, if this is a function then the late-bound regions declared on its
// signature are local to the fn. // signature are local to the fn.
if self.mir_def.did.to_def_id() == closure_base_def_id { if self.mir_def.did.to_def_id() == typeck_root_def_id {
self.infcx self.infcx
.replace_late_bound_regions_with_nll_infer_vars(self.mir_def.did, &mut indices); .replace_late_bound_regions_with_nll_infer_vars(self.mir_def.did, &mut indices);
} }
@ -513,12 +513,12 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
/// see `DefiningTy` for details. /// see `DefiningTy` for details.
fn defining_ty(&self) -> DefiningTy<'tcx> { fn defining_ty(&self) -> DefiningTy<'tcx> {
let tcx = self.infcx.tcx; let tcx = self.infcx.tcx;
let closure_base_def_id = tcx.closure_base_def_id(self.mir_def.did.to_def_id()); let typeck_root_def_id = tcx.typeck_root_def_id(self.mir_def.did.to_def_id());
match tcx.hir().body_owner_kind(self.mir_hir_id) { match tcx.hir().body_owner_kind(self.mir_hir_id) {
BodyOwnerKind::Closure | BodyOwnerKind::Fn => { BodyOwnerKind::Closure | BodyOwnerKind::Fn => {
let defining_ty = if self.mir_def.did.to_def_id() == closure_base_def_id { let defining_ty = if self.mir_def.did.to_def_id() == typeck_root_def_id {
tcx.type_of(closure_base_def_id) tcx.type_of(typeck_root_def_id)
} else { } else {
let tables = tcx.typeck(self.mir_def.did); let tables = tcx.typeck(self.mir_def.did);
tables.node_type(self.mir_hir_id) tables.node_type(self.mir_hir_id)
@ -545,8 +545,8 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
} }
BodyOwnerKind::Const | BodyOwnerKind::Static(..) => { BodyOwnerKind::Const | BodyOwnerKind::Static(..) => {
let identity_substs = InternalSubsts::identity_for_item(tcx, closure_base_def_id); let identity_substs = InternalSubsts::identity_for_item(tcx, typeck_root_def_id);
if self.mir_def.did.to_def_id() == closure_base_def_id { if self.mir_def.did.to_def_id() == typeck_root_def_id {
let substs = let substs =
self.infcx.replace_free_regions_with_nll_infer_vars(FR, identity_substs); self.infcx.replace_free_regions_with_nll_infer_vars(FR, identity_substs);
DefiningTy::Const(self.mir_def.did.to_def_id(), substs) DefiningTy::Const(self.mir_def.did.to_def_id(), substs)
@ -574,19 +574,19 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
defining_ty: DefiningTy<'tcx>, defining_ty: DefiningTy<'tcx>,
) -> UniversalRegionIndices<'tcx> { ) -> UniversalRegionIndices<'tcx> {
let tcx = self.infcx.tcx; let tcx = self.infcx.tcx;
let closure_base_def_id = tcx.closure_base_def_id(self.mir_def.did.to_def_id()); let typeck_root_def_id = tcx.typeck_root_def_id(self.mir_def.did.to_def_id());
let identity_substs = InternalSubsts::identity_for_item(tcx, closure_base_def_id); let identity_substs = InternalSubsts::identity_for_item(tcx, typeck_root_def_id);
let fr_substs = match defining_ty { let fr_substs = match defining_ty {
DefiningTy::Closure(_, ref substs) DefiningTy::Closure(_, ref substs)
| DefiningTy::Generator(_, ref substs, _) | DefiningTy::Generator(_, ref substs, _)
| DefiningTy::InlineConst(_, ref substs) => { | DefiningTy::InlineConst(_, ref substs) => {
// In the case of closures, we rely on the fact that // In the case of closures, we rely on the fact that
// the first N elements in the ClosureSubsts are // the first N elements in the ClosureSubsts are
// inherited from the `closure_base_def_id`. // inherited from the `typeck_root_def_id`.
// Therefore, when we zip together (below) with // Therefore, when we zip together (below) with
// `identity_substs`, we will get only those regions // `identity_substs`, we will get only those regions
// that correspond to early-bound regions declared on // that correspond to early-bound regions declared on
// the `closure_base_def_id`. // the `typeck_root_def_id`.
assert!(substs.len() >= identity_substs.len()); assert!(substs.len() >= identity_substs.len());
assert_eq!(substs.regions().count(), identity_substs.regions().count()); assert_eq!(substs.regions().count(), identity_substs.regions().count());
substs substs
@ -765,8 +765,8 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
indices: &mut UniversalRegionIndices<'tcx>, indices: &mut UniversalRegionIndices<'tcx>,
) { ) {
debug!("replace_late_bound_regions_with_nll_infer_vars(mir_def_id={:?})", mir_def_id); debug!("replace_late_bound_regions_with_nll_infer_vars(mir_def_id={:?})", mir_def_id);
let closure_base_def_id = self.tcx.closure_base_def_id(mir_def_id.to_def_id()); let typeck_root_def_id = self.tcx.typeck_root_def_id(mir_def_id.to_def_id());
for_each_late_bound_region_defined_on(self.tcx, closure_base_def_id, |r| { for_each_late_bound_region_defined_on(self.tcx, typeck_root_def_id, |r| {
debug!("replace_late_bound_regions_with_nll_infer_vars: r={:?}", r); debug!("replace_late_bound_regions_with_nll_infer_vars: r={:?}", r);
if !indices.indices.contains_key(&r) { if !indices.indices.contains_key(&r) {
let region_vid = self.next_nll_region_var(FR); let region_vid = self.next_nll_region_var(FR);

View file

@ -322,7 +322,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
type_names::push_item_name(self.tcx(), def_id, false, &mut name); type_names::push_item_name(self.tcx(), def_id, false, &mut name);
// Find the enclosing function, in case this is a closure. // Find the enclosing function, in case this is a closure.
let enclosing_fn_def_id = self.tcx().closure_base_def_id(def_id); let enclosing_fn_def_id = self.tcx().typeck_root_def_id(def_id);
// Get_template_parameters() will append a `<...>` clause to the function // Get_template_parameters() will append a `<...>` clause to the function
// name if necessary. // name if necessary.

View file

@ -99,7 +99,7 @@ impl<'a, 'tcx> OutlivesEnvironment<'tcx> {
/// function. We can then add implied bounds and the like from the /// function. We can then add implied bounds and the like from the
/// closure arguments into the environment -- these should only /// closure arguments into the environment -- these should only
/// apply in the closure body, so once we exit, we invoke /// apply in the closure body, so once we exit, we invoke
/// `pop_snapshot_post_closure` to remove them. /// `pop_snapshot_post_typeck_child` to remove them.
/// ///
/// Example: /// Example:
/// ///
@ -129,12 +129,12 @@ impl<'a, 'tcx> OutlivesEnvironment<'tcx> {
/// seems like it'd be readily fixed if we wanted. There are /// seems like it'd be readily fixed if we wanted. There are
/// similar leaks around givens that seem equally suspicious, to /// similar leaks around givens that seem equally suspicious, to
/// be honest. --nmatsakis /// be honest. --nmatsakis
pub fn push_snapshot_pre_closure(&self) -> usize { pub fn push_snapshot_pre_typeck_child(&self) -> usize {
self.region_bound_pairs_accum.len() self.region_bound_pairs_accum.len()
} }
/// See `push_snapshot_pre_closure`. /// See `push_snapshot_pre_typeck_child`.
pub fn pop_snapshot_post_closure(&mut self, len: usize) { pub fn pop_snapshot_post_typeck_child(&mut self, len: usize) {
self.region_bound_pairs_accum.truncate(len); self.region_bound_pairs_accum.truncate(len);
} }

View file

@ -797,7 +797,7 @@ rustc_queries! {
/// additional requirements that the closure's creator must verify. /// additional requirements that the closure's creator must verify.
query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> { query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) } desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
cache_on_disk_if(tcx) { tcx.is_closure_or_inline_const(key.to_def_id()) } cache_on_disk_if(tcx) { tcx.is_typeck_child(key.to_def_id()) }
} }
query mir_borrowck_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::BorrowCheckResult<'tcx> { query mir_borrowck_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::BorrowCheckResult<'tcx> {
desc { desc {

View file

@ -56,7 +56,7 @@ impl<'tcx> Const<'tcx> {
let ty = tcx.type_of(def.def_id_for_type_of()); let ty = tcx.type_of(def.def_id_for_type_of());
match Self::try_eval_body_expr(tcx, ty, expr) { match Self::try_eval_lit_or_param(tcx, ty, expr) {
Some(v) => v, Some(v) => v,
None => tcx.mk_const(ty::Const { None => tcx.mk_const(ty::Const {
val: ty::ConstKind::Unevaluated(ty::Unevaluated { val: ty::ConstKind::Unevaluated(ty::Unevaluated {
@ -69,7 +69,7 @@ impl<'tcx> Const<'tcx> {
} }
} }
fn try_eval_body_expr( fn try_eval_lit_or_param(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
ty: Ty<'tcx>, ty: Ty<'tcx>,
expr: &'tcx hir::Expr<'tcx>, expr: &'tcx hir::Expr<'tcx>,
@ -141,12 +141,12 @@ impl<'tcx> Const<'tcx> {
let ty = tcx.typeck(def_id).node_type(hir_id); let ty = tcx.typeck(def_id).node_type(hir_id);
let ret = match Self::try_eval_body_expr(tcx, ty, expr) { let ret = match Self::try_eval_lit_or_param(tcx, ty, expr) {
Some(v) => v, Some(v) => v,
None => { None => {
let outer_def_id = tcx.closure_base_def_id(def_id.to_def_id()); let typeck_root_def_id = tcx.typeck_root_def_id(def_id.to_def_id());
let parent_substs = let parent_substs =
tcx.erase_regions(InternalSubsts::identity_for_item(tcx, outer_def_id)); tcx.erase_regions(InternalSubsts::identity_for_item(tcx, typeck_root_def_id));
let substs = let substs =
InlineConstSubsts::new(tcx, InlineConstSubstsParts { parent_substs, ty }) InlineConstSubsts::new(tcx, InlineConstSubstsParts { parent_substs, ty })
.substs; .substs;

View file

@ -423,8 +423,9 @@ impl<'tcx> TyCtxt<'tcx> {
matches!(self.def_kind(def_id), DefKind::Closure | DefKind::Generator) matches!(self.def_kind(def_id), DefKind::Closure | DefKind::Generator)
} }
/// Returns `true` if `def_id` refers to a closure, generator or inline const. /// Returns `true` if `def_id` refers to a definition that does not have its own
pub fn is_closure_or_inline_const(self, def_id: DefId) -> bool { /// type-checking context, i.e. closure, generator or inline const.
pub fn is_typeck_child(self, def_id: DefId) -> bool {
matches!( matches!(
self.def_kind(def_id), self.def_kind(def_id),
DefKind::Closure | DefKind::Generator | DefKind::InlineConst DefKind::Closure | DefKind::Generator | DefKind::InlineConst
@ -458,9 +459,9 @@ impl<'tcx> TyCtxt<'tcx> {
/// Therefore, when we fetch the /// Therefore, when we fetch the
/// `typeck` the closure, for example, we really wind up /// `typeck` the closure, for example, we really wind up
/// fetching the `typeck` the enclosing fn item. /// fetching the `typeck` the enclosing fn item.
pub fn closure_base_def_id(self, def_id: DefId) -> DefId { pub fn typeck_root_def_id(self, def_id: DefId) -> DefId {
let mut def_id = def_id; let mut def_id = def_id;
while self.is_closure_or_inline_const(def_id) { while self.is_typeck_child(def_id) {
def_id = self.parent(def_id).unwrap_or_else(|| { def_id = self.parent(def_id).unwrap_or_else(|| {
bug!("closure {:?} has no parent", def_id); bug!("closure {:?} has no parent", def_id);
}); });

View file

@ -196,7 +196,7 @@ fn emit_unused_generic_params_error<'tcx>(
generics: &'tcx ty::Generics, generics: &'tcx ty::Generics,
unused_parameters: &FiniteBitSet<u32>, unused_parameters: &FiniteBitSet<u32>,
) { ) {
let base_def_id = tcx.closure_base_def_id(def_id); let base_def_id = tcx.typeck_root_def_id(def_id);
if !tcx.get_attrs(base_def_id).iter().any(|a| a.has_name(sym::rustc_polymorphize_error)) { if !tcx.get_attrs(base_def_id).iter().any(|a| a.has_name(sym::rustc_polymorphize_error)) {
return; return;
} }

View file

@ -818,9 +818,9 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
} }
fn region_scope_tree(tcx: TyCtxt<'_>, def_id: DefId) -> &ScopeTree { fn region_scope_tree(tcx: TyCtxt<'_>, def_id: DefId) -> &ScopeTree {
let closure_base_def_id = tcx.closure_base_def_id(def_id); let typeck_root_def_id = tcx.typeck_root_def_id(def_id);
if closure_base_def_id != def_id { if typeck_root_def_id != def_id {
return tcx.region_scope_tree(closure_base_def_id); return tcx.region_scope_tree(typeck_root_def_id);
} }
let id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); let id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());

View file

@ -1474,7 +1474,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
let span = self.tcx.def_span(generator_did); let span = self.tcx.def_span(generator_did);
let in_progress_typeck_results = self.in_progress_typeck_results.map(|t| t.borrow()); let in_progress_typeck_results = self.in_progress_typeck_results.map(|t| t.borrow());
let generator_did_root = self.tcx.closure_base_def_id(generator_did); let generator_did_root = self.tcx.typeck_root_def_id(generator_did);
debug!( debug!(
"maybe_note_obligation_cause_for_async_await: generator_did={:?} \ "maybe_note_obligation_cause_for_async_await: generator_did={:?} \
generator_did_root={:?} in_progress_typeck_results.hir_owner={:?} span={:?}", generator_did_root={:?} in_progress_typeck_results.hir_owner={:?} span={:?}",

View file

@ -92,7 +92,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let parent_substs = InternalSubsts::identity_for_item( let parent_substs = InternalSubsts::identity_for_item(
self.tcx, self.tcx,
self.tcx.closure_base_def_id(expr_def_id.to_def_id()), self.tcx.typeck_root_def_id(expr_def_id.to_def_id()),
); );
let tupled_upvars_ty = self.infcx.next_ty_var(TypeVariableOrigin { let tupled_upvars_ty = self.infcx.next_ty_var(TypeVariableOrigin {

View file

@ -297,9 +297,9 @@ fn primary_body_of(
fn has_typeck_results(tcx: TyCtxt<'_>, def_id: DefId) -> bool { fn has_typeck_results(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
// Closures' typeck results come from their outermost function, // Closures' typeck results come from their outermost function,
// as they are part of the same "inference environment". // as they are part of the same "inference environment".
let outer_def_id = tcx.closure_base_def_id(def_id); let typeck_root_def_id = tcx.typeck_root_def_id(def_id);
if outer_def_id != def_id { if typeck_root_def_id != def_id {
return tcx.has_typeck_results(outer_def_id); return tcx.has_typeck_results(typeck_root_def_id);
} }
if let Some(def_id) = def_id.as_local() { if let Some(def_id) = def_id.as_local() {
@ -348,9 +348,9 @@ fn typeck_with_fallback<'tcx>(
) -> &'tcx ty::TypeckResults<'tcx> { ) -> &'tcx ty::TypeckResults<'tcx> {
// Closures' typeck results come from their outermost function, // Closures' typeck results come from their outermost function,
// as they are part of the same "inference environment". // as they are part of the same "inference environment".
let outer_def_id = tcx.closure_base_def_id(def_id.to_def_id()).expect_local(); let typeck_root_def_id = tcx.typeck_root_def_id(def_id.to_def_id()).expect_local();
if outer_def_id != def_id { if typeck_root_def_id != def_id {
return tcx.typeck(outer_def_id); return tcx.typeck(typeck_root_def_id);
} }
let id = tcx.hir().local_def_id_to_hir_id(def_id); let id = tcx.hir().local_def_id_to_hir_id(def_id);

View file

@ -347,7 +347,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
// Save state of current function. We will restore afterwards. // Save state of current function. We will restore afterwards.
let old_body_id = self.body_id; let old_body_id = self.body_id;
let old_body_owner = self.body_owner; let old_body_owner = self.body_owner;
let env_snapshot = self.outlives_environment.push_snapshot_pre_closure(); let env_snapshot = self.outlives_environment.push_snapshot_pre_typeck_child();
let body_id = body.id(); let body_id = body.id();
self.body_id = body_id.hir_id; self.body_id = body_id.hir_id;
@ -359,7 +359,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
self.visit_region_obligations(body_id.hir_id); self.visit_region_obligations(body_id.hir_id);
// Restore state from previous function. // Restore state from previous function.
self.outlives_environment.pop_snapshot_post_closure(env_snapshot); self.outlives_environment.pop_snapshot_post_typeck_child(env_snapshot);
self.body_id = old_body_id; self.body_id = old_body_id;
self.body_owner = old_body_owner; self.body_owner = old_body_owner;
} }
@ -429,13 +429,13 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionCtxt<'a, 'tcx> {
// `visit_fn_body`. We will restore afterwards. // `visit_fn_body`. We will restore afterwards.
let old_body_id = self.body_id; let old_body_id = self.body_id;
let old_body_owner = self.body_owner; let old_body_owner = self.body_owner;
let env_snapshot = self.outlives_environment.push_snapshot_pre_closure(); let env_snapshot = self.outlives_environment.push_snapshot_pre_typeck_child();
let body = self.tcx.hir().body(body_id); let body = self.tcx.hir().body(body_id);
self.visit_fn_body(hir_id, body, span); self.visit_fn_body(hir_id, body, span);
// Restore state from previous function. // Restore state from previous function.
self.outlives_environment.pop_snapshot_post_closure(env_snapshot); self.outlives_environment.pop_snapshot_post_typeck_child(env_snapshot);
self.body_id = old_body_id; self.body_id = old_body_id;
self.body_owner = old_body_owner; self.body_owner = old_body_owner;
} }

View file

@ -1495,14 +1495,14 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
Some(parent_def_id.to_def_id()) Some(parent_def_id.to_def_id())
} }
Node::Expr(&Expr { kind: ExprKind::ConstBlock(_), .. }) => { Node::Expr(&Expr { kind: ExprKind::ConstBlock(_), .. }) => {
Some(tcx.closure_base_def_id(def_id)) Some(tcx.typeck_root_def_id(def_id))
} }
_ => None, _ => None,
} }
} }
} }
Node::Expr(&hir::Expr { kind: hir::ExprKind::Closure(..), .. }) => { Node::Expr(&hir::Expr { kind: hir::ExprKind::Closure(..), .. }) => {
Some(tcx.closure_base_def_id(def_id)) Some(tcx.typeck_root_def_id(def_id))
} }
Node::Item(item) => match item.kind { Node::Item(item) => match item.kind {
ItemKind::OpaqueTy(hir::OpaqueTy { impl_trait_fn, .. }) => { ItemKind::OpaqueTy(hir::OpaqueTy { impl_trait_fn, .. }) => {

View file

@ -281,9 +281,9 @@ crate fn create_config(
// Closures' tables come from their outermost function, // Closures' tables come from their outermost function,
// as they are part of the same "inference environment". // as they are part of the same "inference environment".
// This avoids emitting errors for the parent twice (see similar code in `typeck_with_fallback`) // This avoids emitting errors for the parent twice (see similar code in `typeck_with_fallback`)
let outer_def_id = tcx.closure_base_def_id(def_id.to_def_id()).expect_local(); let typeck_root_def_id = tcx.typeck_root_def_id(def_id.to_def_id()).expect_local();
if outer_def_id != def_id { if typeck_root_def_id != def_id {
return tcx.typeck(outer_def_id); return tcx.typeck(typeck_root_def_id);
} }
let hir = tcx.hir(); let hir = tcx.hir();