Repository navigation
ICE: can't get the span of an arbitrary parsed attribute #142783
Copy link
Copy link
Closed
Labels
A-attributesArea: Attributes (`#[…]`, `#![…]`)Area: Attributes (`#[…]`, `#![…]`)C-bugCategory: This is a bug.Category: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Activity
- addedI-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.C-bugCategory: This is a bug.Category: This is a bug.
on Jun 20, 2025 - addedneeds-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triagingThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
on Jun 20, 2025 bisects to #138165
- addedA-attributesArea: Attributes (`#[…]`, `#![…]`)Area: Attributes (`#[…]`, `#![…]`)
on Jun 20, 2025 on current stable:
warning: unused macro definition: `contained` --> a.rs:3:14 | 3 | macro_rules! contained { () => {} } | ^^^^^^^^^ | = note: `#[warn(unused_macros)]` on by default error[E0518]: attribute should be applied to function or closure --> a.rs:1:1 | 1 | #[inline] | ^^^^^^^^^ not a function or closure warning: `#[inline]` is ignored on struct fields, match arms and macro defs --> a.rs:1:1 | 1 | #[inline] | ^^^^^^^^^ | = note: `#[warn(unused_attributes)]` on by default warning: `#[track_caller]` is ignored on struct fields, match arms and macro defs --> a.rs:1:1 | 1 | #[inline] | ^^^^^^^^^ warning: `#[track_caller]` is ignored on struct fields, match arms and macro defs --> a.rs:2:1 | 2 | #[track_caller] | ^^^^^^^^^^^^^^^It might be fixed by #142552 (haven't checked) but personally I do not believe that that approach is worth it. I think the best path forward (at least for now) is to change every parsed attribute to carry a span so we need not panic at
rust/compiler/rustc_hir/src/hir.rs
Lines 1298 to 1307 in 9c4ff56
#[inline] fn span(&self) -> Span { match &self { Attribute::Unparsed(u) => u.span, // FIXME: should not be needed anymore when all attrs are parsed Attribute::Parsed(AttributeKind::Deprecation { span, .. }) => *span, Attribute::Parsed(AttributeKind::DocComment { span, .. }) => *span, a => panic!("can't get the span of an arbitrary parsed attribute: {a:?}"), } } cc @jdonszelmann what do you think?
the entire reason for this ICE is wrong
warning: `#[track_caller]` is ignored on struct fields, match arms and macro defs --> a.rs:1:1 | 1 | #[inline] | ^^^^^^^^^this entire diagnostic is nonsensical as is the code that generates it
Reacted by Matthias Krüger and waffle- removedneeds-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triagingThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
on Jun 21, 2025 - added 2 commits that reference this issue
on Jun 25, 2025 - added a commit that references this issue
on Jun 25, 2025
Metadata
Metadata
Assignees
Labels
A-attributesArea: Attributes (`#[…]`, `#![…]`)Area: Attributes (`#[…]`, `#![…]`)C-bugCategory: This is a bug.Category: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.

auto-reduced (treereduce-rust):
original:
Version information
Command:
/home/matthias/.rustup/toolchains/master/bin/rustcProgram output