Commit Graph

5602 Commits

Author SHA1 Message Date
Oli Scherer
60956837cf s/Generator/Coroutine/ 2023-10-20 21:10:38 +00:00
ltdk
b9c2d0e4ab Fix typo in atomic docs 2023-10-20 00:57:29 -04:00
León Orell Valerian Liehr
80c9588549
Rollup merge of #116795 - DaniPopes:track-caller-option, r=cuviper
Add `#[track_caller]` to `Option::unwrap_or_else`

Same as #116317 but for `Option`.

Closes #115302
2023-10-19 04:34:46 +02:00
Oli Scherer
bcdd3d7739 Disable effects in libcore again 2023-10-17 17:55:49 +00:00
bors
93e62a260f Auto merge of #115577 - RalfJung:atomic-load, r=Amanieu
document when atomic loads are guaranteed read-only

Based on this [discussion in Zulip](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/Can.20.60Atomic*.3A.3Aload.60.20perform.20a.20write).

The values for x86 and x86_64 are complete guesswork on my side, and I have no clue what the values might be for other architectures. I hope we can get the right people to chime in to gather the required information. :)

I'll update Miri to respect these rules once we have more data.
2023-10-17 14:11:31 +00:00
Ralf Jung
e494df436d remove 128bit atomics, they are anyway not exposed on those targets 2023-10-17 07:56:49 +02:00
Nilstrieb
414135d522 Make rustc_onunimplemented export path agnostic
This makes it so that all the matchers that match against paths use the
definition path instead of the export path. This removes all duplication
around `std`/`alloc`/`core`.

This is not necessarily optimal because we now depend on internal
implementation details like `core::ops::control_flow::ControlFlow`,
which is not very nice and probably not acceptable for a stable
`on_unimplemented`.

An alternative would be to just string-replace normalize away
`alloc`/`core` to `std` as a special case, keeping the export paths but
making it so that we're still fully standard library flavor agnostic.
2023-10-16 19:37:12 +02:00
Ralf Jung
6605116463 use target-arch based table 2023-10-16 19:29:16 +02:00
DaniPopes
0df670fb67
Add #[track_caller] to Option::unwrap_or_else 2023-10-16 15:17:15 +02:00
Matthias Krüger
17113f7db6
Rollup merge of #115955 - tgross35:ip-to-canonical, r=dtolnay
Stabilize `{IpAddr, Ipv6Addr}::to_canonical`

Make `IpAddr::to_canonical` and `IpV6Addr::to_canonical` stable (+const), as well as const stabilize `Ipv6Addr::to_ipv4_mapped`.

Newly stable API:

```rust
impl IpAddr {
    // Newly stable under `ip_to_canonical`
    const fn to_canonical(&self) -> IpAddr;
}

impl Ipv6Addr {
    // Newly stable under `ip_to_canonical`
    const fn to_canonical(&self) -> IpAddr;

    // Already stable, this makes it const stable under
    // `const_ipv6_to_ipv4_mapped`
    const fn to_ipv4_mapped(&self) -> Option<Ipv4Addr>
}
```

These stabilize a subset of the following tracking issues:

- https://github.com/rust-lang/rust/issues/27709
- https://github.com/rust-lang/rust/issues/76205

Stabilization of all methods under the `ip` gate was attempted once at https://github.com/rust-lang/rust/pull/66584 then again at https://github.com/rust-lang/rust/pull/76098. These were not successful because there are still unknowns about `is_documentation` `is_benchmarking` and similar; `to_canonical` is much more straightforward.

I have looked and could not find any known issues with `to_canonical`. These were added in 2021 in https://github.com/rust-lang/rust/pull/87708

cc implementor ``@the8472``

r? libs-api
``@rustbot`` label +T-libs-api +needs-fcp
2023-10-16 06:26:20 +02:00
bors
30d310cc1f Auto merge of #113747 - clarfonthey:ip_bitops, r=dtolnay
impl Not, Bit{And,Or}{,Assign} for IP addresses

ACP: rust-lang/libs-team#235

Note: since these are insta-stable, these require an FCP.

Implements, where `N` is either `4` or `6`:

