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
Conversation
…ed attribute args Fixes #9786
This was referenced Mar 31, 2026
Collaborator
Author
This was referenced Mar 31, 2026
eytan-starkware
approved these changes
Mar 31, 2026
Contributor
eytan-starkware
left a comment
There was a problem hiding this comment.
@eytan-starkware reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on TomerStarkware).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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:
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 likerefandmut.What was the behavior or documentation before?
The
Modifier::frommethod 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::Reforast::Modifier::Mut) and calls the appropriatetext()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/mutmodifier 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/muttoken text via the concreteast::Modifiervariants instead ofas_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.