3333 Commits

Author SHA1 Message Date
bors
040a98af70 Auto merge of #144086 - clubby789:alloc-zeroed, r=nikic
Pass `alloc-variant-zeroed` to LLVM

Makes use of https://github.com/llvm/llvm-project/pull/138299 (once we pull in a version of LLVM with this attribute). ~~Unfortunately also requires https://github.com/llvm/llvm-project/pull/149336 to work.~~

Closes rust-lang/rust#104847
2025-08-20 17:16:34 +00:00
clubby789
8ea3b09381 Pass alloc-variant-zeroed to LLVM 2025-08-20 17:08:46 +01:00
Jacob Pratt
41e40f3630
Rollup merge of #143717 - Jules-Bertholet:pin-default, r=dtolnay
Add `Default` impls for `Pin`ned `Box`, `Rc`, `Arc`

Fixes rust-lang/rust#143688.

`@rustbot` label T-libs-api needs-fcp

Also needs a crater run, as the `Box` impls could theoretically be breaking due to `#[fundamental]` (though a [cursory search](https://github.com/search?q=%2Fimpl%28%3C.*%3E%29%3F+Default+for+Pin%3C%2F+path%3A*.rs&type=code) suggests this is unlikely to cause issues).
2025-08-15 18:13:26 -04:00
ltdk
d6945f6d8c Add cast_init and cast_uninit methods for pointers 2025-08-12 16:57:56 -04:00
SabrinaJewson
1ce4b370e4
Handle the capacity == 0 case 2025-08-12 05:12:34 +01:00
SabrinaJewson
45e2449b2a
Respond to review comments 2025-08-11 19:02:00 +01:00
SabrinaJewson
19df24b3b8
Make explicit guarantees about Vec’s allocator
This commit amends the documentation of `Vec::as_mut_ptr` and
`Vec::into_raw_parts` to make it explicit that such calls may be paired
with calls to `dealloc` with a suitable layout. This guarantee was
effectively already provided by the docs of `Vec::from_raw_parts`
mentioning `alloc`.

Additionally, we copy-paste and adjust the “Memory layout” section from
the documentation of `std::boxed` to `std::vec`. This explains the allocator
guarantees in more detail.
2025-08-11 17:15:53 +01:00
Ada Alakbarova
c0a3e4802a
{BTree,Hash}Map: add "Entry API" section heading 2025-08-09 19:41:32 +02:00
bors
cd434309ef Auto merge of #144997 - BoxyUwU:bootstrap_bump, r=Mark-Simulacrum
bump bootstrap compiler to 1.90 beta

There were significantly less `cfg(bootstrap)` and `cfg(not(bootstrap))` this release. Presumably due to the fact that we change the bootstrap stage orderings to reduce the need for them and it was successful 🙏
2025-08-07 10:56:05 +00:00
Boxy
9ccc9f177e replace version placeholder 2025-08-06 13:22:38 +01:00
Jonathan Brouwer
b3317dd055
Correct the use of must_use on btree::IterMut
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-08-04 22:20:30 +02:00
Samuel Tardieu
d082ff4c04
Rollup merge of #144478 - joshtriplett:doc-code-formatting-prep, r=Amanieu
Improve formatting of doc code blocks

We don't currently apply automatic formatting to doc comment code blocks. As a
result, it has built up various idiosyncracies, which make such automatic
formatting difficult. Some of those idiosyncracies also make things harder for
human readers or other tools.

This PR makes a few improvements to doc code formatting, in the hopes of making
future automatic formatting easier, as well as in many cases providing net
readability improvements.

I would suggest reading each commit separately, as each commit contains one
class of changes.
2025-08-02 11:24:24 +02:00
Stuart Cook
dc8aec4cf2
Rollup merge of #135975 - balt-dev:master, r=tgross35
Implement `push_mut`

Implementation of rust-lang/rust#135974.
2025-07-31 15:41:58 +10:00
Balt
3ccfa14e48 Implement push_mut 2025-07-30 12:26:16 -05:00
Scott McMurray
173926da2b Remove [T]::array_chunks(_mut) 2025-07-27 23:03:07 -07:00
Josh Triplett
b6c54a97b3 Avoid placing // FIXME comments inside doc code blocks
This leads tools like rustfmt to get confused, because the doc code
block effectively spans two doc comments. As a result, the tools think
the first code block is unclosed, and the subsequent terminator opens a
new block.

Move the FIXME comments outside the doc code blocks, instead.
2025-07-25 22:02:09 -07:00
Josh Triplett
715088094c Improve and regularize comment placement in doc code
Because doc code does not get automatically formatted, some doc code has
creative placements of comments that automatic formatting can't handle.
Reformat those comments to make the resulting code support standard Rust
formatting without breaking; this is generally an improvement to
readability as well.

Some comments are not indented to the prevailing indent, and are instead
aligned under some bit of code. Indent them to the prevailing indent,
and put spaces *inside* the comments to align them with code.

Some comments span several lines of code (which aren't the line the
comment is about) and expect alignment. Reformat them into one comment
not broken up by unrelated intervening code.

Some comments are placed on the same line as an opening brace, placing
them effectively inside the subsequent block, such that formatting would
typically format them like a line of that block. Move those comments to
attach them to what they apply to.

Some comments are placed on the same line as a one-line braced block,
effectively attaching them to the closing brace, even though they're
about the code inside the block. Reformat to make sure the comment will
stay on the same line as the code it's commenting.
2025-07-25 22:02:09 -07:00
Trevor Gross
51c5f191de Remove compiler-builtins-mangled-names
This config was added in 207de019dc67 ("libary: Forward
compiler-builtins "asm"  and "mangled-names" feature") but it does not
appear this has ever been used. The PR adding it (RUST-78472) says that
this was exposed to help with configuration and points at the [Hermit
Cargo config], but as far as I can tell, this feature name has never
been mentioned in that repository's git history.

Thus, clean up a seemingly unneeded feature.

[Hermit Cargo config]: ab2b830930/.cargo/config
2025-07-25 19:21:20 -05:00
Trevor Gross
a076bd8a61 Remove compiler-builtins-no-asm
This feature used to be for when Cranelift didn't support inline
assembly, but its last uses were removed in 52933e0bd200 ("Don't disable
inline asm usage in compiler-builtins when the cranelift backend is
enabled"). and cba05a7a14b3 ("Support naked functions").

This doesn't remove the feature from the `compiler-builtins` crate, that
will be done separately in the subtree repo.
2025-07-25 17:08:57 -05:00
Guillaume Gomez
a27f3e3fd1 Rename tests/codegen into tests/codegen-llvm 2025-07-22 14:28:48 +02:00
Matthias Krüger
744ca5959a
Rollup merge of #143909 - nik-rev:patch-1, r=jhpratt
docs(alloc::fmt): Make type optional, instead of matching empty string

Think this is clearer.

Noticed as I was implementing [`tree-sitter-rust-format-args`](https://github.com/nik-rev/tree-sitter-rust-format-args), and attempting to match the empty string results in an error.
2025-07-18 14:49:19 +02:00
León Orell Valerian Liehr
83288db888
Rollup merge of #143595 - fee1-dead-contrib:push-sylpykzkmynr, r=RalfJung,fee1-dead
add `const_make_global`; err for `const_allocate` ptrs if didn't call

Implements as discussed on Zulip: [#t-compiler/const-eval > const heap](https://rust-lang.zulipchat.com/#narrow/channel/146212-t-compiler.2Fconst-eval/topic/const.20heap/with/527125421)

r? ```@rust-lang/wg-const-eval```

Fixes https://github.com/rust-lang/rust/issues/129233
2025-07-17 03:58:30 +02:00
Jules Bertholet
87dd4695fe
Add Default impls for Pinned Box, Rc, Arc 2025-07-15 17:41:31 -04:00
Deadbeef
3f2dc2bd1a add const_make_global; err for const_allocate ptrs if didn't call
Co-Authored-By: Ralf Jung <post@ralfj.de>
Co-Authored-By: Oli Scherer <github333195615777966@oli-obk.de>
2025-07-16 00:32:12 +08:00
bors
3014e79f9c Auto merge of #143877 - xizheyin:143813, r=scottmcm,saethlin
`std::vec`: Add UB check for `set_len`, `from_raw_parts_in`, and etc.

Closes rust-lang/rust#143813

I noticed that `from_parts_in` do the similar things like `from_raw_parts_in`, so I add the UB check in the last commit. If it is not appropriate, I will remove it.

And I fix a typo in the first commit.

r? `@scottmcm`
2025-07-15 14:47:10 +00:00
Nik Revenco
f5485e5564
docs(alloc::fmt): Make type optional, instead of matching the empty string 2025-07-13 23:24:27 +01:00
Deadbeef
6b02597ed3 update issue number for const_trait_impl 2025-07-13 23:55:06 +08:00
xizheyin
48caa5f889
std::vec: Add UB check in from_parts_in
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-07-13 16:18:56 +08:00
xizheyin
090c177003
std::vec: Add UB check in from_raw_parts_in
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-07-13 16:17:43 +08:00
xizheyin
1cab09ed9c
std::vec: Upgrade debug_assert to UB check in set_len
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-07-13 16:06:53 +08:00
xizheyin
10866f4617
Fix typo in std::vec
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-07-13 15:51:32 +08:00
bors
f838cbc06d Auto merge of #134628 - estebank:const-default, r=oli-obk
Make `Default` const and add some `const Default` impls

Full list of `impl const Default` types:

- ()
- bool
- char
- std::ascii::Char
- usize
- u8
- u16
- u32
- u64
- u128
- i8
- i16
- i32
- i64
- i128
- f16
- f32
- f64
- f128
- std::marker::PhantomData<T>
- Option<T>
- std::iter::Empty<T>
- std::ptr::Alignment
- &[T]
- &mut [T]
- &str
- &mut str
- String
- Vec<T>
2025-07-08 14:04:40 +00:00
Matthias Krüger
fd05071727
Rollup merge of #143608 - codexarafat:fix-string-doc, r=Noratrieb
Fix in std::String docs

This PR removes the word “else” from the sentence ('something else similar') in the String documentation to improve clarity.
Fixes rust-lang/rust#143579.
2025-07-08 03:09:59 +02:00
Matthias Krüger
d41f046de5
Rollup merge of #142098 - GuillaumeGomez:int_format_into, r=Amanieu
Implement `int_format_into` feature

I took over rust-lang/rust#138338 with `@madhav-madhusoodanan's` approval.

Since https://github.com/rust-lang/rust/pull/136264, a lot of changes happened so I made use of them to reduce the number of changes.

ACP approval: https://github.com/rust-lang/libs-team/issues/546#issuecomment-2707244569

## Associated Issue
- https://github.com/rust-lang/rust/issues/138215

r? `@hanna-kruppe`
2025-07-08 03:09:56 +02:00
Esteban Küber
c3301503b9 Make Default const and add some const Default impls
Full list of `impl const Default` types:

- ()
- bool
- char
- Cell
- std::ascii::Char
- usize
- u8
- u16
- u32
- u64
- u128
- i8
- i16
- i32
- i64
- i128
- f16
- f32
- f64
- f128
- std::marker::PhantomData<T>
- Option<T>
- std::iter::Empty<T>
- std::ptr::Alignment
- &[T]
- &mut [T]
- &str
- &mut str
- String
- Vec<T>
2025-07-07 22:09:37 +00:00
Md. Yeasin Arafat
2bff99c275 Fix in String docs: remove 'else' from 'something else similar' 2025-07-08 01:05:16 +06:00
Joshua Gentry
39575d39c5 Renamed retain_mut to retain on LinkedList as mentioned in the ACP 2025-07-06 10:40:55 -04:00
Matthias Krüger
2faf66d091
Rollup merge of #143387 - dpaoliello:shouldpanicfn, r=bjorn3
Make __rust_alloc_error_handler_should_panic a function

Fixes rust-lang/rust#143253

`__rust_alloc_error_handler_should_panic` is a static but was being exported as a function.

For most targets this doesn't matter, but Arm64EC Windows uses different decorations for exported variables vs functions, hence it fails to link when `-Z oom=abort` is enabled.

We've had issues in the past with statics like this (see rust-lang/rust#141061) but the tldr; is that Arm64EC needs symbols correctly exported as either a function or data, and data MUST and MUST ONLY be marked `dllimport` when the symbol is being imported from another binary, which is non-trivial to calculate for these compiler-generated statics.

So, instead, the easiest thing to do is to make `__rust_alloc_error_handler_should_panic` a function instead.

Since `__rust_alloc_error_handler_should_panic` isn't involved in any linking shenanigans, I've marked it as `AlwaysInline` with the hopes that the various backends will see that it is just returning a constant and perform the same optimizations as the previous implementation.

r? `@bjorn3`
2025-07-04 16:22:36 +02:00
Michael Goulet
e2e3f5809b Remove PointerLike trait 2025-07-03 20:03:49 +00:00
Daniel Paoliello
2b22d0f0d2 Make __rust_alloc_error_handler_should_panic a function 2025-07-03 10:52:21 -07:00
Guillaume Gomez
82c6037b2a Implement int_format_into feature 2025-07-03 18:57:16 +02:00
bors
25face9808 Auto merge of #143338 - matthiaskrgr:rollup-ykaxh04, r=matthiaskrgr
Rollup of 11 pull requests

Successful merges:

 - rust-lang/rust#131923 (Derive `Copy` and `Hash` for `IntErrorKind`)
 - rust-lang/rust#138340 (Remove some unsized tuple impls now that we don't support unsizing tuples anymore)
 - rust-lang/rust#141219 (Change `{Box,Arc,Rc,Weak}::into_raw` to only work with `A = Global`)
 - rust-lang/rust#142212 (bootstrap: validate `rust.codegen-backends` & `target.<triple>.codegen-backends`)
 - rust-lang/rust#142237 (Detect more cases of unused_parens around types)
 - rust-lang/rust#142964 (Attribute rework: a parser for single attributes without arguments)
 - rust-lang/rust#143070 (Rewrite `macro_rules!` parser to not use the MBE engine itself)
 - rust-lang/rust#143235 (Assemble const bounds via normal item bounds in old solver too)
 - rust-lang/rust#143261 (Feed `explicit_predicates_of` instead of `predicates_of`)
 - rust-lang/rust#143276 (loop match: handle opaque patterns)
 - rust-lang/rust#143306 (Add `track_caller` attributes to trace origin of Clippy lints)

r? `@ghost`
`@rustbot` modify labels: rollup

try-job: aarch64-apple
try-job: x86_64-msvc-1
try-job: x86_64-gnu
try-job: dist-i586-gnu-i586-i686-musl
try-job: test-various
2025-07-02 23:29:03 +00:00
Matthias Krüger
6a31e693eb
Rollup merge of #142138 - ashivaram23:vec_into_chunks, r=scottmcm
Add `Vec::into_chunks`

Tracking issue rust-lang/rust#142137
2025-07-02 19:28:04 +02:00
Ralf Jung
8797d54812 make Box::into_raw compatible with Stacked Borrows again 2025-07-01 19:54:38 +02:00
Amanieu d'Antras
15bd619d5f Change {Box,Arc,Rc,Weak}::into_raw to only work with A = Global
Also applies to `Vec::into_raw_parts`.

The expectation is that you can round-trip these methods with
`from_raw`, but this is only true when using the global allocator. With
custom allocators you should instead be using
`into_raw_with_allocator` and `from_raw_in`.

The implementation of `Box::leak` is changed to use
`Box::into_raw_with_allocator` and explicitly leak the allocator (which
was already the existing behavior). This is because, for `leak` to be
safe, the allocator must not free its underlying backing store. The
`Allocator` trait only guarantees that allocated memory remains valid
until the allocator is dropped.
2025-07-01 18:25:30 +02:00
Cheng Xu
cd1713ebba
BTreeSet: remove duplicated code by reusing from_sorted_iter
The method `BTreeSet::from_sorted_iter` was introduced in 49ccb7519f55bd117d2ab50b7a030637f380aec6,
but it was not consistently used throughout the codebase. As a result, some code redundantly reimplemented its logic.
This commit fixes the problem.
2025-06-27 11:12:32 -07:00
Michael Goulet
58cda76585
Rollup merge of #142700 - theemathas:remove-weak-comment, r=ibraheemdev
Remove incorrect comments in `Weak`

It is currently possible to create a dangling `Weak` to a DST by calling `Weak::new()` for a sized type, then doing an unsized coercion. Therefore, the comments are wrong.

These comments were added in <https://github.com/rust-lang/rust/pull/73845>. As far as I can tell, the guarantee in the comment was only previously used in the `as_ptr` method. However, the current implementation of `as_ptr` no longer relies on this guarantee.
2025-06-26 20:15:20 -04:00
Guillaume Gomez
30550c048d
Rollup merge of #137268 - bjoernager:c-string-eq-c-str, r=Amanieu
Allow comparisons between `CStr`, `CString`, and `Cow<CStr>`.

Closes: #137265

This PR adds the trait implementations proposed in the [ACP](https://github.com/rust-lang/libs-team/issues/517/) under the `c_string_eq_c_str` feature gate:

```rust
// core::ffi

impl PartialEq<&Self> for CStr;

impl PartialEq<CString> for CStr;

impl PartialEq<Cow<'_, Self>> for CStr;

// alloc::ffi

impl PartialEq<CStr> for CString;

impl PartialEq<&CStr> for CString;

impl PartialEq<Cow<'_, CStr>> for CString;

// alloc::borrow

impl PartialEq<CStr> for Cow<'_, CStr>;

impl PartialEq<&CStr> for Cow<'_, CStr>;

impl PartialEq<CString> for Cow<'_, CStr>;
```

As I understand it, stable traits cannot be unstably implemented for stable types, and we would thereby be forced to skip the FCP and directly stabilise these implementations (as is done in this PR).

(`@joshtriplett` mentioned that Crater may have to be run).
2025-06-24 15:39:37 +02:00
bors
8387d61a6e Auto merge of #142728 - kornelski:string-track, r=tgross35
Let String pass #[track_caller] to its Vec calls

I've added `#[track_caller]` to `String` methods that delegate to `Vec` methods that already have `#[track_caller]`.

I've also added `#[track_caller]` to methods that have `assert!` or `panic!` due to invalid inputs.
2025-06-22 23:30:10 +00:00
Jakub Beránek
74cea635e1
Rollup merge of #142764 - ChaiTRex:ilog_10_to_ilog10, r=workingjubilee
Convert `ilog(10)` to `ilog10()`

Except in tests, convert `integer.ilog(10)` to `integer.ilog10()` for better speed and to provide better examples of code that efficiently counts decimal digits. I couldn't find any instances of `integer.ilog(2)`.
2025-06-20 20:03:24 +02:00