Uh oh!
There was an error while loading. Please reload this page.
auto-impl: parser support - #149335
Conversation
rustbot
commented
Nov 25, 2025
Some changes occurred in src/tools/clippy cc @rust-lang/clippy Some changes occurred in compiler/rustc_passes/src/check_attr.rs This PR changes rustc_public cc @oli-obk, @celinval, @ouz-a HIR ty lowering was modified cc @fmease Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt Some changes occurred in compiler/rustc_sanitizers cc @rcvalle |
rustbot
commented
Nov 25, 2025
r? @fee1-dead rustbot has assigned @fee1-dead. Use |
Uh oh!
There was an error while loading. Please reload this page.
644d1ce to
fac5797Comparedingxiangfei2009
commented
Dec 1, 2025
I think the priority here is to first get parser code proof-read. |
Uh oh!
There was an error while loading. Please reload this page.
It's probably more a language-related comment, than compiler-related, but the placement of auto impls doesn't seem right. Auto impls are not associated items, they could very well live as free items, and placed into the traits just for the proximity. Even from the compiler point of view in HIR and below we'd now need to separate real associated items from the things that just live there in source code, and may break some other assumptions across the compiler about only one level of associated item nesting existing, making building the prototype harder. |
petrochenkov
commented
Dec 2, 2025
The semicolon in |
petrochenkov
commented
Dec 2, 2025
Could you add some tests executing all the supported syntax, including |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
petrochenkov
commented
Dec 2, 2025
(I'll continue the review tomorrow.) |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
petrochenkov
commented
Dec 3, 2025
After reading the PR I'd again suggest to implement these impls as free items first, because you'll have a whole host of issues just from trying to move them from free to associated items. |
rustbot
commented
Dec 3, 2025
Reminder, once the PR becomes ready for a review, use |
469a4cc to
c19307aCompareUh oh!
There was an error while loading. Please reload this page.
This comment has been minimized.
This comment has been minimized.
adfc499 to
ed73c51CompareUh oh!
There was an error while loading. Please reload this page.
This comment has been minimized.
This comment has been minimized.
ed73c51 to
05561ebCompare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
05561eb to
9e5b35bComparerustbot
commented
Mar 1, 2026
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This patch introduce AST elements for `auto impl` inside the `trait` and `impl` block. This patch does not handle the name resolution, yet. It will be handled in the next patch series. Signed-off-by: Xiangfei Ding <dingxiangfei2009@protonmail.ch>
9e5b35b to
79a479eComparedingxiangfei2009
commented
Mar 1, 2026
@rustbot ready
|
☔ The latest upstream changes (presumably #153344) made this pull request unmergeable. Please resolve the merge conflicts. |
petrochenkov
commented
Mar 6, 2026
Again, my suggestion was to turn traitBigTrait:Supertrait{
auto implSupertrait;fnfoo(..);}into something like traitBigTrait:Supertrait{fnfoo(..);}
autoimplSupertraitforBigTrait{}// or similarso auto impls are never associated items at any IR level. After the feature semantics are fully implemented in this and following PRs, we can consider moving them to associated items at some level, but that would be a separate work. |
Thank you so much for reviewing @petrochenkov
Okay I can do that. If we go down this route, I would further propose adding a keyword auto impl $Supertrait for trait $Subtrait { .. }How does it sound? |
It makes sense to be syntactically explicit in some way here since one would otherwise expect that to be a type context. The other keyword that comes to mind as plausible would be |
petrochenkov
commented
Mar 12, 2026
My comment above was only about auto impls, not extern impls, because auto impls are actually similar to regular impls, and because I didn't understand what extern impls do. Now I reread the RFC and the extern impls look more like modifiers (?) to other impls, rather than (associated) items on their own? traitDerivedTrait:BaseTrait1,BaseTrait2,BaseTrait3{}
autoimplBaseTrait1for trait DerivedTrait{}
autoimplBaseTrait2for trait DerivedTrait{}
autoimplBaseTrait3for trait DerivedTrait{}implDerivedTraitforType
except BaseTrait3// "extern impl" as an impl modifier{fnbase_method1(){}fnbase_method2(){}// but no base_method3, it comes from elsewhere}(As the RFC says, technically the modifier can even be inferred automatically.) This feels like a sufficiently independent extension to auto impls, so I suggest to also defer its implementation until auto impls themselves are ready. |
@petrochenkov@dingxiangfei2009 How about change to the following style: Use pubtraitTraitA{fnfoo();}pubtraitTraitB{fnfoo();}pubtraitTraitC{fnfoo();}pubtraitSubtrait:TraitA + TraitB + TraitC{fnfoo();// Also OK (*)}
autoimplTraitAfor trait Subtrait{}
autoimplTraitBfor trait Subtrait{}
autoimplTraitCfor trait Subtrait{}structMyType;implTraitCforMyType{fnfoo(){}}implSubtrait - TraitCforMyType{implTraitA{fnfoo(){}}implTraitB{fnfoo(){}}fnfoo(){}// Also OK (*)}fnmain(){let _ = <MyTypeasSubtrait>::foo();// OK, `Subtrait::foo` resolves to the instance (**)// NOT `<MyType as TraitA>::foo` or `<MyType as TraitB>::foo`} |
Dylan-DPC
commented
Jun 12, 2026
@dingxiangfei2009 any updates on this? thanks |
View all comments
Tracking:
auto impl#149556This patch introduce AST elements for
auto implinside thetraitandimplblock.This patch does not handle the name resolution, yet. It will be handled in the next patch series.
RFC: rust-lang/rfcs#3851
cc
As a tracking issue is pending, I will link rust-lang/goals#393 for more context.