Skip to content

Omit suggestions when spans overlap #929

@jdonszelmann

Description

@jdonszelmann

Proposal

Currently, there are two cases in which suggestions in diagnostics are invalid: their spans span more than one file, or their span overlaps. In the former case, we skip the suggestion silently, in the latter we ICE.

This is the code that skips suggestions when they span multiple files: https://github.com/rust-lang/rust/blob/c8a31b780d5415358566a20b94912620a3f27067/compiler/rustc_errors/src/lib.rs#L371

This usually is good! It often means a broken diagnostic. However, this code shows that because users can change the spans on tokens, they can cause spans to overlap, and diagnostics to ICE:

rust-lang/rust@436c2eb

Currently, we ICE here because when running rustfix, it crashes when suggestions overlap.

My proposal is to, instead of ICEing, omit suggestions with invalid spans, but not silently.
This means we also don't emit these suggestions in JSON output; that way rustfix doesn't stumble over them.

This pull request shows what that would look like: rust-lang/rust#147849, and specifically here:
https://github.com/jdonszelmann/rust/blob/b876dd753e0dcc6be5c0b6c1ed6844b67266dc25/tests/ui/parser/attribute/invalid-delimeter-ice-146808.stderr#L8
is an example of what "non silent omission" could look like.

I think this is better than either crashing or silently omitting suggestions.

Mentors or Reviewers

If you have a reviewer or mentor in mind for this work, mention them here. You can put your own name here if you are planning to mentor the work.

Process

The main points of the Major Change Process are as follows:

  • File an issue describing the proposal.
  • A compiler team member who is knowledgeable in the area can second by writing @rustbot second or kickoff a team FCP with @rfcbot fcp $RESOLUTION.
  • Once an MCP is seconded, the Final Comment Period begins.
    • Final Comment Period lasts for 10 days after all outstanding concerns are solved.
    • Outstanding concerns will block the Final Comment Period from finishing. Once all concerns are resolved, the 10 day countdown is restarted.
    • If no concerns are raised after 10 days since the resolution of the last outstanding concern, the MCP is considered approved.

You can read more about Major Change Proposals on forge.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-compilerAdd this label so rfcbot knows to poll the compiler teammajor-changeA proposal to make a major change to rustcto-announceAnnounce this issue on triage meeting

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions