Skip to content

Rollup of 16 pull requests - #160308

Closed
jhpratt wants to merge 41 commits into
rust-lang:mainfrom
jhpratt:rollup-KR6wnpI
Closed

Rollup of 16 pull requests#160308
jhpratt wants to merge 41 commits into
rust-lang:mainfrom
jhpratt:rollup-KR6wnpI

Conversation

@jhpratt

@jhpratt jhpratt commented Aug 1, 2026

Copy link
Copy Markdown
Member

Successful merges:

r? @ghost

Create a similar rollup

cjgillot and others added 30 commits July 11, 2026 18:19
Constructing an Rc<[T]> or Arc<[T]> whose header + payload layout exceeds
isize::MAX unwrapped a LayoutError, panicking with the opaque "called
`Result::unwrap()` on an `Err` value: LayoutError". Match Vec and Box by
reporting "capacity overflow" instead, and add regression tests.
This FIXME was added in [1], at which point there were 8 arguments. Now
there are only 5, which is much more reasonable.

This commit was brought to you by https://oli-obk.github.io/fixmeh/.

[1]: rust-lang#78923
Forbid super/crate/self/Self to be used in register_tool.
Also, add test for raw identifier and unicode identifiers.
This adds back the previously existing duplicate tool error, but as a
suppressable lint.
This is already *supposed* to be impossible in layout, but this emphasizes that better.

Ironically I was inspired to do this as part of looking at making `Simd<T, 0>` *work*, but importantly if that's going to happen I think it should be `BackendRepr::Memory` like other ZSTs, *not* a `BackendRepr::ScalarVector` that would need to carry around a useless LLVM value in `OperandValue::Immediate` (where it's not even clear what the LLVM type of that value would be).
* docs: document the non_exhaustive attribute
* Add newline at end of attribute_docs.rs
* Update library/core/src/attribute_docs.rs

* Update library/core/src/attribute_docs.rs

Co-authored-by: Guillaume Gomez <contact@guillaume-gomez.fr>
Co-authored-by: Krisitan Erik Olsen <kristian.erik@outlook.com>
* fundamental only on first arg
* woo this made error messages nicer
* oh the test was misnamed lol
* special case only box
* rename tests

Co-authored-by: Nia Deckers <nia-e@haecceity.cc>
Instead of displaying all kind of tuples that implement a given trait, which
might flood the user, it displays a concise message only when all the involved
types are tuples.
…aethlin

Drop elaboration: Only create a reset block if there are flags to reset.

Follow-up to rust-lang#157491

I'm not totally convinced this is worth the effort. The generated pattern is trivially cleaned-up by SimplifyCfg, so we should not need to bother.

r? @saethlin since you reviewed the earlier PR
…-5, r=saethlin

Emit retags in codegen to support BorrowSanitizer (part 5)

Tracking issue: rust-lang#154760
[Zulip Thread](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Staging.20for.20emitting.20retags.20in.20codegen/with/592364811)

This is one of several PRs that add experimental support for emitting retags as function calls in codegen.

This PR adds support for emitting global arrays that specify the ranges of interior mutable and pinned data. For example,
```rust
fn cell(x: &(i32, Cell<i32>)) { ... }
```
This program will have IR similar to the following:
```llvm
@anon.0 = unnamed_addr constant [16 x i8] c"\04...\04..."
define void @cell(ptr %0)  {
start:
  %x = call ptr @__rust_retag_reg(ptr %0, i64 8, i8 1, ptr @anon.0, ptr null)
  ...
}
```
The last four bytes at offset four are interior mutable.

Users can disable this behavior by passing `no-precise-im` or `no-precise-pin` as options to  `-Zcodegen-emit-retag`. In that case, the last two parameters to the retag intrinsic will always be null pointers.

BorrowSanitizer will be able to switch to using nightly once this is merged. Thank you @saethlin for reviewing these PRs!

Note: we still do not support retagging SIMD types, since cg-ssa does not support `insertelement`.

Related: rust-lang#158100

Cc: @RalfJung
r? @saethlin
…overflow, r=JohnTitor

Report "capacity overflow" for oversized Rc<[T]>/Arc<[T]>

Fixes rust-lang#136797.

Building an Rc<[T]>/Arc<[T]> whose header + payload layout exceeds
isize::MAX unwrapped a LayoutError and panicked with "called
Result::unwrap() on an Err value: LayoutError". Vec and Box report
"capacity overflow" here; this makes Rc/Arc do the same.

Used an inline panic!("capacity overflow") rather than raw_vec's
capacity_overflow(), since that helper is cfg'd out under
no_global_oom_handling while these two layout fns still compile there.
miri: ensure validity of references and pointers we dereference and cast

Conceptually, when we evaluate the place expression `*place`, there are two steps that happen:
- perform a (typed) load from `place`, which yields a value of pointer/ref type
- construct a new place from that value

Since this is a typed load, we have to ensure that the value satisfies the validity invariant. We forgot to do that, which led to Miri missing a bunch of UB. This PR fixes that by adding the missing checks.

Triggering this UB is a bit non-trivial: you cannot just store an invalid value into `place` using regular assignment (that would already be caught as part of the assignment). However, you can take a raw pointer to `place` and then use that to mutate the contents of `place` in a way that its validity invariant no longer holds. For example:
```rust
fn main() {
    let mut x = &();
    // Overwrite `x` with null.
    unsafe { (&raw mut x).cast::<usize>().write(0) };
    let _val = *x; //~ERROR: null reference
}
```
This program clearly (IMO) should have UB, and has UB in MiniRust, but Miri accepted that program before this PR. The same applies to references that are invalid because they are unaligned (even if we end up only accessing a 1-aligned field, i.e. the rest of the place expression evaluates just fine), and to references that are invalid because they are not dereferenceable (even if we end up projecting to a zero-sized field, i.e., the rest of the place expression evaluates just fine).

Even raw pointers have this problem: a raw pointer can be invalid if its vtable pointer is wrong, and we did not check that.

And finally, this also affects `Box`, and this is where things get tricky. `Box` derefs are not even present any more in the MIR Miri sees; they have been replaced by derefs of the underlying raw pointer. But that means we have no way to know that we should check all those things. So to fix that I adjusted the ElaborateBoxDerefs to emit a new special kind of cast that's almost a transmute but also checks `Box` validity.

Fixes rust-lang/miri#5226
Fixes rust-lang/unsafe-code-guidelines#617
Cc @rust-lang/opsem
make atomic operations const

In a similar vein to rust-lang#159094, it makes sense to make these `const fn` so that code can be shared between compile-time and run-time even if the runtime version has to deal with concurrency.

This constifies the following:
```rust
// core::sync::atomic

impl AtomicBool {
    pub const fn get_mut(&mut self) -> &mut bool;
    pub const fn from_mut(v: &mut bool) -> &mut Self;
    pub const fn get_mut_slice(this: &mut [Self]) -> &mut [bool];
    pub const fn from_mut_slice(v: &mut [bool]) -> &mut [Self];
    pub const fn load(&self, order: Ordering) -> bool;
    pub const fn store(&self, val: bool, order: Ordering);
    pub const fn swap(&self, val: bool, order: Ordering) -> bool;
    pub const fn compare_and_swap(&self, current: bool, new: bool, order: Ordering) -> bool;
    pub const fn compare_exchange(
        &self,
        current: bool,
        new: bool,
        success: Ordering,
        failure: Ordering,
    ) -> Result<bool, bool>;
    pub const fn compare_exchange_weak(
        &self,
        current: bool,
        new: bool,
        success: Ordering,
        failure: Ordering,
    ) -> Result<bool, bool>;
    pub const fn fetch_and(&self, val: bool, order: Ordering) -> bool;
    pub const fn fetch_nand(&self, val: bool, order: Ordering) -> bool;
    pub const fn fetch_or(&self, val: bool, order: Ordering) -> bool;
    pub const fn fetch_xor(&self, val: bool, order: Ordering) -> bool;
    pub const fn fetch_not(&self, order: Ordering) -> bool;
}

impl AtomicPtr<T> {
    pub const fn get_mut(&mut self) -> &mut *mut T;
    pub const fn from_mut(v: &mut *mut T) -> &mut Self;
    pub const fn get_mut_slice(this: &mut [Self]) -> &mut [*mut T];
    pub const fn from_mut_slice(v: &mut [*mut T]) -> &mut [Self];
    pub const fn load(&self, order: Ordering) -> *mut T;
    pub const fn store(&self, ptr: *mut T, order: Ordering);
    pub const fn swap(&self, ptr: *mut T, order: Ordering) -> *mut T;
}

impl Atomic$Int {
    pub const fn get_mut(&mut self) -> &mut $int_type;
    pub const fn from_mut(v: &mut $int_type) -> &mut Self;
    pub const fn get_mut_slice(this: &mut [Self]) -> &mut [$int_type];
    pub const fn from_mut_slice(v: &mut [$int_type]) -> &mut [Self];
    pub const fn load(&self, order: Ordering) -> $int_type;
    pub const fn store(&self, val: $int_type, order: Ordering);
    pub const fn swap(&self, val: $int_type, order: Ordering) -> $int_type;
    pub const fn compare_and_swap(&self,
                                    current: $int_type,
                                    new: $int_type,
                                    order: Ordering) -> $int_type;
    pub const fn compare_exchange(&self,
                                    current: $int_type,
                                    new: $int_type,
                                    success: Ordering,
                                    failure: Ordering) -> Result<$int_type, $int_type>;
    pub const fn compare_exchange_weak(&self,
                                         current: $int_type,
                                         new: $int_type,
                                         success: Ordering,
                                         failure: Ordering) -> Result<$int_type, $int_type>;
    pub const fn fetch_add(&self, val: $int_type, order: Ordering) -> $int_type;
    pub const fn fetch_sub(&self, val: $int_type, order: Ordering) -> $int_type;
    pub const fn fetch_and(&self, val: $int_type, order: Ordering) -> $int_type;
    pub const fn fetch_nand(&self, val: $int_type, order: Ordering) -> $int_type;
    pub const fn fetch_or(&self, val: $int_type, order: Ordering) -> $int_type;
    pub const fn fetch_xor(&self, val: $int_type, order: Ordering) -> $int_type;
    pub const fn fetch_max(&self, val: $int_type, order: Ordering) -> $int_type;
    pub const fn fetch_min(&self, val: $int_type, order: Ordering) -> $int_type;
}

pub const fn fence(order: Ordering);
pub const fn compiler_fence(order: Ordering);
```

