Skip to content

fix: use Terminal::text() for modifier text to avoid panic on malformed attribute args#9813

Open
orizi wants to merge 1 commit intoorizi/03-31-fix_missing_struct_field_in_constfrom
orizi/03-31-fix_modifier_terminal_text
Open

fix: use Terminal::text() for modifier text to avoid panic on malformed attribute args#9813
orizi wants to merge 1 commit intoorizi/03-31-fix_missing_struct_field_in_constfrom
orizi/03-31-fix_modifier_terminal_text

Conversation

@orizi
Copy link
Copy Markdown
Collaborator

@orizi orizi commented Mar 31, 2026

Summary

Fixed text extraction for modifier tokens in attribute arguments by directly accessing the text from the specific modifier variant instead of using the generic syntax node method.


Type of change

Please check one:

  • Bug fix (fixes incorrect behavior)
  • New feature
  • Performance improvement
  • Documentation change with concrete technical impact
  • Style, wording, formatting, or typo-only change

Why is this change needed?

The previous implementation used modifier.as_syntax_node().text(db) which could fail to extract text properly from modifier tokens in attribute arguments. This caused issues when processing attributes with modifier keywords like ref and mut.


What was the behavior or documentation before?

The Modifier::from method used a generic approach to extract text from modifier tokens by converting to a syntax node first, which was unreliable for certain modifier types.


What is the behavior or documentation after?

The method now pattern matches on the specific modifier variant (ast::Modifier::Ref or ast::Modifier::Mut) and calls the appropriate text() method directly, ensuring reliable text extraction for all modifier types.


Related issue or discussion (if any)

Fixes #9786


Additional context

The test case added demonstrates that attribute arguments with modifier keywords (like #[cfg(ref x)]) now parse correctly without generating diagnostics.


Note

Low Risk
Low risk bug fix in syntax attribute structuring that changes how ref/mut modifier text is read and adds a small regression test; no behavior changes outside malformed/edge-case parsing.

Overview
Fixes modifier text extraction for structured attribute arguments by reading ref/mut token text via the concrete ast::Modifier variants instead of as_syntax_node().text(db), preventing a potential panic on malformed attribute args.

Adds a semantic test case for an attribute argument containing a modifier keyword (#[cfg(ref x)]) to ensure it produces no diagnostics.

Written by Cursor Bugbot for commit a8da0fc. This will update automatically on new commits. Configure here.

@reviewable-StarkWare
Copy link
Copy Markdown

This change is Reviewable

Copy link
Copy Markdown
Contributor

@eytan-starkware eytan-starkware left a comment

Choose a reason for hiding this comment

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

:lgtm:

@eytan-starkware reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on TomerStarkware).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Compiler panic in attribute structurization: .expect() on None for modifier text

3 participants