Commit graph

270 commits

Author SHA1 Message Date
Nicholas Bishop
f408a4e9bd Fix doc link to Eq trait from PartialEq trait
The `Eq` link was incorrectly going to the `eq` method of `PartialEq`
instead of to the `Eq` trait.
2020-04-29 12:06:32 -04:00
Josh Stone
2edd123a23 Dogfood or_patterns in the standard library 2020-04-16 12:44:57 -07:00
Linus Färnstrand
c831265940 Replace float module consts with assoc consts in documentation 2020-04-03 09:33:10 +02:00
Michael Bradshaw
4ac468c038 Mark several functions and methods in core::cmp as #[must_use] 2020-02-08 10:42:23 -08:00
Guillaume Gomez
2f575dab30 Add missing links for cmp traits 2020-01-30 13:58:33 +01:00
Igor Aleksanov
f720469fd0 Use matches macro in libcore and libstd 2020-01-08 07:10:28 +03:00
JP Sugarbroad
d935a26d9d
Less-than is asymmetric, not antisymmetric
This has bothered me for a while. It's such a small nit, but...
2019-12-30 12:17:23 -08:00
Mark Rousskov
a06baa56b9 Format the world 2019-12-22 17:42:47 -05:00
Ross MacArthur
f7256d28d1
Require issue = "none" over issue = "0" in unstable attributes 2019-12-21 13:16:18 +02:00
Niko Matsakis
d286113024 Revert "Stabilize the never_type, written !."
This reverts commit 15c30ddd69.
2019-12-14 09:01:09 -05:00
Mazdak Farrokhzad
830b4ee76a
Rollup merge of #66881 - krishna-veerareddy:issue-66780-bool-ord-optimization, r=sfackler
Optimize Ord trait implementation for bool

Casting the booleans to `i8`s and converting their difference into `Ordering` generates better assembly than casting them to `u8`s and comparing them.

Fixes #66780

#### Comparison([Godbolt link](https://rust.godbolt.org/z/PjBpvF))

##### Old assembly:
```asm
example::boolean_cmp:
        mov     ecx, edi
        xor     ecx, esi
        test    esi, esi
        mov     eax, 255
        cmove   eax, ecx
        test    edi, edi
        cmovne  eax, ecx
        ret
```

##### New assembly:
```asm
example::boolean_cmp:
        mov     eax, edi
        sub     al, sil
        ret
```

##### Old LLVM-MCA statistics:
```
Iterations:        100
Instructions:      800
Total Cycles:      234
Total uOps:        1000

Dispatch Width:    6
uOps Per Cycle:    4.27
IPC:               3.42
Block RThroughput: 1.7
```

##### New LLVM-MCA statistics:
```
Iterations:        100
Instructions:      300
Total Cycles:      110
Total uOps:        500

Dispatch Width:    6
uOps Per Cycle:    4.55
IPC:               2.73
Block RThroughput: 1.0
```
2019-12-11 10:10:41 +01:00
Krishna Sai Veera Reddy
1f07aa582a Add better documentation for unsafe block 2019-12-10 14:30:06 -07:00
Krishna Sai Veera Reddy
a30ee8e763 Document usage of unsafe block 2019-12-02 08:45:35 -07:00
cad97
ac57e1b647
Remove ord lang item 2019-12-01 16:09:07 -05:00
Krishna Sai Veera Reddy
4ca769ad09 Optimize Ord trait implementation for bool
Casting the booleans to `i8`s and converting their difference
into `Ordering` generates better assembly than casting them to
`u8`s and comparing them.
2019-11-29 15:22:44 -07:00
Guanqun Lu
55d725884b follow the same function order in the trait
This removes several warnings in IDE.
2019-11-26 22:55:38 +08:00
Mazdak Farrokhzad
afc78e19dd
Rollup merge of #66566 - robamler:issue-66476, r=rkruppe
Document pitfall with `impl PartialEq<B> for A`

Fixes #66476 by turning the violating example into an explicit
counterexample.
2019-11-22 19:57:46 +01:00
Robert Bamler
5028fd8ab9 Document pitfall with impl PartialEq<B> for A
Fixes #66476 by turning the violating example into an explicit
counterexample.
2019-11-21 23:16:44 -08:00
Mazdak Farrokhzad
15c30ddd69 Stabilize the never_type, written !. 2019-11-21 14:55:32 +01:00
Felix S. Klock II
98f5b11b6b Migrate from #[structural_match] attribute a lang-item trait.
(Or more precisely, a pair of such traits: one for `derive(PartialEq)` and one
for `derive(Eq)`.)