```rust
impl Not for IpvNAddr
impl Not for &IpvNAddr

impl BitAnd<IpvNAddr> for IpvNAddr
impl BitAnd<&IpvNAddr> for IpvNAddr
impl BitAnd<IpvNAddr> for &IpvNAddr
impl BitAnd<&IpvNAddr> for &IpvNAddr

impl BitAndAssign<IpvNAddr> for IpvNAddr
impl BitAndAssign<&IpvNAddr> for IpvNAddr

impl BitOr<IpvNAddr> for IpvNAddr
impl BitOr<&IpvNAddr> for IpvNAddr
impl BitOr<IpvNAddr> for &IpvNAddr
impl BitOr<&IpvNAddr> for &IpvNAddr

impl BitOrAssign<IpvNAddr> for IpvNAddr
impl BitOrAssign<&IpvNAddr> for IpvNAddr
```
2023-10-15 23:05:06 +00:00
Matthias Krüger
32da83d338
Rollup merge of #116760 - Nilstrieb:triviality, r=oli-obk
Remove trivial cast in `guaranteed_eq`

I found this while accidentally breaking trivial casts in another branch.

r? oli-obk
2023-10-15 21:29:09 +02:00
bors
64368d0279 Auto merge of #110729 - ColinFinck:decode-utf16-fused-iterator, r=dtolnay
Implement FusedIterator for DecodeUtf16 when the inner iterator does

I have just implemented an iterator that wraps `DecodeUtf16` and wanted to implement `FusedIterator` for my iterator when I noticed that `DecodeUtf16` currently doesn't implement `FusedIterator` at all.
A quick look at the code of `DecodeUtf16` revealed that `DecodeUtf16::next` only returns `None` when its inner iterator returns `None`:
3462f79e94/library/core/src/char/decode.rs (L45)

As a result, we can implement `FusedIterator` for `DecodeUtf16` when the inner iterator does.

