Rollup of 9 pull requests - #162474
Closed
JonathanBrouwer wants to merge 21 commits into
Closed
Conversation
I ended up deciding not to add docs about `bounds` as it seems like a relatively minor feature of the derive, and there are docs at [1]. [1]: https://github.com/rust-lang/rust/blob/3ffb26fbf5bf232cf59e314e75ea325973f4f583/compiler/rustc_type_ir_macros/src/lib.rs#L21-L55
Just specifying `T: GenericTypeVisitable` doesn't work, as the trait has a generic: `V`, the visitor. `T: GenericTypeVisitable<__V>` is what actually works, as `__V` is the generic added to the impl generated by the derive macro. We discussed[1] different ways of making this nicer, but settled on not doing anything, as we don't expect people to need to specify any actual bounds. [1]: https://rust-lang.zulipchat.com/#narrow/channel/185405-t-compiler.2Frust-analyzer/topic/Updating.20next-solver/near/618331780 and below
…ods, 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/rust-lang#1, AA/rust-lang#2, BB/rust-lang#3, '{region error}, 'd/rust-lang#4, (), {const error}, T/rust-lang#5, B/rust-lang#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
…call-args, r=WaffleLapkin mir: validate `Move` call arguments are locals or box derefs Fixes rust-lang#103362. This PR adds a MIR validation check for `Move` arguments passed to `Call` and `TailCall` terminators. A moved argument should be either a local or the contents of the `Box`. Other places can deinitialize memory that codegen does not track correctly. The check is only enabled with `-Zvalidate-mir`, using the same phase restriction as the existing `Copy` check. Added a regression test covering the invalid case.
…nBrouwer Add tests and docs for `#[derive(GenericTypeVisitable)]` ..given the added complexity from the newly-added `bounds` attribute Follow-up to rust-lang#160914 More details in individual commits. cc @JonathanBrouwer (you might want to take over the review of this since you have some context already.. but as you wish) cc @ChayimFriedman2
…r=WaffleLapkin run `extern "tail"` with `byval` argument test With LLVM 23 we can run `extern "tail"` tests with `byval` arguments on x86 and x86_64. AArch64 does not (yet) support this, see llvm/llvm-project#206718.
…nnethercote windows-gnu: document libgcc requirement Fixes rust-lang#158933
Update books ## rust-lang/book 1 commits in 917544888a55e4da7109bdba8c88c893c0da70f4..1500248d8f230566e4ec9f27fcbb8fe9e2898ab1 2026-09-02 16:04:34 UTC to 2026-09-02 16:04:34 UTC - Update to Rust 1.98 (rust-lang/book#4823) ## rust-lang/edition-guide 1 commits in f5abcf137698e5ad6ebed359d69654ff705346af..ab8544aeed7b792984366aa122ac19bd47ad9a2f 2026-08-25 19:50:54 UTC to 2026-08-25 19:50:54 UTC - Update never-type-fallback for never type stabilization (rust-lang/edition-guide#384) ## rust-lang/reference 12 commits in 3b38834b39f732c64686f7c64aa29dcf3cd83ba5..e24eecf97b0c9a6dbac67191098204dc8a190aaa 2026-09-02 04:25:27 UTC to 2026-08-25 07:52:18 UTC - Fix nested block comment grammar (rust-lang/reference#2348) - dangling pointers: turn some consequences of the definition into notes (rust-lang/reference#2336) - Fix the nightly grammar validation job (rust-lang/reference#2347) - Order grammar summary deterministically (rust-lang/reference#2346) - Remove leftover `types/textual.md` file (rust-lang/reference#2345) - Fix non-leaf rules with bodies (rust-lang/reference#2344) - Fix rule IDs not following the header hierarchy (rust-lang/reference#2343) - Fix heading level of the `verbatim` modifier section (rust-lang/reference#2342) - Fix `...diagnostics.deprecated...` rule ID (rust-lang/reference#2341) - Update for stabilization of the never type (rust-lang/reference#2283) - Add missing punctuation (rust-lang/reference#2339) - Fix field-less `repr(C)` enum docs (rust-lang/reference#2018)
…-diagnostic-attribute-lint, r=mejrs Add regression test for item-local diagnostic attribute lint levels Closes rust-lang#135772 This issue was fixed by rust-lang#160499 indirectly. r? @mejrs
…, r=Darksonn docs(time): replace "method" with "function" I used the word "method" in rust-lang#162195 and rust-lang#162199, but these are associated functions, not methods, so I think it's correct to use the word "function". @rustbot label +A-docs
…athanBrouwer Fix my duplicate thanks entry r? @ghost I accidentally committed with the wrong email :3
Member
Author
|
@bors r+ p=5 |
Contributor
Contributor
|
Tree closed for PRs with priority less than 5. |
This comment has been minimized.
This comment has been minimized.
rust-bors Bot
pushed a commit
that referenced
this pull request
Sep 8, 2026
…uwer Rollup of 9 pull requests Successful merges: - #160505 (delegation: supporting inherent impls) - #160651 (mir: validate `Move` call arguments are locals or box derefs) - #161806 (Add tests and docs for `#[derive(GenericTypeVisitable)]`) - #161912 (run `extern "tail"` with `byval` argument test) - #162435 (windows-gnu: document libgcc requirement) - #162439 (Update books) - #162451 (Add regression test for item-local diagnostic attribute lint levels) - #162459 (docs(time): replace "method" with "function") - #162465 (Fix my duplicate thanks entry)
This was referenced Sep 8, 2026
Collaborator
|
A job failed! Check out the build log: (web) (plain enhanced) (plain) Click to see the possible cause of the failure (guessed by this bot) |
Contributor
|
💔 Test for 8c107de failed: CI. Failed job:
|
Member
Author
|
Guessing #160505 |
Contributor
|
This pull request was unapproved due to being closed. |
Collaborator
|
The job Click to see the possible cause of the failure (guessed by this bot)Important For more information how to resolve CI failures of this job, visit this link. |
This was referenced Sep 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Successful merges:
Movecall arguments are locals or box derefs #160651 (mir: validateMovecall arguments are locals or box derefs)#[derive(GenericTypeVisitable)]#161806 (Add tests and docs for#[derive(GenericTypeVisitable)])extern "tail"withbyvalargument test #161912 (runextern "tail"withbyvalargument test)r? @ghost
Create a similar rollup