However, this excludes the `fetch_*` and `compare_*` operations on `AtomicPtr`, as that kind of pointer arithmetic is not possible at compile time.

Tracking issue: rust-lang#160078
Cc @rust-lang/wg-const-eval @rust-lang/opsem
jhpratt added 5 commits July 31, 2026 21:47
…ttribute, r=GuillaumeGomez

Add documentation for the `non_exhaustive` attribute

Document the built-in `non_exhaustive` attribute using the `#[doc(attribute = "…")]` mechanism.

Part of rust-lang#157604

Tested with `./x test library/std --doc --test-args attribute_docs`.

r? @GuillaumeGomez
Fix `hidden_glob_reexports` in `rustc_ast`

See rust-lang#159901 for why the downstream changes are necessary
Align expect messages with guidance

Issue: rust-lang#159751

- Changed 3 `expect` messages and some relevant comments in `library/core/src/result.rs` and `library/core/src/primitive_docs.rs`

- I intentionally left the below snippet unchanged in `library/core/src/result.rs`.
The example is quite minimal and focuses on showing the panic output format, so I thought it was better to keep the message short and simple.
```
    /// # Panics
    ///
    /// Panics if the value is an [`Err`], with a panic message including the
    /// passed message, and the content of the [`Err`].
    ///
    ///
    /// # Examples
    ///
    /// ```should_panic
    /// let x: Result<u32, &str> = Err("emergency failure");
    /// x.expect("Testing expect"); // panics with `Testing expect: emergency failure`
    /// ```
