Commit Graph

3150 Commits

Author SHA1 Message Date
Trevor Gross
8c1b49d5e9 Use public-dependencies in all sysroot crates
In [1], most dependencies of `std` and other sysroot crates were marked
private, but this did not happen for `alloc` and `test`. Update these
here, marking public standard library crates as the only non-private
dependencies.

[1]: https://github.com/rust-lang/rust/pull/111076
2025-02-21 17:37:03 +00:00
Matthias Krüger
8d52aae968
Rollup merge of #136089 - jwong101:box-default-debug-stack-usage, r=Amanieu
Reduce `Box::default` stack copies in debug mode

The `Box::new(T::default())` implementation of `Box::default` only
had two stack copies in debug mode, compared to the current version,
which has four. By avoiding creating any `MaybeUninit<T>`'s and just writing
`T` directly to the `Box` pointer, the stack usage in debug mode remains
the same as the old version.

Another option would be to mark `Box::write` as `#[inline(always)]`,
and change it's implementation to to avoid calling `MaybeUninit::write`
(which creates a `MaybeUninit<T>` on the stack) and to use `ptr::write` instead.

Fixes: #136043
2025-02-21 12:45:22 +01:00
Marijn Schouten
da7210b17f Explain how Vec::with_capacity is faithful
Co-authored-by: Jubilee <workingjubilee@gmail.com> and jmaargh
2025-02-21 12:43:45 +01:00
Matthias Krüger
7b7b1d4ee9
Rollup merge of #132268 - elichai:string_try_from_vec, r=Amanieu
Impl TryFrom<Vec<u8>> for String

I think this is useful enough to have :)
As a general question, is there any policy around adding "missing" trait implementations? (like adding `AsRef<T> for T` for std types), I mostly stumble upon them when using a lot of "impl Trait in argument position" like (`foo: impl Into<String>`)
2025-02-19 21:16:02 +01:00
Matthias Krüger
84e9f29007
Rollup merge of #120580 - HTGAzureX1212:HTGAzureX1212/issue-45795, r=m-ou-se
Add `MAX_LEN_UTF8` and `MAX_LEN_UTF16` Constants

This pull request adds the `MAX_LEN_UTF8` and `MAX_LEN_UTF16` constants as per #45795, gated behind the `char_max_len` feature.

The constants are currently applied in the `alloc`, `core` and `std` libraries.
2025-02-19 21:16:01 +01:00
Josh Stone
3c45324e67 update cfg(bootstrap) 2025-02-18 09:32:44 -08:00
Josh Stone
fdba8a7c47 update version placeholders
(cherry picked from commit e4840ce59b)
2025-02-18 08:50:21 -08:00
Matthias Krüger
fae72a07dd
Rollup merge of #137105 - zachs18:cow-derefpure-restrict, r=Nadrieril
Restrict DerefPure for Cow<T> impl to T = impl Clone, [impl Clone], str.

Fixes #136046

`feature(deref_patterns)` tracking issue: https://github.com/rust-lang/rust/issues/87121

`Cow<'_, T>` should only implement `DerefPure` if its `Deref` impl is pure, which requires `<T::Owned as Borrow<T>>::borrow`  to be pure. This PR restricts `impl DerefPure for Cow<'_, T>` to `T: Sized + Clone`, `T = [U: Clone]`, and `T = str` (for all of whom `<T::Owned as Borrow<T>>::borrow` is implemented in the stdlib and is pure).

cc ``@Nadrieril``

------

An alternate approach would be to introduce a new `unsafe trait BorrowPure<T>` analogous to `DerefPure`  that could be implemented for `T: Sized`, `&T`, `&mut T`, `String`, `Vec`, `Box`, `PathBuf`, `OsString`, etc. https://github.com/rust-lang/rust/compare/master...zachs18:borrow-pure-trait
2025-02-17 06:38:15 +01:00
bendn
92fd960ca4
stabilize (const_)ptr_sub_ptr 2025-02-17 10:07:27 +07:00
HTGAzureX1212
eec49bbf59 add MAX_LEN_UTF8 and MAX_LEN_UTF16 constants 2025-02-16 21:08:38 +08:00
Zachary S
0f220efb1a Restrict DerefPure for Cow<T> impl to T = impl Clone, [impl Clone], str. 2025-02-15 21:02:00 -06:00
Michael Howell
4d551dd754 docs: fix broken intra-doc links that never worked 2025-02-15 12:21:38 -07:00
Jacob Pratt
26be558650
Rollup merge of #136749 - mzeitlin11:extend-asciichar, r=scottmcm
Implement Extend<AsciiChar> for String

