1
Fork 0

Improve spans in custom mir

This commit is contained in:
Jakob Degen 2022-11-27 21:23:39 -08:00
parent 52ce1f7697
commit 5a34dbf193
10 changed files with 47 additions and 39 deletions

View file

@ -74,7 +74,7 @@ pub(super) fn build_custom_mir<'tcx>(
let mut pctxt = ParseCtxt {
tcx,
thir,
source_info: SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE },
source_scope: OUTERMOST_SOURCE_SCOPE,
body: &mut body,
local_map: FxHashMap::default(),
block_map: FxHashMap::default(),
@ -128,7 +128,7 @@ fn parse_attribute(attr: &Attribute) -> MirPhase {
struct ParseCtxt<'tcx, 'body> {
tcx: TyCtxt<'tcx>,
thir: &'body Thir<'tcx>,
source_info: SourceInfo,
source_scope: SourceScope,
body: &'body mut Body<'tcx>,
local_map: FxHashMap<LocalVarId, Local>,

View file

@ -233,15 +233,23 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
let mut data = BasicBlockData::new(None);
for stmt_id in &*block.stmts {
let stmt = self.statement_as_expr(*stmt_id)?;
let span = self.thir[stmt].span;
let statement = self.parse_statement(stmt)?;
data.statements.push(Statement { source_info: self.source_info, kind: statement });
data.statements.push(Statement {
source_info: SourceInfo { span, scope: self.source_scope },
kind: statement,
});
}
let Some(trailing) = block.expr else {
return Err(self.expr_error(expr_id, "terminator"))
};
let span = self.thir[trailing].span;
let terminator = self.parse_terminator(trailing)?;
data.terminator = Some(Terminator { source_info: self.source_info, kind: terminator });
data.terminator = Some(Terminator {
source_info: SourceInfo { span, scope: self.source_scope },
kind: terminator,
});
Ok(data)
}

View file

@ -492,7 +492,7 @@ fn construct_fn<'tcx>(
arguments,
return_ty,
return_ty_span,
span,
span_with_body,
custom_mir_attr,
);
}