Improve workings of attribute suggestions#159633
Open
nnethercote wants to merge 2 commits into
Open
Conversation
Collaborator
|
Some changes occurred in compiler/rustc_attr_parsing |
Collaborator
|
|
This comment has been minimized.
This comment has been minimized.
nnethercote
force-pushed
the
attr-suggestions
branch
from
July 21, 2026 06:06
0f09f33 to
6f28338
Compare
This comment has been minimized.
This comment has been minimized.
Attribute templated mismatch suggestions come in two forms: - for a normal attribute, something like `#[inline(always)]`; - for an attribute embedded in `cfg_attr`, something like `inline(always)`. This commit replaces the former with the latter, and removes the need for the fragile span-based test for detecting embedded attributes in `template_suggestions`. It takes advantage of the newly added (and accurate) `AttrItem::span` field. This change has a minor effect on error messages: when there are multiple suggestions their order can change because the `#[`/`]` are no longer included. This actually improves things, because e.g. if you write the invalid `#[inline(please)]`, the simpler `#[inline]` will be suggested ahead of the longer `#[inline(always)]` and `#[inline(never)`] alternatives.
We can use `AttrSuggestionStyle::EmbeddedAttribute` instead now that `AttrItem::span` exists and is accurate.
nnethercote
force-pushed
the
attr-suggestions
branch
from
July 21, 2026 07:55
6f28338 to
3f77289
Compare
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.
AttrItemspan tracking improved in #159587, which lets us slightly simplify the workings of attribute suggestions.r? @JonathanBrouwer