1
Fork 0

Auto merge of #99908 - Nilstrieb:mir-opt-span, r=oli-obk

Show absolute line numbers if span is outside relative span

In the MIR pretty printing, it can sometimes happen that the span of the statement is outside the span of the body (for example through inlining). In this case, don't display a relative span but an absolute span. This will make the mir-opt-tests a little more prone to diffs again, but the impact should be small.

Fixes #99854

r? `@oli-obk`
This commit is contained in:
bors 2022-08-22 14:59:21 +00:00
commit e0dc8d7801
43 changed files with 407 additions and 397 deletions

View file

@ -250,7 +250,18 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
// of `mir_build`, so now we can steal it
let thir = thir.steal();
build::construct_const(&thir, &infcx, expr, def, id, return_ty, return_ty_span)
let span_with_body = span_with_body.to(tcx.hir().span(body_id.hir_id));
build::construct_const(
&thir,
&infcx,
expr,
def,
id,
return_ty,
return_ty_span,
span_with_body,
)
};
lints::check(tcx, &body);
@ -705,9 +716,8 @@ fn construct_const<'a, 'tcx>(
hir_id: hir::HirId,
const_ty: Ty<'tcx>,
const_ty_span: Span,
span: Span,
) -> Body<'tcx> {
let tcx = infcx.tcx;
let span = tcx.hir().span(hir_id);
let mut builder = Builder::new(
thir,
infcx,

View file

@ -472,7 +472,7 @@ impl SourceMap {
let hi = self.lookup_char_pos(sp.hi());
let offset = self.lookup_char_pos(relative_to.lo());
if lo.file.name != offset.file.name {
if lo.file.name != offset.file.name || !relative_to.contains(sp) {
return self.span_to_embeddable_string(sp);
}