Implement `Extend<AsciiChar>` for `String` as suggested in https://github.com/rust-lang/rust/issues/110998#issuecomment-2590122968. Also implements `Extend<&AsciiChar>` since there's an analogous impl for `Extend<&char>`, but happy to remove if not thought useful.

r? `@scottmcm`
since you requested it, but no pressure to review!
2025-02-15 02:37:28 -05:00
Jubilee
922119b79c
Rollup merge of #136983 - ehuss:misc-2024-prep, r=tgross35
Prepare standard library for Rust 2024 migration

This includes a variety of commits preparing the standard library for migration to Rust 2024.

The actual migration is blocked on a few things, so I wanted to get this out of the way in a relatively digestable PR.
2025-02-14 14:05:24 -08:00
Matthias Krüger
145e35a6e3
Rollup merge of #136976 - jedbrown:jed/doc-boxed-deferred-init, r=tgross35
alloc boxed: docs: use MaybeUninit::write instead of as_mut_ptr

In the deferred initialization pattern, the docs were needlessly going through `as_mut_ptr().write()` to initialize, which is unnecessary use of a pointer, needs to be inside an `unsafe` block, and may weaken alias analysis.
2025-02-14 16:23:33 +01:00
Eric Huss
07ebbddeff alloc: Apply missing_unsafe_on_extern 2025-02-13 13:10:27 -08:00
Eric Huss
55ef73c00d alloc: Apply unsafe_attr_outside_unsafe 2025-02-13 13:10:27 -08:00
Eric Huss
890530e186 alloc: Workaround hidden doctest line
A small workaround for https://github.com/rust-lang/rust/issues/136899,
rustdoc's invalid_rust_codeblocks was not handling this well in 2024.
This may be needed when migrating to 2024 when building with stage0.
2025-02-13 13:10:27 -08:00
bors
a567209daa Auto merge of #134633 - GrigorenkoPV:get_disjoint_mut, r=cuviper
Stabilize `get_many_mut` as `get_disjoint_mut`

Tracking issue: #104642

Closes #104642

FCP completed in https://github.com/rust-lang/rust/issues/104642#issuecomment-2558161073
2025-02-13 21:09:31 +00:00
Eric Huss
b7c975b22e library: Update rand to 0.9.0 2025-02-13 12:20:55 -08:00
Jed Brown
2f27236745 alloc boxed: docs: use MaybeUninit::write instead of as_mut_ptr
In the deferred initialization pattern, the docs were needlessly going
through as_mut_ptr().write() to initialize, which is unnecessary use of
a pointer, needs to be inside an unsafe block, and may weaken alias
analysis.
2025-02-13 09:13:33 -07:00
Matthias Krüger
ad92b850c6
Rollup merge of #136714 - tgross35:update-builtins, r=tgross35
Update `compiler-builtins` to 0.1.146

Exposes the error function so we can expose this in the standard library [1].

[1]: https://github.com/rust-lang/compiler-builtins/pull/753
2025-02-10 16:38:26 +01:00
Jubilee
72f0205d28
Rollup merge of #136705 - compiler-errors:edition-library, r=jhpratt
Some miscellaneous edition-related library tweaks

Some library edition tweaks that can be done separately from upgrading the whole standard library to edition 2024 (which is blocked on getting the submodules upgraded, for example)
2025-02-10 00:51:54 -08:00
Jubilee
888b438476
Rollup merge of #136228 - hkBst:patch-28, r=Mark-Simulacrum
Simplify Rc::as_ptr docs + typo fix
2025-02-10 00:51:50 -08:00
Matthias Krüger
b83a30c1b6
Rollup merge of #135488 - GrigorenkoPV:vec_pop_if, r=jhpratt
Stabilize `vec_pop_if`

Tracking issue: #122741

FCP completed in https://github.com/rust-lang/rust/issues/122741#issuecomment-2605116387
2025-02-09 19:44:50 +01:00
Michael Goulet
4312d7b541 Fix pattern matching mode changes and unsafe_op_in_unsafe_fn 2025-02-09 17:11:13 +00:00
Michael Goulet
a4e7f8f9bf Mark extern blocks as unsafe 2025-02-09 17:11:13 +00:00
Robert Bastian
65a5d8bf6c
Update string.rs 2025-02-09 17:08:39 +01:00
bors
124cc92199 Auto merge of #136751 - bjorn3:update_rustfmt, r=Mark-Simulacrum
Update bootstrap compiler and rustfmt

