Skip to content

Fix ICE from cfg_attr_trace #154803

Open
chenyukang wants to merge 1 commit intorust-lang:mainfrom
chenyukang:yukang-fix-154801-cfg-attr-span
Open

Fix ICE from cfg_attr_trace #154803
chenyukang wants to merge 1 commit intorust-lang:mainfrom
chenyukang:yukang-fix-154801-cfg-attr-span

Conversation

@chenyukang
Copy link
Copy Markdown
Member

@chenyukang chenyukang commented Apr 4, 2026

Fixes #154801
Fixes #143094

r? @JonathanBrouwer

The root cause is we recovery from parsing attribute error here:


while the later suggestion code from type checking try to inspect the attr span of the expr in the second error, keep the span seems reasonable.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 4, 2026

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred in compiler/rustc_hir/src/attrs

cc @jdonszelmann, @JonathanBrouwer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) 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 Apr 4, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 4, 2026

JonathanBrouwer is currently at their maximum review capacity.
They may take a while to respond.

@rust-log-analyzer

This comment has been minimized.

@chenyukang chenyukang force-pushed the yukang-fix-154801-cfg-attr-span branch from ed6f9af to 952c5ba Compare April 4, 2026 09:44
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 4, 2026

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@rustbot rustbot added the T-clippy Relevant to the Clippy team. label Apr 4, 2026

/// Represents the trace attribute of `#[cfg_attr]`
CfgAttrTrace,
CfgAttrTrace(Span),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How does this behave with multiple cfg_attr attributes? Since this attribute can exist multiple times, ideally we should have a ThinVec<Span> here?

@rustbot rustbot 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 Apr 4, 2026
@chenyukang chenyukang changed the title Fix ICE from cfg_attr_trace by storing span Fix ICE from cfg_attr_trace Apr 4, 2026
@chenyukang chenyukang force-pushed the yukang-fix-154801-cfg-attr-span branch from 952c5ba to 46e2396 Compare April 4, 2026 22:20
@rust-bors

This comment has been minimized.

@JonathanBrouwer JonathanBrouwer self-requested a review April 12, 2026 15:40
@chenyukang chenyukang force-pushed the yukang-fix-154801-cfg-attr-span branch from 46e2396 to 45b4e3c Compare April 25, 2026 03:17
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 25, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Copy link
Copy Markdown
Contributor

@JonathanBrouwer JonathanBrouwer left a comment

Choose a reason for hiding this comment

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

@bors r+ rollup
While the is_prefix_attr_for_suggestions is far from correct, this solution is better than ICE'ing and it's only for diagnostics anyways, so doesn't need to be perfect

View changes since this review

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 25, 2026

📌 Commit 45b4e3c has been approved by JonathanBrouwer

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 25, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 25, 2026
…ttr-span, r=JonathanBrouwer

Fix ICE from cfg_attr_trace

Fixes rust-lang#154801
Fixes rust-lang#143094

r? @JonathanBrouwer

The root cause is we recovery from parsing attribute error here:
https://github.com/rust-lang/rust/blob/ed6f9af7d47f5a5eda2a4a1925d1e250b51a37f2/compiler/rustc_attr_parsing/src/parser.rs#L550
while the later suggestion code from type checking try to inspect the attr span of the `expr` in the second error, keep the span seems reasonable.
rust-bors Bot pushed a commit that referenced this pull request Apr 25, 2026
…uwer

Rollup of 6 pull requests

Successful merges:

 - #154803 (Fix ICE from cfg_attr_trace )
 - #155485 (Add an edge-case test for `--remap-path-prefix` for `rustc` & `rustdoc`)
 - #155659 (cleanup, restructure and merge `tests/ui/deriving` into `tests/ui/derives`)
 - #155696 (Add a higher-level API for parsing attributes)
 - #155734 (Lint doc comments in cfg_select branches)
 - #155769 (triagebot.toml: Ping Enselic when tests/debuginfo/basic-stepping.rs changes)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 25, 2026
…ttr-span, r=JonathanBrouwer

Fix ICE from cfg_attr_trace

Fixes rust-lang#154801
Fixes rust-lang#143094

r? @JonathanBrouwer

The root cause is we recovery from parsing attribute error here:
https://github.com/rust-lang/rust/blob/ed6f9af7d47f5a5eda2a4a1925d1e250b51a37f2/compiler/rustc_attr_parsing/src/parser.rs#L550
while the later suggestion code from type checking try to inspect the attr span of the `expr` in the second error, keep the span seems reasonable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-clippy Relevant to the Clippy team. 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: can't get the span of an arbitrary parsed attribute: Parsed(Cold [ICE]: can't get span of parsed attr

4 participants