I'm following the example of #96397 here and consider this change minor and non-controversial, which is why I haven't added an RFC. I have also added the required feature name (`"decode_utf16_fused_iterator"`), however without adding a chapter to the Rust Unstable book (same as #96397).
2023-10-15 17:09:37 +00:00
Ralf Jung
9d8506d27f acquire loads can be done as relaxed load; acquire fence 2023-10-15 17:41:50 +02:00
Ralf Jung
9b8686d832 only guarantee for Relaxed; add ptr-size fallback 2023-10-15 17:41:50 +02:00
Ralf Jung
275d5c8251 wording 2023-10-15 17:41:50 +02:00
Ralf Jung
69b62ecc69 define 'read-only memory' 2023-10-15 17:41:50 +02:00
Ralf Jung
07b8c10ed8 add general powerpc64le bound
(some powerpc64le targets can guarantee more, but for now it doesn't seem worth separating by OS/vendor)
2023-10-15 17:41:50 +02:00
Ralf Jung
7453235feb add ARM and RISC-V values 2023-10-15 17:41:50 +02:00
Ralf Jung
b5e67a00d9 document when atomic loads are guaranteed read-only 2023-10-15 17:41:50 +02:00
Maybe Waffle
5c13c69f63 Add tests for SocketAddrV6 ordering with scope_id and flowinfo 2023-10-15 12:25:58 +00:00
Nilstrieb
fe9d422e7b Remove trivial cast in guaranteed_eq
I found this while accidentally breaking trivial casts in another
branch.
2023-10-15 12:33:44 +02:00
Matthias Krüger
e86e6b45e7
Rollup merge of #116594 - tae-soo-kim:convert-tryfrom-doc, r=scottmcm
Fix `std::convert::TryFrom` doc

Original text:

> truncating the [i64](https://doc.rust-lang.org/std/primitive.i64.html) to an [i32](https://doc.rust-lang.org/std/primitive.i32.html) (essentially giving the [i64](https://doc.rust-lang.org/std/primitive.i64.html)’s value modulo [i32::MAX](https://doc.rust-lang.org/std/primitive.i32.html#associatedconstant.MAX))

This can't be true, because `i32::MAX` is an odd number. The correct value seems `(i32::MAX + 1) * 2`, but this is complicated and distracting, and I suggest removing the parentheses entirely.
2023-10-15 11:37:23 +02:00
bors
0d410be23c Auto merge of #115515 - the8472:zip-for-arrays, r=scottmcm
optimize zipping over array iterators

Fixes #115339 (somewhat)

the new assembly:

```asm
zip_arrays:
        .cfi_startproc
        vmovups (%rdx), %ymm0
        leaq    32(%rsi), %rcx
        vxorps  %xmm1, %xmm1, %xmm1
        vmovups %xmm1, -24(%rsp)
        movq    $0, -8(%rsp)
        movq    %rsi, -88(%rsp)
        movq    %rdi, %rax
        movq    %rcx, -80(%rsp)
        vmovups %ymm0, -72(%rsp)
        movq    $0, -40(%rsp)
        movq    $32, -32(%rsp)
        movq    -24(%rsp), %rcx
        vmovups (%rsi,%rcx), %ymm0
        vorps   -72(%rsp,%rcx), %ymm0, %ymm0
        vmovups %ymm0, (%rsi,%rcx)
        vmovups (%rsi), %ymm0
        vmovups %ymm0, (%rdi)
        vzeroupper
        retq
```

This is still longer than the slice version given in the issue but at least it eliminates the terrible  `vpextrb`/`orb` chain. I guess this is due to excessive memcpys again (haven't looked at the llvmir)?

The `TrustedLen` specialization is a drive-by change since I had to do something for the default impl anyway to be able to specialize the `TrustedRandomAccessNoCoerce` impl.
2023-10-15 00:49:21 +00:00
Guillaume Gomez
fcd75ccc90
Rollup merge of #116540 - daxpedda:once-cell-lock-try-insert, r=Mark-Simulacrum
Implement `OnceCell/Lock::try_insert()`

I took inspiration from [`once_cell`](https://crates.io/crates/once_cell):
- [`once_cell::unsync::OnceCell::try_insert()`](874f9373ab/src/lib.rs (L551-L563))
- [`once_cell::sync::OnceCell::try_insert()`](874f9373ab/src/lib.rs (L1080-L1087))

I tried to change as little code as possible in the first commit and applied some obvious optimizations in the second one.

ACP: https://github.com/rust-lang/libs-team/issues/276
Tracking issue: #116693
2023-10-14 22:35:05 +02:00
Matthias Krüger
3899957086
Rollup merge of #115653 - joshlf:patch-9, r=dtolnay
Guarantee that Layout::align returns a non-zero power of two
2023-10-14 13:48:18 +02:00
bors
39acbed8d6 Auto merge of #116407 - Mark-Simulacrum:bootstrap-bump, r=onur-ozkan
Bump bootstrap compiler to just-released beta

https://forge.rust-lang.org/release/process.html#master-bootstrap-update-t-2-day-tuesday
2023-10-14 05:44:48 +00:00
bors
2a7c2df506 Auto merge of #115719 - tgross35:atomic-from-ptr, r=dtolnay
Stabilize `atomic_from_ptr`

This stabilizes `atomic_from_ptr` and moves the const gate to `const_atomic_from_ptr`. Const stability is blocked on `const_mut_refs`.

Tracking issue:  #108652

Newly stable API:

```rust
// core::atomic

impl AtomicBool { pub unsafe fn from_ptr<'a>(ptr: *mut bool) -> &'a AtomicBool; }

impl<T> AtomicPtr<T> { pub unsafe fn from_ptr<'a>(ptr: *mut *mut T) -> &'a AtomicPtr<T>; }

impl AtomicU8    { pub unsafe fn from_ptr<'a>(ptr: *mut u8)    -> &'a AtomicU8;    }
impl AtomicU16   { pub unsafe fn from_ptr<'a>(ptr: *mut u16)   -> &'a AtomicU16;   }
impl AtomicU32   { pub unsafe fn from_ptr<'a>(ptr: *mut u32)   -> &'a AtomicU32;   }
impl AtomicU64   { pub unsafe fn from_ptr<'a>(ptr: *mut u64)   -> &'a AtomicU64;   }
impl AtomicUsize { pub unsafe fn from_ptr<'a>(ptr: *mut usize) -> &'a AtomicUsize; }

impl AtomicI8    { pub unsafe fn from_ptr<'a>(ptr: *mut i8)    -> &'a AtomicI8;    }
impl AtomicI16   { pub unsafe fn from_ptr<'a>(ptr: *mut i16)   -> &'a AtomicI16;   }
impl AtomicI32   { pub unsafe fn from_ptr<'a>(ptr: *mut i32)   -> &'a AtomicI32;   }
impl AtomicI64   { pub unsafe fn from_ptr<'a>(ptr: *mut i64)   -> &'a AtomicI64;   }
impl AtomicIsize { pub unsafe fn from_ptr<'a>(ptr: *mut isize) -> &'a AtomicIsize; }
```
2023-10-14 02:45:21 +00:00
Maybe Waffle
963131e99c Derive Ord, PartialOrd and Hash for SocketAddr*
...instead of hand rolling impls, since
1. It's nicer
2. It fixes a buggy `Ord` impl of `SocketAddrV6`, which ignored half of the fields
2023-10-14 00:48:22 +00:00
Trevor Gross
227c844b16 Stabilize 'atomic_from_ptr', move const gate to 'const_atomic_from_ptr' 2023-10-13 16:10:33 -04:00
Trevor Gross
3209d2d46e Correct documentation for atomic_from_ptr
* Remove duplicate alignment note that mentioned `AtomicBool` with other
  types
* Update safety requirements about when non-atomic operations are
  allowed
2023-10-13 16:10:29 -04:00
bors
57ef889852 Auto merge of #116233 - DaniPopes:stabilize-const_maybe_uninit_assume_init_read, r=dtolnay
Stabilize `const_maybe_uninit_assume_init_read`

AFAICT the only reason this was not included in the `maybe_uninit_extra` stabilization was because `ptr::read` was unstable (https://github.com/rust-lang/rust/pull/92768#issuecomment-1011101383), which has since been stabilized in 1.71.

Needs a separate FCP from the [original `maybe_uninit_extra` one](https://github.com/rust-lang/rust/issues/63567#issuecomment-964428807).

Tracking issue: #63567
2023-10-13 17:11:03 +00:00
daxpedda
dd34d9027a
Add some optimizations 2023-10-13 14:54:33 +02:00
daxpedda
6db2587999
Implement OnceCell/Lock::try_insert() 2023-10-13 14:54:32 +02:00
ltdk
91405ab74a Clean up unchecked_math, separate out unchecked_shifts 2023-10-13 02:17:08 -04:00
ltdk
6b13950978 Remove Not for IpAddr 2023-10-13 02:15:19 -04:00
ltdk
46bb49acb5 impl Not, Bit{And,Or,Xor}{,Assign} for IP addresses 2023-10-13 02:15:19 -04:00
Joshua Liebow-Feeser
a9b0966aa5
Update library/core/src/alloc/layout.rs
Co-authored-by: David Tolnay <dtolnay@gmail.com>
2023-10-12 16:03:45 -07:00
bors
156da98b29 Auto merge of #112818 - Benjamin-L:add-slice_split_once, r=cuviper
Implement `slice::split_once` and `slice::rsplit_once`

Feature gate is `slice_split_once` and tracking issue is #112811. These are equivalents to the existing `str::split_once` and `str::rsplit_once` methods.
2023-10-11 08:19:13 +00:00
tae-soo-kim
e15e9a673e
Update mod.rs 2023-10-10 07:05:25 +00:00
Michael Howell
c6e6ecb1af rustdoc: remove rust logo from non-Rust crates 2023-10-08 20:17:53 -07:00
Mark Rousskov
ea1066d0be Bump to latest beta 2023-10-08 19:57:43 -04:00
bors
598e29bf70 Auto merge of #100806 - timvermeulen:split_inclusive_double_ended_bound, r=dtolnay
Fix generic bound of `str::SplitInclusive`'s `DoubleEndedIterator` impl

`str::SplitInclusive`'s `DoubleEndedIterator` implementation currently uses a `ReverseSearcher` bound for the corresponding searcher. A `DoubleEndedSearcher` bound should have been used instead.

`DoubleEndedIterator` requires that repeated `next_back` calls produce the same items as repeated `next` calls, in opposite order. `ReverseSearcher` lets you search starting from the back of a string, but it makes no guarantees about how its matches correspond to the matches found by a forward search. `DoubleEndedSearcher` is a subtrait of `ReverseSearcher` and does require that the same matches are found in both directions.

This bug fix is a breaking change. Calling `next_back` on `"a+++b".split_inclusive("++")` is currently accepted with repeated calls producing `"b"` and `"a+++"`, while forward iteration yields `"a++"` and `"+b"`. Also see https://github.com/rust-lang/rust/issues/100756#issuecomment-1221307166 for more details.

I believe that this is the only iterator that uses this bound incorrectly — other related iterators such as `str::Split` do have a `DoubleEndedSearcher` bound for their `DoubleEndedIterator` implementation. And `slice::SplitInclusive` doesn't face this problem at all because it doesn't use patterns, only a predicate.

cc `@SkiFire13`
2023-10-07 17:10:02 +00:00
Matthias Krüger
f8dae0c20a
Rollup merge of #116481 - scottmcm:tweak-combinators, r=cuviper
Reuse existing `Some`s in `Option::(x)or`

LLVM still has trouble re-using discriminants sometimes when rebuilding a two-variant enum, so when we have the correct variant already built, just use it.

That's shorter in the Rust code, as well as simpler in MIR and the optimized LLVM, so might as well: <https://rust.godbolt.org/z/KhdE8eToW>

Thanks to `@veber-alex` for pointing out this opportunity in https://github.com/rust-lang/rust/issues/101210#issuecomment-1732470941
2023-10-06 21:17:50 +02:00
Matthias Krüger
4dfa5e5dec
Rollup merge of #114564 - scottmcm:when-to-from, r=dtolnay
Attempt to describe the intent behind the `From` trait further

Inspired by the <https://internals.rust-lang.org/t/allow-use-as-and-try-as-for-from-and-tryfrom-traits/19240/26?u=scottmcm> thread.

`@rustbot` label +T-libs-api
2023-10-06 21:17:48 +02:00
The 8472
b018ad3d41 optimize zipping over array iterators 2023-10-06 18:33:25 +02:00
Guillaume Gomez
9e28a9349c
Rollup merge of #116329 - RalfJung:swap-comments, r=scottmcm
update some comments around swap()

Based on ``@eddyb's`` comment [here](https://github.com/rust-lang/unsafe-code-guidelines/issues/461#issuecomment-1742156410).

And then I noticed the wrong capitalization for Miri and fixed it in some other places as well.
2023-10-06 13:18:35 +02:00
Guillaume Gomez
3785fed021
Rollup merge of #116198 - Jarcho:diag_items, r=WaffleLapkin
Add more diagnostic items for clippy
2023-10-06 13:18:34 +02:00
Guillaume Gomez
382701e6b6
Rollup merge of #115588 - tifv:fix-comment-successors, r=scottmcm
Fix a comment in std::iter::successors

The `unfold` function have since #58062 been renamed to `from_fn`.
(I'm not sure if this whole comment is still useful—it's not like there are many iterators that *can't* be based on `from_fn`. Anyway, in its current form this comment is not correct, and it sent me into a half-hour research of what happened to `unfold` function, so I want to do *something* with it 🙃 deleting these three lines is a perfectly fine alternative, in my opinion.)
2023-10-06 13:18:34 +02:00
Guillaume Gomez
525c661842
Rollup merge of #115522 - joshlf:patch-8, r=scottmcm
Clarify ManuallyDrop bit validity

Clarify that `ManuallyDrop<T>` has the same bit validity as `T`.
2023-10-06 13:18:33 +02:00
Guillaume Gomez
4e818f6b72
Rollup merge of #115454 - vwkd:patch-1, r=scottmcm
Clarify example in docs of str::char_slice

Just a one word improvement.

“Last” can be misread as meaning the last (third) instead of the previous (first).
2023-10-06 13:18:33 +02:00
Scott McMurray
5432d13bb0 Reuse existing Somes in Option::(x)or
LLVM still has trouble re-using discriminants sometimes when rebuilding a two-variant enum, so when we have the correct variant already built, just use it.

That's simpler in LLVM *and* in MIR, so might as well: <https://rust.godbolt.org/z/KhdE8eToW>
2023-10-06 01:41:48 -07:00
Scott McMurray
1651f1f4b8 Elaborate some caveats to lossless 2023-10-05 23:03:02 -07:00
scottmcm
44f92c1f80
Don't mention "recover the original" in From docs
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2023-10-06 05:31:54 +00:00
Scott McMurray
b80e653ca1 Attempt to describe the intent behind the From trait further 2023-10-05 22:21:45 -07:00
Jason Newcomb
d464b72970 Add more diagnostic items for clippy 2023-10-05 18:21:47 -04:00
bors
cdca82c2c8 Auto merge of #116455 - matthiaskrgr:rollup-p226a5u, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #116220 (stabilize `Option::as_`(`mut_`)`slice`)
 - #116288 (Add Span to various smir types)
 - #116415 (Move subtyper below reveal_all and change reveal_all)
 - #116428 (Add a note to duplicate diagnostics)
 - #116452 (Do not assert that hidden types don't have erased regions.)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-05 17:50:50 +00:00
Matthias Krüger
864e5d8d94
Rollup merge of #116220 - llogiq:stabilize-option-as-slice, r=BurntSushi
stabilize `Option::as_`(`mut_`)`slice`

This is the stabilization to #108545. Thanks to everyone who helped getting this into Rust proper.
2023-10-05 19:24:33 +02:00
bors
3bcad65fbf Auto merge of #103046 - JanBeh:PR_clarify_cmp_terminology, r=workingjubilee
docs: Correct terminology in std::cmp

This PR is the result of some discussions on URLO:

* [Traits in `std::cmp` and mathematical terminology](https://users.rust-lang.org/t/traits-in-std-cmp-and-mathematical-terminology/69887)
* [Are poker hands `Ord` or `PartialOrd`?](https://users.rust-lang.org/t/are-poker-hands-ord-or-partialord/82644)

Arguably, the documentation currently isn't very precise regarding mathematical terminology. This can lead to misunderstandings of what `PartialEq`, `Eq`, `PartialOrd`, and `Ord` actually do.

While I believe this PR doesn't give any new API guarantees, it expliclitly mentions that `PartialEq::eq(a, b)` may return `true` for two distinct values `a` and `b` (i.e. where `a` and `b` are not equal in the mathematical sense). This leads to the consequence that `Ord` may describe a weak ordering instead of a total ordering.

In either case, I believe this PR should be thoroughly reviewed, ideally by someone with mathematical background to make sure the terminology is correct now, and also to ensure that no unwanted new API guarantees are made.

In particular, the following problems are addressed:

* Some clarifications regarding used (mathematical) terminology:
    * Avoid using the terms "total equality" and "partial equality" in favor of "equivalence relation" and "partial equivalence relation", which are well-defined and unambiguous.
    * Clarify that `Ordering` is an ordering between two values (and not an order in the mathematical sense).
    * Avoid saying that `PartialEq` and `Eq` are "equality comparisons" because the terminology "equality comparison" could be misleading: it's possible to implement `PartialEq` and `Eq` for other (partial) equivalence relations, in particular for relations where `a == b` for some `a` and `b` even when `a` and `b` are not the same value.
    * Added a section "Strict and non-strict partial orders" to document that the `<=` and `>=` operators do not correspond to non-strict partial orders.
    * Corrected section "Corollaries" in documenation of `Ord` in regard to `<` only describing a strict total order in cases where `==` conforms to mathematical equality.
    * ~~Added a section "Weak orders" to explain that `Ord` may also describe a weak order or total preorder, depending on how `PartialEq::eq` has been implemented.~~ (Removed, see [comment](https://github.com/rust-lang/rust/pull/103046#issuecomment-1279929676))
* Made documentation easier to understand:
    * Explicitly state at the beginning of `PartialEq`'s documentation comment that implementing the trait will provide the `==` and `!=` operators.
    * Added an easier to understand rule when to implement `Eq` in addition to `PartialEq`: "if it’s guaranteed that `PartialEq::eq(a, a)` always returns `true`."
    *  Explicitly mention in documentation of `Eq` that the properties "symmetric" and "transitive" are already required by `PartialEq`.
2023-10-05 15:24:54 +00:00
bors
cf9fd95b1c Auto merge of #114042 - liushuyu:ubuntu/i586-fpmath, r=workingjubilee
core library: Disable fpmath tests for i586 ...

This patch disables the floating-point epsilon test for i586 since x87 registers are too imprecise and can't produce the expected results.
2023-10-05 13:35:18 +00:00
Jan Behrens
86b031b734 docs: Correct terminology in std::cmp
Some clarifications regarding used (mathematical) terminology:

* Avoid using the terms "total equality" and "partial equality" in favor
  of "equivalence relation" and "partial equivalence relation", which
  are well-defined and unambiguous.
* Clarify that `Ordering` is an ordering between two values (and not an
  order in the mathematical sense).
* Avoid saying that `PartialEq` and `Eq` are "equality comparisons"
  because the terminology "equality comparison" could be misleading:
  it's possible to implement `PartialEq` and `Eq` for other (partial)
  equivalence relations, in particular for relations where `a == b` for
  some `a` and `b` even when `a` and `b` are not the same value.
* Added a section "Strict and non-strict partial orders" to document
  that the `<=` and `>=` operators do not correspond to non-strict
  partial orders.
* Corrected section "Corollaries" in documenation of Ord in regard to
  `<` only describing a strict total order in cases where `==` conforms
  to mathematical equality.

Made documentation easier to understand:

* Explicitly state at the beginning of `PartialEq`'s documentation
  comment that implementing the trait will provide the `==` and `!=`
  operators.
* Added an easier to understand rule when to implement `Eq` in addition
  to `PartialEq`: "if it’s guaranteed that `PartialEq::eq(a, a)` always
  returns `true`."
* Explicitly mention in documentation of `Eq` that the properties
  "symmetric" and "transitive" are already required by `PartialEq`.
2023-10-05 14:44:42 +02:00
bors
90f3a6f920 Auto merge of #104153 - tspiteri:doc-float-constants, r=workingjubilee
doc: expand description for f32 and f64 associated constants

This explains the meaning of some of the floating-point associated constants.
2023-10-05 11:46:55 +00:00
Ramon de C Valle
7b45674015 Disable CFI for core and std CFI violations
Works around #115199 by temporarily disabling CFI for core and std CFI
violations to allow the user rebuild and use both core and std with CFI
enabled using the Cargo build-std feature.
2023-10-04 10:05:54 -07:00
bors
a7bb2f67bf Auto merge of #116408 - matthiaskrgr:rollup-hmolg4m, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #115961 (Replace 'mutex' with 'lock' in RwLock documentation)
 - #116146 (Clarify `arg` and `args` documentation)
 - #116363 (Adapt `todo!` documentation to mention displaying custom values)
 - #116365 (bootstrap: make copying linker binaries conditional)
 - #116388 (rustdoc: fix & clean up handling of cross-crate higher-ranked parameters)
 - #116393 (Emit feature gate *warning* for `auto` traits pre-expansion)
 - #116395 (Mark myself as vacation or whatever)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-04 03:38:42 +00:00
Matthias Krüger
0363cc561d
Rollup merge of #116363 - Colonial-Dev:issue-116130-fix, r=thomcc
Adapt `todo!` documentation to mention displaying custom values

Resolves #116130.

I copied from the [existing documentation](https://doc.rust-lang.org/std/macro.unimplemented.html) for `unimplemented!` more or less directly, down to the example trait used. I also took the liberty of fixing some formatting and typographical errors that I noticed.
2023-10-04 05:02:04 +02:00
Mark Rousskov
787d32324c Bump version placeholders 2023-10-03 20:26:36 -04:00
Elichai Turkel
92c9bcdff4
Add missing inline attributes to Duration trait impls 2023-10-03 18:39:56 +03:00
Matthias Krüger
c3daf77132
Rollup merge of #116361 - eduardosm:bump-stdarch, r=Amanieu
Bump stdarch submodule

r? `@Amanieu`
2023-10-03 08:58:50 +02:00
Matthias Krüger
043fcc487a
Rollup merge of #116355 - orlp:signed-zero-rounding-mode, r=thomcc
Clarify float rounding direction for signed zero

Closes https://github.com/rust-lang/rust/issues/116339.
2023-10-03 08:58:50 +02:00
Matthias Krüger
cebe393a4a
Rollup merge of #116351 - asquared31415:ptr_eq_must_use, r=workingjubilee
Add `must_use` on pointer equality functions

`ptr == ptr` (like all use of `==`) has a similar warning, and these functions are simple convenience wrappers over that.
2023-10-03 08:58:49 +02:00
James Haywood
0c6d279728 Appease tidy 2023-10-02 19:22:42 -04:00
James Haywood
f96cfb533a Adapt todo! documentation to mention displaying custom values
Correct hidden trait in doc test
2023-10-02 19:09:11 -04:00
Eduardo Sánchez Muñoz
f2918b4a3d Bump stdarch submodule 2023-10-02 23:43:35 +02:00
Tyler Mandry
132e38366f
Rollup merge of #116350 - Nilstrieb:in-situ, r=Dylan-DPC
Improve wording of `hint::black_box` docs

The wording is a bit confusing.

squash of #109634
2023-10-02 16:09:43 -04:00
Orson Peters
07e96314ec Clarify float rounding direction for signed zero 2023-10-02 22:05:17 +02:00
4gboframram
44c9818993 Improve wording of hint::black_box docs
The wording is a bit confusing.

Co-authored-by: Chris Denton <christophersdenton@gmail.com>
2023-10-02 20:07:14 +02:00
asquared31415
34ea540720 add must_use on pointer equality functions 2023-10-02 15:10:51 +00:00
Matthias Krüger
b3853ccc9d
Rollup merge of #116326 - Colonial-Dev:issue-116165-fix, r=joshtriplett
Correct misleading std::fmt::Binary example (#116165)

Nothing too crazy...

- Add two to the width specifier (so all 32 bits are correctly displayed)
- Pad out the compared string so the assert passes
- Add `// Note` comment highlighting the need for the extra width when using the `#` flag.

The exact contents (and placement?) of the note are, of course, highly bikesheddable.
2023-10-02 16:23:53 +02:00
Ralf Jung
bfc0f23acb MIRI -> Miri 2023-10-02 08:35:08 +02:00
Ralf Jung
ec2e00c404 update some comments around swap() 2023-10-02 08:34:10 +02:00
bors
15783292e5 Auto merge of #116325 - scottmcm:addr_eq, r=dtolnay
Add `ptr::addr_eq`

Seconded ACP: https://github.com/rust-lang/libs-team/issues/274#issuecomment-1741853598
Tracking issue: https://github.com/rust-lang/rust/issues/116324
cc `@dtolnay` https://github.com/rust-lang/rust/issues/106447
2023-10-02 04:17:01 +00:00
James Haywood
f2ecf7c511 Correct misleading std::fmt::Binary example 2023-10-01 23:58:54 -04:00
Scott McMurray
18787914aa Add ptr::addr_eq 2023-10-01 18:56:38 -07:00
ravenclaw900
ba0b7f0f01
Add track_caller attribute to Result::unwrap_or_else 2023-10-01 09:42:37 -05:00
Matthias Krüger
de7053133a
Rollup merge of #116295 - asquared31415:mem_drop_docs, r=WaffleLapkin
Fix `core::mem::drop` docs inaccuracy

r? `@Nilstrieb`
2023-10-01 12:18:12 +02:00
bors
8fa7bdf191 Auto merge of #115670 - Zoxc:outline-panic-macro-1, r=Mark-Simulacrum
Partially outline code inside the panic! macro

This outlines code inside the panic! macro in some cases. This is split out from https://github.com/rust-lang/rust/pull/115562 to exclude changes to rustc.
2023-10-01 05:56:47 +00:00
asquared31415
bc3c445764 mem::drop docs 2023-09-30 14:41:56 -04:00
Matthias Krüger
4db2b741c8
Rollup merge of #116241 - dtolnay:exclusivefwd, r=Amanieu
Add Exclusive forwarding impls (FnOnce, FnMut, Generator)

This is adapted from #104057.
2023-09-29 22:27:51 +02:00
bors
a6dfd89fa7 Auto merge of #113797 - RalfJung:offset_from_docs, r=workingjubilee
offset_from: docs improvements

This is the part of https://github.com/rust-lang/rust/pull/112837 that doesn't add a new function, just tweaks the existing docs.
2023-09-29 13:53:11 +00:00
bors
b8536c1aa1 Auto merge of #116176 - FedericoStra:isqrt, r=dtolnay
Add "integer square root" method to integer primitive types

For every suffix `N` among `8`, `16`, `32`, `64`, `128` and `size`, this PR adds the methods

```rust
const fn uN::isqrt() -> uN;
const fn iN::isqrt() -> iN;
const fn iN::checked_isqrt() -> Option<iN>;
```

to compute the [integer square root](https://en.wikipedia.org/wiki/Integer_square_root), addressing issue #89273.

The implementation is based on the [base 2 digit-by-digit algorithm](https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Binary_numeral_system_(base_2)) on Wikipedia, which after some benchmarking has proved to be faster than both binary search and Heron's/Newton's method. I haven't had the time to understand and port [this code](http://atoms.alife.co.uk/sqrt/SquareRoot.java) based on lookup tables instead, but I'm not sure whether it's worth complicating such a function this much for relatively little benefit.
2023-09-29 07:35:44 +00:00
David Tolnay
fd207e67d5
Const stabilize mem::discriminant 2023-09-28 11:07:06 -07:00
David Tolnay
a95f20c9ad
Add Exclusive forwarding impls (FnOnce, FnMut, Generator) 2023-09-28 10:22:19 -07:00
Federico Stra
25648de28f isqrt: disable long running tests in Miri 2023-09-28 17:43:01 +02:00
DaniPopes
58ed8ad0df
Stabilize const_maybe_uninit_assume_init_read 2023-09-28 16:19:33 +02:00
Matthias Krüger
ff958ae3e4
Rollup merge of #116221 - ArchUsr64:patch-1, r=ChrisDenton
core/slice: Fix inconsistency between docs for `rotate_left` and `rotate_right`

A minor fix for documentation inconsistency as shown below:
## Before:
![2023_09_28_0k3_Kleki](https://github.com/rust-lang/rust/assets/83179501/569a49d3-0d72-49ac-92a2-ef5e1d94130b)
## After:
![image](https://github.com/rust-lang/rust/assets/83179501/afd0c8d7-6fb7-4878-801b-b47c8fe23c7d)
Docs url: https://doc.rust-lang.org/stable/core/primitive.slice.html#method.rotate_left
2023-09-28 15:58:44 +02:00
Federico Stra
fcdfd5b0b9 isqrt: assume that isqrt takes half as many bits
https://github.com/rust-lang/rust/issues/89273#issuecomment-970581089
2023-09-28 14:05:10 +02:00
Federico Stra
77f9eae995 fixup! isqrt: fix stability 2023-09-28 12:32:58 +02:00
Federico Stra
51463175a4 isqrt: cite source and rename variables to match original C code 2023-09-28 12:12:18 +02:00
Federico Stra
c97ab23141 isqrt: fix stability 2023-09-28 11:39:55 +02:00
Federico Stra
17dfb18bd1 fixup! isqrt: initial implementation
Fix C-ism and type inference.
2023-09-28 11:39:17 +02:00