The rustfmt version we previously used formats things differently from what the latest nightly rustfmt does. This causes issues for subtrees that get formatted both in-tree and in their own repo. Updating the rustfmt used in-tree solves those issues. Also bumped the bootstrap compiler as the stage0 update command always updates both at the same
time.
2025-02-09 15:44:16 +00:00
bjorn3
1fcae03369 Rustfmt 2025-02-08 22:12:13 +00:00
Matthew Zeitlin
d566b5db9b
Implement Extend<AsciiChar> for String 2025-02-08 16:51:04 -05:00
Matthias Krüger
785a4eb2d2
Rollup merge of #136099 - Kijewski:pr-rc-str-default, r=ibraheemdev
Optimize `Rc::<str>::default()` implementation

This PR lets `impl Default for Rc<str>` re-use the implementation for `Rc::<[u8]>::default()`. The previous version only calculted the memory layout at runtime, even though it should be known at compile time, resulting in an additional function call.

The same optimization is done for `Rc<CStr>`.

Generated byte code: <https://godbolt.org/z/dfq73jsoP>.

Resolves <https://github.com/rust-lang/rust/issues/135784>.

Cc `@Billy-Sheppard.`
2025-02-08 21:37:24 +01:00
Trevor Gross
38a8302616 Update compiler-builtins to 0.1.146
Exposes the error function so we can expose this in the standard
library [1].

[1]: https://github.com/rust-lang/compiler-builtins/pull/753
2025-02-07 20:58:28 +00:00
Esteban Küber
3815ed63ed Remove some unnecessary parens in assert! conditions
While working on #122661, some of these started triggering our "unnecessary parens" lints due to a change in the `assert!` desugaring. A cursory search identified a few more. Some of these have been carried from before 1.0, were a bulk rename from the previous name of `assert!` left them in that state. I went and removed as many of these unnecessary parens as possible in order to have fewer annoyances in the future if we make the lint smarter.
2025-02-06 22:28:44 +00:00
Trevor Gross
90fee92fcc Update compiler-builtins to 0.1.145
This includes [1] which is required for LLVM 20.

[1]: https://github.com/rust-lang/compiler-builtins/pull/752
2025-02-04 11:49:01 +00:00
Marijn Schouten
860476f6e0 Update encode_utf16 to mention it is native endian 2025-01-31 11:44:11 +01:00
Stuart Cook
3a2f26f542
Rollup merge of #136215 - btj:patch-1, r=cuviper
btree/node.rs: remove incorrect comment from pop_internal_level docs
2025-01-30 14:25:05 +11:00
Bart Jacobs
810e4c1bc6
btree/node.rs: pop_internal_level: does not invalidate other handles 2025-01-29 08:35:29 +01:00
Marijn Schouten
717d36abc9
Simplify Rc::as_ptr docs + typo fix 2025-01-29 06:22:39 +01:00
Bart Jacobs
6763561161
btree/node.rs: remove incorrect comment from pop_internal_level docs 2025-01-28 21:42:51 +01:00
bors
bf1b174e7d Auto merge of #136203 - matthiaskrgr:rollup-1k0f44l, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #135869 (Make docs for AtomicUsize::from_mut platform-independent)
 - #135892 (-Znext-solver: "normalize" signature before checking it mentions self in `deduce_closure_signature`)
 - #136055 (Implement MIR const trait stability checks)
 - #136066 (Pass spans to `perform_locally_in_new_solver`)
 - #136071 ([Clippy] Add vec_reserve & vecdeque_reserve diagnostic items)
 - #136124 (Arbitrary self types v2: explain test.)
 - #136149 (Flip the `rustc-rayon`/`indexmap` dependency order)
 - #136173 (Update comments and sort target_arch in c_char_definition)
 - #136178 (Update username in build helper example)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-01-28 20:15:51 +00:00
Matthias Krüger
d43e78d6ea
Rollup merge of #136071 - wowinter13:clippy-add-diagnostic-items, r=flip1995
[Clippy] Add vec_reserve & vecdeque_reserve diagnostic items

