Commit Graph

339578 Commits

Author SHA1 Message Date
Matyas Susits
704858caa7 test async closure reproducibility with the parallel frontend 2026-09-10 10:06:17 +02:00
bors
eca445e5ae Auto merge of #162510 - Zalathar:rollup-0hi6WtW, r=Zalathar
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#162482 (Make `run-make` testsuite work with other codegen backend than LLVM)
 - rust-lang/rust#161587 (Avoid invalid suggestion in case of macro expansion without inferrable generic type)
 - rust-lang/rust#162363 (Use correct `dir_path` when parsing module from path)
 - rust-lang/rust#162408 (add crashtests [7/N])
 - rust-lang/rust#162502 (triagebot: Subscribe me to amdgpu changes)
 - rust-lang/rust#162505 (Revert "fuchsia: Add safestack as a supported sanitizer for x86_64 fuchsia")
2026-09-09 06:31:46 +00:00
Stuart Cook
b2e166a43b Rollup merge of #162505 - PiJoules:revert-fuchsia-safestack-default, r=chenyukang
Revert "fuchsia: Add safestack as a supported sanitizer for x86_64 fuchsia"

This reverts commit 7a44484407.

This is leading to the issue seen in
https://github.com/rust-lang/rust/issues/162272. We're also seeing the same build issues when using a rust toolchain that contains this commit for building fuchsia targets.
2026-09-09 16:25:20 +10:00
Stuart Cook
1a80d5e270 Rollup merge of #162502 - Flakebi:notifications, r=jieyouxu
triagebot: Subscribe me to amdgpu changes
2026-09-09 16:25:19 +10:00
Stuart Cook
41b157e38b Rollup merge of #162408 - cyrgani:tests-7, r=adwinwhite
add crashtests [7/N]

