Commit Graph

8223 Commits

Author SHA1 Message Date
bjorn3
fcf78bbd75 Update comment 2025-01-26 10:26:37 +00:00
bjorn3
b6a3841942 Put all coretests in a separate crate 2025-01-26 10:26:36 +00:00
Jacob Pratt
359c5047ab
Rollup merge of #136019 - scottmcm:alias-unchecked-div, r=Mark-Simulacrum
Add an `unchecked_div` alias to the `Div<NonZero<_>>` impls

Inspired by https://github.com/rust-lang/libs-team/issues/526, if people are looking for `unchecked_div`, point them to `u32: Div<NonZero<u32>>` and friends which do no runtime checks -- and are safe! -- rather than today's behaviour of [the intrinsic being the top result](https://doc.rust-lang.org/std/?search=unchecked_div).

![image](https://github.com/user-attachments/assets/cf2a3c06-4876-49c1-8e33-64cd431c772a)
2025-01-26 01:51:18 -05:00
Jacob Pratt
b3a5d0a5f4
Implement phantom variance markers 2025-01-26 04:57:11 +00:00
Jacob Pratt
b58221ec9d
Rollup merge of #135948 - bjorn3:update_emscripten_std_tests, r=Mark-Simulacrum
Update emscripten std tests

This disables a bunch of emscripten tests that test things emscripten doesn't support and re-enables a whole bunch of tests which now work just fine on emscripten.

Tested with `EMCC_CFLAGS="-s MAXIMUM_MEMORY=2GB" ./x.py test library/ --target wasm32-unknown-emscripten`.
2025-01-25 23:27:00 -05:00
Matthias Krüger
65fb6286e0
Rollup merge of #136039 - nvanbenschoten:pin-typo, r=Amanieu
docs: fix typo in std::pin overview

Unimportant fix in `std::pin` documentation.
2025-01-25 23:15:25 +01:00
Matthias Krüger
f14993b454
Rollup merge of #136005 - BLANKatGITHUB:library, r=RalfJung
ports last few library files to new intrinsic style

This pr ports the last 2 library files to new intrinsic style this pr is part of issue #132735
2025-01-25 23:15:24 +01:00
Matthias Krüger
5c821ae4e8
Rollup merge of #135977 - nyurik:fix-fmt-options, r=joboet
Fix `FormattingOptions` instantiation with `Default`

The `fill` value by default should be set to `' '` (space), but the current implementation uses `#[derive(Default)]` which sets it to `\0`.

Note that `FormattingOptions` is being released as part of 1.85 (unstable) - so this might warrant a backport to that branch.

Tracking issue: https://github.com/rust-lang/rust/issues/118117

Follow up from https://github.com/rust-lang/rust/pull/118159

CC: ``@EliasHolzmann`` ``@programmerjake``

r? ``@m-ou-se``
2025-01-25 08:03:34 +01:00
Nathan VanBenschoten
83c09ff3bd docs: fix typo in std::pin overview 2025-01-24 23:26:02 -07:00
Matthias Krüger
884ec6b4ab
Rollup merge of #135938 - carlsverre:master, r=joboet
Add memory layout documentation to generic NonZero<T>

The documentation I've added is based on the same Layout documentation that appears on the other `NonZero*` types. For example see [the Layout docs on `NonZeroI8`](https://doc.rust-lang.org/std/num/type.NonZeroI8.html#layout-1).
2025-01-24 23:25:44 +01:00
Scott McMurray
2d11559f56 Add an unchecked_div alias to the Div<NonZero<_>> impls 2025-01-24 09:51:59 -08:00
Carl Sverre
4a8de9ac41
Update library/core/src/num/nonzero.rs
Tweak language

Co-authored-by: Jonas Böttiger <jonasboettiger@icloud.com>
2025-01-24 09:15:19 -08:00
aaishwarymishra@gmail.com
72e514981f ports last few library files to new intrinsic style 2025-01-24 21:50:56 +05:30
bjorn3
88ff147c56 Remove a bunch of emscripten test ignores
They are either outdated as emscripten now supports i128 or they are
subsumed by #[cfg_attr(not(panic = "unwind"), ignore]
2025-01-24 09:25:34 +00:00
Matthias Krüger
a3fb2a0572
Rollup merge of #135489 - RalfJung:TryFromSliceError, r=tgross35
remove pointless allowed_through_unstable_modules on TryFromSliceError

This got added in https://github.com/rust-lang/rust/pull/132482 but the PR does not explain why. `@lukas-code` do you still remember? Also Cc `@Noratrieb` as reviewer of that PR.

If I understand the issue description correctly, all paths under which this type is exported are stable now: `core::array::TryFromSliceError` and `std::array::TryFromSliceError`. If that is the case, we shouldn't have the attribute; it's a terrible hack that should only be used when needed to maintain backward compatibility. Getting some historic information right is IMO *not* sufficient justification to risk accidentally exposing this type via more unstable paths today or in the future.
2025-01-24 08:08:06 +01:00
Yuri Astrakhan
c9ae0bbffb Fix FormattingOptions instantiation with Default
The `fill` value by default should be set to `' '` (space), but the current implementation uses `#[derive(Default)]` which sets it to `\0`
2025-01-24 01:58:33 -05:00
Matthias Krüger
08d5b2303a
Rollup merge of #135073 - joshtriplett:bstr, r=BurntSushi
Implement `ByteStr` and `ByteString` types

Approved ACP: https://github.com/rust-lang/libs-team/issues/502
Tracking issue: https://github.com/rust-lang/rust/issues/134915

These types represent human-readable strings that are conventionally,
but not always, UTF-8. The `Debug` impl prints non-UTF-8 bytes using
escape sequences, and the `Display` impl uses the Unicode replacement
character.

This is a minimal implementation of these types and associated trait
impls. It does not add any helper methods to other types such as `[u8]`
or `Vec<u8>`.

I've omitted a few implementations of `AsRef`, `AsMut`, and `Borrow`,
when those would be the second implementation for a type (counting the
`T` impl), to avoid potential inference failures. We can attempt to add
more impls later in standalone commits, and run them through crater.

In addition to the `bstr` feature, I've added a `bstr_internals` feature
for APIs provided by `core` for use by `alloc` but not currently
intended for stabilization.

This API and its implementation are based *heavily* on the `bstr` crate
by Andrew Gallant (`@BurntSushi).`

r? `@BurntSushi`
2025-01-23 19:54:23 +01:00
Carl Sverre
f4166487ff Add memory layout documentation to generic NonZero<T> 2025-01-23 08:51:21 -08:00
Pavel Grigorenko
c06ed545df Implement AtomicT::update & AtomicT::try_update 2025-01-22 23:22:21 +03:00
Josh Triplett
865471f99b Implement CloneToUninit for ByteStr 2025-01-22 17:53:39 +02:00
Josh Triplett
022e7c0bb9 Add doc aliases for BStr and BString 2025-01-22 09:19:24 +02:00
Lukas Markeffsky
cc19dfa125 Add AsyncFn* to core prelude 2025-01-22 00:20:54 +01:00
Matthias Krüger
317769f152
Rollup merge of #135750 - scottmcm:cma-example, r=cuviper
Add an example of using `carrying_mul_add` to write wider multiplication

Just the basic quadratic version that you wouldn't actually use for really-big integers, but it's nice and short so is useful as for a demonstration of why you might find `carrying_mul_add` useful :)

cc #85532 ``````@clarfonthey``````
2025-01-21 23:30:19 +01:00
edwloef
6b48b67dfc
optimize slice::ptr_rotate for compile-time-constant small rotates 2025-01-21 22:54:39 +01:00
Caio
7d9fe91ccb [cfg_match] Document the use of expressions 2025-01-21 17:54:16 -03:00
bors
a42d5ecf34 Auto merge of #134286 - Urgau:unreach_pub-std, r=ibraheemdev
Enable `unreachable_pub` lint in core

This PR enables the [`unreachable_pub`](https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#unreachable-pub) as warn in `core`, `rtstartup` and `panic_unwind`.

The motivation is similar to the compiler [MCP: Enable deny(unreachable_pub) on `rustc_*` crates](https://github.com/rust-lang/compiler-team/issues/773#issue-2467219005) :

> "Where is this thing used?" is a question I ask all the time when reading unfamiliar code. Because of this, I generally find it annoying when things are marked with a more permissive visibility than necessary. "This thing marked pub, which other crates is it used in? Oh, it's not used in any other crates."

Another motivation is to help to lint by utilizing it in-tree and seeing it's limitation in more complex scenarios.

The diff was mostly generated with `./x.py fix --stage 1 library/core/ -- --broken-code`, as well as manual edits for code in macros, generated code and other targets.

r? libs
2025-01-20 23:34:04 +00:00
Matthias Krüger
8a7db695a6
Rollup merge of #135741 - bardiharborow:std/net/rfc9637, r=Amanieu
Recognise new IPv6 documentation range from IETF RFC 9637

This PR adds the `3fff::/20` range defined by [IETF RFC 9637](https://datatracker.ietf.org/doc/rfc9637/) to those ranges which `Ipv6Addr::is_documentation` recognises as a documentation IP.

See also: https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml
Unstable tracking issue: #27709
2025-01-20 20:58:36 +01:00
Matthias Krüger
bbec1510bb
Rollup merge of #133695 - x17jiri:hint_likely, r=Amanieu
Reexport likely/unlikely in std::hint

Since `likely`/`unlikely` should be working now, we could reexport them in `std::hint`. I'm not sure if this is already approved or if it requires approval

Tracking issue: #26179
2025-01-20 20:58:34 +01:00
Urgau
15f345b815 core: #[allow(unreachable_pub)] on unreachable pub use 2025-01-20 18:35:32 +01:00
Urgau
8e61502484 core: add #![warn(unreachable_pub)] 2025-01-20 18:35:32 +01:00
Jiri Bobek
cb2efaf5bc 1. Removed 'rustc_nounwind' 2. Rewording of comments 2025-01-20 16:16:46 +01:00
Tom Fryers
8ba0d2db18
Correct counting to four in cell module docs 2025-01-20 10:16:27 +00:00
Scott McMurray
b2b12ae0cb Add an example of using carrying_mul_add to write wider multiplication
Just the basic quadratic version that you wouldn't actually want for a true bigint, but it's nice and short so is useful as an example :)
2025-01-19 16:15:00 -08:00
Bardi Harborow
1f0e35eeca Recognise new IPv6 documentation range from RFC9637
This commit adds the 3fff::/20 range defined by RFC9637 to those ranges which Ipv6Addr::is_documentation recognises as a documentation IP.
2025-01-20 07:39:33 +11:00
bors
678e669cc4 Auto merge of #134976 - mgsloan:improve-select-nth-unstable-docs, r=ibraheemdev
Improve `select_nth_unstable` documentation clarity

* Instead uses `before` and `after` variable names in the example
where `greater` and `lesser` are flipped.

* Uses `<=` and `>=` instead of "less than or equal to" and "greater
than or equal to" to make the docs more concise.

* General attempt to remove unnecessary words and be more precise. For
example it seems slightly wrong to say "its final sorted position",
since this implies there is only one sorted position for this element.
2025-01-19 08:50:12 +00:00
bors
c62b732724 Auto merge of #135709 - lqd:bring-back-len, r=compiler-errors
Temporarily bring back `Rvalue::Len`

r? `@compiler-errors` as requested in https://github.com/rust-lang/rust/issues/135671#issuecomment-2599580364

> However, in the mean time, I'd rather we not crunch trying to find and more importantly validate the soundness of a solution 🤔

Agreed. To fix the IMO P-critical #135671 for which we somehow didn't have test coverage, this PR temporarily reverts:
- https://github.com/rust-lang/rust/pull/133734
- its bugfix https://github.com/rust-lang/rust/pull/134371
- https://github.com/rust-lang/rust/pull/134330

cc `@scottmcm`

I added the few samples from that issue as a test, but we can add more in the future, in particular it seems `@steffahn` [will work on that](https://github.com/rust-lang/rust/issues/135671#issuecomment-2599714354).

Fixes #135671. And if we want to land this, it should also be nominated for beta backport.
2025-01-19 06:09:51 +00:00
Michael Sloan
3a6eea0c6a Rewrap following accepting review suggestions from @ibraheemdev 2025-01-18 18:40:16 -07:00
Michael Sloan
fd89cf9b8f
Update library/core/src/slice/mod.rs
Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
2025-01-18 18:35:41 -07:00
Michael Sloan
6ac44fa5fa
Update library/core/src/slice/mod.rs
Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
2025-01-18 18:35:22 -07:00
Michael Sloan
c0aa7b5cf0
Update library/core/src/slice/mod.rs
Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
2025-01-18 18:35:12 -07:00
Michael Sloan
de7f1b670b
Update library/core/src/slice/mod.rs
Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
2025-01-18 18:34:29 -07:00
Michael Sloan
a3c65805ad
Update library/core/src/slice/mod.rs
Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
2025-01-18 18:34:21 -07:00
Michael Sloan
2eef440c22
Update library/core/src/slice/mod.rs
Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
2025-01-18 18:33:42 -07:00
Michael Sloan
a506f9d210
Update library/core/src/slice/mod.rs
Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
2025-01-18 18:33:33 -07:00
Michael Sloan
305bd856b2
Update library/core/src/slice/mod.rs
Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
2025-01-18 18:33:23 -07:00
Michael Sloan
d39d0ecd57
Update library/core/src/slice/mod.rs
Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
2025-01-18 18:33:02 -07:00
Michael Sloan
ecf68f3cd0
Update library/core/src/slice/mod.rs
Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
2025-01-18 18:32:47 -07:00
Rémy Rakic
ca1c17c88d Revert "Auto merge of #134330 - scottmcm:no-more-rvalue-len, r=matthewjasper"
This reverts commit e108481f74, reversing
changes made to 303e8bd768.
2025-01-18 22:09:34 +00:00
Michael Sloan
0257cfb974 then be -> be based on feedback from @ibraheemdev 2025-01-18 14:52:16 -07:00
Trevor Gross
809f61a783 Add references to the IEEE functions for float_next_up_down
Mention the IEEE function by name and create a doc alias of the same.
2025-01-17 23:01:23 +00:00
Trevor Gross
366cecacdd Stabilize float_next_up_down
FCP completed at [1].

Closes https://github.com/rust-lang/rust/issues/91399

[1]: https://github.com/rust-lang/rust/issues/91399#issuecomment-2598734570
2025-01-17 23:01:10 +00:00
Matthias Krüger
fca148185e
Rollup merge of #133720 - c410-f3r:cfg-match-foo-bar-baz, r=joshtriplett
[cfg_match] Adjust syntax

A year has passed since the creation of #115585 and the feature, as expected, is not moving forward. Let's change that.

This PR proposes changing the arm's syntax from  `cfg(SOME_CONDITION) => { ... }` to `SOME_CODITION => {}`.

```rust
match_cfg! {
   unix => {
        fn foo() { /* unix specific functionality */ }
    }
    target_pointer_width = "32" => {
        fn foo() { /* non-unix, 32-bit functionality */ }
    }
    _ => {
        fn foo() { /* fallback implementation */ }
    }
}
```

Why? Because after several manual migrations in https://github.com/rust-lang/rust/pull/116342 it became clear,  at least for me, that `cfg` prefixes are unnecessary, verbose and redundant.

Again, everything is just a proposal to move things forward. If the shown syntax isn't ideal, feel free to close this PR or suggest other alternatives.
2025-01-16 17:00:44 +01:00
Scott McMurray
c18718c9c2 Less unsafe in dangling/without_provenance 2025-01-15 22:17:57 -08:00
bors
6fc8a27931 Auto merge of #135555 - matthiaskrgr:rollup-jnqdbuu, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #135497 (fix typo in typenames of pin documentation)
 - #135522 (add incremental test for issue 135514)
 - #135523 (const traits: remove some known-bug that do not seem to make sense)
 - #135535 (Add GUI test for #135499)
 - #135541 (Methods of const traits are const)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-01-15 22:22:48 +00:00
Matthias Krüger
85d2b2af15
Rollup merge of #135497 - DJMrTV:master, r=jhpratt
fix typo in typenames of pin documentation

I noticed this whilst reading the documentation for pin.

Basically there was just one to many closing angle brackets on the type parameters in the documentation where instead of being `Pin<&mut T>` it was `Pin<&mut T>>`
2025-01-15 22:06:11 +01:00
Jiri Bobek
c656f879c9 Export likely(), unlikely() and cold_path() in std::hint 2025-01-15 21:42:47 +01:00
DJMrTV
b535a1dd65 fix typo in typenames of pin documentation 2025-01-15 19:18:17 +01:00
Guillaume Gomez
369d135733
Rollup merge of #135003 - RalfJung:deprecate-allowed-through-unstable, r=davidtwco
deprecate `std::intrinsics::transmute` etc, use `std::mem::*` instead

The `rustc_allowed_through_unstable_modules` attribute lets users call `std::mem::transmute` as `std::intrinsics::transmute`. The former is a reexport of the latter, and for a long time we didn't properly check stability for reexports, so making this a hard error now would be a breaking change for little gain. But at the same time, `std::intrinsics::transmute` is not the intended path for this function, so I think it is a good idea to show a deprecation warning when that path is used. This PR implements that, for all the functions in `std::intrinsics` that carry the attribute.

I assume this will need ``@rust-lang/libs-api`` FCP.
2025-01-15 16:30:11 +01:00
bors
2776bdfe42 Auto merge of #135525 - jhpratt:rollup-4gu2wpm, r=jhpratt
Rollup of 7 pull requests

Successful merges:

 - #132397 (Make missing_abi lint warn-by-default.)
 - #133807 (ci: Enable opt-dist for dist-aarch64-linux builds)
 - #134143 (Convert `struct FromBytesWithNulError` into enum)
 - #134338 (Use a C-safe return type for `__rust_[ui]128_*` overflowing intrinsics)
 - #134678 (Update `ReadDir::next` in `std::sys::pal::unix::fs` to use `&raw const (*p).field` instead of `p.byte_offset().cast()`)
 - #135424 (Detect unstable lint docs that dont enable their feature)
 - #135520 (Make sure we actually use the right trivial lifetime substs when eagerly monomorphizing drop for ADTs)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-01-15 09:20:25 +00:00
Jacob Pratt
229c91bc31
Rollup merge of #134143 - nyurik:err-nul, r=dtolnay
Convert `struct FromBytesWithNulError` into enum

This PR renames the former `kind` enum from `FromBytesWithNulErrorKind` to `FromBytesWithNulError`, and removes the original struct.

See https://github.com/rust-lang/libs-team/issues/493

## Possible Changes - TBD
* [x] should the new `enum FromBytesWithNulError` derive `Copy`?
* [ ] should there be any new/changed attributes?
* [x] add some more tests

## Problem

One of `CStr` constructors, `CStr::from_bytes_with_nul(bytes: &[u8])` handles 3 cases:
1. `bytes` has one NULL as the last value - creates CStr
2. `bytes` has no NULL - error
3. `bytes` has a NULL in some other position - error

The 3rd case is error that may require lossy conversion, but the 2nd case can easily be handled by the user code. Unfortunately, this function returns an opaque `FromBytesWithNulError` error in both 2nd and 3rd case, so the user cannot detect just the 2nd case - having to re-implement the entire function and bring in the `memchr` dependency.

## Motivating examples or use cases

In [this code](f86d7a8768/varnish-sys/src/vcl/ws.rs (L158)), my FFI code needs to copy user's `&[u8]` into a C-allocated memory blob in a NUL-terminated `CStr` format.  My code must first validate if `&[u8]` has a trailing NUL (case 1), no NUL (adds one on the fly - case 2), or NUL in the middle (3rd case - error). I had to re-implement `from_bytes_with_nul` and add `memchr`dependency just to handle the 2nd case.

r? `@Amanieu`
2025-01-15 04:08:11 -05:00
Ralf Jung
f1c95c9000 intrinsics: deprecate calling them via the unstable std::intrinsics path 2025-01-15 09:41:33 +01:00
Michael Goulet
2743df848b Enforce syntactical stability of const traits in HIR 2025-01-14 19:12:08 +00:00
Ralf Jung
5c2006b79a remove pointless allowed_through_unstable_modules on TryFromSliceError 2025-01-14 16:54:28 +01:00
Ralf Jung
9ac62f972f remove Rustc{En,De}codable from library and compiler 2025-01-14 16:16:38 +01:00
Ralf Jung
4df78a07e5 make rustc_encodable_decodable feature properly unstable 2025-01-14 16:16:38 +01:00
bors
48a426eca9 Auto merge of #135384 - saethlin:inline-copy-from-slice, r=joboet
Add #[inline] to copy_from_slice

I'm doing cooked things to CGU partitioning for compiler-builtins (https://github.com/rust-lang/rust/pull/135395) and this was the lone symbol in my compiler-builtins rlib that wasn't an intrinsic. Adding `#[inline]` makes it go away.

Perf report indicates a marginal but chaotic effect on compile time, marginal improvement in codegen. As expected.
2025-01-12 20:16:25 +00:00
Josh Triplett
22a4ec39fb Omit some more From impls to avoid inference failures 2025-01-12 12:27:24 +02:00
ltdk
e37daf0c86 Add inherent versions of MaybeUninit methods for slices 2025-01-11 23:57:00 -05:00
Ben Kimock
cda566e226 Add #[inline] to copy_from_slice 2025-01-11 18:00:44 -05:00
bors
12445e0b2c Auto merge of #135360 - RalfJung:structural-partial-eq, r=compiler-errors
update and clarify StructuralPartialEq docs

This apparently hasn't been updated when we finalized the current const pattern matching behavior.

Fixes https://github.com/rust-lang/rust/issues/92454 by providing rationale and context in the docs linked from that error message.
2025-01-11 21:46:43 +00:00
Ralf Jung
41857a3d42 update and clarify StructuralPartialEq docs 2025-01-11 11:00:41 +01:00
Yuri Astrakhan
86b86fa8fb Rename pos to position 2025-01-11 02:56:58 -05:00
Yuri Astrakhan
2f5a3d4b06 Convert struct FromBytesWithNulError into enum
One of `CStr` constructors, `CStr::from_bytes_with_nul(bytes: &[u8])` handles 3 cases:
1. `bytes` has one NULL as the last value - creates CStr
2. `bytes` has no NULL - error
3. `bytes` has a NULL in some other position - error

The 3rd case is error that may require lossy conversion, but the 2nd case can easily be handled by the user code. Unfortunately, this function returns an opaque `FromBytesWithNulError` error in both 2nd and 3rd case, so the user cannot detect just the 2nd case - having to re-implement the entire function and bring in the `memchr` dependency.

In [this code](f86d7a8768/varnish-sys/src/vcl/ws.rs (L158)), my FFI code needs to copy user's `&[u8]` into a C-allocated memory blob in a NUL-terminated `CStr` format.  My code must first validate if `&[u8]` has a trailing NUL (case 1), no NUL (adds one on the fly - case 2), or NUL in the middle (3rd case - error). I had to re-implement `from_bytes_with_nul` and add `memchr`dependency just to handle the 2nd case.

This PR renames the former `kind` enum from `FromBytesWithNulErrorKind` to `FromBytesWithNulError`, and removes the original struct.
2025-01-11 02:47:55 -05:00
Jacob Pratt
46222ce6f8
Rollup merge of #135347 - samueltardieu:push-qvyxtxsqyxyr, r=jhpratt
Use `NonNull::without_provenance` within the standard library

This API removes the need for several `unsafe` blocks, and leads to clearer code. It uses feature `nonnull_provenance` (#135243).

Close #135343
2025-01-11 01:55:09 -05:00
Jacob Pratt
351e6188a8
Rollup merge of #135236 - scottmcm:more-mcp807-library-updates, r=ChrisDenton
Update a bunch of library types for MCP807

This greatly reduces the number of places that actually use the `rustc_layout_scalar_valid_range_*` attributes down to just 3:
```
library/core\src\ptr\non_null.rs
68:#[rustc_layout_scalar_valid_range_start(1)]

library/core\src\num\niche_types.rs
19:        #[rustc_layout_scalar_valid_range_start($low)]
20:        #[rustc_layout_scalar_valid_range_end($high)]
```

Everything else -- PAL Nanoseconds, alloc's `Cap`, niched FDs, etc -- all just wrap those `niche_types` types.

r? ghost
2025-01-11 01:55:05 -05:00
Josh Triplett
2808977e05 Implement ByteStr and ByteString types
Approved ACP: https://github.com/rust-lang/libs-team/issues/502
Tracking issue: https://github.com/rust-lang/rust/issues/134915

These types represent human-readable strings that are conventionally,
but not always, UTF-8. The `Debug` impl prints non-UTF-8 bytes using
escape sequences, and the `Display` impl uses the Unicode replacement
character.

This is a minimal implementation of these types and associated trait
impls. It does not add any helper methods to other types such as `[u8]`
or `Vec<u8>`.

I've omitted a few implementations of `AsRef`, `AsMut`, `Borrow`,
`From`, and `PartialOrd`, when those would be the second implementation
for a type (counting the `T` impl) or otherwise may cause inference
failures. These impls are important, but we can attempt to add them
later in standalone commits, and run them through crater.

In addition to the `bstr` feature, I've added a `bstr_internals` feature
for APIs provided by `core` for use by `alloc` but not currently
intended for stabilization.

This API and its implementation are based *heavily* on the `bstr` crate
by Andrew Gallant (@BurntSushi).
2025-01-11 06:35:21 +02:00
Scott McMurray
ebd6d3f225 Improve the safety documentation on new_unchecked 2025-01-10 18:52:22 -08:00
Samuel Tardieu
9ab77f1ccb Use NonNull::without_provenance within the standard library
This API removes the need for several `unsafe` blocks, and leads to
clearer code.
2025-01-10 23:23:10 +01:00
Scott McMurray
6f2a78345e Update a bunch of library types for MCP807
This greatly reduces the number of places that actually use the `rustc_layout_scalar_valid_range_*` attributes down to just 3:
```
library/core\src\ptr\non_null.rs
68:#[rustc_layout_scalar_valid_range_start(1)]

library/core\src\num\niche_types.rs
19:        #[rustc_layout_scalar_valid_range_start($low)]
20:        #[rustc_layout_scalar_valid_range_end($high)]
```

Everything else -- PAL Nanoseconds, alloc's `Cap`, niched FDs, etc -- all just wrap those `niche_types` types.
2025-01-09 23:47:11 -08:00
Matthias Krüger
6a40d50edc
Rollup merge of #134908 - madsmtm:ptr-from_ref-docs, r=ibraheemdev
Fix `ptr::from_ref` documentation example comment

The comment says that the expression involves no function call, but that was only true for the example above, the example here _does_ contain a function call.

``@rustbot`` label A-docs
2025-01-10 06:28:39 +01:00
Matthias Krüger
380612737a
Rollup merge of #134619 - hkBst:patch-7, r=jhpratt
Improve prose around `as_slice` example of IterMut

I've removed the cryptic message about not being able to call `&mut self` methods while retaining a shared borrow of the iterator, such as `as_slice` produces. This is just normal borrowing rules and does not seem especially relevant here. I can whip up a replacement if someone thinks it has value.
2025-01-10 06:28:38 +01:00
bors
251206c27b Auto merge of #135268 - pietroalbini:pa-bump-stage0, r=Mark-Simulacrum
Master bootstrap update

Part of the release process.

r? `@Mark-Simulacrum`
2025-01-09 13:33:16 +00:00
Pietro Albini
d894ce8827
fmt 2025-01-08 22:11:33 +01:00
Pietro Albini
2af3ba9a8a
update cfg(bootstrap) 2025-01-08 21:26:39 +01:00
Pietro Albini
4ae92b7adb
update version placeholders 2025-01-08 20:02:18 +01:00
Ralf Jung
2d23601541 add missing provenance APIs on NonNull 2025-01-08 12:49:36 +01:00
Jacob Pratt
e78b1321e5
Rollup merge of #135139 - c410-f3r:8-years-rfc, r=jhpratt
[generic_assert] Constify methods used by the formatting system

cc #44838

Starts the "constification" of all the elements required to allow the execution of the formatting system in constant environments.

```rust
const _: () = { panic!("{:?}", 1i32); };
```

Further stuff is blocked by #133999.
2025-01-06 22:04:17 -05:00
Caio
db17be84fe [generic_assert] Constify methods used by the formatting system 2025-01-05 20:49:04 -03:00
Jacob Pratt
0f9f91cccf
Rollup merge of #135121 - okaneco:const_slice_reverse, r=jhpratt
Mark `slice::reverse` unstably const

Tracking issue #135120

This is unblocked by the stabilization of `const_swap`
2025-01-05 18:35:05 -05:00
okaneco
03c2ac248f Mark slice::reverse unstably const 2025-01-05 08:01:50 -05:00
ranger-ross
6243c0f818
Clarified the documentation on core::iter::from_fn and core::iter::successors 2025-01-05 19:25:24 +09:00
The 8472
3d871b3ced do not in-place-iterate over flatmap/flatten
The implementation is unsound when a partially consumed iterator has
some elements buffered in the front/back parts and cloning the Iterator
removes the capacity from the backing vec::IntoIter.
2025-01-04 19:26:58 +01:00
Matthias Krüger
695da5b782
Rollup merge of #133964 - joboet:select_unpredictable, r=tgross35
core: implement `bool::select_unpredictable`

Tracking issue: #133962
ACP: https://github.com/rust-lang/libs-team/issues/468
2025-01-04 09:54:36 +01:00
Matthias Krüger
fac31a1398
Rollup merge of #134985 - mgsloan:remove-unnecessary-qualification-in-Ord-trait-docs, r=Noratrieb
Remove qualification of `std::cmp::Ordering` in `Ord` doc
2025-01-01 22:04:17 +01:00
bors
eeeff9a66c Auto merge of #134969 - Marcondiro:master, r=jhpratt,programmerjake
char to_digit: avoid unnecessary casts to u64

Hello,
in the `char::to_digit` method there are a few `as u64` casts that are not strictly necessary.
I assume that the reason behind these casts is to avoid possible overflows in the `+ 10` add.

This PR removes the aforementioned casts, avoiding the overflow issue by slightly modifying the ASCII letter to int mapping.

Thanks,
Happy new year.
2025-01-01 10:54:12 +00:00
Michael Sloan
217e10a70c Improve select_nth_unstable documentation clarity
* Instead uses `before` and `after` variable names in the example
where `greater` and `lesser` are flipped.

* Uses `<=` and `>=` instead of "less than or equal to" and "greater
than or equal to" to make the docs more concise.

* General attempt to remove unnecessary words and be more precise. For
example it seems slightly wrong to say "its final sorted position",
since this implies there is only one sorted position for this element.
2024-12-31 15:59:28 -07:00
Michael Sloan
cdd55bfda2 Remove qualification of std::cmp::Ordering in Ord doc 2024-12-31 14:29:03 -07:00
bors
d117b7f211 Auto merge of #132195 - clarfonthey:bigint-mul, r=scottmcm
Tidy up bigint multiplication methods

This tidies up the library version of the bigint multiplication methods after the addition of the intrinsics in #133663. It follows [this summary](https://github.com/rust-lang/rust/issues/85532#issuecomment-2403442775) of what's desired for these methods.

Note that, if `2H = N`, then `uH::MAX * uH::MAX + uH::MAX + uH::MAX` is `uN::MAX`, and that we can effectively add two "carry" values without overflowing.

For ease of terminology, the "low-order" or "least significant" or "wrapping" half of multiplication will be called the low part, and the "high-order" or "most significant" or "overflowing" half of multiplication will be called the high part. In all cases, the return convention is `(low, high)` and left unchanged by this PR, to be litigated later.

## API Changes

The original API:

```rust
impl uN {
    // computes self * rhs
    pub const fn widening_mul(self, rhs: uN) -> (uN, uN);

    // computes self * rhs + carry
    pub const fn carrying_mul(self, rhs: uN, carry: uN) -> (uN, uN);
}
```

The added API:

```rust
impl uN {
    // computes self * rhs + carry1 + carry2
    pub const fn carrying2_mul(self, rhs: uN, carry: uN, add: uN) -> (uN, uN);
}
impl iN {
    // note that the low part is unsigned
    pub const fn widening_mul(self, rhs: iN) -> (uN, iN);
    pub const fn carrying_mul(self, rhs: iN, carry: iN) -> (uN, iN);
    pub const fn carrying_mul_add(self, rhs: iN, carry: iN, add: iN) -> (uN, iN);
}
```

Additionally, a naive implementation has been added for `u128` and `i128` since there are no double-wide types for those. Eventually, an intrinsic will be added to make these more efficient, but rather than doing this all at once, the library changes are added first.

## Justifications for API

The unsigned parts are done to ensure consistency with overflowing addition: for a two's complement integer, you want to have unsigned overflow semantics for all parts of the integer except the highest one. This is because overflow for unsigned integers happens on the highest bit (from `MAX` to zero), whereas overflow for signed integers happens on the second highest bit (from `MAX` to `MIN`). Since the sign information only matters in the highest part, we use unsigned overflow for everything but that part.

There is still discussion on the merits of signed bigint *addition* methods, since getting the behaviour right is very subtle, but at least for signed bigint *multiplication*, the sign of the operands does make a difference. So, it feels appropriate that at least until we've nailed down the final API, there should be an option to do signed versions of these methods.

Additionally, while it's unclear whether we need all three versions of bigint multiplication (widening, carrying-1, and carrying-2), since it's possible to have up to two carries without overflow, there should at least be a method to allow that. We could potentially only offer the carry-2 method and expect that adding zero carries afterword will optimise correctly, but again, this can be litigated before stabilisation.

## Note on documentation

While a lot of care was put into the documentation for the `widening_mul` and `carrying_mul` methods on unsigned integers, I have not taken this same care for `carrying_mul_add` or the signed versions. While I have updated the doc tests to be more appropriate, there will likely be many documentation changes done before stabilisation.

## Note on tests

Alongside this change, I've added several tests to ensure that these methods work as expected. These are alongside the codegen tests for the intrinsics.
2024-12-31 18:49:36 +00:00
Marcondiro
aa685bccca
char to_digit: avoid unnecessary casts to u64 2024-12-31 16:17:10 +01:00
Matthias Krüger
852440ba5f
Rollup merge of #134953 - DiuDiu777:unaligned-doc, r=RalfJung
Fix doc for read&write unaligned in zst operation

### PR Description
This PR addresses an inconsistency in the Rust documentation regarding `read_unaligned ` and `write_unaligned` on zero-sized types (ZSTs). The current documentation for [pointer validity](https://doc.rust-lang.org/nightly/std/ptr/index.html#safety) states that for zero-sized types (ZSTs), null pointers are valid:
> For zero-sized types (ZSTs), every pointer is valid, including the null pointer.

However, there is an inconsistency in the documentation for the unaligned read operation in the function [ptr::read_unaligned](https://doc.rust-lang.org/nightly/std/ptr/fn.read_unaligned.html)(as well as `write_unaligned`), which states:
> Note that even if T has size 0, the pointer must be non-null.

This change is also supported by [PR #134912](https://github.com/rust-lang/rust/pull/134912)
> the _unaligned method docs should be fixed.
2024-12-31 14:30:43 +01:00