Commit Graph

25 Commits

Author SHA1 Message Date
Jad Ghalayini f847ff1511 Added #[repr(transparent)] to core::cmp::Reverse 2021-02-08 12:07:59 +00:00
David Tolnay 8758083aad
Remove requirement that forces symmetric and transitive PartialEq impls to exist 2021-01-19 14:26:09 -08:00
Marvin Huber 7276b6c328
Update cmp.rs
Fixed space
2021-01-17 16:11:48 +01:00
Eric Seppanen eef95871a4 fix broken link in PartialEq doc
PartialEq doc was attempting to link to [`Eq`] but instead we got a link
to `eq`. Disambiguate with "trait@Eq".
2021-01-09 22:40:48 -08:00
Chayim Refael Friedman 777ca999a9 Optimization for bool's PartialOrd impl 2020-12-14 23:32:52 +02:00
Lyndon Brown 169c59ff0f Add some core::cmp::Ordering helpers
...to allow easier greater-than-or-equal-to and less-than-or-equal-to
comparisons, and variant checking without needing to import the enum,
similar to `Option::is_none()` / `Option::is_some()`, in situations where
you are dealing with an `Ordering` value. (Simple `PartialOrd` / `Ord`
based evaluation may not be suitable for all situations).

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_ge() {
    // 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::*`.
2020-12-10 20:32:12 +00:00
bors 5d5ff84130 Auto merge of #77872 - Xaeroxe:stabilize-clamp, r=scottmcm
Stabilize clamp

Tracking issue: https://github.com/rust-lang/rust/issues/44095

Clamp has been merged and unstable for about a year and a half now. How do we feel about stabilizing this?
2020-11-22 10:50:04 +00:00
Jacob Kiesel fb6ceac46b We missed 1.49.0, so bump version to 1.50.0 2020-11-20 10:37:22 -07:00
Camelid 8258cf285f Convert a bunch of intra-doc links 2020-11-07 12:50:57 -08:00
Rustin-Liu 42844ed2cf Add lexicographical comparison doc
Add links

Fix typo

Use `sequence`

Fix typo

Fix broken link

Fix broken link

Fix broken link

Fix broken links

Fix broken links
2020-10-26 22:39:43 +08:00
Jacob Kiesel a7d3368448 Stabilize clamp 2020-10-12 15:09:45 -06:00
Alexis Bourget b6e72837fd Use Self more in core/src/cmp.rs 2020-09-22 23:36:08 +02:00
CDirkx ea5dc0909e Make some Ordering methods const
Constify the following methods of `core::cmp::Ordering`:
 - `reverse`
 - `then`

Stabilizes these methods as const under the `const_ordering` feature.
Also adds a test for these methods in a const context.

Possible because of #49146 (Allow `if` and `match` in constants).
2020-09-01 15:44:00 +02:00
Dylan MacKenzie 4404cc5bc7 Revert #75463
This was approved by me prematurely. It needs T-libs approval.
2020-08-31 10:22:14 -07:00
bors 92290d1631 Auto merge of #75463 - CDirkx:ordering-const, r=CDirkx
Make some Ordering methods const

Constify the following methods of `core::cmp::Ordering`:
 - `reverse`
 - `then`

Possible because of #49146 (Allow `if` and `match` in constants).

Tracking issue:  #76113
2020-08-31 01:28:42 +00:00
CDirkx 12f4624f71 Update `since` to correct release
`const_ordering` will stabilize in version 1.48.0
2020-08-30 23:59:37 +02:00
CDirkx 89fc3fb93b Stabilize feature `const_ordering` 2020-08-30 23:48:54 +02:00
CDirkx 5fac991bf6 Add unstable `const_ordering` feature, and some tests. 2020-08-30 19:40:00 +02:00
Yuki Okushi 25a677ccef
Rollup merge of #75831 - lzutao:https, r=Dylan-DPC
doc: Prefer https link for wikipedia URLs

A tiny changes.
2020-08-24 11:48:47 +09:00
Ayush Kumar Mishra 18f47d81da Misleading documentation for derived Ord/PartialOrd implementation for enums #75620 2020-08-23 15:56:01 +05:30
Lzu Tao 2c995d29f7 Prefer https link for wikipedia URLs 2020-08-23 10:02:42 +00:00
CDirkx 6b0d44e92a Make some Ordering methods const
Constify the following methods of `core::cmp::Ordering`:
 - `reverse`
 - `then`

Possible because of #49146 (Allow `if` and `match` in constants).
2020-08-12 22:10:32 +02:00
Denis Vasilik eea85814e1 Use intra-doc links 2020-08-10 23:16:01 +02:00
Denis Vasilik f260462c32 Remove links that are in scope 2020-08-10 23:14:43 +02:00
mark 2c31b45ae8 mv std libs to library/ 2020-07-27 19:51:13 -05:00