Skip to content

Commit 26eb223

Browse files
authored
Unrolled build for #158696
Rollup merge of #158696 - camsteffen:body-id, r=oli-obk Rename some `body_id` to `body_def_id` Since body IDs and item IDs are distinct things, try to use names that do not conflate them. `body_def_id` is a little easier to read as "body-owning definition ID" whereas `body_id` is hard not to just read as "body ID". Related: #158611 - I noticed this afterwards. I suspect that `FnCtxt` ought to keep `body_def_id` but maybe add `body_id: BodyId` in addition.
2 parents f10db29 + f13657c commit 26eb223

48 files changed

Lines changed: 262 additions & 231 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/rustc_hir_analysis/src/autoderef.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub struct Autoderef<'a, 'tcx> {
3434
// Meta infos:
3535
infcx: &'a InferCtxt<'tcx>,
3636
span: Span,
37-
body_id: LocalDefId,
37+
body_def_id: LocalDefId,
3838
param_env: ty::ParamEnv<'tcx>,
3939

4040
// Current state:
@@ -119,7 +119,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
119119
Autoderef {
120120
infcx,
121121
span,
122-
body_id: body_def_id,
122+
body_def_id,
123123
param_env,
124124
state: AutoderefSnapshot {
125125
steps: vec![],
@@ -149,7 +149,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
149149
(tcx.lang_items().deref_trait()?, tcx.lang_items().deref_target()?)
150150
};
151151
let trait_ref = ty::TraitRef::new(tcx, trait_def_id, [ty]);
152-
let cause = traits::ObligationCause::misc(self.span, self.body_id);
152+
let cause = traits::ObligationCause::misc(self.span, self.body_def_id);
153153
let obligation = traits::Obligation::new(
154154
tcx,
155155
cause.clone(),
@@ -181,7 +181,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
181181
) -> Option<(Ty<'tcx>, PredicateObligations<'tcx>)> {
182182
let ocx = ObligationCtxt::new(self.infcx);
183183
let normalized_ty = ocx.normalize(
184-
&traits::ObligationCause::misc(self.span, self.body_id),
184+
&traits::ObligationCause::misc(self.span, self.body_def_id),
185185
self.param_env,
186186
ty,
187187
);

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@ fn compare_method_predicate_entailment<'tcx>(
177177
trait_m: ty::AssocItem,
178178
impl_trait_ref: ty::TraitRef<'tcx>,
179179
) -> Result<(), ErrorGuaranteed> {
180-
// This node-id should be used for the `body_id` field on each
180+
// This node-id should be used for the `body_def_id` field on each
181181
// `ObligationCause` (and the `FnCtxt`).
182182
//
183-
// FIXME(@lcnr): remove that after removing `cause.body_id` from
183+
// FIXME(@lcnr): remove that after removing `cause.body_def_id` from
184184
// obligations.
185185
let impl_m_def_id = impl_m.def_id.expect_local();
186186
let impl_m_span = tcx.def_span(impl_m_def_id);
@@ -798,7 +798,7 @@ struct ImplTraitInTraitCollector<'a, 'tcx, E> {
798798
types: FxIndexMap<DefId, (Ty<'tcx>, ty::GenericArgsRef<'tcx>)>,
799799
span: Span,
800800
param_env: ty::ParamEnv<'tcx>,
801-
body_id: LocalDefId,
801+
impl_m_id: LocalDefId,
802802
}
803803

804804
impl<'a, 'tcx, E> ImplTraitInTraitCollector<'a, 'tcx, E>
@@ -809,9 +809,9 @@ where
809809
ocx: &'a ObligationCtxt<'a, 'tcx, E>,
810810
span: Span,
811811
param_env: ty::ParamEnv<'tcx>,
812-
body_id: LocalDefId,
812+
impl_m_id: LocalDefId,
813813
) -> Self {
814-
ImplTraitInTraitCollector { ocx, types: FxIndexMap::default(), span, param_env, body_id }
814+
ImplTraitInTraitCollector { ocx, types: FxIndexMap::default(), span, param_env, impl_m_id }
815815
}
816816
}
817817

@@ -847,7 +847,7 @@ where
847847
{
848848
let pred = pred.fold_with(self);
849849
let pred = self.ocx.normalize(
850-
&ObligationCause::misc(self.span, self.body_id),
850+
&ObligationCause::misc(self.span, self.impl_m_id),
851851
self.param_env,
852852
Unnormalized::new_wip(pred),
853853
);
@@ -856,7 +856,7 @@ where
856856
self.cx(),
857857
ObligationCause::new(
858858
self.span,
859-
self.body_id,
859+
self.impl_m_id,
860860
ObligationCauseCode::WhereClause(def_id, pred_span),
861861
),
862862
self.param_env,
@@ -2346,7 +2346,7 @@ fn compare_type_predicate_entailment<'tcx>(
23462346
return Ok(());
23472347
}
23482348

2349-
// This `DefId` should be used for the `body_id` field on each
2349+
// This `DefId` should be used for the `body_def_id` field on each
23502350
// `ObligationCause` (and the `FnCtxt`). This is what
23512351
// `regionck_item` expects.
23522352
let impl_ty_def_id = impl_ty.def_id.expect_local();

compiler/rustc_hir_typeck/src/_match.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
216216
prior_arm: Option<(Option<hir::HirId>, Ty<'tcx>, Span)>,
217217
) {
218218
// First, check that we're actually in the tail of a function.
219-
let Some(body) = self.tcx.hir_maybe_body_owned_by(self.body_id) else {
219+
let Some(body) = self.tcx.hir_maybe_body_owned_by(self.body_def_id) else {
220220
return;
221221
};
222222
let hir::ExprKind::Block(block, _) = body.value.kind else {
@@ -233,7 +233,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
233233

234234
// Next, make sure that we have no type expectation.
235235
let Some(ret) =
236-
self.tcx.hir_node_by_def_id(self.body_id).fn_decl().map(|decl| decl.output.span())
236+
self.tcx.hir_node_by_def_id(self.body_def_id).fn_decl().map(|decl| decl.output.span())
237237
else {
238238
return;
239239
};

compiler/rustc_hir_typeck/src/autoderef.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use super::{FnCtxt, PlaceOp};
1515

1616
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1717
pub(crate) fn autoderef(&'a self, span: Span, base_ty: Ty<'tcx>) -> Autoderef<'a, 'tcx> {
18-
Autoderef::new(self, self.param_env, self.body_id, span, base_ty)
18+
Autoderef::new(self, self.param_env, self.body_def_id, span, base_ty)
1919
}
2020

2121
pub(crate) fn try_overloaded_deref(

compiler/rustc_hir_typeck/src/callee.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ pub(crate) fn check_legal_trait_for_method_call(
3939
receiver: Option<Span>,
4040
expr_span: Span,
4141
trait_id: DefId,
42-
body_id: DefId,
42+
body_def_id: DefId,
4343
) -> Result<(), ErrorGuaranteed> {
4444
if tcx.is_lang_item(trait_id, LangItem::Drop)
4545
// Allow calling `Drop::pin_drop` in `Drop::drop`
46-
&& !tcx.is_lang_item(tcx.parent(body_id), LangItem::Drop)
46+
&& !tcx.is_lang_item(tcx.parent(body_def_id), LangItem::Drop)
4747
{
4848
let sugg = if let Some(receiver) = receiver.filter(|s| !s.is_empty()) {
4949
diagnostics::ExplicitDestructorCallSugg::Snippet {
@@ -1042,7 +1042,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10421042
callee_did: DefId,
10431043
callee_args: GenericArgsRef<'tcx>,
10441044
) {
1045-
let const_context = self.tcx.hir_body_const_context(self.body_id);
1045+
let const_context = self.tcx.hir_body_const_context(self.body_def_id);
10461046

10471047
if let hir::Constness::Const { always: true } = self.tcx.constness(callee_did) {
10481048
match const_context {
@@ -1062,7 +1062,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10621062
}
10631063

10641064
// If we have `rustc_do_not_const_check`, do not check `[const]` bounds.
1065-
if self.has_rustc_attrs && find_attr!(self.tcx, self.body_id, RustcDoNotConstCheck) {
1065+
if self.has_rustc_attrs && find_attr!(self.tcx, self.body_def_id, RustcDoNotConstCheck) {
10661066
return;
10671067
}
10681068

compiler/rustc_hir_typeck/src/cast.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub(crate) struct CastCheck<'tcx> {
6464
cast_ty: Ty<'tcx>,
6565
cast_span: Span,
6666
span: Span,
67-
pub body_id: LocalDefId,
67+
pub body_def_id: LocalDefId,
6868
}
6969

7070
/// The kind of pointer and associated metadata (thin, length or vtable) - we
@@ -247,8 +247,15 @@ impl<'a, 'tcx> CastCheck<'tcx> {
247247
span: Span,
248248
) -> Result<CastCheck<'tcx>, ErrorGuaranteed> {
249249
let expr_span = expr.span.find_ancestor_inside(span).unwrap_or(expr.span);
250-
let check =
251-
CastCheck { expr, expr_ty, expr_span, cast_ty, cast_span, span, body_id: fcx.body_id };
250+
let check = CastCheck {
251+
expr,
252+
expr_ty,
253+
expr_span,
254+
cast_ty,
255+
cast_span,
256+
span,
257+
body_def_id: fcx.body_def_id,
258+
};
252259

253260
// For better error messages, check for some obviously unsized
254261
// cases now. We do a more thorough check at the end, once

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12581258
let sig = if fn_attrs.safe_target_features {
12591259
// Allow the coercion if the current function has all the features that would be
12601260
// needed to call the coercee safely.
1261-
match tcx.adjust_target_feature_sig(def_id, sig, self.body_id.into()) {
1261+
match tcx.adjust_target_feature_sig(def_id, sig, self.body_def_id.into()) {
12621262
Some(adjusted_sig) => adjusted_sig,
12631263
None if matches!(expected_safety, Some(hir::Safety::Safe)) => {
12641264
return Err(TypeError::TargetFeatureCast(def_id));
@@ -1477,12 +1477,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14771477
pub fn can_coerce<'tcx>(
14781478
tcx: TyCtxt<'tcx>,
14791479
param_env: ty::ParamEnv<'tcx>,
1480-
body_id: LocalDefId,
1480+
body_def_id: LocalDefId,
14811481
ty: Ty<'tcx>,
14821482
output_ty: Ty<'tcx>,
14831483
) -> bool {
1484-
let root_ctxt = crate::typeck_root_ctxt::TypeckRootCtxt::new(tcx, body_id);
1485-
let fn_ctxt = FnCtxt::new(&root_ctxt, param_env, body_id);
1484+
let root_ctxt = crate::typeck_root_ctxt::TypeckRootCtxt::new(tcx, body_def_id);
1485+
let fn_ctxt = FnCtxt::new(&root_ctxt, param_env, body_def_id);
14861486
fn_ctxt.may_coerce(ty, output_ty)
14871487
}
14881488

@@ -2057,7 +2057,7 @@ impl<'tcx> CoerceMany<'tcx> {
20572057
if due_to_block
20582058
&& let Some(expr) = expression
20592059
&& let Some(parent_fn_decl) =
2060-
fcx.tcx.hir_fn_decl_by_hir_id(fcx.tcx.local_def_id_to_hir_id(fcx.body_id))
2060+
fcx.tcx.hir_fn_decl_by_hir_id(fcx.tcx.local_def_id_to_hir_id(fcx.body_def_id))
20612061
{
20622062
fcx.suggest_missing_break_or_return_expr(
20632063
&mut err,
@@ -2066,14 +2066,14 @@ impl<'tcx> CoerceMany<'tcx> {
20662066
expected,
20672067
found,
20682068
block_or_return_id,
2069-
fcx.body_id,
2069+
fcx.body_def_id,
20702070
);
20712071
}
20722072

20732073
let is_return_position = fcx
20742074
.tcx
20752075
.hir_get_fn_id_for_return_block(block_or_return_id)
2076-
.is_some_and(|fn_id| fn_id == fcx.tcx.local_def_id_to_hir_id(fcx.body_id));
2076+
.is_some_and(|fn_id| fn_id == fcx.tcx.local_def_id_to_hir_id(fcx.body_def_id));
20772077

20782078
if is_return_position
20792079
&& let Some(sp) = fcx.ret_coercion_span.get()
@@ -2083,7 +2083,7 @@ impl<'tcx> CoerceMany<'tcx> {
20832083
// may occur at the first return expression we see in the closure
20842084
// (if it conflicts with the declared return type). Skip adding a
20852085
// note in this case, since it would be incorrect.
2086-
&& let Some(fn_sig) = fcx.body_fn_sig()
2086+
&& let Some(fn_sig) = fcx.fn_sig()
20872087
&& fn_sig.output().is_ty_var()
20882088
{
20892089
err.span_note(sp, format!("return type inferred to be `{expected}` here"));
@@ -2096,7 +2096,7 @@ impl<'tcx> CoerceMany<'tcx> {
20962096
/// sure we consider `dyn Trait: Sized` where clauses, which are trivially
20972097
/// false but technically valid for typeck.
20982098
fn is_return_ty_definitely_unsized(&self, fcx: &FnCtxt<'_, 'tcx>) -> bool {
2099-
if let Some(sig) = fcx.body_fn_sig() {
2099+
if let Some(sig) = fcx.fn_sig() {
21002100
!fcx.predicate_may_hold(&Obligation::new(
21012101
fcx.tcx,
21022102
ObligationCause::dummy(),

compiler/rustc_hir_typeck/src/demand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
332332
}
333333

334334
let mut expr_finder = FindExprs { hir_id: local_hir_id, uses: init.into_iter().collect() };
335-
let body = self.tcx.hir_body_owned_by(self.body_id);
335+
let body = self.tcx.hir_body_owned_by(self.body_def_id);
336336
expr_finder.visit_expr(body.value);
337337

338338
// Replaces all of the variables in the given type with a fresh inference variable.

compiler/rustc_hir_typeck/src/expectation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ impl<'a, 'tcx> Expectation<'tcx> {
7676
pub(super) fn rvalue_hint(fcx: &FnCtxt<'a, 'tcx>, ty: Ty<'tcx>) -> Expectation<'tcx> {
7777
let span = match ty.kind() {
7878
ty::Adt(adt_def, _) => fcx.tcx.def_span(adt_def.did()),
79-
_ => fcx.tcx.def_span(fcx.body_id),
79+
_ => fcx.tcx.def_span(fcx.body_def_id),
8080
};
81-
let cause = ObligationCause::misc(span, fcx.body_id);
81+
let cause = ObligationCause::misc(span, fcx.body_def_id);
8282

8383
// FIXME(#155345): Missing normalization call
8484
match fcx.tcx.struct_tail_raw(ty, &cause, |ty| ty.skip_normalization(), || {}).kind() {

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
965965
return_expr_ty,
966966
);
967967

968-
if let Some(fn_sig) = self.body_fn_sig()
968+
if let Some(fn_sig) = self.fn_sig()
969969
&& fn_sig.output().has_opaque_types()
970970
{
971971
// Point any obligations that were registered due to opaque type
@@ -2764,8 +2764,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
27642764
return Ty::new_error(self.tcx(), guar);
27652765
}
27662766

2767-
let (ident, def_scope) =
2768-
self.tcx.adjust_ident_and_get_scope(field, base_def.did(), self.body_id);
2767+
let (ident, def_scope) = self.tcx.adjust_ident_and_get_scope(
2768+
field,
2769+
base_def.did(),
2770+
self.body_def_id,
2771+
);
27692772

27702773
if let Some((idx, field)) = self.find_adt_field(*base_def, ident) {
27712774
self.write_field_index(expr.hir_id, idx);
@@ -2938,7 +2941,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
29382941
field_ident.span,
29392942
"field not available in `impl Future`, but it is available in its `Output`",
29402943
);
2941-
match self.tcx.coroutine_kind(self.body_id) {
2944+
match self.tcx.coroutine_kind(self.body_def_id) {
29422945
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _)) => {
29432946
err.span_suggestion_verbose(
29442947
base.span.shrink_to_hi(),
@@ -2949,7 +2952,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
29492952
}
29502953
_ => {
29512954
let mut span: MultiSpan = base.span.into();
2952-
span.push_span_label(self.tcx.def_span(self.body_id), "this is not `async`");
2955+
span.push_span_label(self.tcx.def_span(self.body_def_id), "this is not `async`");
29532956
err.span_note(
29542957
span,
29552958
"this implements `Future` and its output type has the field, \
@@ -3119,7 +3122,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
31193122
}
31203123

31213124
fn point_at_param_definition(&self, err: &mut Diag<'_>, param: ty::ParamTy) {
3122-
let generics = self.tcx.generics_of(self.body_id);
3125+
let generics = self.tcx.generics_of(self.body_def_id);
31233126
let generic_param = generics.type_param(param, self.tcx);
31243127
if let ty::GenericParamDefKind::Type { synthetic: true, .. } = generic_param.kind {
31253128
return;
@@ -3703,7 +3706,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
37033706

37043707
fn check_expr_asm(&self, asm: &'tcx hir::InlineAsm<'tcx>, span: Span) -> Ty<'tcx> {
37053708
if let rustc_ast::AsmMacro::NakedAsm = asm.asm_macro {
3706-
if !find_attr!(self.tcx, self.body_id, Naked(..)) {
3709+
if !find_attr!(self.tcx, self.body_def_id, Naked(..)) {
37073710
self.tcx.dcx().emit_err(NakedAsmOutsideNakedFn { span });
37083711
}
37093712
}
@@ -3802,8 +3805,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
38023805
.emit();
38033806
break;
38043807
};
3805-
let (subident, sub_def_scope) =
3806-
self.tcx.adjust_ident_and_get_scope(subfield, variant.def_id, self.body_id);
3808+
let (subident, sub_def_scope) = self.tcx.adjust_ident_and_get_scope(
3809+
subfield,
3810+
variant.def_id,
3811+
self.body_def_id,
3812+
);
38073813

38083814
let Some((subindex, field)) = variant
38093815
.fields
@@ -3854,7 +3860,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
38543860
let (ident, def_scope) = self.tcx.adjust_ident_and_get_scope(
38553861
field,
38563862
container_def.did(),
3857-
self.body_id,
3863+
self.body_def_id,
38583864
);
38593865

38603866
let fields = &container_def.non_enum_variant().fields;

0 commit comments

Comments
 (0)