-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Port cfg!()
macro to the new attribute parsing system
#147945
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
| ^^^^^---^ | ||
| | | | ||
| | expected a valid identifier here | ||
| help: must be of the form: `#![cfg(predicate)]` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This help message is suggesting attribute related things, which is awful. Will fix in a separate PR that will go before this one (which is why this is in draft)
This comment has been minimized.
This comment has been minimized.
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
e4bea66
to
58efee4
Compare
&CFG_ATTR_TEMPLATE, | ||
) | ||
.ok_or_else(|| { | ||
.map_err(|_err: ErrorGuaranteed| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the delayed bug below necessary? Having an error guaranteed here effectively proves error emission already
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this is in a Parser
run, we need to produce PResult
, which is Result<T, Diag>
. This was my hack to create a Diag, I was still gonna see if there was a better way to do this
cfg!(); //~ ERROR macro requires a cfg-pattern | ||
cfg!(123); //~ ERROR literal in `cfg` predicate value must be a boolean | ||
cfg!(foo = 123); //~ ERROR literal in `cfg` predicate value must be a string | ||
cfg!(123); //~ ERROR malformed `cfg` attribute input |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I like these diagnostics, it's not an attribute!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is already a discussion open for this, that's why it's a draft :)
|
||
Erroneous code example: | ||
|
||
```compile_fail,E0536 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this old error code was correct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old error code (E0536) is no longer emitted by anything, except cfg
in the doc attribute. This example now emits the new error code.
I may change the example to use the doc
attribute for now
r? @jdonszelmann