Skip to content

Commit 7b33d0b

Browse files
authored
Add a 2025H2 project goal for the delegation language feature (#356)
1 parent 7ab1743 commit 7b33d0b

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed

src/2025h2/delegation.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Unsafe Fields
2+
3+
| Metadata | |
4+
| :-- | :-- |
5+
| Point of contact | @petrochenkov |
6+
| Teams | <!-- TEAMS WITH ASKS --> |
7+
| Task owners | <!-- TASK OWNERS --> |
8+
| Status | Proposed |
9+
| Zulip channel | N/A |
10+
| Tracking issue | [rust-lang/rust#118212] |
11+
12+
## Summary
13+
14+
Finish implementation of the delegation language as described in [RFC 3530], and update the RFC
15+
with more detailed design based on the implementation experience.
16+
17+
## Motivation
18+
19+
This proposal falls under the [Efficient code reuse](https://github.com/rust-lang/rfcs/issues/349)
20+
umbrella.
21+
22+
Rust doesn't have the sort of data inheritance common for object oriented languages, in which
23+
derived data structure can inherit from some base data structure and automatically use its methods
24+
that way.
25+
In Rust this pattern is typically expressed through composition, in which the "base" data structure
26+
is put into the "derived" data structure as a (possibly nested) field or some similar kind of
27+
sub-object.
28+
Newtypes (`struct Derived(Base);`) are an especially popular example of such pattern.
29+
30+
With composition methods that in other languages could be potentially inherited automatically need
31+
to be implemented manually (possibly with help of macros).
32+
Such trivial implementations may create a lot of boilerplate, and even prevent people from using
33+
newtypes when it would be appropriate for type safety.
34+
35+
This proposal aims to support a sugar that would allow to avoid such boilerplate in cases
36+
similar to inheritance and newtypes, and in other cases too if they fit into the same basic
37+
mechanism, while staying in limited syntactic budget.
38+
39+
### The status quo
40+
41+
The base parts of the RFC, and some advanced features were implemented in 2024, reported bugs were
42+
fixed and the feature is already in a usable state, even if the functionality is limited.
43+
44+
The detailed checklist for the sub-features can be found on the
45+
[tracking issue](https://github.com/rust-lang/rust/issues/118212).
46+
47+
### The "shiny future" we are working towards
48+
49+
Rust programmers will be able to conveniently delegate implementations of functions (struct methods
50+
in particular) to other already implemented functions (for some fields of those structs in particular).
51+
52+
Some special support for newtypes will be available, like adjustment of the return type from the
53+
wrapped type to newtype.
54+
55+
Some higher level sugar, like delegating the whole trait implementation at once will also be
56+
supported.
57+
58+
### The next 6 months
59+
60+
We plan to complete implmentation of the sub-features as described in the
61+
[tracking issue](https://github.com/rust-lang/rust/issues/118212) and update the RFC with the more
62+
detailed design based on the implementation experience.
63+
64+
## Design axioms
65+
66+
Our design of delegation feature is guided by a number of principles described in the [RFC 3530].
67+
68+
1. Limit the syntactic budget for the feature, so a delegated function looks more like an import,
69+
than a function implementation.
70+
2. Use statistics from existing code to select functionality that we should fit into that limited
71+
budget.
72+
3. Support more rarely used functionality if it fits into the same implementation scheme and
73+
doesn't extend the syntactic budget.
74+
75+
## Ownership and team asks
76+
77+
**Owner:** @petrochenkov
78+
79+
| Task | Owner(s) or team(s) | Notes |
80+
|--------------------------------|----------------------|--------------------------------|
81+
| Discussion and moral support | ![Team][] [lang] | |
82+
| Author RFC | @petrochenkov | [RFC 3530] |
83+
| Implementation | @bryanskiy, @petrochenkov | |
84+
| Standard reviews | ![Team][] [compiler] | |
85+
| Design meeting | ![Team][] [lang] | |
86+
| Lang-team champion | ![Team][] [lang] | @traviscross |
87+
| RFC decision | ![Team][] [lang] | |
88+
89+
[RFC 3530]: https://github.com/rust-lang/rfcs/pull/3530
90+
[tracking issue]: https://github.com/rust-lang/rust/issues/118212
91+
92+
### Definitions
93+
94+
For definitions for terms used above, see the [About > Team Asks](https://rust-lang.github.io/rust-project-goals/about/team_asks.html) page.
95+
96+
* *Discussion and moral support* is the lowest level offering, basically committing the team to nothing but good vibes and general support for this endeavor.
97+
* *Author RFC* and *Implementation* means actually writing the code, document, whatever.
98+
* *Design meeting* means holding a synchronous meeting to review a proposal and provide feedback (no decision expected).
99+
* *RFC decisions* means reviewing an RFC and deciding whether to accept.
100+
* *Org decisions* means reaching a decision on an organizational or policy matter.
101+
* *Secondary review* of an RFC means that the team is "tangentially" involved in the RFC and should be expected to briefly review.
102+
* *Stabilizations* means reviewing a stabilization and report and deciding whether to stabilize.
103+
* *Standard reviews* refers to reviews for PRs against the repository; these PRs are not expected to be unduly large or complicated.
104+
* *Prioritized nominations* refers to prioritized lang-team response to nominated issues, with the expectation that there will be *some* response from the next weekly triage meeting.
105+
* *Dedicated review* means identifying an individual (or group of individuals) who will review the changes, as they're expected to require significant context.
106+
* Other kinds of decisions:
107+
* [Lang team experiments](https://lang-team.rust-lang.org/how_to/experiment.html) are used to add nightly features that do not yet have an RFC. They are limited to trusted contributors and are used to resolve design details such that an RFC can be written.
108+
* Compiler [Major Change Proposal (MCP)](https://forge.rust-lang.org/compiler/mcp.html) is used to propose a 'larger than average' change and get feedback from the compiler team.
109+
* Library [API Change Proposal (ACP)](https://std-dev-guide.rust-lang.org/development/feature-lifecycle.html) describes a change to the standard library.
110+
111+
## Frequently asked questions
112+
113+
TBD

0 commit comments

Comments
 (0)