Assert well-formedness of spans

d0cd474
Opened by Esteban Kuber at 2024-09-24 11:30:31

rustc currently has peppered throughout the codebase some checks for "backwards spans", spans where their end is earlier than their start. I believe that the current approach of actively checking for this and not fail is very reasonable in beta and stable rustc, but in nightly builds I would like to have an assertion so that we expose this incorrectly formatted spans so that the underlying cause can be fixed.

This might take the form of a simple assert and ICEing (not my preference, but it would certainly bring attention to the problem) to generating a diagnostic error and emitting it, allowing the compiler to continue working, but making the problem visible to anyone using the nightly compiler, with text prompting a report in this issue tracker. If we go down the later route, it probably should be a warning, so that anyone using the nightly compiler in production isn't stopped from using it due to a rustc bug.

  1. rustc currently has peppered throughout the codebase some checks for "backwards spans", spans where their end is earlier than their start. I believe that the current approach of actively checking for this and not fail is very reasonable in beta and stable rustc, but in nightly builds I would like to have an assertion so that we expose this incorrectly formatted spans so that the underlying cause can be fixed.

    This might take the form of a simple assert and ICEing (not my preference, but it would certainly bring attention to the problem) to generating a diagnostic error and emitting it, allowing the compiler to continue working, but making the problem visible to anyone using the nightly compiler, with text prompting a report in this issue tracker. If we go down the later route, it probably should be a warning, so that anyone using the nightly compiler in production isn't stopped from using it due to a rustc bug.

    <!-- TRIAGEBOT_START --> <!-- TRIAGEBOT_ASSIGN_START --> <!-- TRIAGEBOT_ASSIGN_DATA_START$${"user":"starmut"}$$TRIAGEBOT_ASSIGN_DATA_END --> <!-- TRIAGEBOT_ASSIGN_END --> <!-- TRIAGEBOT_END -->

    rustbot at 2023-10-14 03:40:38

  2. @rustbot claim

    Mansoor Zia Faqiri at 2023-10-14 03:40:36

  3. I would like to work on this. Should the assertion be in functions returning a Span or even in functions accepting Spans as arguments?

    Malik Ammar Faisal at 2023-12-14 01:49:05

  4. @rustbot claim

    Quinn Smith at 2024-01-28 02:04:24

  5. Also relevant: #106192

    if someone wants to pick that up, that would be very welcome

    nora at 2024-01-29 17:27:46

  6. @rustbot claim

    I want to work on this, but I'll need some pointers on how to approach it.

    Ari Prakash at 2024-03-11 03:21:21

  7. open a thread on zulip in t-compiler/help (link)

    nora at 2024-03-11 06:54:25

  8. I remove the E-easy tag, because #122418 shows that this is harder than it first appears.

    Nicholas Nethercote at 2024-09-24 11:30:31