-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,10 @@ | ||
| #### Note: this error code is no longer emitted by the compiler. | ||
|
|
||
| The `not` cfg-predicate was malformed. | ||
|
|
||
| Erroneous code example: | ||
|
|
||
| ```compile_fail,E0536 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. The old error code (E0536) is no longer emitted by anything, except |
||
| ```compile_fail,E0805 | ||
| pub fn main() { | ||
| if cfg!(not()) { } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| fn main() { | ||
| 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 commentThe 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 commentThe 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 :) |
||
| cfg!(foo = 123); //~ ERROR malformed `cfg` attribute input | ||
| cfg!(foo, bar); //~ ERROR expected 1 cfg-pattern | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,17 +4,27 @@ error: macro requires a cfg-pattern as an argument | |
| LL | cfg!(); | ||
| | ^^^^^^ cfg-pattern required | ||
|
|
||
| error[E0565]: literal in `cfg` predicate value must be a boolean | ||
| --> $DIR/cfg.rs:3:10 | ||
| error[E0539]: malformed `cfg` attribute input | ||
| --> $DIR/cfg.rs:3:5 | ||
| | | ||
| LL | cfg!(123); | ||
| | ^^^ | ||
| | ^^^^^---^ | ||
| | | | | ||
| | | 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 commentThe 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) |
||
| | | ||
| = note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute> | ||
|
|
||
| error[E0565]: literal in `cfg` predicate value must be a string | ||
| --> $DIR/cfg.rs:4:16 | ||
| error[E0539]: malformed `cfg` attribute input | ||
| --> $DIR/cfg.rs:4:5 | ||
| | | ||
| LL | cfg!(foo = 123); | ||
| | ^^^ | ||
| | ^^^^^^^^^^^---^ | ||
| | | | | ||
| | | expected a string literal here | ||
| | help: must be of the form: `#![cfg(predicate)]` | ||
| | | ||
| = note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute> | ||
|
|
||
| error: expected 1 cfg-pattern | ||
| --> $DIR/cfg.rs:5:5 | ||
|
|
@@ -24,4 +34,4 @@ LL | cfg!(foo, bar); | |
|
|
||
| error: aborting due to 4 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0565`. | ||
| For more information about this error, try `rustc --explain E0539`. | ||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| pub fn main() { | ||
| if cfg!(not()) { } //~ ERROR E0805 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| error[E0805]: malformed `cfg` attribute input | ||
| --> $DIR/E0805.rs:2:8 | ||
| | | ||
| LL | if cfg!(not()) { } | ||
| | ^^^^^^^^--^ | ||
| | | | | ||
| | | expected a single argument here | ||
| | help: must be of the form: `#![cfg(predicate)]` | ||
| | | ||
| = note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute> | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
||
| For more information about this error, try `rustc --explain E0805`. |
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
Parserrun, we need to producePResult, which isResult<T, Diag>. This was my hack to create a Diag, I was still gonna see if there was a better way to do this