Create const block DefIds in typeck instead of ast lowering
This commit is contained in:
parent
e5cba17b84
commit
ddc5f9b6c1
39 changed files with 162 additions and 189 deletions
|
@ -568,11 +568,8 @@ fn construct_const<'a, 'tcx>(
|
|||
..
|
||||
}) => (*span, ty.span),
|
||||
Node::AnonConst(ct) => (ct.span, ct.span),
|
||||
Node::ConstBlock(_) => {
|
||||
let span = tcx.def_span(def);
|
||||
(span, span)
|
||||
}
|
||||
_ => span_bug!(tcx.def_span(def), "can't build MIR for {:?}", def),
|
||||
Node::Expr(&hir::Expr { span, kind: hir::ExprKind::ConstBlock(_), .. }) => (span, span),
|
||||
node => span_bug!(tcx.def_span(def), "can't build MIR for {def:?}: {node:#?}"),
|
||||
};
|
||||
|
||||
let infcx = tcx.infer_ctxt().build();
|
||||
|
|
|
@ -671,9 +671,9 @@ impl<'tcx> Cx<'tcx> {
|
|||
ExprKind::OffsetOf { container, fields }
|
||||
}
|
||||
|
||||
hir::ExprKind::ConstBlock(ref anon_const) => {
|
||||
let ty = self.typeck_results().node_type(anon_const.hir_id);
|
||||
let did = anon_const.def_id.to_def_id();
|
||||
hir::ExprKind::ConstBlock(body) => {
|
||||
let ty = self.typeck_results().node_type(body.hir_id);
|
||||
let did = self.typeck_results().inline_consts[&expr.hir_id.local_id].into();
|
||||
let typeck_root_def_id = tcx.typeck_root_def_id(did);
|
||||
let parent_args =
|
||||
tcx.erase_regions(GenericArgs::identity_for_item(tcx, typeck_root_def_id));
|
||||
|
|
|
@ -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,7 +24,22 @@ pub(crate) fn thir_body(
|
|||
owner_def: LocalDefId,
|
||||
) -> Result<(&Steal<Thir<'_>>, ExprId), ErrorGuaranteed> {
|
||||
let hir = tcx.hir();
|
||||
let body = hir.body(hir.body_owned_by(owner_def));
|
||||
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 mut cx = Cx::new(tcx, owner_def);
|
||||
if let Some(reported) = cx.typeck_results.tainted_by_errors {
|
||||
return Err(reported);
|
||||
|
@ -165,7 +180,7 @@ impl<'tcx> Cx<'tcx> {
|
|||
&'a mut self,
|
||||
owner_id: HirId,
|
||||
fn_decl: &'tcx hir::FnDecl<'tcx>,
|
||||
body: &'tcx hir::Body<'tcx>,
|
||||
body: &hir::Body<'tcx>,
|
||||
) -> impl Iterator<Item = Param<'tcx>> + 'a {
|
||||
let fn_sig = self.typeck_results.liberated_fn_sigs()[owner_id];
|
||||
|
||||
|
|
|
@ -637,15 +637,13 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
|||
/// Converts inline const patterns.
|
||||
fn lower_inline_const(
|
||||
&mut self,
|
||||
block: &'tcx hir::ConstBlock,
|
||||
expr: &'tcx hir::Expr<'tcx>,
|
||||
id: hir::HirId,
|
||||
span: Span,
|
||||
) -> PatKind<'tcx> {
|
||||
let tcx = self.tcx;
|
||||
let def_id = block.def_id;
|
||||
let body_id = block.body;
|
||||
let expr = &tcx.hir().body(body_id).value;
|
||||
let ty = tcx.typeck(def_id).node_type(block.hir_id);
|
||||
let def_id = self.typeck_results.inline_consts[&id.local_id];
|
||||
let ty = tcx.typeck(def_id).node_type(expr.hir_id);
|
||||
|
||||
// Special case inline consts that are just literals. This is solely
|
||||
// a performance optimization, as we could also just go through the regular
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue