Improve workings of attribute suggestions#159633
Conversation
|
Some changes occurred in compiler/rustc_attr_parsing |
|
|
This comment has been minimized.
This comment has been minimized.
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.
6f28338 to
3f77289
Compare
| AttrSuggestionStyle::EmbeddedAttribute | ||
| } | ||
| ParsedDescription::Attribute => AttrSuggestionStyle::Attribute(self.attr_style), | ||
| ParsedDescription::Attribute => AttrSuggestionStyle::EmbeddedAttribute, |
There was a problem hiding this comment.
Hmmm this file has two functions
template_suggestions: https://github.com/nnethercote/rust/blob/ae3bbe78ec2a9bb57a03f10ad6ee0388e12bcefb/compiler/rustc_attr_parsing/src/context.rs#L946
suggestions:
https://github.com/nnethercote/rust/blob/ae3bbe78ec2a9bb57a03f10ad6ee0388e12bcefb/compiler/rustc_attr_parsing/src/context.rs#L1141
This PR changes template_suggestions, but not suggestions. These methods seem identical to me so the fact that there are two is probably a mistake?
suggestions is the last usage of AttrSuggestionStyle::Attribute, so would be nice to also change that
|
Reminder, once the PR becomes ready for a review, use |
AttrItemspan tracking improved in #159587, which lets us slightly simplify the workings of attribute suggestions.r? @JonathanBrouwer