Skip to content

Commit e0dc8d7

Browse files
committedAug 22, 2022
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`
2 parents a8a33cf + 5d7ce21 commit e0dc8d7

File tree

43 files changed

+407
-397
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+407
-397
lines changed
 

‎compiler/rustc_mir_build/src/build/mod.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,18 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
250250
// of `mir_build`, so now we can steal it
251251
let thir = thir.steal();
252252

253-
build::construct_const(&thir, &infcx, expr, def, id, return_ty, return_ty_span)
253+
let span_with_body = span_with_body.to(tcx.hir().span(body_id.hir_id));
254+
255+
build::construct_const(
256+
&thir,
257+
&infcx,
258+
expr,
259+
def,
260+
id,
261+
return_ty,
262+
return_ty_span,
263+
span_with_body,
264+
)
254265
};
255266

256267
lints::check(tcx, &body);
@@ -705,9 +716,8 @@ fn construct_const<'a, 'tcx>(
705716
hir_id: hir::HirId,
706717
const_ty: Ty<'tcx>,
707718
const_ty_span: Span,
719+
span: Span,
708720
) -> Body<'tcx> {
709-
let tcx = infcx.tcx;
710-
let span = tcx.hir().span(hir_id);
711721
let mut builder = Builder::new(
712722
thir,
713723
infcx,

‎compiler/rustc_span/src/source_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ impl SourceMap {
472472
let hi = self.lookup_char_pos(sp.hi());
473473
let offset = self.lookup_char_pos(relative_to.lo());
474474

475-
if lo.file.name != offset.file.name {
475+
if lo.file.name != offset.file.name || !relative_to.contains(sp) {
476476
return self.span_to_embeddable_string(sp);
477477
}
478478

0 commit comments

Comments
 (0)
Please sign in to comment.