diff options
| author | bors <bors@rust-lang.org> | 2023-09-24 04:23:43 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-09-24 04:23:43 +0000 |
| commit | 8a6bae28247fbaa3257856e00d084ac8c90712f3 (patch) | |
| tree | 3de8818c2e8376f9361014ed9e75fdc1c3904e2a /compiler/rustc_codegen_llvm/src/llvm_util.rs | |
| parent | 42ca6e4e5760a548a6fa858482de6d237f6fb3b8 (diff) | |
| parent | d63959f2faa0a3e1164dd42c641685de1fcad295 (diff) | |
| download | rust-8a6bae28247fbaa3257856e00d084ac8c90712f3.tar.gz rust-8a6bae28247fbaa3257856e00d084ac8c90712f3.zip | |
Auto merge of #115416 - c410-f3r:match_cfg, r=Amanieu
Add the `cfg_match!` macro
# Movitation
Adds a match-like version of the `cfg_if` crate without a RFC [for the same reasons that caused `matches!` to be included in the standard library](https://github.com/rust-lang/rust/pull/65479).
* General-purpose (not domain-specific)
* Simple (the implementation is short) and useful (things can become difficult with several `cfg`s)
* Very popular [on crates.io ](https://crates.io/crates/cfg-if) (currently 3th in all-time downloads)
* The two previous points combined make it number three in [left-pad index](https://twitter.com/bascule/status/1184523027888988160) score
```rust
match_cfg! {
cfg(unix) => {
fn foo() { /* unix specific functionality */ }
}
cfg(target_pointer_width = "32") => {
fn foo() { /* non-unix, 32-bit functionality */ }
}
_ => {
fn foo() { /* fallback implementation */ }
}
}
```
# 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.
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/llvm_util.rs')
0 files changed, 0 insertions, 0 deletions
