1
Fork 0

Remember the MirSource for each Body

This commit is contained in:
Dylan MacKenzie 2020-10-04 11:01:38 -07:00
parent 938d8fd805
commit 6f61e71648
41 changed files with 284 additions and 349 deletions

View file

@ -296,6 +296,7 @@ struct Builder<'a, 'tcx> {
hir: Cx<'a, 'tcx>,
cfg: CFG<'tcx>,
def_id: DefId,
fn_span: Span,
arg_count: usize,
generator_kind: Option<GeneratorKind>,
@ -597,6 +598,7 @@ where
let mut builder = Builder::new(
hir,
fn_def_id.to_def_id(),
span_with_body,
arguments.len(),
safety,
@ -675,8 +677,9 @@ fn construct_const<'a, 'tcx>(
) -> Body<'tcx> {
let tcx = hir.tcx();
let owner_id = tcx.hir().body_owner(body_id);
let def_id = tcx.hir().local_def_id(owner_id);
let span = tcx.hir().span(owner_id);
let mut builder = Builder::new(hir, span, 0, Safety::Safe, const_ty, const_ty_span, None);
let mut builder = Builder::new(hir, def_id.to_def_id(), span, 0, Safety::Safe, const_ty, const_ty_span, None);
let mut block = START_BLOCK;
let ast_expr = &tcx.hir().body(body_id).value;
@ -705,6 +708,7 @@ fn construct_const<'a, 'tcx>(
fn construct_error<'a, 'tcx>(hir: Cx<'a, 'tcx>, body_id: hir::BodyId) -> Body<'tcx> {
let tcx = hir.tcx();
let owner_id = tcx.hir().body_owner(body_id);
let def_id = tcx.hir().local_def_id(owner_id);
let span = tcx.hir().span(owner_id);
let ty = tcx.ty_error();
let num_params = match hir.body_owner_kind {
@ -722,7 +726,7 @@ fn construct_error<'a, 'tcx>(hir: Cx<'a, 'tcx>, body_id: hir::BodyId) -> Body<'t
hir::BodyOwnerKind::Const => 0,
hir::BodyOwnerKind::Static(_) => 0,
};
let mut builder = Builder::new(hir, span, num_params, Safety::Safe, ty, span, None);
let mut builder = Builder::new(hir, def_id.to_def_id(), span, num_params, Safety::Safe, ty, span, None);
let source_info = builder.source_info(span);
// Some MIR passes will expect the number of parameters to match the
// function declaration.
@ -740,6 +744,7 @@ fn construct_error<'a, 'tcx>(hir: Cx<'a, 'tcx>, body_id: hir::BodyId) -> Body<'t
impl<'a, 'tcx> Builder<'a, 'tcx> {
fn new(
hir: Cx<'a, 'tcx>,
def_id: DefId,
span: Span,
arg_count: usize,
safety: Safety,
@ -750,6 +755,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let lint_level = LintLevel::Explicit(hir.root_lint_level);
let mut builder = Builder {
hir,
def_id,
cfg: CFG { basic_blocks: IndexVec::new() },
fn_span: span,
arg_count,
@ -790,6 +796,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
Body::new(
MirSource::item(self.def_id),
self.cfg.basic_blocks,
self.source_scopes,
self.local_decls,