1
Fork 0

Make body_owned_by return the body directly.

Almost all callers want this anyway, and now we can use it to also return fed bodies
This commit is contained in:
Oli Scherer 2024-05-29 10:03:40 +00:00
parent ceb45d5519
commit a34c26e7ec
38 changed files with 136 additions and 131 deletions

View file

@ -452,7 +452,7 @@ fn construct_fn<'tcx>(
assert_eq!(expr.as_usize(), thir.exprs.len() - 1);
// Figure out what primary body this item has.
let body_id = tcx.hir().body_owned_by(fn_def);
let body = tcx.hir().body_owned_by(fn_def);
let span_with_body = tcx.hir().span_with_body(fn_id);
let return_ty_span = tcx
.hir()
@ -512,9 +512,9 @@ fn construct_fn<'tcx>(
);
let call_site_scope =
region::Scope { id: body_id.hir_id.local_id, data: region::ScopeData::CallSite };
region::Scope { id: body.id().hir_id.local_id, data: region::ScopeData::CallSite };
let arg_scope =
region::Scope { id: body_id.hir_id.local_id, data: region::ScopeData::Arguments };
region::Scope { id: body.id().hir_id.local_id, data: region::ScopeData::Arguments };
let source_info = builder.source_info(span);
let call_site_s = (call_site_scope, source_info);
unpack!(builder.in_scope(call_site_s, LintLevel::Inherited, |builder| {

View file

@ -13,10 +13,10 @@ use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::lang_items::LangItem;
use rustc_hir::HirId;
use rustc_hir::Node;
use rustc_middle::bug;
use rustc_middle::middle::region;
use rustc_middle::thir::*;
use rustc_middle::ty::{self, RvalueScopes, TyCtxt};
use rustc_middle::{bug, span_bug};
use tracing::instrument;
pub(crate) fn thir_body(
@ -24,22 +24,7 @@ pub(crate) fn thir_body(
owner_def: LocalDefId,
) -> Result<(&Steal<Thir<'_>>, ExprId), ErrorGuaranteed> {
let hir = tcx.hir();
let body;
let body = match tcx.def_kind(owner_def) {
// Inline consts do not have bodies of their own, so create one to make the follow-up logic simpler.
DefKind::InlineConst => {
let e = hir.expect_expr(tcx.local_def_id_to_hir_id(owner_def));
body = hir::Body {
params: &[],
value: match e.kind {
hir::ExprKind::ConstBlock(body) => body,
_ => span_bug!(e.span, "InlineConst was not a ConstBlock: {e:#?}"),
},
};
&body
}
_ => hir.body(hir.body_owned_by(owner_def)),
};
let body = hir.body_owned_by(owner_def);
let mut cx = Cx::new(tcx, owner_def);
if let Some(reported) = cx.typeck_results.tainted_by_errors {
return Err(reported);
@ -49,7 +34,7 @@ pub(crate) fn thir_body(
let owner_id = tcx.local_def_id_to_hir_id(owner_def);
if let Some(fn_decl) = hir.fn_decl_by_hir_id(owner_id) {
let closure_env_param = cx.closure_env_param(owner_def, owner_id);
let explicit_params = cx.explicit_params(owner_id, fn_decl, body);
let explicit_params = cx.explicit_params(owner_id, fn_decl, &body);
cx.thir.params = closure_env_param.into_iter().chain(explicit_params).collect();
// The resume argument may be missing, in that case we need to provide it here.