Commit Graph

759 Commits

Author SHA1 Message Date
Kevin Reid c48cdfe8ee Remove unnecessary `let`s and borrowing from `Waker::noop()` usage.
`Waker::noop()` now returns a `&'static Waker` reference, so it can be
passed directly to `Context` creation with no temporary lifetime issue.
2024-01-17 12:00:27 -08:00
klensy aa696c5a22 apply fmt 2024-01-11 15:04:48 +03:00
Jakub Stasiak 4621357d14 Make is_global/is_unicast_global special address handling complete
IANA explicitly documents 192.0.0.9/32, 192.0.0.9/32 and 2001:30::/28 as
globally reachable[1][2] and the is_global implementations declare
following IANA so let's make this happen.

In case of 2002::/16 IANA says N/A so I think it's safe to say we
shouldn't return true there either.

[1] https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml
[2] https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml
2024-01-11 01:03:34 +01:00
The8472 a2a7caacf7 implement TrustedLen for StepBy 2024-01-10 18:55:34 +01:00
Trevor Gross 500d6f6479 Stabilize `slice_first_last_chunk`
This stabilizes all methods under `slice_first_last_chunk`.

Additionally, it const stabilizes the non-mut functions and moves the `_mut`
functions under `const_slice_first_last_chunk`. These are blocked on
`const_mut_refs`.

As part of this change, `slice_split_at_unchecked` was marked const-stable for
internal use (but not fully stable).
2024-01-10 03:06:49 -05:00
Michael Goulet 8bea1df254
Rollup merge of #119583 - AngelicosPhosphoros:const_assume, r=RalfJung
Make `intrinsics::assume` const stable

Closes https://github.com/rust-lang/rust/issues/76972
Blocks https://github.com/rust-lang/rust/pull/119452

Approved in https://github.com/rust-lang/rust/pull/119452#issuecomment-1875741678

r? `@RalfJung`
2024-01-05 10:57:23 -05:00
AngelicosPhosphoros 59c76fb21b Make `intrinsics::assume` const stable
Closes https://github.com/rust-lang/rust/issues/76972
Blocks https://github.com/rust-lang/rust/pull/119452

Approved in https://github.com/rust-lang/rust/pull/119452#issuecomment-1875741678
2024-01-04 19:14:31 +01:00
Jake Goulding 5772818dc8 Adjust library tests for unused_tuple_struct_fields -> dead_code 2024-01-02 15:34:37 -05:00
Linus Färnstrand 98899b7131 Stabilize ip_in_core feature 2023-12-24 12:23:50 +01:00
Michael Goulet eef023c806
Rollup merge of #119222 - eholk:into-async-iterator, r=compiler-errors,dtolnay
Add `IntoAsyncIterator`

This introduces the `IntoAsyncIterator` trait and uses it in the desugaring of the unstable `for await` loop syntax. This is mostly added for symmetry with `Iterator` and `IntoIterator`.

r? `@compiler-errors`

cc `@rust-lang/libs-api,` `@rust-lang/wg-async`
2023-12-22 21:41:04 -05:00
Eric Holk 8e34391d6a
Add IntoAsyncIterator 2023-12-22 11:01:05 -08:00
Pietro Albini f9f5840eb4
update cfg(bootstrap)s 2023-12-22 11:14:11 +01:00
Christiaan Dirkx 605504c5bf Add Ipv6Addr::is_ipv4_mapped
This change consists of cherry-picking the content from the original
PR[1], which got closed due to inactivity, and applying the following
changes:

* Resolving merge conflicts (obviously)
* Linked to to_ipv4_mapped instead of to_ipv4 in the documentation (seems
  more appropriate)
* Added the must_use and rustc_const_unstable attributes the original
  didn't have

I think it's a reasonably useful method.

[1] https://github.com/rust-lang/rust/pull/86490
2023-12-18 13:54:26 +01:00
surechen 40ae34194c remove redundant imports
detects redundant imports that can be eliminated.

for #117772 :

In order to facilitate review and modification, split the checking code and
removing redundant imports code into two PR.
2023-12-10 10:56:22 +08:00
Michael Goulet 19bf749560
Rollup merge of #118123 - RalfJung:internal-lib-features, r=compiler-errors
Add support for making lib features internal

