491 Commits

Author SHA1 Message Date
Jacob Pratt 53b9b9a108 Rollup merge of #155564 - tshakalekholoane:tshaka/const_default/cstr, r=jhpratt
Implement const Default for &CStr

Implements `const Default` for `&CStr`.

Tracking issue: rust-lang/rust#143894.
2026-04-21 02:20:27 -04:00
Tshaka Lekholoane 339a2f0ba0 Implement const Default for &CStr 2026-04-20 17:40:30 +02:00
Zac Harrold fe2b39f064 Move std::io::ErrorKind to core::io
Move `std::io::ErrorKind` to `core::io`
* Update `rustdoc-html` tests for the new path
* Add `core_io` feature to control stability. This replaces the use of `core_io_borrowed_buf` on the `core::io` module itself.
* Re-export `core::io::ErrorKind` in `std::io::error`
2026-04-20 18:38:25 +10:00
Jonathan Brouwer b07688dc2e Rollup merge of #153873 - folkertdev:deprecate-char-max, r=Mark-Simulacrum
deprecate `std::char` constants and functions

similar to how constants in those modules for numeric types have been deprecated. The `std::char` module contains:

Three stable constants that this PR deprecates. These already link to their associated constant equivalents.

- `MAX`
- `REPLACEMENT_CHARACTER`
- `UNICODE_VERSION`

two unstable constants that this PR removes. The constants are already stablized as associated constants on `char`.

- `MAX_LEN_UTF8`
- `MAX_LEN_UTF16`

Four stable functions that this PR deprecates. These already link to their method equivalents.

- `fn decode_utf16`
- `fn from_digit`
- `fn from_u32`
- `fn from_u32_unchecked⚠`

