Fix incorrect cfg
structured suggestion and make suggestion verbose by estebank · Pull Request #137773 · rust-lang/rust (original) (raw)
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.