Fix incorrect cfg structured suggestion and make suggestion verbose#137773
Fix incorrect cfg structured suggestion and make suggestion verbose#137773estebank wants to merge 1 commit intorust-lang:mainfrom
cfg structured suggestion and make suggestion verbose#137773Conversation
This comment has been minimized.
This comment has been minimized.
cfg structured suggestioncfg structured suggestion and make suggestion verbose
oli-obk
left a comment
There was a problem hiding this comment.
I'll give it another review after the duplicate arg function is duplicating it internally. I can't tell what else is simplifyable without checking out the PR locally and playing with it
| help: expected syntax is | ||
| | | ||
| LL - #[cfg = 10] | ||
| LL + #[cfg(/* predicate */)] |
There was a problem hiding this comment.
Maybe keep the value? Seems like often ppl may have written #[cfg = "linux"]
There was a problem hiding this comment.
We should do that only if we are certain that the value is a valid flag.
There was a problem hiding this comment.
The user provided input, why would we just overwrite it with a comment?
There was a problem hiding this comment.
The predicates can only be either bare identifiers or ident = lit.
If they write #[cfg = ident] they get
error: attribute value must be a literal
--> $DIR/cfg-attr-syntax-validation.rs:28:9
|
LL | #[cfg = a]
| ^
which is a separate error.
If they write #[cfg = "linux"], then we have to inspect the literal and reverse map it to target_os so that we suggest #[cfg(target_os = "linux)]. If we don't do that, and someone writes #[cfg = "foo"] or #[cfg = true], what should we suggest other than the generic predicate? In those cases we should link to https://doc.rust-lang.org/reference/conditional-compilation.html#set-configuration-options, which is the most comprehensive explanation of what is valid there (even though I don't like linking to the reference if there are more newbie friendly documents, which we don't seem to have for cfg). If we keep that reverse mapping, does that mean we also have to dynamically create the reverse mapping for all features in the current crate as well?
Note that I am not against doing any of that, it's just that this PR was to fix the incorrect suggestion, which needs to happen regardless of additional logic to make the suggestion more comprehensive.
| pub args: AttrArgs, | ||
| // Tokens for the meta item, e.g. just the `foo` within `#[foo]` or `#![foo]`. | ||
| pub tokens: Option<LazyAttrTokenStream>, | ||
| pub span: Span, |
There was a problem hiding this comment.
Pls add docs with examples what it refers to
| unsafety: Safety, | ||
| name: Symbol, | ||
| span: Span, | ||
| inner_span: Span, |
There was a problem hiding this comment.
I think no caller needs this to be different as there are no args
Keep a span for the attribute *within* the square brackets as part of the `AttrKind`. ``` error: `cfg` is not followed by parentheses --> $DIR/cfg-attr-syntax-validation.rs:4:1 | LL | #[cfg = 10] | ^^^^^^^^^^^ | help: expected syntax is | LL - #[cfg = 10] LL + #[cfg(/* predicate */)] | ``` Noticed in rust-lang#137343 (comment).
|
Some changes occurred in compiler/rustc_builtin_macros/src/autodiff.rs cc @ZuseZ4 |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
☔ The latest upstream changes (presumably #143460) made this pull request unmergeable. Please resolve the merge conflicts. |
Keep a span for the attribute within the square brackets as part of the
AttrKind.Noticed in #137343 (comment).