Skip to content

Commit c4103d4

Browse files
committed
Rename functions reflect that inline const is also "typeck_child"
1 parent d0f59f6 commit c4103d4

File tree

18 files changed

+64
-73
lines changed

18 files changed

+64
-73
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
408408
let param = generics.type_param(&param_ty, tcx);
409409
if let Some(generics) = tcx
410410
.hir()
411-
.get_generics(tcx.closure_base_def_id(self.mir_def_id().to_def_id()))
411+
.get_generics(tcx.typeck_root_def_id(self.mir_def_id().to_def_id()))
412412
{
413413
suggest_constraining_type_param(
414414
tcx,

compiler/rustc_borrowck/src/nll.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ pub(super) fn dump_annotation<'a, 'tcx>(
376376
errors_buffer: &mut Vec<Diagnostic>,
377377
) {
378378
let tcx = infcx.tcx;
379-
let base_def_id = tcx.closure_base_def_id(body.source.def_id());
379+
let base_def_id = tcx.typeck_root_def_id(body.source.def_id());
380380
if !tcx.has_attr(base_def_id, sym::rustc_regions) {
381381
return;
382382
}

compiler/rustc_borrowck/src/region_infer/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
569569
// to store those. Otherwise, we'll pass in `None` to the
570570
// functions below, which will trigger them to report errors
571571
// eagerly.
572-
let mut outlives_requirements =
573-
infcx.tcx.is_closure_or_inline_const(mir_def_id).then(Vec::new);
572+
let mut outlives_requirements = infcx.tcx.is_typeck_child(mir_def_id).then(Vec::new);
574573

575574
self.check_type_tests(infcx, body, outlives_requirements.as_mut(), &mut errors_buffer);
576575

@@ -2230,7 +2229,7 @@ impl<'tcx> ClosureRegionRequirementsExt<'tcx> for ClosureRegionRequirements<'tcx
22302229
tcx,
22312230
closure_substs,
22322231
self.num_external_vids,
2233-
tcx.closure_base_def_id(closure_def_id),
2232+
tcx.typeck_root_def_id(closure_def_id),
22342233
);
22352234
debug!("apply_requirements: closure_mapping={:?}", closure_mapping);
22362235

compiler/rustc_borrowck/src/type_check/mod.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -1344,18 +1344,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
13441344
// though.
13451345
let category = match place.as_local() {
13461346
Some(RETURN_PLACE) => {
1347-
if let BorrowCheckContext {
1348-
universal_regions:
1349-
UniversalRegions {
1350-
defining_ty:
1351-
DefiningTy::Const(def_id, _)
1352-
| DefiningTy::InlineConst(def_id, _),
1353-
..
1354-
},
1355-
..
1356-
} = self.borrowck_context
1357-
{
1358-
if tcx.is_static(*def_id) {
1347+
let defining_ty = &self.borrowck_context.universal_regions.defining_ty;
1348+
if defining_ty.is_const() {
1349+
if tcx.is_static(defining_ty.def_id()) {
13591350
ConstraintCategory::UseAsStatic
13601351
} else {
13611352
ConstraintCategory::UseAsConst

compiler/rustc_borrowck/src/universal_regions.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,15 @@ impl<'tcx> UniversalRegions<'tcx> {
247247
tcx: TyCtxt<'tcx>,
248248
closure_substs: SubstsRef<'tcx>,
249249
expected_num_vars: usize,
250-
closure_base_def_id: DefId,
250+
typeck_root_def_id: DefId,
251251
) -> IndexVec<RegionVid, ty::Region<'tcx>> {
252252
let mut region_mapping = IndexVec::with_capacity(expected_num_vars);
253253
region_mapping.push(tcx.lifetimes.re_static);
254254
tcx.for_each_free_region(&closure_substs, |fr| {
255255
region_mapping.push(fr);
256256
});
257257

258-
for_each_late_bound_region_defined_on(tcx, closure_base_def_id, |r| {
258+
for_each_late_bound_region_defined_on(tcx, typeck_root_def_id, |r| {
259259
region_mapping.push(r);
260260
});
261261

@@ -349,8 +349,8 @@ impl<'tcx> UniversalRegions<'tcx> {
349349
// tests, and the resulting print-outs include def-ids
350350
// and other things that are not stable across tests!
351351
// So we just include the region-vid. Annoying.
352-
let closure_base_def_id = tcx.closure_base_def_id(def_id);
353-
for_each_late_bound_region_defined_on(tcx, closure_base_def_id, |r| {
352+
let typeck_root_def_id = tcx.typeck_root_def_id(def_id);
353+
for_each_late_bound_region_defined_on(tcx, typeck_root_def_id, |r| {
354354
err.note(&format!("late-bound region is {:?}", self.to_region_vid(r),));
355355
});
356356
}
@@ -364,8 +364,8 @@ impl<'tcx> UniversalRegions<'tcx> {
364364
// FIXME: As above, we'd like to print out the region
365365
// `r` but doing so is not stable across architectures
366366
// and so forth.
367-
let closure_base_def_id = tcx.closure_base_def_id(def_id);
368-
for_each_late_bound_region_defined_on(tcx, closure_base_def_id, |r| {
367+
let typeck_root_def_id = tcx.typeck_root_def_id(def_id);
368+
for_each_late_bound_region_defined_on(tcx, typeck_root_def_id, |r| {
369369
err.note(&format!("late-bound region is {:?}", self.to_region_vid(r),));
370370
});
371371
}
@@ -422,15 +422,15 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
422422
let mut indices = self.compute_indices(fr_static, defining_ty);
423423
debug!("build: indices={:?}", indices);
424424

425-
let closure_base_def_id = self.infcx.tcx.closure_base_def_id(self.mir_def.did.to_def_id());
425+
let typeck_root_def_id = self.infcx.tcx.typeck_root_def_id(self.mir_def.did.to_def_id());
426426

427427
// If this is a closure or generator, then the late-bound regions from the enclosing
428428
// function are actually external regions to us. For example, here, 'a is not local
429429
// to the closure c (although it is local to the fn foo):
430430
// fn foo<'a>() {
431431
// let c = || { let x: &'a u32 = ...; }
432432
// }
433-
if self.mir_def.did.to_def_id() != closure_base_def_id {
433+
if self.mir_def.did.to_def_id() != typeck_root_def_id {
434434
self.infcx
435435
.replace_late_bound_regions_with_nll_infer_vars(self.mir_def.did, &mut indices)
436436
}
@@ -448,7 +448,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
448448
);
449449
// Converse of above, if this is a function then the late-bound regions declared on its
450450
// signature are local to the fn.
451-
if self.mir_def.did.to_def_id() == closure_base_def_id {
451+
if self.mir_def.did.to_def_id() == typeck_root_def_id {
452452
self.infcx
453453
.replace_late_bound_regions_with_nll_infer_vars(self.mir_def.did, &mut indices);
454454
}
@@ -513,12 +513,12 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
513513
/// see `DefiningTy` for details.
514514
fn defining_ty(&self) -> DefiningTy<'tcx> {
515515
let tcx = self.infcx.tcx;
516-
let closure_base_def_id = tcx.closure_base_def_id(self.mir_def.did.to_def_id());
516+
let typeck_root_def_id = tcx.typeck_root_def_id(self.mir_def.did.to_def_id());
517517

518518
match tcx.hir().body_owner_kind(self.mir_hir_id) {
519519
BodyOwnerKind::Closure | BodyOwnerKind::Fn => {
520-
let defining_ty = if self.mir_def.did.to_def_id() == closure_base_def_id {
521-
tcx.type_of(closure_base_def_id)
520+
let defining_ty = if self.mir_def.did.to_def_id() == typeck_root_def_id {
521+
tcx.type_of(typeck_root_def_id)
522522
} else {
523523
let tables = tcx.typeck(self.mir_def.did);
524524
tables.node_type(self.mir_hir_id)
@@ -545,8 +545,8 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
545545
}
546546

547547
BodyOwnerKind::Const | BodyOwnerKind::Static(..) => {
548-
let identity_substs = InternalSubsts::identity_for_item(tcx, closure_base_def_id);
549-
if self.mir_def.did.to_def_id() == closure_base_def_id {
548+
let identity_substs = InternalSubsts::identity_for_item(tcx, typeck_root_def_id);
549+
if self.mir_def.did.to_def_id() == typeck_root_def_id {
550550
let substs =
551551
self.infcx.replace_free_regions_with_nll_infer_vars(FR, identity_substs);
552552
DefiningTy::Const(self.mir_def.did.to_def_id(), substs)
@@ -574,19 +574,19 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
574574
defining_ty: DefiningTy<'tcx>,
575575
) -> UniversalRegionIndices<'tcx> {
576576
let tcx = self.infcx.tcx;
577-
let closure_base_def_id = tcx.closure_base_def_id(self.mir_def.did.to_def_id());
578-
let identity_substs = InternalSubsts::identity_for_item(tcx, closure_base_def_id);
577+
let typeck_root_def_id = tcx.typeck_root_def_id(self.mir_def.did.to_def_id());
578+
let identity_substs = InternalSubsts::identity_for_item(tcx, typeck_root_def_id);
579579
let fr_substs = match defining_ty {
580580
DefiningTy::Closure(_, ref substs)
581581
| DefiningTy::Generator(_, ref substs, _)
582582
| DefiningTy::InlineConst(_, ref substs) => {
583583
// In the case of closures, we rely on the fact that
584584
// the first N elements in the ClosureSubsts are
585-
// inherited from the `closure_base_def_id`.
585+
// inherited from the `typeck_root_def_id`.
586586
// Therefore, when we zip together (below) with
587587
// `identity_substs`, we will get only those regions
588588
// that correspond to early-bound regions declared on
589-
// the `closure_base_def_id`.
589+
// the `typeck_root_def_id`.
590590
assert!(substs.len() >= identity_substs.len());
591591
assert_eq!(substs.regions().count(), identity_substs.regions().count());
592592
substs
@@ -765,8 +765,8 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
765765
indices: &mut UniversalRegionIndices<'tcx>,
766766
) {
767767
debug!("replace_late_bound_regions_with_nll_infer_vars(mir_def_id={:?})", mir_def_id);
768-
let closure_base_def_id = self.tcx.closure_base_def_id(mir_def_id.to_def_id());
769-
for_each_late_bound_region_defined_on(self.tcx, closure_base_def_id, |r| {
768+
let typeck_root_def_id = self.tcx.typeck_root_def_id(mir_def_id.to_def_id());
769+
for_each_late_bound_region_defined_on(self.tcx, typeck_root_def_id, |r| {
770770
debug!("replace_late_bound_regions_with_nll_infer_vars: r={:?}", r);
771771
if !indices.indices.contains_key(&r) {
772772
let region_vid = self.next_nll_region_var(FR);

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
322322
type_names::push_item_name(self.tcx(), def_id, false, &mut name);
323323

324324
// Find the enclosing function, in case this is a closure.
325-
let enclosing_fn_def_id = self.tcx().closure_base_def_id(def_id);
325+
let enclosing_fn_def_id = self.tcx().typeck_root_def_id(def_id);
326326

327327
// Get_template_parameters() will append a `<...>` clause to the function
328328
// name if necessary.

compiler/rustc_infer/src/infer/outlives/env.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl<'a, 'tcx> OutlivesEnvironment<'tcx> {
9999
/// function. We can then add implied bounds and the like from the
100100
/// closure arguments into the environment -- these should only
101101
/// apply in the closure body, so once we exit, we invoke
102-
/// `pop_snapshot_post_closure` to remove them.
102+
/// `pop_snapshot_post_typeck_child` to remove them.
103103
///
104104
/// Example:
105105
///
@@ -129,12 +129,12 @@ impl<'a, 'tcx> OutlivesEnvironment<'tcx> {
129129
/// seems like it'd be readily fixed if we wanted. There are
130130
/// similar leaks around givens that seem equally suspicious, to
131131
/// be honest. --nmatsakis
132-
pub fn push_snapshot_pre_closure(&self) -> usize {
132+
pub fn push_snapshot_pre_typeck_child(&self) -> usize {
133133
self.region_bound_pairs_accum.len()
134134
}
135135

136-
/// See `push_snapshot_pre_closure`.
137-
pub fn pop_snapshot_post_closure(&mut self, len: usize) {
136+
/// See `push_snapshot_pre_typeck_child`.
137+
pub fn pop_snapshot_post_typeck_child(&mut self, len: usize) {
138138
self.region_bound_pairs_accum.truncate(len);
139139
}
140140

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ rustc_queries! {
797797
/// additional requirements that the closure's creator must verify.
798798
query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
799799
desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
800-
cache_on_disk_if(tcx) { tcx.is_closure_or_inline_const(key.to_def_id()) }
800+
cache_on_disk_if(tcx) { tcx.is_typeck_child(key.to_def_id()) }
801801
}
802802
query mir_borrowck_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::BorrowCheckResult<'tcx> {
803803
desc {

compiler/rustc_middle/src/ty/consts.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl<'tcx> Const<'tcx> {
5656

5757
let ty = tcx.type_of(def.def_id_for_type_of());
5858

59-
match Self::try_eval_body_expr(tcx, ty, expr) {
59+
match Self::try_eval_lit_or_param(tcx, ty, expr) {
6060
Some(v) => v,
6161
None => tcx.mk_const(ty::Const {
6262
val: ty::ConstKind::Unevaluated(ty::Unevaluated {
@@ -69,7 +69,7 @@ impl<'tcx> Const<'tcx> {
6969
}
7070
}
7171

72-
fn try_eval_body_expr(
72+
fn try_eval_lit_or_param(
7373
tcx: TyCtxt<'tcx>,
7474
ty: Ty<'tcx>,
7575
expr: &'tcx hir::Expr<'tcx>,
@@ -141,12 +141,12 @@ impl<'tcx> Const<'tcx> {
141141

142142
let ty = tcx.typeck(def_id).node_type(hir_id);
143143

144-
let ret = match Self::try_eval_body_expr(tcx, ty, expr) {
144+
let ret = match Self::try_eval_lit_or_param(tcx, ty, expr) {
145145
Some(v) => v,
146146
None => {
147-
let outer_def_id = tcx.closure_base_def_id(def_id.to_def_id());
147+
let typeck_root_def_id = tcx.typeck_root_def_id(def_id.to_def_id());
148148
let parent_substs =
149-
tcx.erase_regions(InternalSubsts::identity_for_item(tcx, outer_def_id));
149+
tcx.erase_regions(InternalSubsts::identity_for_item(tcx, typeck_root_def_id));
150150
let substs =
151151
InlineConstSubsts::new(tcx, InlineConstSubstsParts { parent_substs, ty })
152152
.substs;

compiler/rustc_middle/src/ty/util.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,9 @@ impl<'tcx> TyCtxt<'tcx> {
423423
matches!(self.def_kind(def_id), DefKind::Closure | DefKind::Generator)
424424
}
425425

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

compiler/rustc_monomorphize/src/polymorphize.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ fn emit_unused_generic_params_error<'tcx>(
196196
generics: &'tcx ty::Generics,
197197
unused_parameters: &FiniteBitSet<u32>,
198198
) {
199-
let base_def_id = tcx.closure_base_def_id(def_id);
199+
let base_def_id = tcx.typeck_root_def_id(def_id);
200200
if !tcx.get_attrs(base_def_id).iter().any(|a| a.has_name(sym::rustc_polymorphize_error)) {
201201
return;
202202
}

compiler/rustc_passes/src/region.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -818,9 +818,9 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
818818
}
819819

820820
fn region_scope_tree(tcx: TyCtxt<'_>, def_id: DefId) -> &ScopeTree {
821-
let closure_base_def_id = tcx.closure_base_def_id(def_id);
822-
if closure_base_def_id != def_id {
823-
return tcx.region_scope_tree(closure_base_def_id);
821+
let typeck_root_def_id = tcx.typeck_root_def_id(def_id);
822+
if typeck_root_def_id != def_id {
823+
return tcx.region_scope_tree(typeck_root_def_id);
824824
}
825825

826826
let id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
14741474
let span = self.tcx.def_span(generator_did);
14751475

14761476
let in_progress_typeck_results = self.in_progress_typeck_results.map(|t| t.borrow());
1477-
let generator_did_root = self.tcx.closure_base_def_id(generator_did);
1477+
let generator_did_root = self.tcx.typeck_root_def_id(generator_did);
14781478
debug!(
14791479
"maybe_note_obligation_cause_for_async_await: generator_did={:?} \
14801480
generator_did_root={:?} in_progress_typeck_results.hir_owner={:?} span={:?}",

compiler/rustc_typeck/src/check/closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
9292

9393
let parent_substs = InternalSubsts::identity_for_item(
9494
self.tcx,
95-
self.tcx.closure_base_def_id(expr_def_id.to_def_id()),
95+
self.tcx.typeck_root_def_id(expr_def_id.to_def_id()),
9696
);
9797

9898
let tupled_upvars_ty = self.infcx.next_ty_var(TypeVariableOrigin {

compiler/rustc_typeck/src/check/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,9 @@ fn primary_body_of(
297297
fn has_typeck_results(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
298298
// Closures' typeck results come from their outermost function,
299299
// as they are part of the same "inference environment".
300-
let outer_def_id = tcx.closure_base_def_id(def_id);
301-
if outer_def_id != def_id {
302-
return tcx.has_typeck_results(outer_def_id);
300+
let typeck_root_def_id = tcx.typeck_root_def_id(def_id);
301+
if typeck_root_def_id != def_id {
302+
return tcx.has_typeck_results(typeck_root_def_id);
303303
}
304304

305305
if let Some(def_id) = def_id.as_local() {
@@ -348,9 +348,9 @@ fn typeck_with_fallback<'tcx>(
348348
) -> &'tcx ty::TypeckResults<'tcx> {
349349
// Closures' typeck results come from their outermost function,
350350
// as they are part of the same "inference environment".
351-
let outer_def_id = tcx.closure_base_def_id(def_id.to_def_id()).expect_local();
352-
if outer_def_id != def_id {
353-
return tcx.typeck(outer_def_id);
351+
let typeck_root_def_id = tcx.typeck_root_def_id(def_id.to_def_id()).expect_local();
352+
if typeck_root_def_id != def_id {
353+
return tcx.typeck(typeck_root_def_id);
354354
}
355355

356356
let id = tcx.hir().local_def_id_to_hir_id(def_id);

compiler/rustc_typeck/src/check/regionck.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
347347
// Save state of current function. We will restore afterwards.
348348
let old_body_id = self.body_id;
349349
let old_body_owner = self.body_owner;
350-
let env_snapshot = self.outlives_environment.push_snapshot_pre_closure();
350+
let env_snapshot = self.outlives_environment.push_snapshot_pre_typeck_child();
351351

352352
let body_id = body.id();
353353
self.body_id = body_id.hir_id;
@@ -359,7 +359,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
359359
self.visit_region_obligations(body_id.hir_id);
360360

361361
// Restore state from previous function.
362-
self.outlives_environment.pop_snapshot_post_closure(env_snapshot);
362+
self.outlives_environment.pop_snapshot_post_typeck_child(env_snapshot);
363363
self.body_id = old_body_id;
364364
self.body_owner = old_body_owner;
365365
}
@@ -429,13 +429,13 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionCtxt<'a, 'tcx> {
429429
// `visit_fn_body`. We will restore afterwards.
430430
let old_body_id = self.body_id;
431431
let old_body_owner = self.body_owner;
432-
let env_snapshot = self.outlives_environment.push_snapshot_pre_closure();
432+
let env_snapshot = self.outlives_environment.push_snapshot_pre_typeck_child();
433433

434434
let body = self.tcx.hir().body(body_id);
435435
self.visit_fn_body(hir_id, body, span);
436436

437437
// Restore state from previous function.
438-
self.outlives_environment.pop_snapshot_post_closure(env_snapshot);
438+
self.outlives_environment.pop_snapshot_post_typeck_child(env_snapshot);
439439
self.body_id = old_body_id;
440440
self.body_owner = old_body_owner;
441441
}

0 commit comments

Comments
 (0)