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.
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
There was a problem hiding this comment.
It's not a mistake and as initially written the difference was necessary. But I have now added some additional commits that adjust some more error messages, such that the difference is no longer necessary, and I have merged the two methods and done some other related cleanups.
|
Reminder, once the PR becomes ready for a review, use |
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`, and also `AttributeParseError::attr_span`. 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.
The notable thing about this is the inconsistency. In the normal case we get this output: ``` warning: valid forms for the attribute are `#[macro_export(local_inner_macros)]` and `#[macro_export]` --> $DIR/invalid_macro_export_argument.rs:7:1 | LL | #[macro_export(hello, world)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ``` In the `cfg_attr` case we get this output: ``` warning: valid forms for the attribute are `macro_export` and `macro_export(local_inner_macros)` --> $DIR/invalid_macro_export_argument.rs:14:18 | LL | #[cfg_attr(true, macro_export(hello, world))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ``` The difference being the presence/absence of the `#[`/`]` delimiters in both the "warning" line and the carets. This is exactly the kind of inconsistency that rust-lang#159755 started eliminating. The next commit will do so for this case.
3f77289 to
656151a
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
|
@rustbot ready |
|
This pull request was unapproved. |
This comment has been minimized.
This comment has been minimized.
Similar to the commit before the last.
It's identical to `AttributeDiagnosticContext::suggestions`.
It's no longer used. Also remove the `start` and `end` local variables in `AttributeTemplate::suggestions`, because they're now always empty.
It's identical to `ParsedDescription`, modulo the `Attribute` vs `EmbeddedAttribute` naming, but thanks to the previous changes the `Embedded` prefix is no longer relevant.
656151a to
4981cac
Compare
|
I fixed the rustdoc-ui failure. @bors r=JonathanBrouwer |
…nathanBrouwer Improve workings of attribute suggestions `AttrItem` span tracking improved in rust-lang#159587, which lets us slightly simplify the workings of attribute suggestions. r? @JonathanBrouwer
…uwer Rollup of 28 pull requests Successful merges: - #159638 (bootstrap: Split the `Step` trait into multiple traits) - #159774 (rustc_trait_selection: fix trait solver hang caused by degenerate obligations) - #159837 (line-tables-only test: check that the line number matches the function name) - #159946 (Update Enzyme submodule to imporve llvm-cov) - #159962 (miri subtree update) - #156570 (tests: extend remap-path-prefix-std to all stdlib rlibs) - #159617 (Fix up `#[linkage]` target checking) - #159633 (Improve workings of attribute suggestions) - #159733 (std: Switch implementations of `thread_local!` for WASI) - #159783 (Check unsafe impls on safe EIIs) - #159810 (Add tuple never coercion collection regression test) - #159826 (Remove redundant `#[rustc_paren_sugar]` feature gate) - #159846 (Implement `str::copy_from_str`) - #159849 (rustc_parse: Stop returning `Option` from statement parsing) - #159853 (Updated expect messages for `CString` struct and method documentation) - #159875 (More cleanup in `rustc_attr_parsing`) - #159882 (Update expect messages in library/alloc/boxed.rs and library/alloc/string.rs to follow the style guide) - #159891 (Split multiline derives into std/rustc macros) - #159893 (Fix `find_attr` hygiene and `rustc_hir` cleanups) - #159895 (rustc-dev-guide subtree update) - #159902 (Clarify that the expected runtime symbols signature is for the current target only) - #159914 (Fix error in diagnostic on_unmatched_args) - #159917 (spare capacity mut constification) - #159918 (rename abort_unwind → abort_on_unwind) - #159927 (Remove sve2 from the ImpliedFeatures of AArch64 v9a.) - #159936 (Minor `rustc_ast::ast` doc cleanups) - #159945 (Update expect messages in library/core/src/ptr/non_null.rs) - #159950 (Add CFI tests for return types and never type)
AttrItemspan tracking improved in #159587, which lets us slightly simplify the workings of attribute suggestions.r? @JonathanBrouwer