-
Notifications
You must be signed in to change notification settings - Fork 533
Document #[cfg(version(...))] #1828
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
Open
est31
wants to merge
1
commit into
rust-lang:master
Choose a base branch
from
est31:cfg_version
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ ConfigurationPredicate -> | |
| ConfigurationAll | ||
| ConfigurationAny | ||
| ConfigurationNot | ||
| ConfigurationVersion | ||
| `true` | ||
| `false` | ||
|
@@ -23,6 +24,15 @@ ConfigurationAny -> | |
ConfigurationNot -> | ||
`not` `(` ConfigurationPredicate `)` | ||
ConfigurationVersion -> | ||
`version` `(` `"` ConfigurationVersionLiteral `"` `)` | ||
ConfigurationVersionLiteral -> | ||
ConfigurationVersionPart `.` ConfigurationVersionPart (`.` ConfigurationVersionPart)? | ||
ConfigurationVersionPart -> | ||
(DEC_DIGIT)+ | ||
ConfigurationPredicateList -> | ||
ConfigurationPredicate (`,` ConfigurationPredicate)* `,`? | ||
``` | ||
|
@@ -55,6 +65,11 @@ r[cfg.predicate.not] | |
r[cfg.predicate.literal] | ||
* `true` or `false` literals, which are always true or false respectively. | ||
|
||
r[cfg.predicate.version] | ||
* `version()` with a version number inside. It is true if the language version | ||
Comment on lines
+68
to
+69
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. Can we merge |
||
the compiler targets is higher or equal to the contained version number. | ||
It is false otherwise. | ||
Comment on lines
+68
to
+71
This comment was marked as resolved.
Sorry, something went wrong. |
||
|
||
r[cfg.option-spec] | ||
_Configuration options_ are either names or key-value pairs, and are either set or unset. | ||
|
||
|
@@ -299,6 +314,19 @@ r[cfg.proc_macro] | |
Set when the crate being compiled is being compiled with the `proc_macro` | ||
[crate type]. | ||
|
||
r[cfg.version] | ||
### `version()` | ||
|
||
r[cfg.version.behavior] | ||
The `version()` predicate evaluates to true if both: | ||
|
||
* The version number contained inside follows the format and | ||
* The version number contained inside is less than or equal to the version | ||
of the language the compiler targets. | ||
|
||
r[cfg.version.format] | ||
In order for it to be considered of valid format, the version number has to follow either the `"a.b.c"` scheme or the `"a.b"` scheme. Semantically, assume `c` to be 0 if not present. Order wise, version numbers behave as if they were Rust tuples of type `(u16, u16, u16)`. | ||
|
||
r[cfg.panic] | ||
### `panic` | ||
|
||
|
@@ -371,6 +399,12 @@ fn needs_not_foo() { | |
// ... | ||
} | ||
|
||
// This function is only included if the language version is at least 1.50.0 | ||
#[cfg(version("1.50.0"))] | ||
fn needs_new_compiler() { | ||
// ... | ||
} | ||
|
||
// This function is only included when the panic strategy is set to unwind | ||
#[cfg(panic = "unwind")] | ||
fn when_unwinding() { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Shouldn't this be:
and assuming it is, I would just delete the other grammar productions and describe the format of the string in
cfg.predicate.version
in plain English. Or, we can keepConfigurationVersionLiteral
if you want, but the text will still need to be updated to say that the string needs to conform to the format described byConfigurationVersionLiteral
.Uh oh!
There was an error while loading. Please reload this page.
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.
yeah I think
STRING_LITERAL | RAW_STRING_LITERAL
is fine.This works
note that syntactically, we don't require string literals here, i.e. this doesn't give an error:
probably the same for all cfg syntaxes.