Skip to content

Fix ICE caused by parsed attributes applied to where bounds #143781

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

JonathanBrouwer
Copy link
Contributor

@JonathanBrouwer JonathanBrouwer commented Jul 11, 2025

Fixes #143780
Fixes #138510
Fixes #143787
Fixes #143094 still needs a test

r? @oli-obk
cc @jdonszelmann

@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 Jul 11, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 11, 2025

Some changes occurred in compiler/rustc_attr_data_structures

cc @jdonszelmann

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

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

cc @jdonszelmann

@@ -232,7 +232,7 @@ pub enum AttributeKind {
},

/// Represents `#[rustc_const_stable_indirect]`.
ConstStabilityIndirect,
ConstStabilityIndirect(Span),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fixed this issue by giving all AttributeKind variants a span. I think this is the better way, the alternative would be removing the span from all variants and adding it to Attribute::Parsed.

I went for this approach because:

  1. I think Attribute::Unparsed is probably going away in the future anyways? (not sure, cc @jdonszelmann)
  2. Putting the span in Attribute::Unparsed means the find_attr! macro no longer has access to it. This could be fixed by giving the macro the span as a separate argument but that makes the macro calls quite a bit uglier

@rust-log-analyzer

This comment has been minimized.

@JonathanBrouwer JonathanBrouwer force-pushed the fix-attr-where-bounds branch from 018cd73 to 8f5c235 Compare July 11, 2025 12:04
@rustbot
Copy link
Collaborator

rustbot commented Jul 11, 2025

This PR changes a file inside tests/crashes. If a crash was fixed, please move into the corresponding ui subdir and add 'Fixes #' to the PR description to autoclose the issue upon merge.

@JonathanBrouwer JonathanBrouwer force-pushed the fix-attr-where-bounds branch from 8f5c235 to 49e328c Compare July 11, 2025 12:05
@cyrgani
Copy link
Contributor

cyrgani commented Jul 11, 2025

does this also fix #143787?

@JonathanBrouwer
Copy link
Contributor Author

Yes it does fix the ICE, I've added it to the fixes list and added it to the tests

@JonathanBrouwer JonathanBrouwer force-pushed the fix-attr-where-bounds branch from 49e328c to 3d8d1e7 Compare July 11, 2025 13:41
@jdonszelmann
Copy link
Contributor

This exact pr has been proposed several times at this point by different people. However, I'm again blocking it since eventually I want to remove the .span() function from attributes. It's there just for the transition period. Many attributes don't have a single span to point to. Maybe, just maybe I'm in favor of merging this when the method is called "first_span" but even then I think people will use it in a way that makes diagnostics confusing. Diagnostics that care about the span of attributes should either be about a specific attribute (in which case the code knows what all the spans in the parsed attribute mean) or should happen before parsing. Finally there's the case of Unparsed, which will only stick around for tool attributes. My plan for those is to parse those into a kind of meta item syntax tree (remove the tokens) and expose that to whoever wants to deal with tool attrs.

@jdonszelmann
Copy link
Contributor

I know im blocking those ICEs from being fixed rn. But I strongly believe those ICEs should be fixed by not using .span(). Not by expanding the method.

@JonathanBrouwer
Copy link
Contributor Author

JonathanBrouwer commented Jul 11, 2025

@jdonszelmann I understand completely, and I agree that this method should be avoided as much as possible

However, I don't see a way to fix this specific ICE (http://github.com/rust-lang/rust/issues/138510) without such a method, even after all attributes are parsed. This specific check has an allowlist of allowed attributes, and needs to span to error on attributes that are not on that allowlist. And I think this is an ICE that I would like to see fixed, it can be triggered even without the feature flag and has been reported 3 times now.

I propose to create a second method (first_span, like you suggested) that has the implementation from this PR, and make the span method error on ALL parsed attributes (there are a few allowed right now). We should only use this method in very specific places (such as this check) where using it actually makes sense. Would you be ok with this?

r? @jdonszelmann

@rustbot rustbot assigned jdonszelmann and unassigned oli-obk Jul 11, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 11, 2025

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

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-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.
Projects
None yet
6 participants