Skip to content

Avoid empty extra-arg suggestion spans in macro calls#152634

Open
TaKO8Ki wants to merge 2 commits intorust-lang:mainfrom
TaKO8Ki:issue-152414-empty-extra-arg-span
Open

Avoid empty extra-arg suggestion spans in macro calls#152634
TaKO8Ki wants to merge 2 commits intorust-lang:mainfrom
TaKO8Ki:issue-152414-empty-extra-arg-span

Conversation

@TaKO8Ki
Copy link
Member

@TaKO8Ki TaKO8Ki commented Feb 14, 2026

Fixes #152414
Fixes #131762

When building Error::Extra removal suggestions, we extended spans with to and until even when syntax contexts differed in labels_and_suggestion_text. In macro-expanded calls this could fall back to an empty span and triggering an ICE.

I fixed it to combine spans only when contexts match.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 14, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 14, 2026

r? @BoxyUwU

rustbot has assigned @BoxyUwU.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 68 candidates
  • Random selection from 14 candidates

@TaKO8Ki TaKO8Ki changed the title avoid empty extra-arg suggestion spans in macro calls Avoid empty extra-arg suggestion spans in macro calls Feb 14, 2026
@BoxyUwU
Copy link
Member

BoxyUwU commented Feb 14, 2026

r? compiler

@rustbot rustbot assigned fmease and unassigned BoxyUwU Feb 14, 2026
@rust-log-analyzer

This comment has been minimized.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not an MCVE, it contains a lot of distracting elements and leads to distracting errors. Could you please use a more distilled version of the reproducer like:

#![feature(generic_assert)]

fn func(value: usize) {
    assert!(core::mem::size_of(value, 1) >= 1);
}

which only generates 1 error instead of 5.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However note that this reproducer still relies on implementation details of generic_assert. Ideally, we'd define our own macro to be used in this test file. This way, if the implementation of generic_assert changes, this test won't accidentally & likely silently stop testing the right thing...

help: remove the extra argument
|
LL - assert!(core::mem::size_of::<T>(val, 1) >= 1);
LL + assert!(core::mem::size_of::<T>(val, ) >= 1);
Copy link
Member

@fmease fmease Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new suggestion isn't quite right though. It should either suggest removing both extra arguments or if that's not possible due to differing syntax contexts we should err on the safe side and just not suggest anything (unless you can make it work).

The diagnostic knows that 2 args are extra but the suggestion no longer does for some reason.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the source code was assert!(core::mem::size_of(value,)); does rustc now suggest assert!(core::mem::size_of(,)); under your PR? I don't actually know.

@fmease fmease added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ICE]: Span must not be empty and have no suggestion ICE: underline_start >= 0 && underline_end >= 0

5 participants