Followup to rust-lang/rust#161294.
[Link to issue list.](https://github.com/rust-lang/rust/issues?q=is:issue%20state:open%20label:I-ICE%20label:S-has-mcve%20-label:S-bug-has-test%20sort:created-asc%20AND%20(%20140693%20OR%20146210%20OR%20146353%20OR%20149015%20OR%20152204%20OR%20153368%20OR%20154367%20OR%20155482%20OR%20155497%20OR%20157197%20OR%20158243%20OR%20158773%20OR%20158797%20OR%20160329%20OR%20160490%20))
2026-09-09 16:25:19 +10:00
Stuart Cook
a2b84ca4d1 Rollup merge of #162363 - mu001999-contrib:fix-162080, r=petrochenkov
Use correct `dir_path` when parsing module from path

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

We previously used the incorrect `dir_path` (which was `name`, the parent of `name/mod.rs`, in this case), and then joined it with `name/mod.rs` again, resulting in `name/name/mod.rs`.

The first commit adds the regression test and snapshot of current behavior, the second commit fixes it.

r? petrochenkov
2026-09-09 16:25:18 +10:00
Stuart Cook
100c013d89 Rollup merge of #161587 - lsunsi:issue129756, r=ShoyuVanilla
Avoid invalid suggestion in case of macro expansion without inferrable generic type

Closes rust-lang/rust#129756 .

The main challenge for me in this PR was figuring out how to pass down the information of the code being generated from expansion. I went for the simplest approach I could think of, but I questioned myself if the boolean should be placed inside the Visitor. I don't have enough information to figure this out, if it's badly placed I'd be happy to fix and learn!

About the test, I split the two commits because we can see the issue being reproduced in the first commit but being fixed on the second. I also added a non-expansion example of the same code to show it won't get altered.

Oh, also I didn't know the best place to place the test. I went for the place with same kind of errors, but I guess `proc-macros` could also be a place.
2026-09-09 16:25:17 +10:00
Stuart Cook
b604379281 Rollup merge of #162482 - GuillaumeGomez:run-make-backends, r=Kobzol
Make `run-make` testsuite work with other codegen backend than LLVM

Needed for rust-lang/rust#159924.

Currently, we always run `run-make` testsuite with the codegen backend rustc was compiled with. However, in CI it's compiled with LLVM, so when we want to test with GCC (with `--test-codegen-backend`), it compiles `rmake.rs` with the GCC backend, but when running the test, it doesn't use the GCC backend since it just calls `rustc`. So to get around that, I now pass the codegen backend through the environment and set it in the `rustc` function of `run_make_support`.

To be noted that for now it's only for the `rustc` function, no other command uses it. Should I extend it right away for all commands (well, likely only `cargo`) or just `rustc` for now is enough?

r? @jieyouxu
2026-09-09 16:25:16 +10:00
bors
1edd55dcfc Auto merge of #162488 - Kobzol:borrowck-densebit, r=jackh726
Use `DenseBit` for `drop_live_at` in liveness tracing

I noticed that `drop_live_at` only ever gets point, and never range, inserts, so I switched it over to `DenseBitSet`. This provides some nice [wins](https://perf.rust-lang.org/compare.html?start=745de6eca673de5329ec68f2689629a5ca45ab35&end=d1837740534cbf87b9fe919b7a89debf46362197&stat=instructions:u) on `serde`.

However, the `add_drop_live_facts_for` function expects to receive an `IntervalSet`. I first tried to switch the type of `LiveRegions::AtPoints` from `SparseIntervalMatrix` to `SparseBitMatrix`, but that had [regressions](https://perf.rust-lang.org/compare.html?start=745de6eca673de5329ec68f2689629a5ca45ab35&end=c87f1fbff20351758b66ae945c16e061ab4ae54c&stat=instructions:u). 

So in this PR, I simply reconstruct an `IntervalSet` from a `DenseBitSet`. Not super pretty, but perf. looks reasonable.

Let me know if this makes sense or not! :)

r? jackh726
2026-09-09 03:10:29 +00:00
Roland Xu
ac967d636d Use correct dir_path in wrap_flat_map_node_walk_flat_map 2026-09-09 08:32:46 +08:00
bors
0d31508599 Auto merge of #162503 - JonathanBrouwer:rollup-Gh517p9, r=JonathanBrouwer
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#157738 (Support move expressions in coroutine closures)
 - rust-lang/rust#160219 (Implement `Thread::os_id`)
 - rust-lang/rust#162449 (Prefer removing a redundant shared reference over reborrow)
 - rust-lang/rust#162494 (Ignore `self-in-const-generics` test for parallel frontend)
 - rust-lang/rust#162495 (Reserve items in `Extend` implementations)
 - rust-lang/rust#162238 (trait solver: Include implied outlives assumptions)
 - rust-lang/rust#162473 (Small `x perf` improvements)
 - rust-lang/rust#162489 (Clean up on upvar_tys)
 - rust-lang/rust#162500 (Move the `expect-item-after-attribute.rs` test to the correct directory)
2026-09-08 23:50:49 +00:00
Leonard Chan
3206f026cf Revert "fuchsia: Add safestack as a supported sanitizer for x86_64 fuchsia"
This reverts commit 7a44484407.

This is leading to the issue seen in
https://github.com/rust-lang/rust/issues/162272. We're also seeing the
same build issues when using a rust toolchain that contains this commit
for building fuchsia targets.
2026-09-08 22:37:07 +00:00
Jonathan Brouwer
52152ad3ba Rollup merge of #162500 - JonathanBrouwer:move-test, r=GuillaumeGomez
Move the `expect-item-after-attribute.rs` test to the correct directory

To address the comment here: https://github.com/rust-lang/rust/pull/162386#issuecomment-5591496225

r? @GuillaumeGomez
2026-09-08 23:32:21 +02:00
Jonathan Brouwer
588de2eb14 Rollup merge of #162489 - chenyukang:yukang-refactor-upvar_tys, r=JonathanBrouwer
Clean up on upvar_tys

Found some duplicated code when digging https://github.com/rust-lang/rust/issues/162440

r? @lcnr
2026-09-08 23:32:20 +02:00
Jonathan Brouwer
ac73654e3d Rollup merge of #162473 - Kobzol:x-perf, r=JonathanBrouwer
Small `x perf` improvements

Tiny improvements I found while using this command locally.

r? JonathanBrouwer
2026-09-08 23:32:19 +02:00
Jonathan Brouwer
c29e8b2aac Rollup merge of #162238 - Dnreikronos:trait_solver/implied_outlives_assumptions, r=BoxyUwU
trait solver: Include implied outlives assumptions

Part of rust-lang/project-assumptions-on-binders#19

Split out of rust-lang/rust#161988 after @BoxyUwU pointed out that these are about which assumptions we keep, not really about reflexive region constraints.

I went back through where each piece comes from and found two gaps. Inside a binder we kept `Ty: 'a`, but the region relation only knew about explicit region clauses. That means something like `&'b T: 'a` did not also give us `'b: 'a`. At the root it was a slightly different version of the same problem: `known_type_outlives` has the explicit where clauses, while implied bounds from things like `&'b self` live in `region_bound_pairs`, so constraint destructuring never saw them.

`Assumptions::new` now pulls the free region components out of type outlives clauses and adds those edges to the region relation. I think doing it there is the cleanest spot. All callers get the same view of an assumption, and the original type clauses stay around for placeholder and alias cases. Regions bound inside the type are ignored because they do not name anything we can use outside that binder.

The root path now adds its implied type bounds to the same assumption set before destructuring. The regression uses an implied `I: 'b` from a receiver and a separate `'b: 'a` relation, so it covers this without leaning on the reflexive fix from rust-lang/rust#161988. There are also binder checks for a reference and a higher-ranked function type. Those caught an easy testing trap here: a green direct constraint could have depended on the other PR, so the checks look at the lifted candidates instead.

Personally, I think splitting this was the right call. It is really a change to how assumption data is built, and that is easier to reason about on its own than under the reflexive constraint fix.

cc @BoxyUwU, this is the pair of changes you asked me to pull out.
2026-09-08 23:32:18 +02:00
Jonathan Brouwer
31971f012e Rollup merge of #162495 - JonathanBrouwer:reserve-mono-extend, r=Kobzol
Reserve items in `Extend` implementations

This might be a perf win, inspired by @Kobzol's approach in this PR: https://github.com/rust-lang/rust/pull/162480
2026-09-08 23:32:17 +02:00
Jonathan Brouwer
a2cbc0a3b3 Rollup merge of #162494 - JonathanBrouwer:ignore-parallel, r=petrochenkov
Ignore `self-in-const-generics` test for parallel frontend

This is the guidance for failing tests in the parallel frontend per [#t-infra/announcements > rustc parallel frontend CI job @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/533458-t-infra.2Fannouncements/topic/rustc.20parallel.20frontend.20CI.20job/near/612990835)
To work around https://github.com/rust-lang/rust/issues/162316
2026-09-08 23:32:16 +02:00
Jonathan Brouwer
01d313205a Rollup merge of #162449 - chenyukang:yukang-fix-133685-remove-redundant-shared-reference, r=mati865
Prefer removing a redundant shared reference over reborrow

Fixes rust-lang/rust#133685
2026-09-08 23:32:15 +02:00
Jonathan Brouwer
815492b62e Rollup merge of #160219 - valentynkit:thread-os-id, r=nia-e
Implement `Thread::os_id`

Implements `Thread::os_id` as an unstable feature, per the accepted ACP rust-lang/libs-team#635.

Tracking issue: rust-lang/rust#160215

`os_id` returns the OS-level thread id, so Rust programs can tie their own logs to system-level logs (the ACP's stated motivation).

- Using the existing `current_os_id` is much simpler than pulling the id off `imp::Thread` in `spawn_unchecked`. That needs a per-platform arm, and the child still has to fill it in on platforms without a by handle query, so it'd be extra on top of this rather than instead of it.
- `Thread` is handed to user code by spawn hooks before the native thread exists, so the id can only be filled in later. There's no spare `u64` value to mean "not set yet", so a OnceLock is chosen as a simple primitive to use for this purpose.

r? libs
2026-09-08 23:32:14 +02:00
Jonathan Brouwer
cf24767d6e Rollup merge of #157738 - TaKO8Ki:move-expr-coroutine-closures, r=nikomatsakis
Support move expressions in coroutine closures

This adds `move(expr)` support for coroutine closures.

- [x] Support for move expressions in coroutine closures
- [x] Support for move expressions in async blocks

RFC: https://github.com/rust-lang/rfcs/pull/3968
Tracking issue: https://github.com/rust-lang/rust/issues/155050
Project goal:
- https://github.com/rust-lang/rust-project-goals/issues/107
- https://rust-lang.github.io/rust-project-goals/2026/ergonomic-rc.html

I used AI to write the tests and reviewed them myself.

r? @nikomatsakis
2026-09-08 23:32:13 +02:00
Flakebi
cd7a508b3d triagebot: Subscribe me to amdgpu changes 2026-09-08 23:09:22 +02:00
Jonathan Brouwer
71a523b7fd Move the expect-item-after-attribute.rs test to the correct directory 2026-09-08 23:04:10 +02:00
bors
4aa1fbcf46 Auto merge of #162476 - nikic:llvm-23.1.1, r=cuviper
Update to LLVM 23.1.1

Fixes https://github.com/rust-lang/rust/issues/162348.
2026-09-08 20:31:51 +00:00
Guillaume Gomez
21cfbaddb2 Ignore the GCC backend in some run-make tests until the GCC backend works for them
Limit some `run-make` tests to LLVM until GCC backend works for them
2026-09-08 21:34:22 +02:00
Jonathan Brouwer
5bd43f35e5 Do the same optimization in more places 2026-09-08 20:46:38 +02:00
Jonathan Brouwer
c6d1849411 Reserve items in Extend implementation of MonoItems 2026-09-08 20:41:43 +02:00
Jonathan Brouwer
2a61e69644 Ignore self-in-const-generics test for parallel frontend 2026-09-08 20:28:00 +02:00
bors
0b1760a65a Auto merge of #162487 - JonathanBrouwer:rollup-3MKwguM, r=JonathanBrouwer
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#162309 (offload: automate manual clang-linker-wrapper step)
 - rust-lang/rust#160505 (delegation: supporting inherent impls)
 - rust-lang/rust#160712 (windows-gnullvm: always link libunwind statically)
 - rust-lang/rust#161423 (trait_selection: Keep type-op region constraints in borrowck)
 - rust-lang/rust#162461 (limit the api of `fold_predicate` and `visit_predicate`)
 - rust-lang/rust#162475 (Fix unsoundness bug on next trait solver for dyn const generics placeholder)
2026-09-08 17:11:41 +00:00
Jakub Beránek
1b1b92ed33 Use DenseBit for drop_live_at in liveness tracing 2026-09-08 19:06:38 +02:00
Yukang
922fbba38e refactoring on upvar_tys 2026-09-09 00:42:54 +08:00
Takayuki Maeda
2ed8d0db76 add move-expression tests for generator closures 2026-09-09 01:40:45 +09:00
Takayuki Maeda
afff72e3fb update move-expression closure semantics tests 2026-09-09 01:40:45 +09:00
Takayuki Maeda
216cf9e084 evaluate coroutine-closure move expressions at closure creation 2026-09-09 01:40:45 +09:00
Takayuki Maeda
7fabedc462 add UI coverage for nested move expressions 2026-09-09 01:34:13 +09:00
Takayuki Maeda
b3d7ec7492 improve diagnostics for exhausted nested move expressions 2026-09-09 01:34:13 +09:00
Takayuki Maeda
e831c5324f fix nested move expression lowering across capture contexts 2026-09-09 01:34:12 +09:00
Takayuki Maeda
7541f06805 add coroutine block move expr tests 2026-09-09 01:31:19 +09:00
Takayuki Maeda
f5c36e81ab support move expr in coroutine blocks 2026-09-09 01:31:19 +09:00
Takayuki Maeda
db7693a6cc refactor move expr initializer wrapping 2026-09-09 01:31:19 +09:00
Takayuki Maeda
24590c86f6 rustfmt 2026-09-09 01:31:19 +09:00
Takayuki Maeda
79bad7dbba update move-expression coroutine closure tests 2026-09-09 01:31:19 +09:00
Takayuki Maeda
ee0ee6b66f handle move-expression captures in coroutine closures 2026-09-09 01:31:19 +09:00
Takayuki Maeda
2bb92c7a0f lower move expressions in coroutine closures 2026-09-09 01:31:19 +09:00
Jonathan Brouwer
faf7381fdd Rollup merge of #162475 - lsunsi:issue296, r=BoxyUwU
Fix unsoundness bug on next trait solver for dyn const generics placeholder

This seem to fix the related test, which would compile on next trait solver and should not.
It's related to the linked issue where it'd lead to a segmentation fault.

Closes https://github.com/rust-lang/trait-system-refactor-initiative/issues/296

r? @BoxyUwU
2026-09-08 18:19:39 +02:00
Jonathan Brouwer
d8dd9f1d38 Rollup merge of #162461 - jdonszelmann:restrict-fold-predicate, r=BoxyUwU
limit the api of `fold_predicate` and `visit_predicate`

r? @lcnr or anyone in @rust-lang/initiative-trait-system-refactor

In the future, we may want to start compressing clauses in the `ParamEnv`. One major problem was that we are leaking too many implementation details in `fold_predicate` and `visit_predicate`. Almost no code actually cares about dealing with an actual predicate there. Instead, what really matters is the type flags on a predicate for example. As such, this PR majorly limits the API that is exposed to a folder, hiding the underlying predicate data structure used.

As an example why this matters: in the case of compressed clauses, this will mean we won't need to "decompress" them. Instead, we can just fold over the self type, not telling folders whether the predicate was or was not compressed at all.

> [!NOTE]
> I've not used an LLM for any part of this PR, or any other PR I make. This includes any related work like research.
2026-09-08 18:19:39 +02:00
Jonathan Brouwer
9318843e0d Rollup merge of #161423 - Dnreikronos:trait_selection/preserve_type_op_constraints, r=BoxyUwU
trait_selection: Keep type-op region constraints in borrowck

I ran into this while working on rust-lang/rust#158588. `borrowck_env_fail` still had a FIXME because the function body wasn't reporting the outlives error. The next solver creates the region constraint, but the canonical type-op path doesn't put it in `QueryResponse`. Borrowck never sees it, so the type op looks fine and the error is lost.

With `-Zassumptions-on-binders`, these type ops now run locally on borrowck's `InferCtxt`. The fast path still runs first. That leaves the constraint in the same inference context borrowck reads later.

I prefer this over adding more data to the old canonical response. The next solver already caches its work, and teaching the old query path about these constraints felt like extra machinery for something we can avoid. Running locally is pretty boring, but I think that's a good thing here. The old FIXME is now the regression test.
2026-09-08 18:19:38 +02:00
Jonathan Brouwer
37719fa2b6 Rollup merge of #160712 - mati865:gnullvm-static-libunwind, r=petrochenkov
windows-gnullvm: always link libunwind statically

Previously shared library was used by default, meaning that programs and libraries couldn't be loaded if `libunwind.dll` was missing from the PATH. Using Wine (on Linux) because it better shows the problem (and is more convenient):
```
❯ cargo new hello &> /dev/null

❯ cargo rustc --target x86_64-pc-windows-gnullvm &> /dev/null

❯ wine target/x86_64-pc-windows-gnullvm/debug/hello.exe
0024:err:module:import_dll Library libunwind.dll (which is needed by L"Z:\\tmp\\hello\\target\\x86_64-pc-windows-gnullvm\\debug\\hello.exe") not found
0024:err:module:loader_init Importing dlls for L"Z:\\tmp\\hello\\target\\x86_64-pc-windows-gnullvm\\debug\\hello.exe" failed, status c0000135

❯ llvm-readobj --coff-imports target/x86_64-pc-windows-gnullvm/debug/hello.exe
...
Import {
  Name: libunwind.dll
  ImportLookupTableRVA: 0x3D308
  ImportAddressTableRVA: 0x3D678
  Symbol: _GCC_specific_handler (0)
  Symbol: _Unwind_DeleteException (0)
  Symbol: _Unwind_GetDataRelBase (0)
  Symbol: _Unwind_GetIPInfo (0)
  Symbol: _Unwind_GetLanguageSpecificData (0)
  Symbol: _Unwind_GetRegionStart (0)
  Symbol: _Unwind_GetTextRelBase (0)
  Symbol: _Unwind_RaiseException (0)
  Symbol: _Unwind_Resume (0)
  Symbol: _Unwind_SetGR (0)
  Symbol: _Unwind_SetIP (0)
}
...
```
Optionally libunwind could be linked statically via `+crt-static`:
```
❯ cargo rustc --target x86_64-pc-windows-gnullvm -- -C target-feature=+crt-static &> /dev/null

❯ wine target/x86_64-pc-windows-gnullvm/debug/hello.exe
Hello, world!

❯ llvm-readobj --coff-imports target/x86_64-pc-windows-gnullvm/debug/hello.exe | rg 'libunwind.dll' || echo "doesn't depend on shared libunwind"
doesn't depend on shared libunwind
```

After a discussion of approach in rust-lang/rust#159782 with @bjorn3 (thanks BTW!), I changed the proposed approach to always link static libunwind.

I don't have a good solution for https://github.com/rust-lang/rust/pull/121794 that will resurface. I guess the user has three options:
- symlink `libunwind.dll.a` as `libunwind.a`
- add `--unwindlib=none -lunwind` to the linker args
- create linker wrapper
- use self-contained mode which is likely is undesirable

I think the ease of use (not having to deal with additional DLL dependency) outweights the benefit of working with incomplete C toolchain.

The size bloat is also not a problem, sizes (in bytes) of the binary for the literal hello world project:
- debug build:
  - shared libunwind 4194816
  - static libunwind 4323328
- release build:
  - shared libunwind 382464
  - static libunwind 423424

Debug diff +125.5 KiB, release diff: +40 KiB.
Size of `libunwind.dll` that has to be provided when linking shared libunwind: 204288 bytes (199.5 KiB).
2026-09-08 18:19:37 +02:00
Jonathan Brouwer
78280f762a Rollup merge of #160505 - aerooneqq:delegation-inherent-methods, r=petrochenkov
delegation: supporting inherent impls

This PR adds support for delegation to inherent impl functions on the delegation side.

Support for inherent impls in delegation consists of two problems: we need to resolve inherent function through `ProbeContext` routine and then we need to generate delegation function knowing the `DefId` of the signature function. The first problem is a fundamental problem given current compiler architecture, and it is not solved in this PR. To imitate working resolution for tests we adopt simple resolution by name only in inherent impls (not trait impls, which would work if we implement fair resolution through `ProbeContext`). A `resolve_type_relative_delegations` query was created which tries to resolve unresolved delegations after resolve stage. In future, when we will be able to fairly resolve delegations through `ProbeContext` contents of this query can be changed and all other logic implemented in this pull request will work.

## Free to inherent impl

Unlike free to trait delegation where we generated explicit `Self` param, here we just use default parameter.

```rust
struct X<'a, T, const B: bool>(...);
impl<'a, T, const B: bool> X<'a, T, B> {
  fn foo<'b, U, const X: usize>(&self) { ... }
}

reuse X::<'static, (), false>::foo as foo1;
reuse X::<'static, (), false,>::foo::<'static, (), 123> as foo3;

//Desugaring:
#[attr = Inline(Hint)]
fn foo1<'b, U, const X: _>(self: _) -> _ where
    'b:'b { X<'static, (), false>::foo::<'b, U, X>(self) }

#[attr = Inline(Hint)]
fn foo3(self: _) -> _ { X<'static, (), false>::foo::<'static, (), 123>(self) }
```

## Trait to inherent impl

In trait to inherent impl delegation we replace the type of self parameter from impl's type to `Self` generic param (if the signature function is a method).

```rust
trait Trait {
    reuse X::<'static, (), false>::foo as foo1;
    reuse X::<'static, (), false,>::foo::<'static, (), true> as foo3;
}

// Desugaring:
trait Trait {
    #[attr = Inline(Hint)]
    fn foo1<'b, U, const X: _>(self: _) -> _ where
        'b:'b { X<'static, (), false>::foo::<'b, U, X>(self) }

    #[attr = Inline(Hint)]
    fn foo3(self: _)
        -> _ { X<'static, (), false>::foo::<'static, (), 123>(self) }
}
```

Note that we didn't specified target expression, so we would get errors like:
```rust
error[E0308]: mismatched types
  --> $DIR/xd.rs:10:14
   |
LL | trait Trait {
   | ----------- found this type parameter
LL |     reuse X::foo;
   |              ^^^
   |              |
   |              expected `&X<'_, T, B>`, found `&Self`
   |              arguments to this function are incorrect
   |
   = note: expected reference `&X<'_, T, B>`
              found reference `&Self`
```

## Trait impl to inherent impl

Here the resolution should look signature in trait as in other cases where we delegate from trait impl. We generate function whose signature matches the resolved function in trait. We propagate only child generics if they are not specified.

```rust
trait Trait {
    fn foo<A, B, C>(&self) { }
    fn foo1<T, U, V>(&self) { }
    fn foo2<'a, T, U, V>(&self) where 'a:'a { }
    fn foo3(&self) { }
}

impl Trait for X {
    reuse X::<'static, (), false>::foo as foo1;
    reuse X::<'static, (), false,>::foo::<'static, (), 123> as foo3;
}

// Desugaring:
impl Trait for X<'_> {
    #[attr = Inline(Hint)]
    fn foo1<T, U, V>(self: _)
        -> _ { X<'static, (), false>::foo::<T, U, V>(self) }

    #[attr = Inline(Hint)]
    fn foo3(self: _)
        -> _ { X<'static, (), false>::foo::<'static, (), 123>(self) }
}
```

## Inherent impl to inherent impl

In inherent impl to inherent impl delegation we replace signature self type with delegation parent self type in case of methods.
```rust
trait Trait {
    fn foo<A, B, C>(&self) { }
    fn foo1<T, U, V>(&self) { }
    fn foo2<'a, T, U, V>(&self) where 'a:'a { }
    fn foo3(&self) { }
}

struct Y;

impl Trait for Y {
    reuse X::<'static, (), false>::foo as foo1;
    reuse X::<'static, (), false,>::foo::<'static, (), 123> as foo3;
}

impl Trait for Y {
    #[attr = Inline(Hint)]
    fn foo1<T, U, V>(self: _)
        -> _ { X<'static, (), false>::foo::<T, U, V>(self) }

    #[attr = Inline(Hint)]
    fn foo3(self: _)
        -> _ { X<'static, (), false>::foo::<'static, (), 123>(self) }
}
```

We did not specify target expression so we would get errors like:
```rust
error[E0308]: mismatched types
  --> $DIR/xd.rs:12:14
   |
LL |     reuse X::foo;
   |              ^^^
   |              |
   |              expected `&X<'_, T, B>`, found `Y`
   |              arguments to this function are incorrect
   |
   = note: expected reference `&X<'_, T, B>`
                 found struct `Y`
```

## Generics

After some experiments I think that we should force user to always specify generics for parent segment of delegation to inherent impls. Consider the following example and imagine that we can use fair resolution through `ProbeContext`:

```rust
trait M1 {}
trait M2 {}

struct S1;
struct S2;

impl M1 for S1 {}
impl M2 for S2 {}

struct X<T, U>(T, U);

impl<T: M1> X<T, ()> {
    fn foo() {}
}

impl<T: M2> X<T, usize> {
    fn foo() {}
}

reuse X::foo;
```

How to resolve `X::foo`? If we generate parent generics (`fn foo<T, U>() { X::<T, U>::foo() }`) which clauses should we inherit? It is impossible to determine which function to reuse, and despite the fact that there may be some cases where it is possible, I don't think that we should write heuristics for that. So always specifying parent generics seems to be a good option. Also I think we should ban infers in parent segment too.

One implementation aspect of how we map generic args for signature and predicates inheritance, as we inherit predicates not from the ADT declaration but from the impl block we need to take generic args from this impl, not from the declaration. So indices of generic args are taken from the impl block and then they are used in mapping and future instantiation:

```rust
struct S<'a, A, const C: usize> {
    xd: &'a [A; C],
}

// index of A = 3
// index of C = 4
impl<'a, 'b, 'c, A, const C: usize> S<A, C> {
    fn foo_self<'d: 'd, 'e, T, const B: bool>(self) {}
}

trait Trait<'a, AA, BB> where Self: Sized {
    reuse S::<(), ()>::foo_self;
    // Args: [Self/#0, 'a/#1, AA/#2, BB/#3, '{region error}, 'd/#4, (), {const error}, T/#5, B/#6]
    // Mapping: {0: 0, 7: 9, 5: 5, 3: 6, 6: 8, 4: 7}, A (index 3) is mapped into index 6 (`()`), C (index 4) mapped into index 7 (const error)
}
```

## Other concerns

### Glob and list delegations

List delegations are supported, glob delegations are not supported:

```rust
struct X;

impl X {
    fn foo(&self) {}
    fn foo2(&self) {}
}

struct Y;

impl Y {
    reuse X::{foo, foo2} { X }
}

impl Y {
    reuse X::*;
    //~^ ERROR: expected trait, found struct `X`
}
```

### Self type adjustments and target expression deletion

Adjustments for receiver are applied, adjustments for other parameters whose types contain `Self` are not applied as `Self` acts as a type alias to the struct, not a generic param which will can get replaced. The deletion of target expression should work as before.

```rust
enum X {
   ...
}

impl X {
    fn static_f() {}
    fn by_value(self) {}
    fn by_ref(&self) {}
    fn by_mut_ref(&mut self) {}
}

struct Y;

impl Y {
    fn get_x(&self) -> X { X }
    reuse X::{static_f, by_value, by_ref, by_mut_ref} { self.get_x() }
}

impl Y {
    fn get_x(&self) -> X { X }

    #[attr = Inline(Hint)]
    fn static_f() -> _ { X::static_f() }

    #[attr = Inline(Hint)]
    fn by_value(self: _) -> _ { X::by_value(self.get_x()) }

    #[attr = Inline(Hint)]
    fn by_ref(self: _) -> _ { X::by_ref(self.get_x()) }

    #[attr = Inline(Hint)]
    fn by_mut_ref(self: _) -> _ { X::by_mut_ref(self.get_x()) }
}

fn main() {
    let y = Y;
    y.by_ref();
    y.by_mut_ref();
    //~^ ERROR: cannot borrow `y` as mutable, as it is not declared as mutable
    y.by_value();

    let y = &Y;
    y.by_value();
    //~^ ERROR: cannot move out of `*y` which is behind a shared reference
    y.by_ref();
    y.by_mut_ref();
    //~^ ERROR: cannot borrow `*y` as mutable, as it is behind a `&` reference

    let y = &mut Y;
    y.by_value();
    //~^ ERROR: cannot move out of `*y` which is behind a mutable reference
    y.by_ref();
    y.by_mut_ref();
}
```

### Recursive delegations

Works as before, we just check the resolution chain and we do not care whether it came from resolution at resolve stage or from resolution of type relative delegations.

r? @petrochenkov
2026-09-08 18:19:36 +02:00
Jonathan Brouwer
16f306cb78 Rollup merge of #162309 - sgasho:offload-clang-linker-wrapper, r=ZuseZ4
offload: automate manual clang-linker-wrapper step

automate manual clang-linker-wrapper step from https://rustc-dev-guide.rust-lang.org/offload/usage.html
extract bitcode from device.bin and then wraps it into the host module.
needs some refactoring.

r? @ZuseZ4
2026-09-08 18:19:36 +02:00