discussion at [#t-libs > should `std::char::{MIN, MAX}` be deprecated?](https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/should.20.60std.3A.3Achar.3A.3A.7BMIN.2C.20MAX.7D.60.20be.20deprecated.3F/with/579444750).

r? libs-api
2026-04-19 16:04:32 +02:00
Jonathan Brouwer ffcda118ca Rollup merge of #155431 - Voultapher:add-tmp-scope-to-assert-matches, r=Amanieu
Add temporary scope to assert_matches

Addresses https://github.com/rust-lang/rust/issues/154406 in part. `assert_eq` will be done in a separate PR.
2026-04-19 16:04:31 +02:00
Jonathan Brouwer 77cbf96954 Rollup merge of #150230 - bend-n:trusted_len_spec_for_iter_next_chunk, r=Mark-Simulacrum
spec next chunk for trustedlen

relevant to rust-lang/rust#98326
2026-04-18 19:23:12 +02:00
Lukas Bergdoll 3a0c0e9cb7 Apply review feedback 2026-04-18 15:12:33 +02:00
Jacob Pratt 221dab89b4 Rollup merge of #139690 - cuviper:iter_repeat_n_default, r=tgross35
`impl Default for RepeatN`

This creates an empty iterator, like `repeat_n(value, 0)` but without
needing any such value at hand. There's precedent in many other
iterators that the `Default` is empty, like `slice::Iter`.

I found myself wanting this for rayon's `RepeatN` as it lowers to a
sequential iterator [here][1]. Since rayon is also optimizing to avoid
extra clones, it may end up with parallel splits that have count 0 and
no item value. Calling `std::iter::repeat_n(x, 0)` just drops that
value, but there's no way to construct the same result without a value
yet. This would be straightforward with an empty `Default`.

[1]: https://github.com/rayon-rs/rayon/blob/ae07384e3e0b238cea89f0c14891f351c65a5cee/src/iter/repeat.rs#L201-L202

r? libs-api (insta-stable)
2026-04-18 00:05:16 -04:00
Jonathan Brouwer 932d807e7e Rollup merge of #153178 - sorairolake:feature/try-from-int-error-kind, r=tgross35
Add `TryFromIntError::kind` method and `IntErrorKind::NotAPowerOfTwo` variant

- ACP: rust-lang/libs-team#746
- Tracking issue: rust-lang/rust#153978

This pull request adds `kind` method to [`TryFromIntError`](https://doc.rust-lang.org/core/num/struct.TryFromIntError.html), which outputs the detailed cause of converting an integer failing.

This is primarily intended for use in cases where there are multiple causes for failure, such as converting from a large signed integer type to a small signed integer type.

At the moment, this method returns [`&IntErrorKind`](https://doc.rust-lang.org/core/num/enum.IntErrorKind.html). This type implements the `Copy` trait and could return `IntErrorKind`, but returns a reference to align with the behavior of [`ParseIntError::kind`](https://doc.rust-lang.org/core/num/struct.ParseIntError.html#method.kind). If it is not necessary to align the behavior of `TryFromIntError::kind` with `ParseIntError::kind`, I'll change this method to return `IntErrorKind`.

Before this pull request, `IntErrorKind` was only used by [`ParseIntError`](https://doc.rust-lang.org/core/num/struct.ParseIntError.html), but I changed it to be used by `TryFromIntError` as well, so I updated `IntErrorKind`'s documentation.

[`impl TryFrom<usize> for Alignment`](https://doc.rust-lang.org/std/ptr/struct.Alignment.html#impl-TryFrom%3Cusize%3E-for-Alignment) returns `TryFromIntError` as an error if the given value is not a power of two. However, `IntErrorKind` does not have a variant that represents this. So I added the variant `NotAPowerOfTwo` to represent this. For this variant to stabilize, both `try_from_int_error_kind` and `ptr_alignment_type` features must be stabilized.
2026-04-17 13:28:58 +02:00
Lukas Bergdoll e0ef87f880 Add temporary scope to assert_matches
Addresses https://github.com/rust-lang/rust/issues/154406 in part.
assert_eq will be done in a separate PR.
2026-04-17 13:04:29 +02:00
Shun Sakai c35ed1ac32 feat: Add TryFromIntError::kind and IntErrorKind::NotAPowerOfTwo 2026-04-17 14:04:56 +09:00
Josh Stone a66b7810c3 impl Default for RepeatN
This creates an empty iterator, like `repeat_n(value, 0)` but without
needing any such value at hand. There's precedent in many other
iterators that the `Default` is empty, like `slice::Iter`.

I found myself wanting this for rayon's `RepeatN` as it lowers to a
sequential iterator [here][1]. Since rayon is also optimizing to avoid
extra clones, it may end up with parallel splits that have count 0 and
no item value. Calling `std::iter::repeat_n(x, 0)` just drops that
value, but there's no way to construct the same result without a value
yet. This would be straightforward with an empty `Default`.

[1]: https://github.com/rayon-rs/rayon/blob/ae07384e3e0b238cea89f0c14891f351c65a5cee/src/iter/repeat.rs#L201-L202
2026-04-16 16:49:11 -07:00
Jacob Pratt 1c9abe206b Rollup merge of #154699 - Jules-Bertholet:lt-for-cased, r=scottmcm
`core::unicode`: Replace `Cased` table with `Lt`

Shaves off 368 bytes from the total size of all Unicode data tables.

@rustbot label A-unicode
2026-04-16 01:54:06 -04:00
Jonathan Brouwer 0af1a15c9a Rollup merge of #155147 - sorairolake:stabilize-int-lowest-highest-one, r=jhpratt
Stabilize feature `int_lowest_highest_one`

Tracking issue: rust-lang/rust#145203
FCP is finished in https://github.com/rust-lang/rust/issues/145203#issuecomment-4224883617

Closes rust-lang/rust#145203

@rustbot modify labels: +T-libs-api
2026-04-13 20:20:06 +02:00
Jonathan Brouwer 0bfc5efe04 Rollup merge of #155131 - sorairolake:stabilize-uint-bit-width, r=jhpratt
Stabilize feature `uint_bit_width`

Tracking issue: rust-lang/rust#142326
FCP is finished in https://github.com/rust-lang/rust/issues/142326#issuecomment-4224883142

Closes rust-lang/rust#142326

@rustbot modify labels: +T-libs-api
2026-04-13 20:20:05 +02:00
bendn 63f813ab2d spec next chunk for trustedlen 2026-04-13 15:08:04 +07:00
Shun Sakai 63b5ab2994 Stabilize feature int_lowest_highest_one 2026-04-11 18:38:21 +09:00
Shun Sakai fe309a0bed Stabilize feature uint_bit_width 2026-04-11 07:46:34 +09:00
okaneco a69f989fe1 Stabilize feature isolate_most_least_significant_one 2026-04-10 17:59:02 -04:00
Ralf Jung 923311c40b min/max_by tests: also check result 2026-04-08 17:59:14 +02:00
Jonathan Brouwer 6ee4118299 Rollup merge of #154761 - Vastargazing:add-regression-tests-cmp-argument-order, r=jhpratt
coretests: add argument order regression tests for min_by/max_by/minmax_by

PR rust-lang/rust#136307 introduced a regression in min_by, max_by, and minmax_by:
the compare closure received arguments as (v2, v1) instead of (v1, v2),
contrary to the documented contract.
Although this was fixed in rust-lang/rust#139357, no regression tests were added.
This PR adds regression tests for all three functions, verifying that compare
always receives arguments in the documented order (v1, v2).
As a bonus: first coretests coverage for minmax_by.
2026-04-07 17:26:31 +02:00
bors c92036b45b Auto merge of #154832 - JonathanBrouwer:rollup-xJmqF28, r=JonathanBrouwer
Rollup of 2 pull requests

Successful merges:

 - rust-lang/rust#150129 (`BorrowedCursor`: make `init` a boolean)
 - rust-lang/rust#154830 (miri subtree update)
2026-04-05 00:08:46 +00:00
Jonathan Brouwer b7c319cfc4 Rollup merge of #150129 - a1phyr:improve_buf_api, r=joshtriplett
`BorrowedCursor`: make `init` a boolean

This PR changes uninitialized bytes tracking in `BorrowedBuf` from being byte-wise to being buffer-wise.

I've put all the API around `init` a new unstable feature `borrowed_buf_init`, to split the part that needs it and the part that doesn't. It will avoids accidental stabilization of this part.

I'm not really convinced of the rename of `advance_unchecked` to `advance`, but I did it anyway. The old `advance` was kept as `advance_checked`.

Alternative of rust-lang/rust#148937

Cc rust-lang/rust#78485 rust-lang/rust#117693
Cc @joshtriplett

r? @Amanieu
2026-04-05 00:18:45 +02:00
bors 4e836866b5 Auto merge of #154824 - JonathanBrouwer:rollup-neQUhVI, r=JonathanBrouwer
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#147552 ([Debugger Visualizers] Optimize lookup behavior)
 - rust-lang/rust#154052 (float: Fix panic at max exponential precision)
 - rust-lang/rust#154706 (fix compilation of time/hermit.rs)
 - rust-lang/rust#154707 (Make `substr_range` and `subslice_range` return the new `Range` type)
 - rust-lang/rust#154767 (triagebot: roll library reviewers for `{coretests,alloctests}`)
 - rust-lang/rust#154797 (bootstrap: Include shorthand aliases in x completions)
2026-04-04 21:00:26 +00:00
Jonathan Brouwer f523f841db Rollup merge of #154052 - cdown:cdown/2026-03-19/precision, r=Mark-Simulacrum
float: Fix panic at max exponential precision

Rust's formatting machinery allows precision values of up to u16::MAX. Exponential formatting works out the number of significant digits to use by adding one (for the integral digit before the decimal point).

This previously used usize precision, so the maximum validated precision did not overflow, but in commit fb9ce02976 ("Limit formatting width and precision to 16 bits.") the precision type was narrowed to u16 without widening that addition first.

As a result an exponential precision value of 65535 is no longer handled correctly, because the digit count wraps to 0, and thus "{:.65535e}" panics in flt2dec::to_exact_exp_str with "assertion failed: ndigits > 0". Other formats (and the parser) accept values up to u16::MAX.

A naive fix would be to widen that addition back to usize, but that still does not properly address 16-bit targets, where usize is only guaranteed to be able to represent values up to u16::MAX. The real issue is that this internal API is expressed in the wrong units for the formatter.

Fix this by changing exact exponential formatting to take fractional digits internally as well, and compute the temporary significant digit bound only when sizing the scratch buffer. To support that let's also make formatted length accounting saturate so that extremely large rendered outputs do not reintroduce overflows in padding logic.

This preserves the existing intent and keeps FormattingOptions compact while making formatting work consistently again.
2026-04-04 20:19:58 +02:00
bors e0e95a7187 Auto merge of #154815 - JonathanBrouwer:rollup-sdqRx2J, r=JonathanBrouwer
Rollup of 8 pull requests

Successful merges:

 - rust-lang/rust#149868 (rustc: Stop passing `--allow-undefined` on wasm targets)
 - rust-lang/rust#153555 (Clarified docs in std::sync::RwLock + added test to ensure that max reader count is respected)
 - rust-lang/rust#152851 (Fix SGX delayed host lookup via ToSocketAddr)
 - rust-lang/rust#154051 (use libm for acosh and asinh)
 - rust-lang/rust#154581 (More informative `Debug for vec::ExtractIf`)
 - rust-lang/rust#154461 (Edit the docs new_in() and with_capacity_in())
 - rust-lang/rust#154526 (Panic/return false on overflow in no_threads read/try_read impl)
 - rust-lang/rust#154798 (rustdoc-search: match path components on words)
2026-04-04 17:46:11 +00:00
Jonathan Brouwer 69751ec861 Rollup merge of #154051 - malezjaa:approximations-acosh-and-asinh, r=tgross35
use libm for acosh and asinh

Fixes rust-lang/rust#153878

Uses libm for `acosh` and `asinh`
2026-04-04 17:19:10 +02:00
Chris Down 2ae6c6176e float: Fix panic at max exponential precision
Rust's formatting machinery allows precision values of up to u16::MAX.
Exponential formatting works out the number of significant digits to use
by adding one (for the integral digit before the decimal point).

This previously used usize precision, so the maximum validated precision
did not overflow, but in commit fb9ce02976 ("Limit formatting width
and precision to 16 bits.") the precision type was narrowed to u16
without widening that addition first.

As a result an exponential precision value of 65535 is no longer handled
correctly, because the digit count wraps to 0, and thus "{:.65535e}"
panics in flt2dec::to_exact_exp_str with "assertion failed: ndigits >
0". Other formats (and the parser) accept values up to u16::MAX.

A naive fix would be to widen that addition back to usize, but that
still does not properly address 16-bit targets, where usize is only
guaranteed to be able to represent values up to u16::MAX. The real issue
is that this internal API is expressed in the wrong units for the
formatter.

Fix this by changing exact exponential formatting to take fractional
digits internally as well, and compute the temporary significant digit
bound only when sizing the scratch buffer. To support that let's also
make formatted length accounting saturate so that extremely large
rendered outputs do not reintroduce overflows in padding logic.

This preserves the existing intent and keeps FormattingOptions compact
while making formatting work consistently again.
2026-04-04 21:44:05 +09:00
Vastargazing 51c4299433 coretests: add argument order regression tests for min_by/max_by/minmax_by
A recent regression swapped the argument order passed to the compare
closure in min_by, max_by and minmax_by (compare(&v2, &v1) instead of
compare(&v1, &v2)). This was fixed, but no regression test was added.

Add tests that record the arguments the compare closure receives and
assert they match (v1, v2) — the documented contract.
2026-04-04 13:34:45 +03:00
malezjaa a1feab1638 use libm for acosh and asinh 2026-04-04 09:28:39 +02:00
Jalil David Salamé Messina d6b280675e feat(core): impl Step for NonZero<u*>
Implement Step for NonZero unsigned integers as discussed in
[libs-team#130][1].

[1]: https://github.com/rust-lang/libs-team/issues/130

`step_nonzero_impls` was adapted from `step_integer_impls` and the tests
were adapted from the step tests.

Signed-off-by: Jalil David Salamé Messina <jalil.salame@gmail.com>
2026-04-03 13:25:13 -03:00
Jules Bertholet e9b36bd374 core::unicode: Replace Cased table with Lt
Shaves off 368 bytes from the total size of all Unicode data tables.
2026-04-02 10:30:24 -04:00
Peter Jaszkowiak 620e92f016 stabilize new Range type and iterator
stabilizes `core::range::Range`
stabilizes `core::range::RangeIter`
stabilizes `std::range` which was missed in prior PRs

Updates docs to reflect stabilization (removed "experimental")

`RangeIter::remainder` is excluded from stabilization
2026-03-30 22:17:27 -06:00
Jonathan Brouwer df5f98513b Rollup merge of #154190 - Jules-Bertholet:nonfused, r=scottmcm
Don't fuse in `MapWindows`

cc https://github.com/rust-lang/rust/issues/87155

Fusing makes the iterator larger, slower, more complicated, and less useful. Users who need fusing behavior can always use `.fuse()`, but there is no way to get non-fusing behavior from the fused version.

@rustbot label A-iterators
2026-03-29 08:59:36 +02:00
Theemathas Chirananthavat 1e4c1d6f75 Make PinCoerceUnsized require Deref
Also, delete impls on non-Deref types.

Pin doesn't do anything useful for non-Deref types, so PinCoerceUnsized
on such types makes no sense.

This is a breaking change, since stable code can observe the deleted
`PinCoerceUnsized` impls by uselessly coercing between such types
inside a `Pin`.

There is still some strange behavior, such as `Pin<&mut i32>` being
able to coerce to `Pin<&dyn Send>`, but not being able to coerce to
`Pin<&i32>`. However, I don't think it's possible to fix this.

Fixes https://github.com/rust-lang/rust/issues/145081
2026-03-25 11:40:27 +07:00
Jonathan Brouwer 1e3d3bdb24 Rollup merge of #153874 - bend-n:constify-const-fn-destruct, r=oli-obk
constify const Fn*: Destruct

makes closures const destruct where their upvars are. i think this makes sense
and is how this should be implemented.

r? @oli-obk
2026-03-24 18:14:15 +01:00
Jacob Pratt 355b4f05ce Rollup merge of #154132 - bjorn3:fix_missing_feature_gate, r=Mark-Simulacrum
Add missing num_internals feature gate to coretests/benches

This will allow getting rid of the patch at https://github.com/rust-lang/rustc_codegen_cranelift/blob/main/patches/0030-sysroot_tests-Add-missing-feature-gate.patch
2026-03-23 23:42:50 -04:00
Jonathan Brouwer 3cad6d130a Rollup merge of #122668 - Jules-Bertholet:titlecase, r=Mark-Simulacrum
Add APIs for dealing with titlecase

ACP: https://github.com/rust-lang/libs-team/issues/354
Tracking issue: https://github.com/rust-lang/rust/issues/153892

r? libs-api

@rustbot label T-libs -T-libs-api A-unicode

~~The last commit has some insta-stable `PartialEq` impls, therefore: @rustbot label -needs-fcp
Alternatively, I could split those out into a follow-up PR.~~ (Edit: will do in follow-up)
2026-03-23 20:18:32 +01:00
Jules Bertholet e1e903c7b7 Exclude slow tests from miri 2026-03-23 08:17:14 -04:00
Jonathan Brouwer 699e1b395e Rollup merge of #153931 - cyrgani:old-consts, r=Mark-Simulacrum
remove usages of to-be-deprecated numeric constants

Split out from rust-lang/rust#146882.
2026-03-23 12:14:55 +01:00
Jonathan Brouwer cd3e866c7a Rollup merge of #153880 - asder8215:intersperse_nonfused, r=Mark-Simulacrum
Lifted intersperse and intersperse_with Fused transformation and updated documentation + tests

This PR once again builds on top of rust-lang/rust#152855. From the discussion in rust-lang/rust#152855, libs team came to the conclusion that `intersperse`/`intersperse_with` shouldn't transform the given iterator to a fused iterator always and a separator should be emitted between `Some(_)` items for non fused iterators (particularly just right before the subsequent `Some(_)`).

On top of the change Zakarumych added in the PR, I lifted the `FusedIterator` trait and transformation of the inner `iter` for `Intersperse`/`IntersperseWith`, so that we can display this behavior. I've adjusted the documentation and tests accordingly to reflect this change as well.

r? @jhpratt
2026-03-23 12:14:54 +01:00
Jules Bertholet 0a49163be7 Don't fuse in MapWindows 2026-03-21 18:16:51 -04:00
Jules Bertholet 8d072616a5 Add APIs for dealing with titlecase
- `char::is_cased`
- `char::is_titlecase`
- `char::case`
- `char::to_titlecase`
2026-03-21 14:30:38 -04:00
Jonathan Brouwer c82d8db4a8 Rollup merge of #154103 - tgross35:float-test-mod, r=folkertdev
coretests: Expand ieee754 parsing and printing tests to f16

Use `float_test!` to cover all types, with a note about f128 missing the traits. Also includes some minor reorganization.
2026-03-20 13:24:21 +01:00
bjorn3 5ef93c12b6 Add missing num_internals feature gate to coretests/benches 2026-03-20 12:21:24 +01:00
Trevor Gross 16f89853f7 coretests: Expand ieee754 parsing and printing tests to f16
Use `float_test!` to cover all types, with a note about f128 missing the
traits.
2026-03-19 17:04:17 +00:00
Trevor Gross 4211234269 coretests: Give ieee754.rs a more accurate name 2026-03-19 16:21:40 +00:00
Trevor Gross f9c0284206 coretests: Move the float module under num
This is just a single file, so move it under `num` which already has
some float-related tests. This also closer mirrors source in `core`.
2026-03-19 15:42:55 +00:00
Jonathan Brouwer 7c6fc44b7c Rollup merge of #151905 - tgross35:dec2flt-traits, r=Mark-Simulacrum
Split the `dec2flt::RawFloat` trait for easier reuse

`RawFloat` is an internal trait with quite a few useful float properties. It currently resides in the `dec2flt` module but is also used in parsing, and would be nice to reuse other places. Unfortunately it cannot be implemented on `f128` because of limitations with how the parsing API is implemented (mantissa must fit into a u64).

To make the trait easier to work with, split it into the following:

* `Float`: Anything that is reasonably applicable to all floating point types.
* `FloatExt`: Items that should be part of `Float` but don't work for all float types. This will eventually be merged back into `Float` once it can be implemented on f128.
* `Lemire`: Items that are specific to the Lemire dec2flt algorithm.

These traits are then moved to places that make sense.

Builds on top of https://github.com/rust-lang/rust/pull/151900
2026-03-19 13:42:32 +01:00
bendn b90abe64c1 constify const Fn*: Destruct 2026-03-17 23:47:42 +07:00