-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add the cfg_match!
macro
#115416
Add the cfg_match!
macro
#115416
Conversation
r? @cuviper (rustbot has picked a reviewer for you, use r? to override) |
@rustbot labels -T-libs +T-libs-api r? libs-api |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
The implementation is wrong if there are more than 2 non-wildcard match arms. match_cfg! {
cfg(windows) => {
fn foo() {}
}
cfg(unix) => {
fn foo() {}
}
cfg(target_pointer_width = "64") => {
fn foo() {}
}
} Fails to compile on 64-bit unix because Also, the |
Well, it is a surprise... To make things more clever, the implementation will now be based on |
703b67d
to
203728f
Compare
This comment has been minimized.
This comment has been minimized.
We discussed this in the libs-api meeting and are happy to add this as an unstable feature. Please open a tracking issue for this. There was a desire to have this supported directly by a language feature, but nobody could come up with a convincing design. Some issues should be address before stabilization, specifically:
|
A few small notes:
|
I would like to express my sincere appreciation for the quick feedback, thank you @Amanieu and the participating members of the lib team.
Done -> #115585
If that will indeed be the case, then I can fulfil the task.
Changed to
If possible, I will do it in a following PR. |
Luckily that is different - in that case, the problem is there being no way to automatically resolve a conflict between two traits when they put something with the same name in scope. Not a problem here since crates are preferred over the prelude
|
Glad to hear that. Thanks for investigating this scenario! |
Probably because |
@bors r- synchronizing the queue |
OK, everything should be good now. |
This comment has been minimized.
This comment has been minimized.
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (8a6bae2): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDNext Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Bootstrap: 630.937s -> 629.884s (-0.17%) |
Perf is acting stochastically IMO |
Yep this is noise: @rustbot label: +perf-regression-triaged |
For reference, this has broken downstream crates due to name resolution errors, since for some reason the
I will be important in the future that, whenever a new macro is added to the top-level of |
@danielhenrymantilla #117057 (comment) #117162 In my personal opinion, |
Movitation
Adds a match-like version of the
cfg_if
crate without a RFC for the same reasons that causedmatches!
to be included in the standard library.cfg
s)Considerations
A match-like syntax feels more natural in the sense that each macro fragment resembles an arm but I personally don't mind switching to any other desired syntax.
The lack of
#[ ... ]
is intended to reduce typing, nevertheless, the same reasoning described above can also be applied to this aspect.Since blocks are intended to only contain items, anything but
cfg
is not expected to be supported at the current or future time.Credits goes to @gnzlbg because most of the code was shamelessly copied from https://github.com/gnzlbg/match_cfg.Credits goes to @alexcrichton because most of the code was shamelessly copied from https://github.com/rust-lang/cfg-if.