Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions compiler/rustc_hir_analysis/src/autoderef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct Autoderef<'a, 'tcx> {
// Meta infos:
infcx: &'a InferCtxt<'tcx>,
span: Span,
body_id: LocalDefId,
body_def_id: LocalDefId,
param_env: ty::ParamEnv<'tcx>,

// Current state:
Expand Down Expand Up @@ -119,7 +119,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
Autoderef {
infcx,
span,
body_id: body_def_id,
body_def_id,
param_env,
state: AutoderefSnapshot {
steps: vec![],
Expand Down Expand Up @@ -149,7 +149,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
(tcx.lang_items().deref_trait()?, tcx.lang_items().deref_target()?)
};
let trait_ref = ty::TraitRef::new(tcx, trait_def_id, [ty]);
let cause = traits::ObligationCause::misc(self.span, self.body_id);
let cause = traits::ObligationCause::misc(self.span, self.body_def_id);
let obligation = traits::Obligation::new(
tcx,
cause.clone(),
Expand Down Expand Up @@ -181,7 +181,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
) -> Option<(Ty<'tcx>, PredicateObligations<'tcx>)> {
let ocx = ObligationCtxt::new(self.infcx);
let normalized_ty = ocx.normalize(
&traits::ObligationCause::misc(self.span, self.body_id),
&traits::ObligationCause::misc(self.span, self.body_def_id),
self.param_env,
ty,
);
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ fn compare_method_predicate_entailment<'tcx>(
trait_m: ty::AssocItem,
impl_trait_ref: ty::TraitRef<'tcx>,
) -> Result<(), ErrorGuaranteed> {
// This node-id should be used for the `body_id` field on each
// This node-id should be used for the `body_def_id` field on each
// `ObligationCause` (and the `FnCtxt`).
//
// FIXME(@lcnr): remove that after removing `cause.body_id` from
// FIXME(@lcnr): remove that after removing `cause.body_def_id` from
// obligations.
let impl_m_def_id = impl_m.def_id.expect_local();
let impl_m_span = tcx.def_span(impl_m_def_id);
Expand Down Expand Up @@ -798,7 +798,7 @@ struct ImplTraitInTraitCollector<'a, 'tcx, E> {
types: FxIndexMap<DefId, (Ty<'tcx>, ty::GenericArgsRef<'tcx>)>,
span: Span,
param_env: ty::ParamEnv<'tcx>,
body_id: LocalDefId,
impl_m_id: LocalDefId,
}

impl<'a, 'tcx, E> ImplTraitInTraitCollector<'a, 'tcx, E>
Expand All @@ -809,9 +809,9 @@ where
ocx: &'a ObligationCtxt<'a, 'tcx, E>,
span: Span,
param_env: ty::ParamEnv<'tcx>,
body_id: LocalDefId,
impl_m_id: LocalDefId,
) -> Self {
ImplTraitInTraitCollector { ocx, types: FxIndexMap::default(), span, param_env, body_id }
ImplTraitInTraitCollector { ocx, types: FxIndexMap::default(), span, param_env, impl_m_id }
}
}

Expand Down Expand Up @@ -847,7 +847,7 @@ where
{
let pred = pred.fold_with(self);
let pred = self.ocx.normalize(
&ObligationCause::misc(self.span, self.body_id),
&ObligationCause::misc(self.span, self.impl_m_id),
self.param_env,
Unnormalized::new_wip(pred),
);
Expand All @@ -856,7 +856,7 @@ where
self.cx(),
ObligationCause::new(
self.span,
self.body_id,
self.impl_m_id,
ObligationCauseCode::WhereClause(def_id, pred_span),
),
self.param_env,
Expand Down Expand Up @@ -2346,7 +2346,7 @@ fn compare_type_predicate_entailment<'tcx>(
return Ok(());
}

// This `DefId` should be used for the `body_id` field on each
// This `DefId` should be used for the `body_def_id` field on each
// `ObligationCause` (and the `FnCtxt`). This is what
// `regionck_item` expects.
let impl_ty_def_id = impl_ty.def_id.expect_local();
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
prior_arm: Option<(Option<hir::HirId>, Ty<'tcx>, Span)>,
) {
// First, check that we're actually in the tail of a function.
let Some(body) = self.tcx.hir_maybe_body_owned_by(self.body_id) else {
let Some(body) = self.tcx.hir_maybe_body_owned_by(self.body_def_id) else {
return;
};
let hir::ExprKind::Block(block, _) = body.value.kind else {
Expand All @@ -233,7 +233,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

// Next, make sure that we have no type expectation.
let Some(ret) =
self.tcx.hir_node_by_def_id(self.body_id).fn_decl().map(|decl| decl.output.span())
self.tcx.hir_node_by_def_id(self.body_def_id).fn_decl().map(|decl| decl.output.span())
else {
return;
};
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/autoderef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use super::{FnCtxt, PlaceOp};

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

pub(crate) fn try_overloaded_deref(
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_hir_typeck/src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ pub(crate) fn check_legal_trait_for_method_call(
receiver: Option<Span>,
expr_span: Span,
trait_id: DefId,
body_id: DefId,
body_def_id: DefId,
) -> Result<(), ErrorGuaranteed> {
if tcx.is_lang_item(trait_id, LangItem::Drop)
// Allow calling `Drop::pin_drop` in `Drop::drop`
&& !tcx.is_lang_item(tcx.parent(body_id), LangItem::Drop)
&& !tcx.is_lang_item(tcx.parent(body_def_id), LangItem::Drop)
{
let sugg = if let Some(receiver) = receiver.filter(|s| !s.is_empty()) {
diagnostics::ExplicitDestructorCallSugg::Snippet {
Expand Down Expand Up @@ -1042,7 +1042,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
callee_did: DefId,
callee_args: GenericArgsRef<'tcx>,
) {
let const_context = self.tcx.hir_body_const_context(self.body_id);
let const_context = self.tcx.hir_body_const_context(self.body_def_id);

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

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

Expand Down
13 changes: 10 additions & 3 deletions compiler/rustc_hir_typeck/src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub(crate) struct CastCheck<'tcx> {
cast_ty: Ty<'tcx>,
cast_span: Span,
span: Span,
pub body_id: LocalDefId,
pub body_def_id: LocalDefId,
}

/// The kind of pointer and associated metadata (thin, length or vtable) - we
Expand Down Expand Up @@ -247,8 +247,15 @@ impl<'a, 'tcx> CastCheck<'tcx> {
span: Span,
) -> Result<CastCheck<'tcx>, ErrorGuaranteed> {
let expr_span = expr.span.find_ancestor_inside(span).unwrap_or(expr.span);
let check =
CastCheck { expr, expr_ty, expr_span, cast_ty, cast_span, span, body_id: fcx.body_id };
let check = CastCheck {
expr,
expr_ty,
expr_span,
cast_ty,
cast_span,
span,
body_def_id: fcx.body_def_id,
};

// For better error messages, check for some obviously unsized
// cases now. We do a more thorough check at the end, once
Expand Down
18 changes: 9 additions & 9 deletions compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let sig = if fn_attrs.safe_target_features {
// Allow the coercion if the current function has all the features that would be
// needed to call the coercee safely.
match tcx.adjust_target_feature_sig(def_id, sig, self.body_id.into()) {
match tcx.adjust_target_feature_sig(def_id, sig, self.body_def_id.into()) {
Some(adjusted_sig) => adjusted_sig,
None if matches!(expected_safety, Some(hir::Safety::Safe)) => {
return Err(TypeError::TargetFeatureCast(def_id));
Expand Down Expand Up @@ -1477,12 +1477,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn can_coerce<'tcx>(
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
body_id: LocalDefId,
body_def_id: LocalDefId,
ty: Ty<'tcx>,
output_ty: Ty<'tcx>,
) -> bool {
let root_ctxt = crate::typeck_root_ctxt::TypeckRootCtxt::new(tcx, body_id);
let fn_ctxt = FnCtxt::new(&root_ctxt, param_env, body_id);
let root_ctxt = crate::typeck_root_ctxt::TypeckRootCtxt::new(tcx, body_def_id);
let fn_ctxt = FnCtxt::new(&root_ctxt, param_env, body_def_id);
fn_ctxt.may_coerce(ty, output_ty)
}

Expand Down Expand Up @@ -2057,7 +2057,7 @@ impl<'tcx> CoerceMany<'tcx> {
if due_to_block
&& let Some(expr) = expression
&& let Some(parent_fn_decl) =
fcx.tcx.hir_fn_decl_by_hir_id(fcx.tcx.local_def_id_to_hir_id(fcx.body_id))
fcx.tcx.hir_fn_decl_by_hir_id(fcx.tcx.local_def_id_to_hir_id(fcx.body_def_id))
{
fcx.suggest_missing_break_or_return_expr(
&mut err,
Expand All @@ -2066,14 +2066,14 @@ impl<'tcx> CoerceMany<'tcx> {
expected,
found,
block_or_return_id,
fcx.body_id,
fcx.body_def_id,
);
}

let is_return_position = fcx
.tcx
.hir_get_fn_id_for_return_block(block_or_return_id)
.is_some_and(|fn_id| fn_id == fcx.tcx.local_def_id_to_hir_id(fcx.body_id));
.is_some_and(|fn_id| fn_id == fcx.tcx.local_def_id_to_hir_id(fcx.body_def_id));

if is_return_position
&& let Some(sp) = fcx.ret_coercion_span.get()
Expand All @@ -2083,7 +2083,7 @@ impl<'tcx> CoerceMany<'tcx> {
// may occur at the first return expression we see in the closure
// (if it conflicts with the declared return type). Skip adding a
// note in this case, since it would be incorrect.
&& let Some(fn_sig) = fcx.body_fn_sig()
&& let Some(fn_sig) = fcx.fn_sig()
&& fn_sig.output().is_ty_var()
{
err.span_note(sp, format!("return type inferred to be `{expected}` here"));
Expand All @@ -2096,7 +2096,7 @@ impl<'tcx> CoerceMany<'tcx> {
/// sure we consider `dyn Trait: Sized` where clauses, which are trivially
/// false but technically valid for typeck.
fn is_return_ty_definitely_unsized(&self, fcx: &FnCtxt<'_, 'tcx>) -> bool {
if let Some(sig) = fcx.body_fn_sig() {
if let Some(sig) = fcx.fn_sig() {
!fcx.predicate_may_hold(&Obligation::new(
fcx.tcx,
ObligationCause::dummy(),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}

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

// Replaces all of the variables in the given type with a fresh inference variable.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/expectation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ impl<'a, 'tcx> Expectation<'tcx> {
pub(super) fn rvalue_hint(fcx: &FnCtxt<'a, 'tcx>, ty: Ty<'tcx>) -> Expectation<'tcx> {
let span = match ty.kind() {
ty::Adt(adt_def, _) => fcx.tcx.def_span(adt_def.did()),
_ => fcx.tcx.def_span(fcx.body_id),
_ => fcx.tcx.def_span(fcx.body_def_id),
};
let cause = ObligationCause::misc(span, fcx.body_id);
let cause = ObligationCause::misc(span, fcx.body_def_id);

// FIXME(#155345): Missing normalization call
match fcx.tcx.struct_tail_raw(ty, &cause, |ty| ty.skip_normalization(), || {}).kind() {
Expand Down
26 changes: 16 additions & 10 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return_expr_ty,
);

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

let (ident, def_scope) =
self.tcx.adjust_ident_and_get_scope(field, base_def.did(), self.body_id);
let (ident, def_scope) = self.tcx.adjust_ident_and_get_scope(
field,
base_def.did(),
self.body_def_id,
);

if let Some((idx, field)) = self.find_adt_field(*base_def, ident) {
self.write_field_index(expr.hir_id, idx);
Expand Down Expand Up @@ -2938,7 +2941,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
field_ident.span,
"field not available in `impl Future`, but it is available in its `Output`",
);
match self.tcx.coroutine_kind(self.body_id) {
match self.tcx.coroutine_kind(self.body_def_id) {
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _)) => {
err.span_suggestion_verbose(
base.span.shrink_to_hi(),
Expand All @@ -2949,7 +2952,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
_ => {
let mut span: MultiSpan = base.span.into();
span.push_span_label(self.tcx.def_span(self.body_id), "this is not `async`");
span.push_span_label(self.tcx.def_span(self.body_def_id), "this is not `async`");
err.span_note(
span,
"this implements `Future` and its output type has the field, \
Expand Down Expand Up @@ -3119,7 +3122,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}

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

fn check_expr_asm(&self, asm: &'tcx hir::InlineAsm<'tcx>, span: Span) -> Ty<'tcx> {
if let rustc_ast::AsmMacro::NakedAsm = asm.asm_macro {
if !find_attr!(self.tcx, self.body_id, Naked(..)) {
if !find_attr!(self.tcx, self.body_def_id, Naked(..)) {
self.tcx.dcx().emit_err(NakedAsmOutsideNakedFn { span });
}
}
Expand Down Expand Up @@ -3802,8 +3805,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.emit();
break;
};
let (subident, sub_def_scope) =
self.tcx.adjust_ident_and_get_scope(subfield, variant.def_id, self.body_id);
let (subident, sub_def_scope) = self.tcx.adjust_ident_and_get_scope(
subfield,
variant.def_id,
self.body_def_id,
);

let Some((subindex, field)) = variant
.fields
Expand Down Expand Up @@ -3854,7 +3860,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let (ident, def_scope) = self.tcx.adjust_ident_and_get_scope(
field,
container_def.did(),
self.body_id,
self.body_def_id,
);

let fields = &container_def.non_enum_variant().fields;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl<'tcx> TypeInformationCtxt<'tcx> for &FnCtxt<'_, 'tcx> {
}

fn body_owner_def_id(&self) -> LocalDefId {
self.body_id
self.body_def_id
}

fn tcx(&self) -> TyCtxt<'tcx> {
Expand Down
Loading
Loading