I’m currently working on reviving this lint (https://github.com/rust-lang/rust-clippy/pull/10157), and there was [a comment](https://github.com/rust-lang/rust-clippy/pull/10157#discussion_r1091591057) from ``@flip1995`` regarding the necessity of adding new diagnostic items.
2025-01-28 18:17:26 +01:00
Pavel Grigorenko
1abc853562 Stabilize get_many_mut as get_disjoint_mut
* Renames the methods:
	* `get_many_mut` -> `get_disjoint_mut`
	* `get_many_unchecked_mut` -> `get_disjoint_unchecked_mut`
* Does not rename the feature flag: `get_many_mut`
* Marks the feature as stable
* Renames some helper stuff:
	* `GetManyMutError` -> `GetDisjointMutError`
	* `GetManyMutIndex` -> `GetDisjointMutIndex`
	* `get_many_mut_helpers` -> `get_disjoint_mut_helpers`
	* `get_many_check_valid` -> `get_disjoint_check_valid`

This only touches slice methods.
HashMap's methods and feature gates are not renamed here
(nor are they stabilized).
2025-01-28 17:59:31 +03:00
Matthias Krüger
32c04fc509
Rollup merge of #135805 - DiuDiu777:master, r=Noratrieb
Add missing allocator safety in alloc crate

### PR Description
In the previous PR [#135009](https://github.com/rust-lang/rust/pull/135009), PR [#134496](https://github.com/rust-lang/rust/pull/134496), some incomplete API documentation issues have been fixed.

Based on these changes,  other inconsistencies related to the allocator have also been identified, including:

- `Box::from_non_null`
- `Box::from_non_null_in`
- `Weak::from_raw`
2025-01-28 14:23:23 +01:00
Matthias Krüger
e3420f4464
Rollup merge of #135367 - Urgau:unreach_pub-std-3, r=Noratrieb
Enable `unreachable_pub` lint in `alloc`

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

Most of changes are in the btree implementation and in tests.

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

Continuation of #134286 and #135366

r? libs
2025-01-28 14:23:21 +01:00
René Kijewski
e090db8d22 Optimize Rc::<str>::default() implementation
This PR lets `impl Default for Rc<str>` re-use the implementation
for `Rc::<[u8]>::default()`. The previous version only calculted the
memory layout at runtime, even though it should be known at compile
time, resulting in an additional function call.

The same optimization is done for `Rc<CStr>`.

Generated byte code: <https://godbolt.org/z/dfq73jsoP>.

Resolves <https://github.com/rust-lang/rust/issues/135784>.
2025-01-26 19:12:54 +01:00
Joshua Wong
97005678c3 reduce Box::default stack copies in debug mode
The `Box::new(T::default())` implementation of `Box::default` only
had two stack copies in debug mode, compared to the current version,
which has four. By avoiding creating any `MaybeUninit<T>`'s and just writing
`T` directly to the `Box` pointer, the stack usage in debug mode remains
the same as the old version.
2025-01-26 03:48:27 -05: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
wowinter13
2117afdef8 [Clippy] Add vec_reserve & vecdeque_reserve diagnostic items 2025-01-25 23:18:18 +01:00
Matthias Krüger
575081564d
Rollup merge of #135728 - hkBst:patch-8, r=joboet
document order of items in iterator from drain

fixes #135710
2025-01-24 23:25:43 +01:00
Pavel Grigorenko
2ecb40e04a Stabilize vec_pop_if 2025-01-25 01:09:37 +03:00
Matthias Krüger
ed77bf7263
Rollup merge of #135983 - hkBst:patch-13, r=jhpratt
Doc difference between extend and extend_from_slice

fixes #97119
2025-01-24 16:25:46 +01:00
Matthias Krüger
b344e14bde
Rollup merge of #135956 - GrigorenkoPV:vec_pop_off, r=dtolnay
Make `Vec::pop_if` a bit more presentable

#135488 minus stabilization.

As suggested in https://github.com/rust-lang/rust/pull/135488#issuecomment-2608108210.

r? tgross35
2025-01-24 16:25:45 +01:00
Marijn Schouten
3c3961ba69
Doc difference between extend and extend_from_slice
fixes #97119
2025-01-24 10:45:39 +01:00
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
bjorn3
d0a70d9328 Fix testing of the standard library with Emscripten
This does need EMCC_CFLAGS="-s MAXIMUM_MEMORY=2GB" avoid several OOMs.
2025-01-24 09:25:34 +00:00
Matthias Krüger
be15391703
Rollup merge of #135890 - GrigorenkoPV:deque-pop-if, r=thomcc
Implement `VecDeque::pop_front_if` & `VecDeque::pop_back_if`

Tracking issue: #135889
2025-01-24 08:08:09 +01:00
Pavel Grigorenko
b2ad126a55 Make Vec::pop_if a bit more presentable 2025-01-24 01:07:17 +03: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
Pavel Grigorenko
ed7cc3486c Implement VecDeque::pop_front_if & VecDeque::pop_back_if 2025-01-22 20:04:36 +03:00
Pavel Grigorenko
bae2a2f3b5 Remove erroneous unsafe in BTreeSet::upper_bound_mut 2025-01-22 18:36:33 +03:00
Josh Triplett
022e7c0bb9 Add doc aliases for BStr and BString 2025-01-22 09:19:24 +02:00
LemonJ
2fd629654f add missing allocator safety in alloc crate 2025-01-21 16:25:56 +08:00
Urgau
656d1cce7e alloc: add #![warn(unreachable_pub)] 2025-01-20 18:50:56 +01:00
Marijn Schouten
c282ac8336
Fix whitespace 2025-01-19 16:45:07 +01:00
Marijn Schouten
01d1aeff7b
document order of items in iterator from drain
fixes 135710
2025-01-19 14:07:32 +01:00
Matthias Krüger
87b3671ce9
Rollup merge of #134496 - DiuDiu777:fix-doc, r=ibraheemdev
Update documentation for Arc::from_raw, Arc::increment_strong_count, and Arc::decrement_strong_count to clarify allocator requirement

### Related Issue:
This update addresses parts of the issue raised in [#134242](https://github.com/rust-lang/rust/issues/134242), where Arc's documentation lacks `Global Allocator` safety descriptions for three APIs. And this was confirmed by ```@workingjubilee``` :
> Wait, nevermind. I apparently forgot the `increment_strong_count` is implicitly A = Global. Ugh. Another reason these things are hard to track, unfortunately.

### PR Description
This PR updates the document for the following APIs:
- `Arc::from_raw`
- `Arc::increment_strong_count`
- `Arc::decrement_strong_count`

These APIs currently lack an important piece of documentation: **the raw pointer must point to a block of memory allocated by the global allocator**. This crucial detail is specified in the source code but is not reflected in the documentation, which could lead to confusion or incorrect usage by users.

### Problem:
The following example demonstrates the potential confusion caused by the lack of documentation:

```rust
#![feature(allocator_api)]
use std::alloc::{Allocator,AllocError, Layout};
use std::ptr::NonNull;
use std::sync::Arc;

struct LocalAllocator {
    memory: NonNull<u8>,
    size: usize,
}

impl LocalAllocator {
    fn new(size: usize) -> Self {
        Self {
            memory: unsafe { NonNull::new_unchecked(&mut 0u8 as *mut u8) },
            size,
        }
    }
}

unsafe impl Allocator for LocalAllocator {
    fn allocate(&self, _layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
        Ok(NonNull::slice_from_raw_parts(self.memory, self.size))
    }

    unsafe fn deallocate(&self, _ptr: NonNull<u8>, _layout: Layout) {
    }
}

fn main() {
    let allocator = LocalAllocator::new(64);
    let arc = Arc::new_in(5, &allocator); // Here, allocator could be any non-global allocator
    let ptr = Arc::into_raw(arc);

    unsafe {
        Arc::increment_strong_count(ptr);
        let arc = Arc::from_raw(ptr);
        assert_eq!(2, Arc::strong_count(&arc)); // Failed here!
    }
}
```
2025-01-16 17:00:45 +01:00
ClearLove
48e671ec88
fix typo in library/alloc/src/sync.rs
Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
2025-01-16 15:16:43 +08:00
Trevor Gross
f6a2db8e1b Update compiler-builtins to 0.1.143
0.1.142 fixes an issue parsing optimization flags, and 0.1.143 changes
`__rust_[ui]128_*` builtins to use a C-safe signature.
2025-01-15 04:02:19 +00:00
Trevor Gross
fcc34b2c44 Update compiler-builtins to 0.1.141
0.1.141 syncs changes from `libm`. Most of the `libm` changes are
testing- or configuration-related.
2025-01-14 18:36:45 +00:00
Matthias Krüger
bf228a87ff
Rollup merge of #135381 - cod10129:vec-splice-doc, r=tgross35
Add an example for `Vec::splice` inserting elements without removing

This example clearly showcases how `splice` can be used to insert multiple elements efficiently at an index into a vector.

Fixes #135369.

The added example:

> Using `splice` to insert new items into a vector efficiently at a specific position indicated by an empty range:
> ```rust
> let mut v = vec![1, 5];
> let new = [2, 3, 4];
> v.splice(1..1, new);
> assert_eq!(v, [1, 2, 3, 4, 5]);
> ```

`@rustbot` label A-docs A-collections
2025-01-14 07:56:23 +01:00
cod10129
b11f87a53c Add another Vec::splice example
Add an example for using splice to insert multiple elements efficiently into a vector.
2025-01-13 17:37:09 -06:00
Ben Kimock
6024a06dba Update the explanation for why we use box_new in vec! 2025-01-12 13:17:16 -05:00
bors
7bb9888953 Auto merge of #135402 - matthiaskrgr:rollup-cz7hs13, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #129259 (Add inherent versions of MaybeUninit methods for slices)
 - #135374 (Suggest typo fix when trait path expression is typo'ed)
 - #135377 (Make MIR cleanup for functions with impossible predicates into a real MIR pass)
 - #135378 (Remove a bunch of diagnostic stashing that doesn't do anything)
 - #135397 (compiletest: add erroneous variant to `string_enum`s conversions error)
 - #135398 (add more crash tests)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-01-12 14:43:10 +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
Frank Steffahn
df57d65c70 Make UniqueRc invariant for soundness 2025-01-11 22:36:25 +01: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
76780fa10e Support no_rc, no_sync, and no_global_oom_handling
For now, apply `no_global_oom_handling` to all of
library/alloc/src/bstr.rs . We can make it more fine-grained later.
2025-01-11 06:35:21 +02:00
Josh Triplett
fc34bea69d Add #[cfg(not(test))] to some impls to work around https://github.com/rust-lang/rust/issues/135100 2025-01-11 06:35:21 +02: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
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
joboet
4426e9a3c2
alloc: remove unsound IsZero for raw pointers
Fixes #135338
2025-01-10 18:48:48 +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
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
Esteban Küber
eb917ea24d Remove some unnecessary .into() calls 2025-01-08 21:19:28 +00: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
Jacob Pratt
e7ee58243a
Rollup merge of #133057 - tisonkun:into-chars, r=Amanieu
Impl String::into_chars

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

r? `@programmerjake` `@kennytm` `@Amanieu`

This refers to https://github.com/rust-lang/libs-team/issues/268

Before adding tests and creating a tracking issue, I'd like to reach a consensus on the implementation direction and two questions:

1. Whether we'd add a `String::into_char_indices` method also?
2. See inline comment.
2025-01-08 00:52:44 -05:00
Jubilee
5be6c9bc12
Rollup merge of #135104 - the8472:disable-in-place-iter-for-flatten, r=Mark-Simulacrum
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.

This is a fix for #135103 that removes the specialization trait impls without removing some supporting parts. I've kept it small so it can be easily backported. I'll either remove the remaining parts or think of a way to recover the optimization in a separate PR.
2025-01-04 17:23:16 -08:00
The 8472
1ed0ea459d add regression test for unsound Flatten/FlatMap specialization 2025-01-04 19:44:49 +01: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
Ralf Jung
ac9cb908ac turn rustc_box into an intrinsic 2025-01-03 12:01:31 +01:00
LemonJ
a5494a8e6c fix doc for missing Box allocator consistency 2025-01-02 11:12:31 +08:00
Matthias Krüger
344a61e69b
Rollup merge of #134884 - calciumbe:patch1, r=jieyouxu
Fix typos

Hello, I fix some typos in docs and comments. Thank you very much.
2024-12-29 21:18:07 +01:00
calciumbe
4f8bebd6b5
fix: typos
Signed-off-by: calciumbe <192480234+calciumbe@users.noreply.github.com>
2024-12-29 21:35:02 +08:00
Lukas Markeffsky
11ad6ff3cb docs: inline alloc::ffi::c_str types to alloc::ffi 2024-12-28 15:42:39 +01:00
Stuart Cook
d21cdf78f9
Rollup merge of #134832 - tgross35:update-builtins, r=tgross35
Update `compiler-builtins` to 0.1.140

Nothing significant here, just syncing the following small changes:

- https://github.com/rust-lang/compiler-builtins/pull/727
- https://github.com/rust-lang/compiler-builtins/pull/730
- https://github.com/rust-lang/compiler-builtins/pull/736
- https://github.com/rust-lang/compiler-builtins/pull/737
2024-12-28 16:50:38 +11:00
chloefeal
bc05424528
Update library/alloc/tests/sort/tests.rs
Co-authored-by: David Tolnay <dtolnay@gmail.com>
2024-12-28 10:37:02 +08:00