Commit Graph

9899 Commits

Author SHA1 Message Date
Jonathan Brouwer 663d8432f1 Rollup merge of #145933 - GrigorenkoPV:thing_as_thing, r=Amanieu
Expand `str_as_str` to more types

Tracking issue: rust-lang/rust#130366
ACP: https://github.com/rust-lang/libs-team/issues/643

This PR expands `str_from_str` feature and adds analogous methods to more types. Namely:
- `&CStr`
- `&[T]`, `&mut [T]`
- `&OsStr`
- `&Path`
- `&ByteStr`, `&mut ByteStr` (tracking issue:  rust-lang/rust#134915) (technically was not part of ACP)
2025-12-18 18:37:13 +01:00
Jonathan Brouwer 4ea24671ed Rollup merge of #150113 - Darksonn:pin-coerce-unsized-to-150112, r=jackh726
Update tracking issue for PinCoerceUnsized

This uses the newly created tracking issue https://github.com/rust-lang/rust/issues/150112.

Please see https://github.com/rust-lang/rust/issues/68015#issuecomment-3665424732 for motivation.

r? ``@jackh726``
2025-12-17 23:31:22 +01:00
Alice Ryhl 78f52c1d12 Update tracking issue for PinCoerceUnsized 2025-12-17 20:26:41 +00:00
Matthias Krüger 92bd07b17d Rollup merge of #150096 - Amanieu:revert-borrowedbuf, r=ChrisDenton
Revert #148937

https://github.com/rust-lang/rust/issues/148937:  Remove initialized-bytes tracking from `BorrowedBuf` and `BorrowedCursor`

This caused several performance regressions because of existing code which uses `Read::read` and therefore requires full buffer initialization. This is particularly a problem when the same buffer is re-used for multiple read calls since this means it needs to be fully re-initialized each time.

There is still some benefit to landing the API changes, but we will have to add private APIs so that the existing infrastructure can track and avoid redundant initialization.
2025-12-17 18:46:19 +01:00
Matthias Krüger 15c54bc004 Rollup merge of #150088 - folkertdev:riscv-pause-miri, r=RalfJung
miri: add `miri_spin_loop` to make `hint::spin_loop` work consistently

fixes https://github.com/rust-lang/rust/issues/150050

Always use the same implementation when running miri (regardless of target, for consistency). This implementation yields the current thread to try find actual bugs.

r? RalfJung
2025-12-17 18:46:18 +01:00
Folkert de Vries c7dd19b8d6 add miri_spin_loop to make hint::spin_loop work consistently 2025-12-17 16:00:39 +01:00
Amanieu d'Antras 4b07875505 Revert #148937 (Remove initialized-bytes tracking from BorrowedBuf and BorrowedCursor)
This caused several performance regressions because of existing code
which uses `Read::read` and therefore requires full buffer
initialization. This is particularly a problem when the same buffer is
re-used for multiple read calls since this means it needs to be fully
re-initialized each time.

There is still some benefit to landing the API changes, but we will have
to add private APIs so that the existing infrastructure can
track and avoid redundant initialization.
2025-12-17 14:34:56 +00:00
Jonathan Brouwer 25b73c4943 Rollup merge of #150033 - izagawd:try_as_dyn, r=oli-obk
Add try_as_dyn and try_as_dyn_mut

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

Continuation of: https://github.com/rust-lang/rust/pull/144363
2025-12-16 20:21:10 +01:00
Jonathan Brouwer ef2c71c3cc Rollup merge of #149967 - folkertdev:va-list-hexagon, r=workingjubilee
custom `VaList` layout for Hexagon

I noticed while browsing LLVM source that we use an incorrect `VaList` definition for the musl hexagon target.

relevant links

- https://github.com/llvm/llvm-project/blob/0cdc1b6dd4a870fc41d4b15ad97e0001882aba58/clang/include/clang/Basic/TargetInfo.h#L333
- https://github.com/llvm/llvm-project/blob/0cdc1b6dd4a870fc41d4b15ad97e0001882aba58/clang/lib/CodeGen/Targets/Hexagon.cpp#L407-L417

cc target maintainer `@androm3da` can you confirm that this looks OK? In particular the `#[rustc_pass_indirectly_in_non_rustic_abis]` attribute is used to simulate pointer decay (like if the struct were wrapped in a 1-element array in C). The clang comment suggests that the Tag is wrapped in such a single-element array, but I haven't actually been able to confirm it.

For stabilizing `c_variadic` (on the hexagon targets) we will also need a custom `va_arg` implementation to mirror the one in `clang` in [va_arg.rs](https://github.com/rust-lang/rust/blob/main/compiler/rustc_codegen_llvm/src/va_arg.rs). Would you be able to contribute one?

r? `@workingjubilee`
2025-12-16 20:21:08 +01:00
Jonathan Brouwer d93b93bcb0 Rollup merge of #147939 - theemathas:add-const-supertrait, r=oli-obk
Make `const BorrowMut` require `const Borrow` and make `const Fn` require `const FnMut`

This makes it consistent with other const traits in the standard library with supertraits.

I am currently unsure if `const FnMut` should require `const FnOnce` or not. See [zulip discussion](https://rust-lang.zulipchat.com/#narrow/channel/146212-t-compiler.2Fconst-eval/topic/.5Bconst.5D.20implied.20bounds.20for.20implicit.20trait.20bounds/near/546152748).
2025-12-16 20:21:05 +01:00
Ivar Flakstad d5bf1a4c9a Introduce vtable_for intrinsic and use it to implement try_as_dyn and try_as_dyn_mut for fallible coercion from &T / &mut T to &dyn Trait. 2025-12-16 06:39:58 -04:00
Folkert de Vries 023f38fe73 custom VaList layout for Hexagon 2025-12-15 20:00:05 +01:00
Matthias Krüger d05ddf5647 Rollup merge of #149885 - inkreasing:push-ovrwrllvzvmw, r=joboet
replace addr_of_mut with &raw mut in maybeuninit docs

In the docs for `addr_of_mut` it says that the macro is "soft-deprecated" so maybe the std docs should stop recommending it.
I searched for other places where this is used, but didn't find any in public stable documentation.
2025-12-14 20:04:56 +01:00
Matthias Krüger a8460d0cf2 Rollup merge of #149837 - scottmcm:wrapping-shift-docs, r=workingjubilee
Update `wrapping_sh[lr]` docs and examples

Inspired by [#general > `Source` link for `core` items is often inscrutable @ 💬][zulip-thread] I wanted to add some more examples of the actual wrapping as well as update the documentation to emphasize that the behaviour is unusual.

In particular, now that `unbounded_sh[lr]` is stable, point people trying to avoid panics to that instead, since it behaves less weirdly.

[zulip-thread]: https://rust-lang.zulipchat.com/#narrow/channel/122651-general/topic/.60Source.60.20link.20for.20.60core.60.20items.20is.20often.20inscrutable/near/562774474
2025-12-14 20:04:55 +01:00
Chris Denton 01e40d6755 Rollup merge of #148755 - nxsaken:const_drop_guard, r=dtolnay
Constify `DropGuard::dismiss` and trait impls

Feature: `drop_guard` (rust-lang/rust#144426), `const_convert` (rust-lang/rust#143773), `const_drop_guard` (no tracking issue yet)

Constifies `DropGuard::dismiss` and trait impls.
I reused `const_convert` (rust-lang/rust#143773) for the `Deref*` impls.
2025-12-14 09:18:26 +00:00
bors 3f4dc1e02d Auto merge of #146348 - jdonszelmann:eiiv3, r=lcnr,oli-obk
Externally implementable items

Supersedes https://github.com/rust-lang/rust/pull/140010
Tracking issue: https://github.com/rust-lang/rust/issues/125418

Getting started:

```rust
#![feature(eii)]

#[eii(eii1)]
pub fn decl1(x: u64)
// body optional (it's the default)
{
    println!("default {x}");
}

// in another crate, maybe
#[eii1]
pub fn decl2(x: u64) {
    println!("explicit {x}");
}

fn main() {
    decl1(4);
}
```

- tiny perf regression, underlying issue makes multiple things in the compiler slow, not just EII, planning to solve those separately.
- No codegen_gcc support, they don't have bindings for weak symbols yet but could
- No windows support yet for weak definitions

This PR merges the implementation of EII for just llvm + not windows, doesn't yet contain like a new panic handler implementation or alloc handler. With this implementation, it would support implementing the panic handler in terms of EII already since it requires no default implementation so no weak symbols

The PR has been open in various forms for about a year now, but I feel that having some implementation merged to build upon
2025-12-14 04:20:26 +00:00
increasing ebbb4d5ea4 replace addr_of_mut with &raw mut in maybeuninit docs 2025-12-13 13:27:10 +01:00
nxsaken 0ecf91a701 Use an explicit receiver in DropGuard::dismiss 2025-12-13 14:00:44 +04:00
Matthias Krüger b826d06771 Rollup merge of #149791 - clubby789:cfg-bool-lints, r=jdonszelmann
Remove uses of `cfg({any()/all()})`

~~This implements the followup warning suggested in https://github.com/rust-lang/rfcs/pull/3695~~
~~Lint against an empty `cfg(any/all)`, suggest the boolean literal equivalents.~~
https://github.com/rust-lang/rust/pull/149791#issuecomment-3638624348

Tracking issue: https://github.com/rust-lang/rust/issues/131204
2025-12-12 12:19:09 +01:00
Jana Dönszelmann 52e0bfccb0 rename feature gate to extern_item_impls 2025-12-12 11:32:35 +01:00
Jana Dönszelmann 92c03a26fd EII (builtin) macros in std 2025-12-12 11:17:33 +01:00
Scott McMurray f9b830c102 Add more basic shift examples 2025-12-10 18:59:52 -08:00
Jamie Hill-Daniel c96ff2d429 Remove uses of cfg(any()/all()) 2025-12-10 23:41:19 +00:00
Matthias Krüger 03028df750 Rollup merge of #149839 - theemathas:trivial-clone-pointee-sized, r=joboet
Use `PointeeSized` bound for `TrivialClone` impls

These `TrivialClone` impls previously had `?Sized` bounds, which are different from the `PointeeSized` bounds on the corresponding `Clone` and `Copy` impls. So, I've changed the `?Sized` bounds into `PointeeSized` bounds.

This mistake was made presumably because the `TrivialClone` PR (https://github.com/rust-lang/rust/pull/135634) was opened in Jan 2025, but merged in Nov 2025. During that time, the sized hierachy PR (https://github.com/rust-lang/rust/pull/137944) was opened in Mar 2025, and merged in Jun 2025. The `TrivialClone` PR was not updated to account for the sized hierachy changes.

r? `@joboet`
2025-12-10 17:16:50 +01:00
Matthias Krüger 26ae47502a Rollup merge of #148052 - tgross35:stabilize-const_mul_add, r=RalfJung
Stabilize `const_mul_add`

Newly stable API:

```rust
impl {f32, f64} {
    pub const fn mul_add(self, a: Self, b: Self) -> Self;
}
```

This includes making the intrinsics `fmaf{16,32,64,128}` const stable for indirect use, matching similar intrinsics.

Closes: https://github.com/rust-lang/rust/issues/146724
2025-12-10 17:16:46 +01:00
Theemathas Chirananthavat 9e4e9e4390 Use PointeeSized bound for TrivialClone impls
These `TrivialClone` impls previously had `?Sized` bounds, which are
different from the `PointeeSized` bounds on the corresponding
`Clone` and `Copy` impls. So, I've changed the `?Sized` bounds into
`PointeeSized` bounds.

This mistake was made presumably because the `TrivialClone` PR
(https://github.com/rust-lang/rust/pull/135634) was opened in Jan 2025,
but merged in Nov 2025. During that time, the sized hierachy PR
(https://github.com/rust-lang/rust/pull/137944) was opened in Mar 2025,
and merged in Jun 2025. The `TrivialClone` PR was not updated to account
for the sized hierachy changes.
2025-12-10 15:38:16 +07:00
Scott McMurray ff43366dc2 Update wrapping_sh[lr] docs and examples 2025-12-10 00:23:11 -08:00
Matthias Krüger 3a3c7b580f Rollup merge of #149795 - estebank:let-else-std, r=workingjubilee
Use `let`...`else` instead of `match foo { ... _ => return };` and `if let ... else return` in std

Split off rust-lang/rust#148837.
2025-12-10 07:54:21 +01:00
Esteban Küber 0488690d3e Use let...else instead of match foo { ... _ => return }; and if let ... else return in std 2025-12-09 23:35:14 +00:00
Folkert de Vries b9e3e4162a remove explicit discriminants 2025-12-10 00:17:57 +01:00
Folkert de Vries 6407023007 Add a separate function for a non-temporal read prefetch 2025-12-10 00:08:54 +01:00
Folkert de Vries a3b78e0320 add core::hint::prefetch_{read, write}_{data, instruction}
well, we don't expose `prefetch_write_instruction`, that one doesn't really make sense in practice.
2025-12-10 00:08:54 +01:00
bors 03d7ad7dd6 Auto merge of #149750 - Zalathar:rollup-9qjiz5r, r=Zalathar
Rollup of 8 pull requests

Successful merges:

 - rust-lang/rust#148935 (Fix division syntax in doc comments)
 - rust-lang/rust#149207 (Add `ilog10` result range hints)
 - rust-lang/rust#149676 (Tidying up tests/ui/issues tests [3/N])
 - rust-lang/rust#149710 (Move ambient gdb discovery from compiletest to bootstrap)
 - rust-lang/rust#149714 (Check associated type where-clauses for lifetimes)
 - rust-lang/rust#149722 (contracts: fix lowering final declaration without trailing semicolon)
 - rust-lang/rust#149736 (contracts: clean up feature flag warning duplicated across tests)
 - rust-lang/rust#149739 (mailmap: add binarycat)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-12-08 06:27:26 +00:00
Stuart Cook ac729a4b18 Rollup merge of #149207 - EFanZh:add-ilog10-result-range-hints, r=Mark-Simulacrum
Add `ilog10` result range hints

This PR adds hints that the return value of `T::ilog10` will never exceed `T::MAX.ilog10()`.

This works because `ilog10` is a monotonically nondecreasing function, the maximum return value is reached at the max input value.
2025-12-08 11:46:23 +11:00
Stuart Cook 80b4c44f62 Rollup merge of #148935 - Wilfred:fix_remainder_docs, r=Mark-Simulacrum
Fix division syntax in doc comments

`mod` is a keyword in Rust, and since we're talking about remainders we should be using division syntax here.
2025-12-08 11:46:22 +11:00
bors 554952348a Auto merge of #147754 - Dan54:friendly-clamp, r=Mark-Simulacrum
Improve error message for std integer clamp() if min > max

For rust-lang/rust#142309: change the error message for `Ord::clamp()` for std integer types if min > max to be more useful.

Message is now `min > max. min = {min:?}, max = {max:?}`

Also add `#[track_caller]` to `clamp()`
2025-12-08 00:04:02 +00:00
bors 1d6c526bb0 Auto merge of #149690 - RustyYato:inline-layout-helper, r=saethlin
Add `#[inline]` to `Layout::is_size_align_valid`

Fixes rust-lang/rust#149687

r? `@saethlin`
2025-12-07 13:43:57 +00:00
RustyYato 5f9aca7e74 Add #[inline] to Layout::is_size_align_valid
add Alignment::new_unchecked::precondition_check to allowlist
2025-12-06 19:47:13 -06:00
bors ba86c0460b Auto merge of #149704 - matthiaskrgr:rollup-u4zhw99, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#146826 (Implement `Allocator` for `&mut A` where `A: Allocator + ?Sized`)
 - rust-lang/rust#148487 (add Option::into_flat_iter)
 - rust-lang/rust#148814 (stabilize `array_windows`)
 - rust-lang/rust#149401 (Fix `name()` functions for local defs in rustc_public)
 - rust-lang/rust#149683 (Fix armv8r-none-eabihf tier)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-12-06 12:25:12 +00:00
bors da2544bfbe Auto merge of #149495 - scottmcm:assume-filter-count, r=Mark-Simulacrum
Assume the returned value in `.filter(…).count()`

Similar to how this helps in `slice::Iter::position`, LLVM sometimes loses track of how high this can get, so for `TrustedLen` iterators tell it what the upper bound is.
2025-12-06 09:13:21 +00:00
Matthias Krüger 8a6f82efac Rollup merge of #148814 - bend-n:stabilize_array_windows, r=scottmcm
stabilize `array_windows`

Tracking issue: rust-lang/rust#75027
Closes: rust-lang/rust#75027
FCP completed: https://github.com/rust-lang/rust/issues/75027#issuecomment-3477510526
2025-12-06 09:57:59 +01:00
Matthias Krüger f278da8385 Rollup merge of #148487 - Qelxiros:148441-option-into-flat-iter, r=scottmcm
add Option::into_flat_iter

Tracking issue: rust-lang/rust#148441

I only implemented `into_flat_iter` in this PR, but I'd be happy to add `flat_iter` / `flat_iter_mut` (equivalent to calling `as_ref` / `as_mut` first) if those are desired. See rust-lang/libs-team#626 for context.
2025-12-06 09:57:58 +01:00
Matthias Krüger 865650a52f Rollup merge of #146826 - bluurryy:impl-allocator-for-mut-a, r=scottmcm
Implement `Allocator` for `&mut A` where `A: Allocator + ?Sized`

This is a breaking change to the unstable `allocator_api` feature. Tracking issue rust-lang/rust#32838.
It implements the accepted api change proposal from rust-lang/libs-team#508.

The code for the blanket implementation is the same as the one for `&A`, just with the `mut` added.
2025-12-06 09:57:57 +01:00
Jacob Pratt b53b824d06 Rollup merge of #149563 - RalfJung:f-min-max, r=tgross35
f*::min/max: fix comparing with libm and IEEE operations

What we document actually doesn't match what libm does any more, libm got "fixed"/changed in https://sourceware.org/bugzilla/show_bug.cgi?id=20947. So better remove the remark. Instead, explicitly call out that this is a mix of `minNum` and `minimumNumber`.

Also fix the intrinsics which incorrectly claimed to be like `minNum`, but their intended SNaN behavior is actually different from that.

r? `@tgross35`
2025-12-05 23:26:37 -05:00
bors 36b2369c91 Auto merge of #141980 - beetrees:va-list-proposal, r=workingjubilee
`c_variadic`: make `VaList` abi-compatible with C

tracking issue: https://github.com/rust-lang/rust/issues/44930
related PR: rust-lang/rust#144529

On some platforms, the C `va_list` type is actually a single-element array of a struct (on other platforms it is just a pointer). In C, arrays passed as function arguments expirience array-to-pointer decay, which means that C will pass a pointer to the array in the caller instead of the array itself, and modifications to the array in the callee will be visible to the caller (this does not match Rust by-value semantics). However, for `va_list`, the C standard explicitly states that it is undefined behaviour to use a `va_list` after it has been passed by value to a function (in Rust parlance, the `va_list` is moved, not copied). This matches Rust's pass-by-value semantics, meaning that when the C `va_list` type is a single-element array of a struct, the ABI will match C as long as the Rust type is always be passed indirectly.

In the old implementation, this ABI was achieved by having two separate types: `VaList` was the type that needed to be used when passing a `VaList` as a function parameter, whereas `VaListImpl` was the actual `va_list` type that was correct everywhere else. This however is quite confusing, as there are lots of footguns: it is easy to cause bugs by mixing them up (e.g. the C function `void foo(va_list va)` was equivalent to the Rust `fn foo(va: VaList)` whereas the C function `void bar(va_list* va)` was equivalent to the Rust `fn foo(va: *mut VaListImpl)`, not `fn foo(va: *mut VaList)` as might be expected); also converting from `VaListImpl` to `VaList` with `as_va_list()` had platform specific behaviour: on single-element array of a struct platforms it would return a `VaList` referencing the original `VaListImpl`, whereas on other platforms it would return a cioy,

In this PR, there is now just a single `VaList` type (renamed from `VaListImpl`) which represents the C `va_list` type and will just work in all positions. Instead of having a separate type just to make the ABI work, rust-lang/rust#144529 adds a `#[rustc_pass_indirectly_in_non_rustic_abis]` attribute, which when applied to a struct will force the struct to be passed indirectly by non-Rustic calling conventions. This PR then implements the `VaList` rework, making use of the new attribute on all platforms where the C `va_list` type is a single-element array of a struct.

Cleanup of the `VaList` API and implementation is also included in this PR: since it was decided it was OK to experiment with Rust requiring that not calling `va_end` is not undefined behaviour (https://github.com/rust-lang/rust/issues/141524#issuecomment-3028383594), I've removed the `with_copy` method as it was redundant to the `Clone` impl (the `Drop` impl of `VaList` is a no-op as `va_end` is a no-op on all known platforms).

Previous discussion: rust-lang/rust#141524 and [t-compiler > c_variadic API and ABI](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/c_variadic.20API.20and.20ABI)
Tracking issue: https://github.com/rust-lang/rust/issues/44930
r? `@joshtriplett`
2025-12-05 23:36:55 +00:00
Matthias Krüger c7889581ca Rollup merge of #149547 - tgross35:range-iterators, r=joboet
library: Rename `IterRange*` to `Range*Iter`

There is a weak convention in the ecosystem that `IterFoos` is an iterator yielding items of type `Foo` (e.g. `bitflags` `IterNames`, `hashbrown` `IterBuckets`), while `FooIter` is an iterator over `Foo` from an `.iter()` or `.into_iter()` method (e.g. `memchr` `OneIter`, `regex` `SetMatchesIter`). Rename `IterRange`, `IterRangeInclusive`, and `IterRangeFrom` to `RangeIter`, `RangeInclusiveIter`, and `RangeInclusiveIter` to match this.

Tracking issue: https://github.com/rust-lang/rust/issues/125687 (`new_range_api`)
2025-12-05 16:17:09 +01:00
Matthias Krüger 60be663188 Rollup merge of #149477 - RalfJung:minimum-maximum, r=tgross35
float::maximum/minimum: make docs more streamlined

This does with `maximum`/`minimum` what https://github.com/rust-lang/rust/pull/149475 did with `max`/`min`: first a self-contained description of the semantics, then comparing with other operations. It also makes the wording consistent with those other functions. Previously we had some of the semantics below the examples for some reason, and we repeated "If one of the arguments is NaN, then NaN is returned"; that has been streamlined as well.

r? `@tgross35`
2025-12-05 16:17:08 +01:00
Matthias Krüger a308ab8879 Rollup merge of #148811 - Paladynee:doc/location-caller-updated, r=joboet
core docs: rewrite `panic::Location::caller` with visual line/column numbers

no tracking issue

hey, this is my first PR on rust-lang/rust, so hopefully everything goes well.

i noticed the documentation for `core::panic::Location::caller` was kind of unintelligible (and maybe even wrong due to standalone_crate) and filled with magic numbers, so i provided line and column numbers as a visual guidance as to how it should be used.

edit: uh oh, looks like i pushed changes from random commits unrelated to me, what's going on?
edit2: reverted the unintended changes by this pr
2025-12-05 16:17:06 +01:00
Ralf Jung 2421920394 f*::min/max: fix comparing with libm and IEEE operations 2025-12-05 15:36:26 +01:00
bors 3e2dbcdd3a Auto merge of #149646 - matthiaskrgr:rollup-jbfeow8, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#147224 (Emscripten: Turn wasm-eh on by default)
 - rust-lang/rust#149405 (Recover on misspelled item keyword)
 - rust-lang/rust#149443 (Tidying up UI tests [6/N])
 - rust-lang/rust#149524 (Move attribute safety checking to attribute parsing)
 - rust-lang/rust#149593 (powf, powi: point out SNaN non-determinism)
 - rust-lang/rust#149605 (Use branch name instead of HEAD when unshallowing)
 - rust-lang/rust#149612 (Apply the `bors` environment also to the `outcome` job)
 - rust-lang/rust#149623 (Don't require a normal tool build of clippy/rustfmt when running their test steps)
 - rust-lang/rust#149627 (Point to the item that is incorrectly annotated with `#[diagnostic::on_const]`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-12-04 22:04:03 +00:00