We have the notion of an "internal" lang feature: a feature that is never intended to be stabilized, and using which can cause ICEs and other issues without that being considered a bug.

This extends that idea to lib features as well. It is an alternative to https://github.com/rust-lang/rust/pull/115623: instead of using an attribute to declare lib features internal, we simply do this based on the name. Everything ending in `_internals` or `_internal` is considered internal.

Then we rename `core_intrinsics` to `core_intrinsics_internal`, which fixes https://github.com/rust-lang/rust/issues/115597.
2023-12-05 14:52:41 -05:00
Trevor Gross 01337bf1fd Remove `{,r}split_array_ref{,_mut}` methods from slices
The functionality of these methods from `split_array` has been absorbed by the
`slice_first_last_chunk` feature. This only affects the methods on slices,
not those with the same name that are implemented on array types.

Also adjusts testing to reflect this change.
2023-11-29 23:21:57 -05:00
Caleb Zulawski 89b9388af5 Fix library tests 2023-11-26 08:50:39 -05:00
Ralf Jung 74834a9d74 also make 'core_intrinsics' internal 2023-11-22 20:00:56 +01:00
Urgau 4c2d6de70e Stabilize RFC3324 dyn upcasting coercion
Aka trait_upcasting feature.

And also adjust the `deref_into_dyn_supertrait` lint.
2023-11-22 13:56:36 +01:00
bors e24e5af787 Auto merge of #117619 - elomatreb:add-duration-abs-diff, r=thomcc
Add `Duration::abs_diff`

This adds a `Duration::abs_diff` method analogous to the existing one on the primitive integers.

ACP: https://github.com/rust-lang/libs-team/issues/291
Tracking Issue: https://github.com/rust-lang/rust/issues/117618
2023-11-21 13:09:49 +00:00
bors 33688d2467 Auto merge of #117525 - GKFX:remove_option_payload_ptr, r=petrochenkov
Remove option_payload_ptr; redundant to offset_of