((The addition of the second marker trait, `StructuralEq`, is largely a hack to
work-around `fn (&T)` not implementing `PartialEq` and `Eq`; see also issue
rust-lang/rust#46989; otherwise I would just check if `Eq` is implemented.))

Note: this does not use trait fulfillment error-reporting machinery; it just
uses the trait system to determine if the ADT was tagged or not. (Nonetheless, I
have kept an `on_unimplemented` message on the new trait for structural_match
check, even though it is currently not used.)

Note also: this does *not* resolve the ICE from rust-lang/rust#65466, as noted
in a comment added in this commit. Further work is necessary to resolve that and
other problems with the structural match checking, especially to do so without
breaking stable code (adapted from test fn-ptr-is-structurally-matchable.rs):

```rust
fn r_sm_to(_: &SM) {}

fn main() {
    const CFN6: Wrap<fn(&SM)> = Wrap(r_sm_to);
    let input: Wrap<fn(&SM)> = Wrap(r_sm_to);
    match Wrap(input) {
        Wrap(CFN6) => {}
        Wrap(_) => {}
    };
}
```

where we would hit a problem with the strategy of unconditionally checking for
`PartialEq` because the type `for <'a> fn(&'a SM)` does not currently even
*implement* `PartialEq`.

----

added review feedback:
* use an or-pattern
* eschew `return` when tail position will do.
* don't need fresh_expansion; just add `structural_match` to appropriate `allow_internal_unstable` attributes.

also fixed example in doc comment so that it actually compiles.
2019-10-25 14:52:07 +02:00
Mark Rousskov
f359a94849 Snap cfgs to new beta 2019-09-25 08:42:46 -04:00
Alex Crichton
b3f95f460f Move --cfg bootstrap out of rustc.rs
Instead let's do this via `RUSTFLAGS` in `builder.rs`. Currently
requires a submodule update of `stdarch` to fix a problem with previous
compilers.
2019-09-23 09:34:44 -07:00
Tim Vermeulen
6e5ada43bf Add cmp::{min_by, min_by_key, max_by, max_by_key} 2019-09-14 21:52:08 +02:00
Lzu Tao
b6f9523dc6 Fix doc links in std::cmp module
These links are rendered in `core::cmp` but not in `std::cmp`.
2019-09-04 13:52:28 +00:00
Lzu Tao
ade191c70a Small improvement for Ord implementation of integers 2019-08-29 03:52:18 +00:00
Lzu Tao
96983fc530 Add comment to avoid accidentally remove the changes. 2019-08-21 06:25:37 +00:00
Lzu Tao
0337cc117d Use more optimal Ord implementation for integers 2019-08-21 00:37:17 +00:00
Matthew Jasper
6ee60af1ab Make built-in derives opaque macros 2019-08-17 08:59:36 +01:00
Mark Rousskov
2601c86487 Handle cfg(bootstrap) throughout 2019-08-14 05:39:53 -04:00
Vadim Petrochenkov
cbcc7dd182 Give built-in macros stable addresses in the standard library 2019-08-10 00:05:37 +03:00
Tomasz Różański
4a2f9b6d62 Remove redundant mut from variable declaration. 2019-07-26 15:07:55 +02:00
Taiki Endo
360432f1e8 libcore => 2018 2019-04-18 14:47:35 +09:00
Eric Huss
3e01901fcd Remove strange formatting in Ordering docs. 2019-04-09 15:41:38 -07:00
Tobias Bucher
0bb36a2f90 Clarify {Ord,f32,f64}::clamp docs a little
Explicitly call out when it returns NaN, adhere to the panic doc
guidelines.
2019-03-25 12:52:42 +01:00
Vincent Esche
698bbe5253 Replaced self-reflective explicit types with clearer Self or Self::… in stdlib docs 2019-03-18 13:57:51 +01:00
bors
70d1150478 Auto merge of #58710 - EdorianDark:master, r=sfackler
Add clamp for ranges. Implements #44095

Ready for merge
2019-03-15 06:23:21 +00:00
Scott McMurray
df4ea90b39 Use lifetime contravariance to elide more lifetimes in core+alloc+std 2019-03-09 19:10:28 -08:00
Dirk Leifeld
bd2e12609f Revert "Revert "Add clamp functions"" 2019-03-09 19:16:54 +01:00
Alexander Regueiro
b87363e763 tests: doc comments 2019-02-10 23:42:32 +00:00
Mazdak Farrokhzad
bca490808f
Rollup merge of #57357 - frewsxcv:frewsxcv-partial-eq, r=QuietMisdreavus
Cleanup PartialEq docs.

- Cleanup the `impl PartialEq<BookFormat> for Book` implementation
- Implement `impl PartialEq<Book> for BookFormat` so it’s symmetric
  - Fixes https://github.com/rust-lang/rust/issues/53844.
- Removes the last example since it appears to be redundant with the
  previous two examples.
2019-01-18 18:06:30 +01:00
Corey Farwell
32b28340b2
demonstrate symmetry 2019-01-15 21:21:24 -05:00
Corey Farwell
0394dce788
whitespace 2019-01-12 11:19:02 -05:00
Corey Farwell
1445a065de
bring back the example i removed, also add symmetry and simplify impl 2019-01-12 11:17:49 -05:00
Corey Farwell
423a5bb5c4
add comment explaining what the derive does 2019-01-12 11:00:14 -05:00
Steve Klabnik
186d5d7fd4 re-do docs for core::cmp
Fixes #32934
2019-01-11 12:00:09 -05:00
Corey Farwell
bbbabdfc52
Update cmp.rs 2019-01-06 15:18:22 -05:00
Corey Farwell
319a2c1cc2
add missing derive to fix compile error 2019-01-06 11:08:34 -05:00
Corey Farwell
0d3dfdf6aa
Fix compile error 2019-01-05 22:52:13 -05:00
Corey Farwell
96678df838 Cleanup PartialEq docs.
- Cleanup the `impl PartialEq<BookFormat> for Book` implementation
- Implement `impl PartialEq<Book> for BookFormat` so it’s symmetric
  - Fixes https://github.com/rust-lang/rust/issues/53844.
- Removes the last example since it appears to be redundant with the
  previous two examples.
2019-01-05 12:41:12 -05:00
Czipperz
445dadca33 Specify criterion for PartialOrd 2018-12-29 19:14:06 -05:00