Commit Graph

9393 Commits

Author SHA1 Message Date
Trevor Gross
6fa6a854cd Rollup merge of #144192 - RalfJung:atomicrmw-ptr, r=nikic
atomicrmw on pointers: move integer-pointer cast hacks into backend

Conceptually, we want to have atomic operations on pointers of the form `fn atomic_add(ptr: *mut T, offset: usize, ...)`. However, LLVM does not directly support such operations (https://github.com/llvm/llvm-project/issues/120837), so we have to cast the `offset` to a pointer somewhere.

This PR moves that hack into the LLVM backend, so that the standard library, intrinsic, and Miri all work with the conceptual operation we actually want. Hopefully, one day LLVM will gain a way to represent these operations without integer-pointer casts, and then the hack will disappear entirely.

Cc ```@nikic``` -- this is the best we can do right now, right?
Fixes https://github.com/rust-lang/rust/issues/134617
2025-08-08 14:22:44 -05:00
Jakub Beránek
8fcfbcd868 Revert "Rollup merge of #143906 - LorrensP-2158466:miri-float-nondet-foreign-items, r=RalfJung"
This reverts commit 71f04692c3, reversing
changes made to 995ca3e532.
2025-08-08 19:16:48 +02:00
Trevor Gross
3c18b6ce66 Rollup merge of #145045 - Hywan:doc-library-iterator-by_ref, r=GuillaumeGomez
doc(library): Fix Markdown in `Iterator::by_ref`

This patch fixes the Markdown formatting in `std::core::iter::Iterator::by_ref`. Code is used inside a link without the backticks around the code.
2025-08-07 19:36:39 -05:00
Trevor Gross
1d71dc4f26 Rollup merge of #144900 - Kivooeo:unsigned_signed_diff-stabilize, r=dtolnay
Stabilize `unsigned_signed_diff` feature

This closes [tracking issue](https://github.com/rust-lang/rust/issues/126041) and stabilises `checked_signed_diff`

Closes: https://github.com/rust-lang/rust/issues/126041
2025-08-07 19:36:36 -05:00
bors
321a89bec5 Auto merge of #145043 - Zalathar:rollup-3dbvdrm, r=Zalathar
Rollup of 19 pull requests

Successful merges:

 - rust-lang/rust#137831 (Tweak auto trait errors)
 - rust-lang/rust#138689 (add nvptx_target_feature)
 - rust-lang/rust#140267 (implement continue_ok and break_ok for ControlFlow)
 - rust-lang/rust#143028 (emit `StorageLive` and schedule `StorageDead` for `let`-`else`'s bindings after matching)
 - rust-lang/rust#143764 (lower pattern bindings in the order they're written and base drop order on primary bindings' order)
 - rust-lang/rust#143808 (Port `#[should_panic]` to the new attribute parsing infrastructure )
 - rust-lang/rust#143906 (Miri: non-deterministic floating point operations in `foreign_items`)
 - rust-lang/rust#143929 (Mark all deprecation lints in name resolution as deny-by-default and report-in-deps)
 - rust-lang/rust#144133 (Stabilize const TypeId::of)
 - rust-lang/rust#144369 (Upgrade semicolon_in_expressions_from_macros from warn to deny)
 - rust-lang/rust#144439 (Introduce ModernIdent type to unify macro 2.0 hygiene handling)
 - rust-lang/rust#144473 (Address libunwind.a inconsistency issues in the bootstrap program)
 - rust-lang/rust#144601 (Allow `cargo fix` to partially apply `mismatched_lifetime_syntaxes`)
 - rust-lang/rust#144650 (Additional tce tests)
 - rust-lang/rust#144659 (bootstrap: refactor mingw dist and fix gnullvm)
 - rust-lang/rust#144682 (Stabilize `strict_overflow_ops`)
 - rust-lang/rust#145026 (Update books)
 - rust-lang/rust#145033 (Reimplement `print_region` in `type_name.rs`.)
 - rust-lang/rust#145040 (rustc-dev-guide subtree update)

Failed merges:

 - rust-lang/rust#143857 (Port #[macro_export] to the new attribute parsing infrastructure)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-08-07 14:01:43 +00:00
Ivan Enderlin
c65102e745 doc(library): Fix Markdown in Iterator::by_ref.
This patch fixes the Markdown formatting in
`std::core::iter::Iterator::by_ref`. Code is used inside a link without
the backticks around the code.
2025-08-07 13:20:09 +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
Stuart Cook
622b21e80b Rollup merge of #144682 - nxsaken:strict_overflow_ops, r=Mark-Simulacrum
Stabilize `strict_overflow_ops`

Closes rust-lang/rust#118260
2025-08-07 20:49:47 +10:00
Stuart Cook
65114d6f81 Rollup merge of #144133 - oli-obk:stabilize-const-type-id, r=lcnr
Stabilize const TypeId::of

fixes rust-lang/rust#77125

# Stabilization report for `const_type_id`

## General design

### What is the RFC for this feature and what changes have occurred to the user-facing design since the RFC was finalized?

N/A the constness was never RFCed

### What behavior are we committing to that has been controversial? Summarize the major arguments pro/con.

`const_type_id` was kept unstable because we are currently unable to stabilize the `PartialEq` impl for it (in const contexts), so we feared people would transmute the type id to an integer and compare that integer.

### Are there extensions to this feature that remain unstable? How do we know that we are not accidentally committing to those?

`TypeId::eq` is not const at this time, and will only become const once const traits are stable.

## Has a Call for Testing period been conducted? If so, what feedback was received?

This feature has been unstable for a long time, and most people just worked around it on stable by storing a pointer to `TypeId::of` and calling that at "runtime" (usually LLVM devirtualized the function pointer and inlined the call so there was no real performance difference).

A lot of people seem to be using the `const_type_id` feature gate (600 results for the feature gate on github: https://github.com/search?q=%22%23%21%5Bfeature%28const_type_id%29%5D%22&type=code)

We have had very little feedback except desire for stabilization being expressed.

## Implementation quality

Until these three PRs

* https://github.com/rust-lang/rust/pull/142789
* https://github.com/rust-lang/rust/pull/143696
* https://github.com/rust-lang/rust/pull/143736

there was no difference between the const eval feature and the runtime feature except that we prevented you from using `TypeId::of` at compile-time. These three recent PRs have hardened the internals of `TypeId`:

* it now contains an array of pointers instead of integers
* these pointers at compile-time (and in miri) contain provenance that makes them unique and prevents inspection. Both miri and CTFE will in fact error if you mess with the bits or the provenance of the pointers in any way and then try to use the `TypeId` for an equality check. This also guards against creating values of type `TypeId` by any means other than `TypeId::of`

### Summarize the major parts of the implementation and provide links into the code (or to PRs)

N/A see above

### Summarize existing test coverage of this feature

Since we are not stabilizing any operations on `TypeId` except for creating `TypeId`s, the test coverage of the runtime implementation of `TypeId` covers all the interesting use cases not in the list below

#### Hardening against transmutes

* https://github.com/rust-lang/rust/blob/master/tests/ui/consts/const_transmute_type_id.rs
* https://github.com/rust-lang/rust/blob/master/tests/ui/consts/const_transmute_type_id2.rs
* https://github.com/rust-lang/rust/blob/master/tests/ui/consts/const_transmute_type_id3.rs
* https://github.com/rust-lang/rust/blob/master/tests/ui/consts/const_transmute_type_id4.rs
* https://github.com/rust-lang/rust/blob/master/tests/ui/consts/const_transmute_type_id5.rs

#### TypeId::eq is still unstable

* https://github.com/rust-lang/rust/blob/master/tests/ui/consts/const_cmp_type_id.rs

### What outstanding bugs in the issue tracker involve this feature? Are they stabilization-blocking?

https://github.com/rust-lang/rust/issues/129014 is still unresolved, but it affects more the runtime version of `TypeId` than the compile-time.

### What FIXMEs are still in the code for that feature and why is it ok to leave them there?

none

### Summarize contributors to the feature by name for recognition and assuredness that people involved in the feature agree with stabilization

* `@eddyb`
* `@RalfJung`

### Which tools need to be adjusted to support this feature. Has this work been done?

N/A

## Type system and execution rules

### What compilation-time checks are done that are needed to prevent undefined behavior?

Already covered above. Transmuting types with private fields to expose those fields has always been library UB, but for the specific case of `TypeId` CTFE and Miri will detect it if that is done in any way other than for reconstructing the exact same `TypeId` in another location.

### Does the feature's implementation need checks to prevent UB or is it sound by default and needs opt in in places to perform the dangerous/unsafe operations? If it is not sound by default, what is the rationale?

N/A

### Can users use this feature to introduce undefined behavior, or use this feature to break the abstraction of Rust and expose the underlying assembly-level implementation? (Describe.)

N/A

### What updates are needed to the reference/specification? (link to PRs when they exist)

Nothing more than what needs to exist for `TypeId` already.

## Common interactions

### Does this feature introduce new expressions and can they produce temporaries? What are the lifetimes of those temporaries?

N/A

### What other unstable features may be exposed by this feature?

N/A
2025-08-07 20:49:42 +10:00
Stuart Cook
71f04692c3 Rollup merge of #143906 - LorrensP-2158466:miri-float-nondet-foreign-items, r=RalfJung
Miri: non-deterministic floating point operations in `foreign_items`

Part of [rust-lang/miri/#3555](https://github.com/rust-lang/miri/issues/3555#issue-2278914000), this pr does the `foreign_items` work.

Some things have changed since rust-lang/rust#138062 and rust-lang/rust#142514. I moved the "helpers" used for creating fixed outputs and clamping operations to their defined ranges to `math.rs`. These are now also extended to handle the floating-point operations in `foreign_items`. Tests in `miri/tests/float.rs` were changed/added.

Failing tests in `std` were extracted, run under miri with `-Zmiri-many-seeds=0..1000` and changed accordingly. Double checked with `-Zmiri-many-seeds`.

I noticed that the C standard doesn't specify the output ranges for all of its mathematical operations; it just specifies them as:
```
Returns
The sinh functions return sinh x.
```
So I used [Wolfram|Alpha](https://www.wolframalpha.com/).
2025-08-07 20:49:41 +10:00
Stuart Cook
b0fc38a362 Rollup merge of #140267 - jogru0:control_flow, r=dtolnay
implement continue_ok and break_ok for ControlFlow

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

r? ``````@dtolnay``````
2025-08-07 20:49:37 +10:00
Stuart Cook
1cd368a744 Rollup merge of #138689 - jedbrown:jed/nvptx-target-feature, r=ZuseZ4
add nvptx_target_feature

Tracking issue: #141468 (nvptx), which is part of #44839 (catch-all arches)
The feature gate is `#![feature(nvptx_target_feature)]`

This exposes the target features `sm_20` through `sm_120a` [as defined](https://github.com/llvm/llvm-project/blob/llvmorg-20.1.1/llvm/lib/Target/NVPTX/NVPTX.td#L59-L85) by LLVM.

Cc: ``````@gonzalobg``````
``````@rustbot`````` label +O-NVPTX +A-target-feature
2025-08-07 20:49:36 +10:00
Karl Meakin
bf5020937f Optimize char::is_alphanumeric
Avoid an unnecessary call to `unicode::Alphabetic` when `self` is an
ASCII digit (ie `0..=9`).
2025-08-07 00:08:11 +01:00
Boxy
7bc34622f0 tidy 2025-08-06 16:55:50 +01:00
LorrensP-2158466
71add2f5f7 Change stdlib float tests to account for miri nondet floats. 2025-08-06 17:21:04 +02:00
Jakub Beránek
66f0f27290 Rollup merge of #144978 - ehuss:intrinsic-doc-links, r=scottmcm
Fix some doc links for intrinsics

This fixes a few intrinsic docs that had a link directly to itself instead of to the correct function in the `mem` module.
2025-08-06 15:55:49 +02:00
Boxy
9ccc9f177e replace version placeholder 2025-08-06 13:22:38 +01:00
Eric Huss
2cd5b4928d Fix some doc links for intrinsics
This fixes a few intrinsic docs that had a link directly to itself
instead of to the correct function in the `mem` module.
2025-08-05 17:02:01 -07:00
okaneco
eee6f804a9 Renamed isolate_most_least_significant_one functions
libs-api has agreed to rename these functions to
`isolate_highest_one`/`isolate_lowest_one`
2025-08-05 16:37:04 -04:00
Chai T. Rex
d811581ba7 Add std::ascii::Char MIN and MAX constants 2025-08-05 15:03:11 -04:00
Chai T. Rex
9a1d38047f Add u8-as-ASCII methods to core::ascii::Char 2025-08-05 15:02:41 -04:00
Michael Tautschnig
9c0cfd262f Fix description of unsigned checked_exact_div
Like its signed counterpart, this function does not panic. Also, fix the
examples to document how it returns Some/None.
2025-08-05 17:33:04 +00:00
Ross MacArthur
b038197b16 Stabilize core::iter::chain 2025-08-05 17:05:23 +02:00
Samuel Tardieu
1724af9f1e Rollup merge of #144872 - connortsui20:once-poison-docs, r=Amanieu
Document Poisoning in `LazyCell` and `LazyLock`

Currently, there is no documentation of poisoning behavior in either `LazyCell` or `LazyLock`, even though both of them can be observed as poisoned by users.

`LazyCell` [plagyround example](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=9cf38b8dc56db100848f54085c2c697d)

`LazyLock` [playground example](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=f1cd6f9fe16636e347ebb695a0ce30c0)

# Open Questions

- [x] Is it worth making the implementation of `LazyLock` more complicated to ensure that the the panic message is `"LazyLock instance has previously been poisoned"` instead of `"Once instance has previously been poisoned"`? See the `LazyLock` playground link above for more context.
- [x] Does it make sense to move `LazyLock` into the `poison` module? It is certainly a poison-able type, but at the same time it is slightly different from the 4 other types currently in the `poison` module in that it is unrecoverable. I think this is more of a libs-api question.

``@rustbot`` label +T-libs-api

Please let me know if these open questions deserve a separate issue / PR!
2025-08-05 03:51:38 +02:00
Samuel Tardieu
db7ac64997 Rollup merge of #144867 - scottmcm:more-as-array, r=chenyukang
Use `as_array` in PartialEq for arrays

Now that `as_array` exists we might as well use it here, since it's a bit more convenient than getting the correct type out of `try_into`.
2025-08-05 03:51:38 +02:00
Kivooeo
d2cfe486f0 remove feature gate 2025-08-04 16:41:10 +05:00
Stuart Cook
f6b4e45be7 Rollup merge of #144667 - scottmcm:alignment-is-usize, r=tgross35
`AlignmentEnum` should just be `repr(usize)` now

These used to use specific sizes because they were compiled on all widths.  But now that the types themselves are `#[cfg]`'d, we can save some conversions by having it always be `repr(usize)`.
2025-08-04 11:24:38 +10:00
Stuart Cook
625b180035 Rollup merge of #142205 - paolobarbolini:const_swap_with_slice-impl, r=Mark-Simulacrum
Mark `slice::swap_with_slice` unstably const

Tracking issue rust-lang/rust#142204
2025-08-04 11:24:35 +10:00
Connor Tsui
37922fc24c add poisoning documentation to LazyCell 2025-08-03 22:57:07 +02:00
Scott McMurray
eee28138b8 Use as_array in PartialEq for arrays 2025-08-03 12:47:11 -07:00
Isaac Chen
8a0438fee8 moved new test to updated test location 2025-08-02 17:04:08 -04:00
Isaac Chen
557737062d corrected lifetime in core::panic::Location::file return type 2025-08-02 17:04:07 -04:00
Isaac Chen
9c4a35e0e7 added regression test for core::panic::Location::file's lifetime 2025-08-02 16:43:22 -04:00
Isaac Chen
e772f7ab3e corrected lifetime in core::panic::Location::file return type 2025-08-02 16:43:07 -04:00
Pascal S. de Kloe
4ad8606d79 fmt with table lookup for binary, octal and hex
* correct buffer size
* no trait abstraction
* similar to decimal
2025-08-02 13:26:59 +02:00
Samuel Tardieu
5e1ea9cda4 Rollup merge of #144797 - nilehmann:safety-comment-niche, r=Noratrieb
Update safety comment for new_unchecked in niche_types

Change the safety comment on `new_unchecked` to mention the valid range instead of 0. I noticed this while working on https://github.com/model-checking/verify-rust-std
2025-08-02 11:24:29 +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
Nico Lehmann
4c7c9de8ac Fix safety comment for new_unchecked in niche_types 2025-08-01 14:00:56 -07:00
Evgenii Zheltonozhskii
9377e0af52 Constify additional Result functions 2025-08-01 08:55:50 +03:00
Trevor Gross
ad61b3113c Correct some grammar in integer documentation
Update "between" to "among" (more than two items), connect the "which"
dependent clause to the independent part, and remove the redundant
"here".
2025-07-31 22:53:27 -05:00
Jeremy Smart
613080b5f1 add Option::reduce 2025-07-31 23:46:04 -04:00
Nurzhan Sakén
3ff3a1ee00 Stabilize strict_overflow_ops 2025-07-30 23:39:35 +04:00
Scott McMurray
4220587c22 AlignmentEnum should just be repr(usize) now
Since it's cfg'd instead of type-aliased
2025-07-30 00:09:01 -07:00
Ralf Jung
ba5b6b9ec4 const-eval: full support for pointer fragments 2025-07-30 08:13:58 +02:00
bors
c8bb4e8a12 Auto merge of #144658 - jhpratt:rollup-jdzhz27, r=jhpratt
Rollup of 8 pull requests

Successful merges:

 - rust-lang/rust#144034 (tests: Test line number in debuginfo for diverging function calls)
 - rust-lang/rust#144510 (Fix Ord, Eq and Hash implementation of panic::Location)
 - rust-lang/rust#144583 (Enable T-compiler backport nomination)
 - rust-lang/rust#144586 (Update wasi-sdk to 27.0 in CI)
 - rust-lang/rust#144605 (Resolve: cachify `ExternPreludeEntry.binding` through a `Cell`)
 - rust-lang/rust#144632 (Update some tests for LLVM 21)
 - rust-lang/rust#144639 (Update rustc-perf submodule)
 - rust-lang/rust#144640 (Add support for the m68k architecture in 'object_architecture')

r? `@ghost`
`@rustbot` modify labels: rollup
2025-07-29 23:53:04 +00:00
Jacob Pratt
48dfddd39e Rollup merge of #144510 - orlp:fix-location-ord, r=ibraheemdev
Fix Ord, Eq and Hash implementation of panic::Location

Fixes https://github.com/rust-lang/rust/issues/144486.

Now properly compares/hashes the filename rather than the pointer to the string.
2025-07-29 18:55:18 -04:00
bors
ba7e63b638 Auto merge of #144393 - heiher:str-contains-lsx, r=tgross35
LoongArch64 LSX fast-path for `str.contains(&str)`

Benchmark results with LLVM 21 on LA664:

```
OLD:
test bench_is_contained_in ... bench:          43.63 ns/iter (+/- 0.04)

NEW:
test bench_is_contained_in ... bench:          12.81 ns/iter (+/- 0.01)
```
2025-07-29 20:44:32 +00:00
Orson Peters
05da623016 Fix Ord, Eq and Hash implementation of panic::Location
Faster equality compare

Add tests

Add missing files for tests
2025-07-29 22:15:44 +02:00
Stuart Cook
7088bf5cc6 Rollup merge of #144634 - lucaswerkmeister:patch-1, r=lqd
Fix typo in `DropGuard` doc

Follows-up rust-lang/rust#144236 (I happened to see the typo yesterday but didn’t think it should delay the PR’s merge so I kept quiet, sorryyyyy).
2025-07-29 23:50:38 +10:00
WANG Rui
1ceacf55a0 LoongArch64 LSX fast-path for str.contains(&str)
Benchmark results with LLVM 21 on LA664:

```
OLD:
test bench_is_contained_in ... bench:          43.63 ns/iter (+/- 0.04)

NEW:
test bench_is_contained_in ... bench:          12.81 ns/iter (+/- 0.01)
```
2025-07-29 21:38:37 +08:00