Diagnostic for #[cfg(ident=ident)] fails to suggest #[cfg(ident="string")] #58462
Labels
A-attributes
Area: Attributes (`#[…]`, `#![…]`)
A-diagnostics
Area: Messages for errors, warnings, and lints
A-suggestion-diagnostics
Area: Suggestions generated by the compiler applied by `cargo fix`
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
D-papercut
Diagnostics: An error or lint that needs small tweaks.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Consider the following code (play):
On nightly today, this errors (correctly), but gives the diagnostic feedback:
This highlight is totally misleading and the message is not great either. The problem in the above input is not the identifier
key
in the left-hand side of the predicate; it is the use of an identifier for the right-hand side of the predicate. We should be highlighting the right-hand side and probably also suggesting they turn it into a string.Also, the fact that we say "expected unsuffixed literal or identifier, found whoops", where "whoops" is an identifier, is also very confusing in the above.
I'll also note that the behavior here shifted between the current stable+beta and nightly; on beta the diagnostic is not quite as actively misleading as the above, but it isn't really helpful either:
It would probably also be a decent idea to stress the point that the right-hand side must be a string in the various docs that use this form of
#[cfg(...)]
. I am thinking in particular of the#[cfg(feature = "this")]
syntax that integrates with features on a crateThe text was updated successfully, but these errors were encountered: