Skip to content

Improve workings of attribute suggestions#159633

Open
nnethercote wants to merge 2 commits into
rust-lang:mainfrom
nnethercote:attr-suggestions
Open

Improve workings of attribute suggestions#159633
nnethercote wants to merge 2 commits into
rust-lang:mainfrom
nnethercote:attr-suggestions

Conversation

@nnethercote

@nnethercote nnethercote commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

AttrItem span tracking improved in #159587, which lets us slightly simplify the workings of attribute suggestions.

r? @JonathanBrouwer

@rustbot

rustbot commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

@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 21, 2026
@rustbot

rustbot commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

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

@nnethercote nnethercote changed the title Attr suggestions Improve workings of attribute suggestions Jul 21, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

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.
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

Development

Successfully merging this pull request may close these issues.

4 participants