Commit Graph

5451 Commits

Author SHA1 Message Date
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
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
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
Matthias Krüger
698448c0cd
Rollup merge of #115888 - RalfJung:assert_receiver_is_total_eq, r=dtolnay
fix a comment about assert_receiver_is_total_eq

"a type implements #[deriving]" doesn't make any sense, so I assume they meant "implement `Eq`"? Also the attribute is called `derive`.
2023-09-28 09:14:06 +02:00
Matthias Krüger
980fba7345
Rollup merge of #112959 - tbu-:pr_fmt_error_wording, r=dtolnay
Change the wording in `std::fmt::Write::write_str`

Refer to the error instead of expanding its name.
2023-09-28 09:14:05 +02:00
Anshul
5e26e8c5bd
changed 'rotate' to 'rotating' 2023-09-28 11:58:37 +05:30
David Tolnay
e2f7032408
Fix "unresolved link to std::fmt::Error"
error: unresolved link to `std::fmt::Error`
       --> library/core/src/fmt/mod.rs:115:52
        |
    115 |     /// This function will return an instance of [`std::fmt::Error`] on error.
        |
        |
        = note: `-D rustdoc::broken-intra-doc-links` implied by `-D warnings`
2023-09-27 22:55:34 -07:00
Ralf Jung
9b7f9c4328 take more clarifying text from Gankra's PR
original source: https://github.com/rust-lang/rust/pull/95851
2023-09-26 16:41:06 +02:00
Federico Stra
d49da0fe54 isqrt: add more tests 2023-09-26 16:05:51 +02:00
Federico Stra
68f0b475c7 isqrt: remove duplication by delegating to unsigned integers 2023-09-26 15:46:14 +02:00
bors
27b4eb96d1 Auto merge of #116125 - RalfJung:const-param-ty-eq, r=compiler-errors
ConstParamTy: require Eq as supertrait

As discussed with `@BoxyUwu` [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/.60ConstParamTy.60.20and.20.60Eq.60).

We want to say that valtree equality on const generic params agrees with `==`, but that only makes sense if `==` actually exists, hence we should have an appropriate bound. Valtree equality is an equivalence relation, so such a type can always be `Eq` and not just `PartialEq`.
2023-09-26 05:33:55 +00:00
bors
8c04c06317 Auto merge of #116074 - fzs111:clarify-pin-docs, r=Mark-Simulacrum
Clarify example in `Pin::new_unchecked` docs

This example in the docs of `Pin::new_unchecked` puzzled me for a relatively long time. Now I understand that it comes down to the difference between dropping the `Pin` vs dropping the pinned value.

