Summary
This proposal lets a downstream crate replace one method of an existing concrete impl while keeping the rest, via an opt-in impl mut marker and override blocks that forward unlisted methods to super.
Concretely, it adds two new items:
· impl mut Trait for Type { ... } marks an existing impl as open for override. · override Trait for Type { ... } creates a new implementation that only specifies the methods it changes; unlisted methods are implicitly forwarded to the override target.
Inside an override block, super refers to the override target's implementation, allowing reuse of the original behavior.
The goal is to let downstream crates incrementally modify an existing concrete impl without forking the crate, writing a newtype, or hand-writing forwarding boilerplate.
Motivation
Rust's existing reuse tools each have a gap:
· Composition/delegation: Can modify behavior, but requires manually forwarding every method of the wrapped impl. Changing one method still means writing N forwarding stubs. · Newtype: Requires a new type; all signatures at call sites change. · Trait default methods: Reuse is decided by the trait author, not by the consumer; you cannot replace one method of an already written concrete impl. · Macros: Generate code, but the result is independent code with no semantic link to the original impl. · Specialization: Solves overlap at the generic constraint level, not "replace one method of a specific concrete impl and keep the rest."
Concrete scenario: a third-party crate provides impl Parser for TheirType; one method has a bug or poor performance. Today the options are fork the crate, wrap it in a newtype and re-forward everything, or wait for upstream. There is no type-system-level way to say "use their impl, but replace this one method."
This proposal is that mechanism. It is intentionally small: it does not change the default reuse path (traits + composition remain the norm), does not introduce inheritance trees, and does not pass implicit state between types.
Detailed design
- impl mut — opt-in extension point. impl mut A for B { ... } declares the block open for override. A plain impl cannot be overridden.
- override — partial replacement with implicit forwarding.
Only listed methods are replaced; unlisted methods forward to the override target.override A for B { fn foo(&self) { /* new behavior, may call super.foo() */ } // bar, baz, ... automatically forwarded to the override target } - super — reuse the override target. super refers to the implementation named as the override target (the specific impl mut or override it was declared against), not a type hierarchy. super.foo() calls the target's foo. It appears in expression position inside override methods; super elsewhere remains the path keyword.
- Override chains form a DAG. override may target another override (see rule 6). Two overrides with the same target are allowed provided they are declared in different paths. super resolves along the declaration edge one step.
- Resolution scope is the declaration site. A call to T::method() inside a function resolves against the impls/overrides visible where the function is declared, not where it is called. This confines an override's effect to the declaring module and keeps coherence and monomorphization unaffected by call-site imports.
- Overrides are not re-overridable by default. An override can only be overridden if declared override mut. This mirrors the opt-in philosophy of impl mut.
- Orphan-rule exemption, disambiguated by paths. override is exempt from the orphan rule. Conflicts are resolved by import: use path::impl selects the base impl, use path::override selects an override. The same (Trait, Type) pair may not appear twice under one path.
- Missing mut recovery. If a downstream crate wants to override an override that was not marked mut, it copies that override into its own path and declares a fresh override. The new node is independent of the original; no special mechanism needed.
Drawbacks
· Trait resolution complexity. The resolver must incorporate "overrides visible at the declaration site" into trait solving. This is the main engineering cost; rule 5 deliberately fixes the scope to keep it bounded. · Readability of chains. With a DAG and implicit forwarding, "which impl actually runs" needs tooling (e.g., an override-chain expansion). This is a tooling concern, not a semantic one. · Proliferation risk. Authors may mark every impl mut "just in case," diluting the meaning of the extension point. A lint or community convention could mitigate this.
Rationale and alternatives
· Why not specialization? Specialization decides overlap among impls with different generic bounds; it does not let a consumer replace one method of a specific concrete impl while retaining the rest. The two are complementary. · Why not scope-based impl selection? Scoped-impl proposals address orphan-rule bypass and impl selection per scope, and typically change the type's identity. This proposal keeps type identity and adds incremental modification with super reuse. · Why impl mut rather than "any impl is overridable"? Opt-in prevents third parties from silently altering a library's behavior; the library author decides whether an extension point exists.
Prior art
I am not aware of an accepted or open RFC matching this combination (impl mut + partial override + super reuse + declaration-site resolution). Scope-based impl proposals share the "disambiguate by path" idea but differ in purpose and semantics. Feedback on closer prior art is welcome — that is part of why this is a Pre-RFC.
Unresolved questions
- Keyword collision for super. super currently only appears in paths, and an override block's method body is an expression context, so the two usages likely do not collide syntactically. Preferred: keep super, resolved by context. Fallback if the parser or diagnostics object: a contextual keyword base, valid only inside override blocks.
- Naming. Should impl mut / override blocks be optionally nameable for better diagnostics and path imports, without forcing authors to pick names?
- Path-syntax ergonomics. Is use path::impl / use path::override acceptable, or does it need a dedicated syntax?
- Interaction with specialization and coherence. Does declaration-site resolution fully avoid interaction with the existing coherence model, or are there edge cases (e.g., associated type projection through an override)?
- Associated types. The sketch allows associated types to be overridden; projection through an override chain needs specification.
- Object safety and dyn. How do overrides interact with trait objects and vtable construction?
Conclusion
This is a small mechanism aimed at a specific gap: modifying an existing concrete impl incrementally, in a way that is explicit, scoped, and reuses the original via super. It does not replace composition or traits as the default reuse path. I am posting this as a Pre-RFC to validate that the gap is real, check for prior art, and get feedback on the resolution-scope question and the DAG semantics before considering a formal RFC.
Disclosure: The design and core ideas are mine. The English text of this post was drafted with AI assistance.