about summary refs log tree commit diff
path: root/library/core/src/cmp.rs
AgeCommit message (Collapse)AuthorLines
2025-09-17add `[const] PartialEq` bound to `PartialOrd`Nathaniel McCallum-1/+3
This change is included for discussion purposes. The PartialOrd bound on PartialEq is not strictly necessary. It is, rather, logical: anything which is orderable should by definition have equality. Is the same true for constness? Should every type which is const orderable also have const equality?
2025-09-15replace some `#[const_trait]` with `const trait`Nathaniel McCallum-6/+3
2025-09-12Constify Eq, Ord, PartialOrdEvgenii Zheltonozhskii-51/+111
2025-09-06clean up some old const trait impl syntaxNathaniel McCallum-2/+1
2025-08-19Merge remote-tracking branch 'upstream/master'Michael Rieder-27/+35
2025-08-19Remove hs_abs_cmp examplesMichael Rieder-14/+0
2025-08-06tidyBoxy-4/+4
2025-07-20Rollup merge of #143423 - hkBst:clippy-fix-1, r=workingjubileeGuillaume Gomez-2/+3
address clippy formatting nits - int_log10.rs: change top level doc comments to outer - collect.rs: remove empty line after doc comment - clippy fix: markdown indentation for indented items after line break: a markdown list item continued over multiples lines, but those following lines which are part of the same item are not indented - clippy fix: bound in one place: when there is a bound in angle brackets and another bound on the same variable in a where clause
2025-07-18clippy fix: bound in one placeMarijn Schouten-2/+3
2025-07-17Make slices `[const] PartialEq`Oli Scherer-1/+2
2025-07-11fix PartialEq const feature name and const_cmp tracking issueRalf Jung-6/+6
2025-07-03remove redundant #[must_use]Marijn Schouten-4/+0
2025-06-23Make `PartialEq` a `const_trait`Oli Scherer-9/+16
2025-06-16library/compiler: add `PointeeSized` boundsDavid Wood-16/+19
As core uses an extern type (`ptr::VTable`), the default `?Sized` to `MetaSized` migration isn't sufficient, and some code that previously accepted `VTable` needs relaxed to continue to accept extern types. Similarly, the compiler uses many extern types in `rustc_codegen_llvm` and in the `rustc_middle::ty::List` implementation (`OpaqueListContents`) some bounds must be relaxed to continue to accept these types. Unfortunately, due to the current inability to relax `Deref::Target`, some of the bounds in the standard library are forced to be stricter than they ideally would be.
2025-05-05Fix parameter order for `_by()` variants of `min` / `max`/ `minmax` in ↵Michael Rieder-3/+26
`std::cmp`
2025-04-12Extend the chaining logic to slices tooScott McMurray-0/+32
2025-03-25Override PartialOrd methods for boolDaniPopes-27/+23
I noticed that `PartialOrd` implementation for `bool` does not override the individual operator methods, unlike the other primitive types like `char` and integers. This commit extracts these `PartialOrd` overrides shared by the other primitive types into a macro and calls it on `bool` too.
2025-03-23Stop using specialization for thisScott McMurray-75/+87
Uses `__`-named `doc(hidden)` methods instead.
2025-03-19Add chaining versions of lt/le/gt/ge and use them in tuple PartialOrdScott McMurray-0/+84
2025-03-16Rollup merge of #138082 - thaliaarchi:slice-cfg-not-test, r=thomcc许杰友 Jieyou Xu (Joe)-2/+2
Remove `#[cfg(not(test))]` gates in `core` These gates are unnecessary now that unit tests for `core` are in a separate package, `coretests`, instead of in the same files as the source code. They previously prevented the two `core` versions from conflicting with each other.
2025-03-06Remove #[cfg(not(test))] gates in coreThalia Archibald-2/+2
These gates are unnecessary now that unit tests for `core` are in a separate package, `coretests`, instead of in the same files as the source code. They previously prevented the two `core` versions from conflicting with each other.
2025-03-05Make `is_le` and friends work like clang'sScott McMurray-6/+16
2025-02-17Update some comparison tests now that they pass in LLVM20Scott McMurray-4/+4
2025-01-31implement all min/max fns in terms of `<`/`is_lt`Waffle Lapkin-15/+9
`<` seems to be the "lucky one" for llvm
2025-01-31improve doc tests for (min/max/minmax).* functionsWaffle Lapkin-18/+128
- add tests for `a == b` where missing - try to make all the tests more similar - try to use more illustrative test values
2024-12-31Remove qualification of `std::cmp::Ordering` in `Ord` docMichael Sloan-1/+1
2024-12-23Revert "Auto merge of #130766 - clarfonthey:stable-coverage-attribute, ↵Zalathar-1/+1
r=wesleywiser" This reverts commit 1d35638dc38dbfbf1cc2a9823135dfcf3c650169, reversing changes made to f23a80a4c2fbca593b64e70f5970368824b4c5e9.
2024-12-16Stabilize #[coverage] attributeltdk-1/+1
2024-10-25library: consistently use American spelling for 'behavior'Ralf Jung-1/+1
2024-09-29Remove duplicate sectionLukas Bergdoll-13/+1
2024-09-27Apply review feedbackLukas Bergdoll-13/+16
2024-09-27Apply round 1 of review commentsLukas Bergdoll-16/+15
2024-09-27Fix mistake in exampleLukas Bergdoll-1/+1
2024-09-27Improve Ord docsLukas Bergdoll-95/+263
- Makes wording more clear and re-structures some sections that can be overwhelming for some not already in the know. - Adds examples of how *not* to implement Ord, inspired by various anti-patterns found in real world code.
2024-09-17Remove uneeded PartialOrd bound in cmp::Ord::clampArthur Carcano-1/+0
There is a Self: PartialOrd bound in Ord::clamp, but it is already required by the trait itself. Likely a left-over from the const trait deletion in 76dbe2910465072f85e74d6f7115ec9e6803e8bf. Reported-by: @noeensarguet
2024-07-26Fix doc nitsJohn Arundel-10/+10
Many tiny changes to stdlib doc comments to make them consistent (for example "Returns foo", rather than "Return foo", per RFC1574), adding missing periods, paragraph breaks, backticks for monospace style, and other minor nits. https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md#appendix-a-full-conventions-text
2024-06-21Remove `feature(effects)` from the standard libraryDeadbeef-3/+1
2024-05-23Make clamp inlineblyxyas-0/+1
2024-05-01Step bootstrap cfgsMark Rousskov-28/+10
2024-04-17Rollup merge of #122201 - coolreader18:doc-clone_from, r=dtolnayMatthias Krüger-2/+2
Document overrides of `clone_from()` in core/std As mentioned in https://github.com/rust-lang/rust/pull/96979#discussion_r1379502413 Specifically, when an override doesn't just forward to an inner type, document the behavior and that it's preferred over simply assigning a clone of source. Also, change instances where the second parameter is "other" to "source". I reused some of the wording over and over for similar impls, but I'm not sure that the wording is actually *good*. Would appreciate feedback about that. Also, now some of these seem to provide pretty specific guarantees about behavior (e.g. will reuse the exact same allocation iff the len is the same), but I was basing it off of the docs for [`Box::clone_from`](https://doc.rust-lang.org/1.75.0/std/boxed/struct.Box.html#method.clone_from-1) - I'm not sure if providing those strong guarantees is actually good or not.
2024-04-10Revert "Put basic impls for f16 and f128 behind cfg(not(bootstrap))"Trevor Gross-8/+2
This reverts commit 049a91753594422b6c672bf5a46e04076fc45d9e. The resolution to <https://github.com/rust-lang/rust/issues/123282> is that the `f16`/`f128` regression in the beta compiler was fixable without a revert, so the commit adding `#[cfg(not(bootstrap))]` is no longer useful (added in <https://github.com/rust-lang/rust/pull/123390>). Revert this commit because not having these basic impls bootstrap-gated simplifies everything else that uses them.
2024-04-03Auto merge of #123390 - tgross35:f16-f128-libs-basic-impls-bootstrap, r=jhprattbors-2/+8
Put basic impls for f16 and f128 behind cfg(not(bootstrap)) We will lose `f16` and `f128` in the beta compiler after the revert for <https://github.com/rust-lang/rust/issues/123282> lands. Change what was added in <https://github.com/rust-lang/rust/pull/123085> to be behind `#[cfg(not(bootstrap))]` to account for this.
2024-04-02Put basic impls for f16 and f128 behind cfg(not(bootstrap))Trevor Gross-2/+8
We will lose `f16` and `f128` in the beta compiler after the revert for <https://github.com/rust-lang/rust/issues/123282> lands. Change what was added in <https://github.com/rust-lang/rust/pull/123085> to be behind `#[cfg(not(bootstrap))]` to account for this.
2024-04-02Auto merge of #118310 - scottmcm:three-way-compare, r=davidtwcobors-6/+24
Add `Ord::cmp` for primitives as a `BinOp` in MIR Update: most of this OP was written months ago. See https://github.com/rust-lang/rust/pull/118310#issuecomment-2016940014 below for where we got to recently that made it ready for review. --- There are dozens of reasonable ways to implement `Ord::cmp` for integers using comparison, bit-ops, and branches. Those differences are irrelevant at the rust level, however, so we can make things better by adding `BinOp::Cmp` at the MIR level: 1. Exactly how to implement it is left up to the backends, so LLVM can use whatever pattern its optimizer best recognizes and cranelift can use whichever pattern codegens the fastest. 2. By not inlining those details for every use of `cmp`, we drastically reduce the amount of MIR generated for `derive`d `PartialOrd`, while also making it more amenable to MIR-level optimizations. Having extremely careful `if` ordering to μoptimize resource usage on broadwell (#63767) is great, but it really feels to me like libcore is the wrong place to put that logic. Similarly, using subtraction [tricks](https://graphics.stanford.edu/~seander/bithacks.html#CopyIntegerSign) (#105840) is arguably even nicer, but depends on the optimizer understanding it (https://github.com/llvm/llvm-project/issues/73417) to be practical. Or maybe [bitor is better than add](https://discourse.llvm.org/t/representing-in-ir/67369/2?u=scottmcm)? But maybe only on a future version that [has `or disjoint` support](https://discourse.llvm.org/t/rfc-add-or-disjoint-flag/75036?u=scottmcm)? And just because one of those forms happens to be good for LLVM, there's no guarantee that it'd be the same form that GCC or Cranelift would rather see -- especially given their very different optimizers. Not to mention that if LLVM gets a spaceship intrinsic -- [which it should](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Suboptimal.20inlining.20in.20std.20function.20.60binary_search.60/near/404250586) -- we'll need at least a rustc intrinsic to be able to call it. As for simplifying it in Rust, we now regularly inline `{integer}::partial_cmp`, but it's quite a large amount of IR. The best way to see that is with https://github.com/rust-lang/rust/commit/8811efa88b25b5e41d63850e6047e8257c677858#diff-d134c32d028fbe2bf835fef2df9aca9d13332dd82284ff21ee7ebf717bfa4765R113 -- I added a new pre-codegen MIR test for a simple 3-tuple struct, and this PR change it from 36 locals and 26 basic blocks down to 24 locals and 8 basic blocks. Even better, as soon as the construct-`Some`-then-match-it-in-same-BB noise is cleaned up, this'll expose the `Cmp == 0` branches clearly in MIR, so that an InstCombine (#105808) can simplify that to just a `BinOp::Eq` and thus fix some of our generated code perf issues. (Tracking that through today's `if a < b { Less } else if a == b { Equal } else { Greater }` would be *much* harder.) --- r? `@ghost` But first I should check that perf is ok with this ~~...and my true nemesis, tidy.~~
2024-03-30Auto merge of #123085 - tgross35:f16-f128-step4.0-libs-basic-impls, r=Amanieubors-2/+2
Add basic trait impls for `f16` and `f128` Split off part of <https://github.com/rust-lang/rust/pull/122470> so the compiler doesn't ICE because it expects primitives to have some minimal traits. Fixes <https://github.com/rust-lang/rust/issues/123074>
2024-03-29Add diagnostic items for Ord and PartialOrd methodsUrgau-0/+7
2024-03-28Add basic trait impls for `f16` and `f128`Trevor Gross-2/+2
Split off part of <https://github.com/rust-lang/rust/pull/122470> so the compiler doesn't ICE because it expects primitives to have some minimal traits. Fixes <https://github.com/rust-lang/rust/issues/123074>
2024-03-24Address PR feedbackScott McMurray-0/+3
2024-03-24Slightly simplify the `iN::partial_cmp` MIRScott McMurray-7/+14
This saves some debug and scope metadata in every single function that calls it. Normally wouldn't be worth it, but with the derives there's *so* many of these.
2024-03-23Add+Use `mir::BinOp::Cmp`Scott McMurray-0/+8