diff options
| author | bors <bors@rust-lang.org> | 2020-12-11 03:08:32 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-12-11 03:08:32 +0000 |
| commit | 0c9ef564a7688dd4a9047342c7f8395aea909333 (patch) | |
| tree | b3f120c745cc1b46ff4d513306b5d5c40a49d71a /compiler/rustc_codegen_cranelift/src/optimize/code_layout.rs | |
| parent | 8cef65fde3f92a84218fc338de6ab967fafd1820 (diff) | |
| parent | 169c59ff0fcbd606c6f639c2318f71b51f6c9207 (diff) | |
| download | rust-0c9ef564a7688dd4a9047342c7f8395aea909333.tar.gz rust-0c9ef564a7688dd4a9047342c7f8395aea909333.zip | |
Auto merge of #79656 - jnqnfe:ordering, r=sfackler
Add some core::cmp::Ordering helpers
...to allow easier equal-to-or-greater-than and less-than-or-equal-to
comparisons.
Prior to Rust 1.42 a greater-than-or-equal-to comparison might be written
either as a match block, or a traditional conditional check like this:
```rust
if cmp == Ordering::Equal || cmp == Ordering::Greater {
// Do something
}
```
Which requires two instances of `cmp`. Don't forget that while `cmp` here
is very short, it could be something much longer in real use cases.
From Rust 1.42 a nicer alternative is possible:
```rust
if matches!(cmp, Ordering::Equal | Ordering::Greater) {
// Do something
}
```
The commit adds another alternative which may be even better in some cases:
```rust
if cmp.is_equal_or_greater() {
// Do something
}
```
The earlier examples could be cleaner than they are if the variants of
`Ordering` are imported such that `Equal`, `Greater` and `Less` can be
referred to directly, but not everyone will want to do that.
The new solution can shorten lines, help avoid logic mistakes, and avoids
having to import `Ordering` / `Ordering::*`.
Diffstat (limited to 'compiler/rustc_codegen_cranelift/src/optimize/code_layout.rs')
0 files changed, 0 insertions, 0 deletions
