Skip to content

Bad MIR spans #99854

Open
Open
@Noratrieb

Description

@Noratrieb

In #99780 (comment), I tried to add an assertion in the span formatting function to validate that the span for the mir::Body.span span always contains all spans of MIR statements/terminators.

diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs
index 28381157d50..ad44a0366b5 100644
--- a/compiler/rustc_span/src/source_map.rs
+++ b/compiler/rustc_span/src/source_map.rs
@@ -477,6 +477,8 @@ pub fn span_to_relative_line_string(&self, sp: Span, relative_to: Span) -> Strin
             return self.span_to_embeddable_string(sp);
         }

+        assert!(relative_to.contains(sp));
+
         let lo_line = lo.line.saturating_sub(offset.line);
         let hi_line = hi.line.saturating_sub(offset.line);

But this assertion failed for many tests. One such case was for associated constants.

We should investigate all the cases where the MIR body span is not fully correct, and add the assertion back in.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions