Trait implementation splitting #4
Draft
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.
feat: Introduce experimental
implshards syntaxThis PR introduces an experimental
implshards syntax, allowing a trait implementation to be split into multipleimplitems, each defining a single associated item.Why:
To enable more granular organization of trait implementations, potentially across different parts of a module. This is a foundational step for exploring "impl shards" as requested by the user.
How it works:
impl Trait for Type fn method() { ... }is parsed under the#[feature(impl_shards)]gate.rustc_ast_passes::impl_shards) merges these single-itemimplshards into a single, conventionalimpl Trait for Type { ... }block. This occurs early in the compilation pipeline, before macro expansion and name resolution.implshards within the same module that share identicalimplheaders (trait, self type, generics, where clause, modifiers).implblock.Current Limitations:
include!()or macros across different files/modules will not be merged, as the merging pass is module-local and pre-expansion. This means cross-module shards will still trigger existing coherence errors.Tests:
tests/ui/impl-shards/split.rs: Verifies successful compilation of splitimpls.tests/ui/impl-shards/feature-gate.rs: EnsuresE0658is emitted without the feature gate.tests/ui/impl-shards/duplicate.rs: ConfirmsE0201for duplicate method definitions after merging.