The `option_payload_ptr` intrinsic is no longer required as `offset_of` supports traversing enums (#114208). This PR removes it in order to dogfood offset_of (as suggested at https://github.com/rust-lang/rust/issues/106655#issuecomment-1790907626). However, it will not build until those changes reach beta (which I think is within the next 8 days?) so I've opened it as a draft.
2023-11-18 12:45:42 +00:00
George Bateman 661df4fd55
Remove option_payload_ptr; redundant to offset_of 2023-11-16 22:56:25 +00:00
Ralf Jung 1c1b7897d8 avoid exhaustive i16 test in Miri 2023-11-15 19:23:04 +01:00
bors b9175240ea Auto merge of #116301 - mj10021:issue-115737-fix, r=cuviper
fix rounding issue with exponents in fmt

fixes issue #115737 , where the decimal places are rounded incorrectly when formatting scientific notation
2023-11-14 00:04:05 +00:00
Kornel da3db9a4f7 Rename MaybeUninit::write_slice
#79995
2023-11-11 22:54:07 +00:00
James Dietz 3f0908f47c round to even 2023-11-11 17:22:07 -05:00
James Dietz e81964e6f9 fix rounding issue with exponents in fmt 2023-11-11 16:40:22 -05:00
bors 2c1b65ee14 Auto merge of #115694 - clarfonthey:std-hash-private, r=dtolnay
Add `std:#️⃣:{DefaultHasher, RandomState}` exports (needs FCP)

This implements rust-lang/libs-team#267 to move the libstd hasher types to `std::hash` where they belong, instead of `std::collections::hash_map`.

<details><summary>The below no longer applies, but is kept for clarity.</summary>
This is a small refactor for #27242, which moves the definitions of `RandomState` and `DefaultHasher` into `std::hash`, but in a way that won't be noticed in the public API.

I've opened rust-lang/libs-team#267 as a formal ACP to move these directly into the root of `std::hash`, but for now, they're at least separated out from the collections code in a way that will make moving that around easier.

I decided to simply copy the rustdoc for `std::hash` from `core::hash` since I think it would be ideal for the two to diverge longer-term, especially if the ACP is accepted. However, I would be willing to factor them out into a common markdown document if that's preferred.
</details>
2023-11-11 21:12:20 +00:00
John Millikin 341c85648c Move `BorrowedBuf` and `BorrowedCursor` from `std:io` to `core::io`
Assigned new feature name `core_io_borrowed_buf` to distinguish from the
`Read::read_buf` functionality in `std::io`.
2023-11-09 07:10:11 +09:00
Niklas Fiekas 0bccdb34a2
Stabilize `slice_group_by`
Renamed "group by" to "chunk by" a per #80552.

Newly stable items:

* `core::slice::ChunkBy`
* `core::slice::ChunkByMut`
* `[T]::chunk`
* `[T]::chunk_by`

Closes #80552.
2023-11-07 17:46:00 +01:00
Ole Bertram 0ac438c8d4
Add `Duration::abs_diff` 2023-11-05 19:45:17 +01:00
bors da1e0d1d75 Auto merge of #116218 - tgross35:const-maybe-uninit-zeroed, r=dtolnay
Stabilize `const_maybe_uninit_zeroed` and `const_mem_zeroed`

Make `MaybeUninit::zeroed` and `mem::zeroed` const stable. Newly stable API:

```rust
// core::mem
pub const unsafe fn zeroed<T>() ->;

impl<T> MaybeUninit<T> {
    pub const fn zeroed() -> MaybeUninit<T>;
}
```

This relies on features based around `const_mut_refs`. Per `@RalfJung,` this should be OK since we do not leak any `&mut` to the user.

For this to be possible, intrinsics `assert_zero_valid` and `assert_mem_uninitialized_valid` were made const stable.

Tracking issue: #91850
Zulip discussion: https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/.60const_mut_refs.60.20dependents

r? libs-api
`@rustbot` label -T-libs +T-libs-api +A-const-eval
cc `@RalfJung`  `@oli-obk` `@rust-lang/wg-const-eval`
2023-11-05 05:56:21 +00:00
Trevor Gross f6ce646d3f Stabilize `const_maybe_uninit_zeroed`
Make `MaybeUninit::zeroed` const stable. Newly stable API:

    // core::mem
    impl<T> MaybeUninit<T> {
        pub const fn zeroed() -> MaybeUninit<T>;
    }

Use of `const_mut_refs` should be acceptable since we do not leak the
mutability.

Tracking issue: #91850
2023-11-04 15:27:25 -04:00
ltdk 8337e86b28 Add insta-stable std:#️⃣:{DefaultHasher, RandomState} exports 2023-11-02 20:35:20 -04:00
Maybe Waffle e36224118f Stabilize `[const_]pointer_byte_offsets` 2023-10-25 22:35:12 +00:00
Matthias Krüger 845c414fae
Rollup merge of #116714 - WaffleLapkin:order-the-order, r=joshtriplett
Derive `Ord`, `PartialOrd` and `Hash` for `SocketAddr*`

Fixes #116711

The main pain of this PR is to fix the buggy impl of `Ord` for `SocketAddrV6`, which ignored half of the fields (while `PartialEq` is derived):
4603f0b8af/library/core/src/net/socket_addr.rs (L99-L106)

4603f0b8af/library/core/src/net/socket_addr.rs (L676)

For me it looks like a simple copy-paste error made in https://github.com/rust-lang/rust/pull/72239 (copy from v4 impl) (cc `@hch12907),` as I don't see this behavior being mentioned anywhere on the PR and it also does not respect `cmp` trait "rules". I also do not see any reasons for those impls to _not_ be derived.

It's a shame we did not notice this for 28 versions/3 years. I guess this is a bug fix, but I'm not sure what the process here should be.

r? libs
2023-10-24 19:29:54 +02:00
bohan 482275b194 use visibility to check unused imports and delete some stmts 2023-10-22 21:27:46 +08:00
Maybe Waffle 5c13c69f63 Add tests for `SocketAddrV6` ordering with scope_id and flowinfo 2023-10-15 12:25:58 +00: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
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
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
The 8472 b018ad3d41 optimize zipping over array iterators 2023-10-06 18:33:25 +02:00
Ralf Jung bfc0f23acb MIRI -> Miri 2023-10-02 08:35:08 +02: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
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
Federico Stra c97ab23141 isqrt: fix stability 2023-09-28 11:39:55 +02:00
Federico Stra d49da0fe54 isqrt: add more tests 2023-09-26 16:05:51 +02:00
Caio d63959f2fa Add the `cfg_match!` macro 2023-09-23 14:23:51 -03:00
Federico Stra 1b34f1c6b2 isqrt: add tests 2023-09-22 16:11:26 +02:00
bors f9ba43ce14 Auto merge of #113295 - clarfonthey:ascii-step, r=cuviper
Implement Step for ascii::Char

This allows iterating over ranges of `ascii::Char`, similarly to ranges of `char`.

Note that `ascii::Char` is still unstable, tracked in #110998.
2023-09-02 00:02:50 +00:00
Matthias Krüger d2644d9fe9
Rollup merge of #114238 - jhpratt:fix-duration-div, r=thomcc
Fix implementation of `Duration::checked_div`

I ran across this while running some sanity checks on `time`. Quickcheck immediately found a bug, and as I'd modified the code from `std` I knew there was a bug here as well.

tl;dr this code fails ([playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1189a3efcdfc192c27d6d87815359353))

```rust
use std::time::Duration;

fn main() {
    assert_eq!(
        Duration::new(1, 1).checked_div(7),
        Some(Duration::new(0, 142_857_143)),
    );
}
```

The existing code determines that 1/7 = 0 (seconds), 1/7 = 0 (nanoseconds), 1 billion / 7 = 142,857,142 (extra nanoseconds). The billion comes from multiplying the remainder of the seconds (1) by the number of nanoseconds in a second. However, **this wrongly ignores any remaining nanoseconds**. This PR takes that into consideration, adds a test, and also changes the roundabout way of calculating the remainder into directly computing it.

Note: This is _not_ a rounding error. This result divides evenly.

`@rustbot` label +A-time +C-bug +S-waiting-on-reviewer +T-libs
2023-08-28 08:13:57 +02:00
bors 4cea2bc339 Auto merge of #113464 - waynr:remove-provider-trait, r=Amanieu
core/any: remove Provider trait, rename Demand to Request

This touches on two WIP features:

* `error_generic_member_access`
  * tracking issue: https://github.com/rust-lang/rust/issues/99301
  * RFC (WIP): https://github.com/rust-lang/rfcs/pull/2895
* `provide_any`
  * tracking issue: https://github.com/rust-lang/rust/issues/96024
  * RFC: https://github.com/rust-lang/rfcs/pull/3192

The changes in this PR are intended to address libs meeting feedback summarized by `@Amanieu` in https://github.com/rust-lang/rust/issues/96024#issuecomment-1554773172

The specific items this PR addresses so far are:

> We feel that the names "demand" and "request" are somewhat synonymous and would like only one of those to be used for better consistency.

I went with `Request` here since it sounds nicer, but I'm mildly concerned that at first glance it could be confused with the use of the word in networking context.

> The Provider trait should be deleted and its functionality should be merged into Error. We are happy to only provide an API that is only usable with Error. If there is demand for other uses then this can be provided through an external crate.

The net impact this PR has is that examples which previously looked like
```
    core::any::request_ref::<String>(&err).unwramp()
```

now look like
```
    (&err as &dyn core::error::Error).request_value::<String>().unwrap()
```

These are methods that based on the type hint when called return an `Option<T>` of that type. I'll admit I don't fully understand how that's done, but it involves `core::any::tags::Type` and `core::any::TaggedOption`, neither of which are exposed in the public API, to construct a `Request` which is then passed to the `Error.provide` method.

Something that I'm curious about is whether or not they are essential to the use of `Request` types (prior to this PR referred to as `Demand`) and if so does the fact that they are kept private imply that `Request`s are only meant to be constructed privately within the standard library? That's what it looks like to me.

These methods ultimately call into code that looks like:
```
/// Request a specific value by tag from the `Error`.
fn request_by_type_tag<'a, I>(err: &'a (impl Error + ?Sized)) -> Option<I::Reified>
where
    I: tags::Type<'a>,
{
    let mut tagged = core::any::TaggedOption::<'a, I>(None);
    err.provide(tagged.as_request());
    tagged.0
}
```

As far as the `Request` API is concerned, one suggestion I would like to make is that the previous example should look more like this:
```
/// Request a specific value by tag from the `Error`.
fn request_by_type_tag<'a, I>(err: &'a (impl Error + ?Sized)) -> Option<I::Reified>
where
    I: tags::Type<'a>,
{
    let tagged_request = core::any::Request<I>::new_tagged();
    err.provide(tagged_request);
    tagged.0
}
```
This makes it possible for anyone to construct a `Request` for use in their own projects without exposing an implementation detail like `TaggedOption` in the API surface.

Otherwise noteworthy is that I had to add `pub(crate)` on both `core::any::TaggedOption` and `core::any::tags` since `Request`s now need to be constructed in the `core::error` module. I considered moving `TaggedOption` into the `core::error` module but again I figured it's an implementation detail of `Request` and belongs closer to that.

At the time I am opening this PR, I have not yet looked into the following bit of feedback:

> We took a look at the generated code and found that LLVM is unable to optimize multiple .provide_* calls into a switch table because each call fetches the type id from Erased::type_id separately each time and the compiler doesn't know that these calls all return the same value. This should be fixed.

This is what I'll focus on next while waiting for feedback on the progress so far. I suspect that learning more about the type IDs will help me understand the need for `TaggedOption` a little better.
2023-08-14 18:18:03 +00:00
ltdk ef3305449b Implement Step for AsciiChar 2023-08-14 01:34:47 -04:00
wayne warren a646b39965 core/any: remove Provider trait
* remove `impl Provider for Error`
* rename `Demand` to `Request`
* update docstrings to focus on the conceptual API provided by `Request`
* move `core::any::{request_ref, request_value}` functions into `core::error`
* move `core::any::tag`, `core::any::Request`, an `core::any::TaggedOption` into `core::error`
* replace `provide_any` feature name w/ `error_generic_member_access`
* move `core::error::request_{ref,value} tests into core::tests::error module
* update unit and doc tests
2023-08-13 13:07:53 -06:00
Frank King 97c953f561 Add Iterator::map_windows
This is inherited from the old PR.

This method returns an iterator over mapped windows of the starting
iterator. Adding the more straight-forward `Iterator::windows` is not
easily possible right now as the items are stored in the iterator type,
meaning the `next` call would return references to `self`. This is not
allowed by the current `Iterator` trait design. This might change once
GATs have landed.

The idea has been brought up by @m-ou-se here:
https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Iterator.3A.3A.7Bpairwise.2C.20windows.7D/near/224587771

Co-authored-by: Lukas Kalbertodt <lukas.kalbertodt@gmail.com>
2023-08-11 07:26:51 +08:00
Jacob Pratt f1d4e48c9c
Fix implementation of `Duration::checked_div` 2023-07-30 04:00:02 -04:00
bors a5e2eca40e Auto merge of #112699 - bluebear94:mf/more-is-sorted-tests, r=cuviper
Add more comprehensive tests for is_sorted and friends

See #53485 and #55045.
2023-07-21 23:25:04 +00:00
KaDiWa c3462a0676
remove the unstable `core::sync::atomic::ATOMIC_*_INIT` constants 2023-07-18 09:45:52 +02:00
Mark Rousskov 67b0cfc761 Flip cfg's for bootstrap bump 2023-07-12 21:38:55 -04:00
Ralf Jung e1338cc254 enable test_join test in Miri 2023-07-03 14:05:55 +02:00
The 8472 6c87448b57 optimize Cstr/EscapeAscii display
old:
    ascii::bench_ascii_escape_display_mixed      17.97µs/iter +/- 204.00ns
    ascii::bench_ascii_escape_display_no_escape 545.00ns/iter   +/- 6.00ns
new:
    ascii::bench_ascii_escape_display_mixed      4.99µs/iter +/- 56.00ns
    ascii::bench_ascii_escape_display_no_escape 91.00ns/iter  +/- 1.00ns
2023-06-29 01:55:03 +02:00
bors ae8ffa663c Auto merge of #111850 - the8472:external-step-by, r=scottmcm
Specialize `StepBy<Range<{integer}>>`

OLD

    iter::bench_range_step_by_fold_u16      700.00ns/iter +/- 10.00ns
    iter::bench_range_step_by_fold_usize    519.00ns/iter  +/- 6.00ns
    iter::bench_range_step_by_loop_u32      555.00ns/iter  +/- 7.00ns
    iter::bench_range_step_by_sum_reducible  37.00ns/iter  +/- 0.00ns

NEW

    iter::bench_range_step_by_fold_u16       49.00ns/iter +/- 0.00ns
    iter::bench_range_step_by_fold_usize    194.00ns/iter +/- 1.00ns
    iter::bench_range_step_by_loop_u32       98.00ns/iter +/- 0.00ns
    iter::bench_range_step_by_sum_reducible   1.00ns/iter +/- 0.00ns

NEW + `-Ctarget-cpu=x86-64-v3`

    iter::bench_range_step_by_fold_u16      22.00ns/iter +/- 0.00ns
    iter::bench_range_step_by_fold_usize    80.00ns/iter +/- 1.00ns
    iter::bench_range_step_by_loop_u32      41.00ns/iter +/- 0.00ns
    iter::bench_range_step_by_sum_reducible  1.00ns/iter +/- 0.00ns

I have only optimized for walltime of those methods, I haven't tested whether it eliminates bounds checks when indexing into slices via things like `(0..slice.len()).step_by(16)`.
2023-06-26 00:28:30 +00:00
The 8472 070ce235f2 Specialize StepBy<Range<{integer}>>
For ranges < usize we determine the number of items
StepBy would yield and then store that in the range.end
instead of the actual end. This significantly
simplifies calculation of the loop induction variable
especially in cases where StepBy::step (an usize)
could overflow the Range's item type
2023-06-23 00:17:34 +02:00
Benjamin Lee 50246b0587
Implement slice::split_once and slice::rsplit_once
Feature gate is slice_split_once and tracking issue is #112811.
2023-06-19 17:54:52 -07:00
Michael Goulet e24fe97bd9
Rollup merge of #112606 - clarfonthey:ip-display, r=thomcc
Alter `Display` for `Ipv6Addr` for IPv4-compatible addresses

ACP: rust-lang/libs-team#239
2023-06-19 17:53:35 -07:00
+merlan #flirora c2e4e981b3 Add more comprehensive tests for is_sorted and friends
See #53485 and #55045.
2023-06-16 03:04:34 -04:00
许杰友 Jieyou Xu (Joe) 72b3b58efc
Extend `unused_must_use` to cover block exprs 2023-06-15 17:59:13 +08:00
ltdk 2dce58d0f6 Fix `SocketAddrV6: Display` tests 2023-06-14 15:21:15 -04:00
ltdk 2f2c3f55a9 Fix `Ipv6Addr: Display` tests 2023-06-14 14:25:25 -04:00
bors 371994e0d8 Auto merge of #112314 - ferrocene:pa-core-alloc-abort, r=bjorn3
Ignore `core`, `alloc` and `test` tests that require unwinding on `-C panic=abort`

Some of the tests for `core` and `alloc` require unwinding through their use of `catch_unwind`. These tests fail when testing using `-C panic=abort` (in my case through a target without unwinding support, and `-Z panic-abort-tests`), while they should be ignored as they don't indicate a failure.

This PR marks all of these tests with this attribute:

```rust
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
```

I'm not aware of a way to test this on rust-lang/rust's CI, as we don't test any target with `-C panic=abort`, but I tested this locally on a Ferrocene target and it does indeed make the test suite pass.
2023-06-13 19:03:27 +00:00
Pietro Albini 44556eed36
ignore core, alloc and test tests that require unwinding on panic=abort 2023-06-13 15:53:24 +02:00
Urgau d9d1c76ded Allow undropped_manually_drops for some tests 2023-06-08 11:41:34 +02:00
Mark Rousskov 42e757192d Bump to latest beta compiler 2023-05-30 08:00:10 -04:00
Lukas Markeffsky 7cdb23b98a don't skip inference for type in `offset_of!` 2023-05-20 15:20:27 +02:00
est31 30c0e4e72b Add more tests for the offset_of!() macro
* ensuring that offset_of!(Self, ...) works iff inside an impl block
* ensuring that the output type is usize and doesn't coerce. this can be
  changed in the future, but if it is done, it should be a conscious descision
* improving the privacy checking test
* ensuring that generics don't let you escape the unsized check
2023-05-18 13:16:17 +02:00
bors 18bfe5d8a9 Auto merge of #92048 - Urgau:num-midpoint, r=scottmcm
Add midpoint function for all integers and floating numbers

This pull-request adds the `midpoint` function to `{u,i}{8,16,32,64,128,size}`, `NonZeroU{8,16,32,64,size}` and `f{32,64}`.

This new function is analog to the [C++ midpoint](https://en.cppreference.com/w/cpp/numeric/midpoint) function, and basically compute `(a + b) / 2` with a rounding towards ~~`a`~~ negative infinity in the case of integers. Or simply said: `midpoint(a, b)` is `(a + b) >> 1` as if it were performed in a sufficiently-large signed integral type.

Note that unlike the C++ function this pull-request does not implement this function on pointers (`*const T` or `*mut T`). This could be implemented in a future pull-request if desire.

### Implementation

For `f32` and `f64` the implementation in based on the `libcxx` [one](18ab892ff7/libcxx/include/__numeric/midpoint.h (L65-L77)). I originally tried many different approach but all of them failed or lead me with a poor version of the `libcxx`. Note that `libstdc++` has a very similar one; Microsoft STL implementation is also basically the same as `libcxx`. It unfortunately doesn't seems like a better way exist.

For unsigned integers I created the macro `midpoint_impl!`, this macro has two branches:
 - The first one take `$SelfT` and is used when there is no unsigned integer with at least the double of bits. The code simply use this formula `a + (b - a) / 2` with the arguments in the correct order and signs to have the good rounding.
 - The second branch is used when a `$WideT` (at least double of bits as `$SelfT`) is provided, using a wider number means that no overflow can occur, this greatly improve the codegen (no branch and less instructions).

For signed integers the code basically forwards the signed numbers to the unsigned version of midpoint by mapping the signed numbers to their unsigned numbers (`ex: i8 [-128; 127] to [0; 255]`) and vice versa.
I originally created a version that worked directly on the signed numbers but the code was "ugly" and not understandable. Despite this mapping "overhead" the codegen is better than my most optimized version on signed integers.

~~Note that in the case of unsigned numbers I tried to be smart and used `#[cfg(target_pointer_width = "64")]` to determine if using the wide version was better or not by looking at the assembly on godbolt. This was applied to `u32`, `u64` and `usize` and doesn't change the behavior only the assembly code generated.~~
2023-05-14 19:33:02 +00:00
bors 81c2459af6 Stabilize const_ptr_read 2023-05-05 20:36:21 +02:00
Deadbeef e92806704b fix rustdoc and core test 2023-04-29 08:50:56 +00:00
Matthias Krüger 9babe98562
Rollup merge of #110419 - jsoref:spelling-library, r=jyn514
Spelling library

Split per https://github.com/rust-lang/rust/pull/110392

I can squash once people are happy w/ the changes. It's really uncommon for large sets of changes to be perfectly acceptable w/o at least some changes.

I probably won't have time to respond until tomorrow or the next day
2023-04-26 18:51:41 +02:00
Loïc BRANSTETT bf73234d92 Implement midpoint for all floating point f32 and f64 2023-04-26 10:18:53 +02:00
Loïc BRANSTETT 1a72d7c7c4 Implement midpoint for all signed and unsigned integers 2023-04-26 10:18:53 +02:00
Josh Soref 9cb9346005 Spelling library/
* advance
* aligned
* borrowed
* calculate
* debugable
* debuggable
* declarations
* desugaring
* documentation
* enclave
* ignorable
* initialized
* iterator
* kaboom
* monomorphization
* nonexistent
* optimizer
* panicking
* process
* reentrant
* rustonomicon
* the
* uninitialized

Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-04-26 02:10:22 -04:00
DrMeepster a642563d49 major test improvements 2023-04-21 02:45:48 -07:00
DrMeepster 2bcb018253 fmt 2023-04-21 02:14:03 -07:00
DrMeepster b92c2f792c fix incorrect param env in dead code lint 2023-04-21 02:14:03 -07:00
DrMeepster b95852b93c test improvements 2023-04-21 02:14:03 -07:00
DrMeepster 511e457c4b offset_of 2023-04-21 02:14:02 -07:00
John Millikin 4e2797dd76 Implement `Neg` for signed non-zero integers.
Negating a non-zero integer currently requires unpacking to a
primitive and re-wrapping. Since negation of non-zero signed
integers always produces a non-zero result, it is safe to
implement `Neg` for `NonZeroI{N}`.

The new `impl` is marked as stable because trait implementations
for two stable types can't be marked unstable.
2023-04-20 14:27:29 +09:00
bors 3a5c8e91f0 Auto merge of #110393 - fee1-dead-contrib:rm-const-traits, r=oli-obk
Rm const traits in libcore

See [zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/.60const.20Trait.60.20removal.20or.20rework)

* [x] Bless ui tests
* [ ] Re constify some unstable functions with workarounds if they are needed
2023-04-19 13:03:40 +00:00
Deadbeef 4c6ddc036b fix library and rustdoc tests 2023-04-16 11:38:52 +00:00
Deadbeef 76dbe29104 rm const traits in libcore 2023-04-16 06:49:27 +00:00
est31 77821b2eb9 Remove unused unused_macros
The macro is always used
2023-04-16 08:35:39 +02:00
Tobias Decking 65c9c79d3f
remove obsolete test 2023-04-10 21:57:45 +02:00
Tobias Decking 0f96c71792 Improve the floating point parser in `dec2flt`.
* Remove all remaining traces of unsafe.
* Put `parse_8digits` inside a loop.
* Rework parsing of inf/NaN values.
2023-04-10 00:47:08 +02:00
Deadbeef 04a5d61161 Revert "Mark DoubleEndedIterator as #[const_trait] using rustc_do_not_const_check, implement const Iterator and DoubleEndedIterator for Range."
This reverts commit 8a9d6bf4fd.
2023-04-08 08:18:29 +00:00
Trevor Gross dc4ba57566 Stabilize a portion of 'once_cell'
Move items not part of this stabilization to 'lazy_cell' or 'once_cell_try'
2023-03-29 18:04:44 -04:00
bors cdbbce0a9e Auto merge of #108095 - soc:drop-contains, r=Amanieu
Drop unstable `Option::contains`, `Result::contains`, `Result::contains_err`

This is a proposal to drop the three functions `Option::contains`, `Result::contains` and `Result::contains_err`.

The discovery of `Option::is_some_with`/`Result::is_ok_with`/`Result::is_err_with` in https://github.com/rust-lang/rust/pull/93051 obviates the need for these methods (non-stabilization tracked in https://github.com/rust-lang/rust/issues/62358).

An additional benefit of change is that it avoids spurious error messages in IDEs, when `contains` is supplied by a third-party library:
![option-result-unstable](https://user-images.githubusercontent.com/42493/219127961-13cb559e-6ee8-4449-8dc9-d28d07270ad5.png)
2023-03-28 23:20:30 +00:00
The 8472 e29b27b4a4 replace advance_by returning usize with Result<(), NonZeroUsize> 2023-03-27 16:03:14 +02:00
The 8472 69db91b8b2 Change advance(_back)_by to return `usize` instead of `Result<(), usize>`
A successful advance is now signalled by returning `0` and other values now represent the remaining number
of steps that couldn't be advanced as opposed to the amount of steps that have been advanced during a partial advance_by.

This simplifies adapters a bit, replacing some `match`/`if` with arithmetic. Whether this is beneficial overall depends
on whether `advance_by` is mostly used as a building-block for other iterator methods and adapters or whether
we also see uses by users where `Result` might be more useful.
2023-03-27 14:11:49 +02:00