I have extended the explanation to highlight this difference. In my opinion it is clearer now, and I hope it helps others understand `Pin` better.
2023-09-25 03:50:59 +00:00
Ralf Jung
ad509633a2 ConstParamTy: require Eq 2023-09-24 23:38:07 +02:00
bors
44bd31c216 Auto merge of #116075 - Colonial-Dev:issue-116063-fix, r=Mark-Simulacrum
Document panics on unsigned wrapping_div/rem calls (#116063)

Add missing `# Panics` sections to the `uint_impl!` macro, documenting that the `wrapping_rem/div` calls will panic if passed zero.
2023-09-24 07:59:00 +00:00
Caio
d63959f2fa Add the cfg_match! macro 2023-09-23 14:23:51 -03:00
FZs
0f248d8ea9 Clarify example in Pin::new_unchecked docs 2023-09-23 17:28:43 +02:00
James Haywood
f286a75692 Extend fix to wrapping_div, wrapping_div_euclid and wrapping_rem_euclid 2023-09-22 18:07:17 -04:00
James Haywood
1170b7b447 Resolve rust-lang/rust#116063 2023-09-22 15:52:07 -04:00
Federico Stra
1b34f1c6b2 isqrt: add tests 2023-09-22 16:11:26 +02:00
Federico Stra
3e8676c327 isqrt: initial implementation 2023-09-22 16:11:26 +02:00
bors
8759de0a49 Auto merge of #114776 - fee1-dead-contrib:enable-effects-in-libcore, r=oli-obk
Enable effects for libcore

~~r? `@oli-obk~~`

forgot you are on vacation, oops
2023-09-22 07:00:52 +00:00
Guillaume Gomez
0d2c603b12
Rollup merge of #116007 - m-ou-se:const-panic-fmt-panic-display, r=oli-obk
Call panic_display directly in const_panic_fmt.

`panic_str` just directly calls `panic_display`. The only reason `panic_str` exists, is for a lint to detect an expansion of `panic_2015!(expr)` (which expands to `panic_str`).

It is `panic_display` that is hooked by const-eval, which is the reason we call it here.

Part of https://github.com/rust-lang/rust/issues/116005

r? ``@oli-obk``
2023-09-21 13:25:40 +02:00
Ralf Jung
6c73f254b9 avoid talking about inverses 2023-09-21 08:34:05 +02:00
Ralf Jung
14625f5b3e consistent wording 2023-09-21 08:27:10 +02:00
Ralf Jung
39b53dc204 documentation tweaks 2023-09-21 08:27:09 +02:00
Ralf Jung
62bdb1a6e0 offset_from: docs improvements 2023-09-21 08:27:09 +02:00
Matthias Krüger
6bcae4c93e
Rollup merge of #116008 - m-ou-se:boxmeup, r=oli-obk
Rename BoxMeUp to PanicPayload.

"BoxMeUp" is not very clear. Let's rename that to a description of what it actually represents: a panic payload.

This PR also renames the structs that implement this trait to have more descriptive names.

Part of https://github.com/rust-lang/rust/issues/116005

r? `@oli-obk`
2023-09-21 00:11:37 +02:00
Mara Bos
667bba46b0 Fix typo. 2023-09-20 22:37:39 +02:00
Mara Bos
76d9b3689c Rename BoxMeUp to PanicPayload. 2023-09-20 19:24:52 +02:00
Mara Bos
0d07b4c2ce Call panic_display directly in const_panic_fmt. 2023-09-20 18:59:12 +02:00
Deadbeef
7446012c1e fix rustdoc tests 2023-09-20 03:02:14 +00:00
Deadbeef
04eec37dc2 Enable effects for libcore 2023-09-20 03:02:14 +00:00
bors
3b9e0feff4 Auto merge of #114443 - tgross35:cstr-len, r=dtolnay
Implement `cstr_count_bytes`

This has not yet been approved via ACP, but it's simple enough to get started on.

- ACP: https://github.com/rust-lang/libs-team/issues/256
- Tracking issue: https://github.com/rust-lang/rust/issues/114441

`@rustbot` label +T-libs-api
2023-09-20 00:02:45 +00:00
Ralf Jung
028c78c6c7 explain mysterious addition in float minimum/maximum 2023-09-19 20:13:04 +02:00
Matthias Krüger
0a66c87bd4
Rollup merge of #115494 - RalfJung:primitive_docs, r=Mark-Simulacrum
get rid of duplicate primitive_docs

Having this duplicate makes editing that file very annoying. And at least locally the generated docs still look perfectly fine...
2023-09-18 18:27:19 +02:00
Matthias Krüger
db9e217989
Rollup merge of #109409 - WaffleLapkin:progamer, r=dtolnay
Add `minmax{,_by,_by_key}` functions to `core::cmp`

This PR adds the following functions:

```rust
// mod core::cmp
#![unstable(feature = "cmp_minmax")]

pub fn minmax<T>(v1: T, v2: T) -> [T; 2]
where
    T: Ord;

pub fn minmax_by<T, F>(v1: T, v2: T, compare: F) -> [T; 2]
where
    F: FnOnce(&T, &T) -> Ordering;

pub fn minmax_by_key<T, F, K>(v1: T, v2: T, mut f: F) -> [T; 2]
where
    F: FnMut(&T) -> K,
    K: Ord;
```
(they are also `const` under `#[feature(const_cmp)]`, I've omitted `const` stuff for simplicity/readability)

----

Semantically these functions are equivalent to `{ let mut arr = [v1, v2]; arr.sort(); arr }`, but since they operate on 2 elements only, they are implemented as a single comparison.

Even though that's basically a sort, I think "sort 2 elements" operation is useful on it's own in many cases. Namely, it's a common pattern when you have 2 things, and need to know which one is smaller/bigger to operate on them differently.

I've wanted such functions countless times, most recently in #109402, so I thought I'd propose them.

----

r? libs-api
2023-09-18 18:27:18 +02:00
Maybe Waffle
0c3e0abbf8 Fill-in tracking issue for feature(cmp_minmax) 2023-09-18 16:21:03 +00:00
Maybe Waffle
fe87063a18 Add minmax* functions to core::cmp 2023-09-18 16:13:25 +00:00
Ralf Jung
7b7caae30e get rid of duplicate primitive_docs 2023-09-18 08:17:36 +02:00
bors
df99bc151a Auto merge of #108043 - a1phyr:string_write_fmt, r=workingjubilee
Small wins for formatting-related code

This PR does two small wins in fmt code:
- Override `write_char` for `PadAdapter` to use inner buffer's `write_char`
- Override some `write_fmt` implementations to avoid avoid the additional indirection and vtable generated by the default impl.
2023-09-18 03:33:53 +00:00
bors
8a7cab8d0e Auto merge of #115547 - WaffleLapkin:spin_looping, r=Mark-Simulacrum
Simplify `core::hint::spin_loop`

The grouping was inconsistent and not really helpful.

r? t-libs
2023-09-18 00:02:40 +00:00
Benoît du Garreau
78846d17c1 Specialize fmt::Write::write_fmt for Sized types 2023-09-17 23:14:53 +02:00