```

r? @fee1-dead
Expand checks for register_tool

Follow up to rust-lang#158038 (review) and rust-lang#158038 (comment)

* Add tool-attribute test to ensure tools are not preserved across crate
* Reject invalid identifiers (super/self/Self/crate) in register_tool
* Add lint for duplicate tools

r? @mejrs
…GuillaumeGomez

Update `minifier` version to `0.4.0`

Contains security fix added by @Eh2406 done in GuillaumeGomez/minifier-rs#130.

r? ghost
@rust-bors rust-bors Bot added the rollup A PR which is a rollup label Aug 1, 2026
@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Aug 1, 2026
@jhpratt

jhpratt commented Aug 1, 2026

Copy link
Copy Markdown
Member Author

@bors r+ rollup=never p=5

@bors try jobs=dist-various-1,test-various,x86_64-gnu-aux,x86_64-gnu-llvm-21-3,x86_64-msvc-1,aarch64-apple,x86_64-mingw-1,i686-msvc-*

@rust-bors

rust-bors Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

📌 Commit e3b47a5 has been approved by jhpratt

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 1, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 1, 2026
Rollup of 16 pull requests


try-job: dist-various-1
try-job: test-various
try-job: x86_64-gnu-aux
try-job: x86_64-gnu-llvm-21-3
try-job: x86_64-msvc-1
try-job: aarch64-apple
try-job: x86_64-mingw-1
try-job: i686-msvc-*
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job x86_64-gnu-llvm-21-3 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
test [mir-opt] tests/mir-opt/unreachable_enum_branching.rs ... ok

failures:

---- [mir-opt] tests/mir-opt/coroutine/async_drop.rs stdout ----
65 +         _26 = std::future::ResumeTy(move _27);
66 +         _25 = copy (_1.0: &mut {async fn body of array()});
67 +         _24 = discriminant((*_25));
- +         switchInt(move _24) -> [0: bb26, 1: bb25, 2: bb24, 3: bb22, 4: bb23, otherwise: bb11];
+ +         switchInt(move _24) -> [0: bb25, 1: bb24, 2: bb23, 3: bb21, 4: bb22, otherwise: bb11];
69       }
70   
71       bb1: {

85 -         StorageDead(_3);
86 -         drop(_1) -> [return: bb4, unwind: bb8];
87 +         nop;
- +         goto -> bb20;
+ +         goto -> bb4;
89       }
90   
91       bb4: {

104 -     bb6: {
---
108       }
109   
110 -     bb7 (cleanup): {

201 +         _21 = Pin::<&mut [AsyncInt; 2]>::new_unchecked(move _22) -> [return: bb18, unwind: bb5];
202       }
203   
-       bb20: {
+ -     bb20: {
205 -         _13 = &mut _6;
206 -         _10 = Pin::<&mut impl Future<Output = ()>>::new_unchecked(move _13) -> [return: bb19, unwind: bb11];
- +         goto -> bb4;
+ +     bb20 (cleanup): {
+ +         discriminant((*_25)) = 2;
+ +         resume;
208       }
209   
- -     bb21: {
+       bb21: {
211 -         _2 = move _14;
212 -         StorageDead(_14);
213 -         goto -> bb27;

- +     bb21 (cleanup): {
- +         discriminant((*_25)) = 2;
- +         resume;
+ +         StorageLive(_7);
+ +         _7 = move _26;
+ +         goto -> bb10;
217       }
218   
219       bb22: {

220 -         _2 = move _14;
---
227   
228       bb23: {

-           StorageLive(_14);
+ -         StorageLive(_14);
230 -         _14 = yield(const ()) -> [resume: bb21, drop: bb22];
- +         _14 = move _26;
- +         goto -> bb12;
+ +         assert(const false, "`async fn` resumed after panicking") -> [success: bb23, unwind continue];
233       }
234   
235       bb24: {

236 -         _16 = discriminant(_15);
237 -         switchInt(move _16) -> [0: bb9, 1: bb23, otherwise: bb16];
- +         assert(const false, "`async fn` resumed after panicking") -> [success: bb24, unwind continue];
+ +         assert(const false, "`async fn` resumed after completion") -> [success: bb24, unwind continue];
239       }
240   
241       bb25: {

242 -         _15 = <impl Future<Output = ()> as Future>::poll(move _17, move _18) -> [return: bb24, unwind: bb11];
- +         assert(const false, "`async fn` resumed after completion") -> [success: bb25, unwind continue];
-       }
-   
-       bb26: {
+ -     }
+ - 
+ -     bb26: {
247 -         _19 = move _2;
248 -         _18 = std::future::get_context::<'_, '_>(move _19) -> [return: bb25, unwind: bb11];
249 -     }


thread '[mir-opt] tests/mir-opt/coroutine/async_drop.rs' panicked at src/tools/compiletest/src/runtest/mir_opt.rs:73:21:
Actual MIR output differs from expected MIR output /checkout/tests/mir-opt/coroutine/async_drop.array-{closure#0}.StateTransform.diff
stack backtrace:
   5: __rustc::rust_begin_unwind
             at /rustc/08d5b675a9b2abdca5e2fe4eabe0e07bbda15d49/library/std/src/panicking.rs:679:5
   6: core::panicking::panic_fmt
             at /rustc/08d5b675a9b2abdca5e2fe4eabe0e07bbda15d49/library/core/src/panicking.rs:80:14

@jhpratt jhpratt closed this Aug 1, 2026
@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 1, 2026
@rust-bors

rust-bors Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

PR #160012, which is a member of this rollup, was unapproved.

This rollup was thus unapproved.

@jhpratt
jhpratt deleted the rollup-KR6wnpI branch August 1, 2026 02:21
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job aarch64-gnu-llvm-21-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
test [mir-opt] tests/mir-opt/unusual_item_types.rs ... ok

failures:

---- [mir-opt] tests/mir-opt/coroutine/async_drop.rs stdout ----
65 +         _26 = std::future::ResumeTy(move _27);
66 +         _25 = copy (_1.0: &mut {async fn body of array()});
67 +         _24 = discriminant((*_25));
- +         switchInt(move _24) -> [0: bb26, 1: bb25, 2: bb24, 3: bb22, 4: bb23, otherwise: bb11];
+ +         switchInt(move _24) -> [0: bb25, 1: bb24, 2: bb23, 3: bb21, 4: bb22, otherwise: bb11];
69       }
70   
71       bb1: {

85 -         StorageDead(_3);
86 -         drop(_1) -> [return: bb4, unwind: bb8];
87 +         nop;
- +         goto -> bb20;
+ +         goto -> bb4;
89       }
90   
91       bb4: {

104 -     bb6: {
---
108       }
109   
110 -     bb7 (cleanup): {

201 +         _21 = Pin::<&mut [AsyncInt; 2]>::new_unchecked(move _22) -> [return: bb18, unwind: bb5];
202       }
203   
-       bb20: {
+ -     bb20: {
205 -         _13 = &mut _6;
206 -         _10 = Pin::<&mut impl Future<Output = ()>>::new_unchecked(move _13) -> [return: bb19, unwind: bb11];
- +         goto -> bb4;
+ +     bb20 (cleanup): {
+ +         discriminant((*_25)) = 2;
+ +         resume;
208       }
209   
- -     bb21: {
+       bb21: {
211 -         _2 = move _14;
212 -         StorageDead(_14);
213 -         goto -> bb27;

- +     bb21 (cleanup): {
- +         discriminant((*_25)) = 2;
- +         resume;
+ +         StorageLive(_7);
+ +         _7 = move _26;
+ +         goto -> bb10;
217       }
218   
219       bb22: {

220 -         _2 = move _14;
---
227   
228       bb23: {

-           StorageLive(_14);
+ -         StorageLive(_14);
230 -         _14 = yield(const ()) -> [resume: bb21, drop: bb22];
- +         _14 = move _26;
- +         goto -> bb12;
+ +         assert(const false, "`async fn` resumed after panicking") -> [success: bb23, unwind continue];
233       }
234   
235       bb24: {

236 -         _16 = discriminant(_15);
237 -         switchInt(move _16) -> [0: bb9, 1: bb23, otherwise: bb16];
- +         assert(const false, "`async fn` resumed after panicking") -> [success: bb24, unwind continue];
+ +         assert(const false, "`async fn` resumed after completion") -> [success: bb24, unwind continue];
239       }
240   
241       bb25: {

242 -         _15 = <impl Future<Output = ()> as Future>::poll(move _17, move _18) -> [return: bb24, unwind: bb11];
- +         assert(const false, "`async fn` resumed after completion") -> [success: bb25, unwind continue];
-       }
-   
-       bb26: {
+ -     }
+ - 
+ -     bb26: {
247 -         _19 = move _2;
248 -         _18 = std::future::get_context::<'_, '_>(move _19) -> [return: bb25, unwind: bb11];
249 -     }


thread '[mir-opt] tests/mir-opt/coroutine/async_drop.rs' panicked at src/tools/compiletest/src/runtest/mir_opt.rs:73:21:
Actual MIR output differs from expected MIR output /checkout/tests/mir-opt/coroutine/async_drop.array-{closure#0}.StateTransform.diff
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
---- [mir-opt] tests/mir-opt/coroutine/async_drop.rs stdout end ----

failures:
    [mir-opt] tests/mir-opt/coroutine/async_drop.rs

@rust-bors

rust-bors Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

💔 Test for aa67491 failed: CI. Failed jobs:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. rollup A PR which is a rollup S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.