You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Emphasize the possibility of continuing to use `#[refine]` in future
editions, and list out all the options under Unresolved Questions.
Include the attribute in examples.
Simplify the usage of `#[refine]` in existing editions so that it is
needed to refine any aspect of an API, instead of new features being
refine-able by default and old ones needing the attribute.
Move any discussion of *not* doing a soft transition to Unresolved
Questions to simplify the Reference Level Explanation a bit.
@@ -187,56 +190,33 @@ Refined APIs are available anywhere knowledge of the impl being used is availabl
187
190
188
191
## Transitioning away from the current behavior
189
192
190
-
Because we allow writing impls that look refined, but are [not usable][not-usable] as such, landing this feature means we are auto-stabilizing new ecosystem API surface. There are two ways of dealing with this:
191
-
192
-
### Do nothing
193
-
194
-
Assume that public types want to expose the APIs they actually wrote in their implementations, and allow using those APIs immediately.
195
-
196
-
### Soft transition
193
+
Because we allow writing impls that look refined, but are [not usable][not-usable] as such, landing this feature could mean auto-stabilizing new ecosystem API surface. We should probably be conservative and require library authors to opt in to refined APIs with a `#[refine]` attribute. This can be done in two parts.
197
194
198
-
Be conservative and require library authors to opt in to refined APIs. This can be done in two parts.
199
-
200
-
#### Lint against unmarked refined impls
195
+
### Lint against unmarked refined impls
201
196
202
197
After this RFC is merged, we should warn when a user writes an impl that looks refined and suggest that they copy the exact API of the trait they are implementing. Once this feature stabilizes, we can should add and suggest using `#[refine]` attribute to mark that an impl is intentionally refined.
203
198
204
-
####Automatic migration for the next edition
199
+
### Automatic migration for the next edition
205
200
206
-
Because refinement will be the default behavior for the next edition, we should rewrite users' code to preserve its semantics over edition migrations. That means we will replace trait implementations that look refined with the original API of the trait items being implemented.
201
+
We may want to upgrade the above lint to an error in 2024 or make refinement the default without any attribute at all. In either of these cases, we should have an automatic edition migration that rewrites users' code to preserve its semantics. That means we will replace trait implementations that look refined with the original API of the trait items being implemented.
207
202
208
-
####Documentation
203
+
### Documentation
209
204
210
-
The following text should be added to document the difference in editions.
205
+
The following can be added to the reference to document the difference in editions.
211
206
212
-
For historical reasons, not all kinds of refinement are automatically supported in older editions.
| Method | impl Trait in return position[^future]| All editions|
220
-
| Method | Lifetimes | 2024 and newer |
221
-
| Method | Where clauses | 2024 and newer |
222
-
| Method | impl Trait in argument position | 2024 and newer |
223
-
| Const | Lifetimes | 2024 and newer |
224
-
| Const | Where clauses | 2024 and newer |
209
+
Refinements of trait items that do not match the API of the trait exactly must be accompanied by a `#[refine]` attribute on the item in Rust 2021 and older editions.[^refine-edition]
225
210
226
-
[^future]: This feature is not accepted at the time of writing the RFC; it is included here for demonstration purposes.
211
+
For historical reasons, we allow valid refinements on the following features in Rust 2021 and earlier without a `#[refine]` attribute. However, no refinements are available to callers without this attribute; it will be as if the trait API was copied directly.
227
212
228
-
You can opt in to the new behavior in older editions with a `#[refine]` attribute on the associated item.
213
+
* Lifetimes
214
+
* Where clauses
215
+
* impl Trait in argument position
216
+
* Lifetimes
217
+
* Where clauses
229
218
230
-
```rust
231
-
implErrorforMyError {
232
-
#[refine]
233
-
fndescription(&self) ->&'staticstr {
234
-
"My Error Message"
235
-
}
236
-
}
237
-
```
238
-
239
-
This enables refining all features in the table above.
219
+
[^refine-edition]: Depending on the outcome of the Unresolved Questions in this RFC, this may also be the case for future editions.
240
220
241
221
## Preventing future ambiguity
242
222
@@ -332,23 +312,23 @@ One piece of related prior art here is the [leakage of auto traits][auto-leakage
332
312
# Unresolvedquestions
333
313
[unresolved-questions]: #unresolved-questions
334
314
335
-
## Doweneedasofttransition?
336
-
337
-
In"Transitioning away from the current behavior"wedescribetwopossiblepaths:immediatestabilizationofanyAPIthecompileracceptsthathappenstolookrefinedtoday, anddoingasofttransition.
In"Transitioning away from the current behavior"abovewedescribedoingasofttransition.However, theanalysisoncrates.io justdescribed_could_revealthat"dormant refinements"arealmostneveramistake, anda `#[refine]` attributeisnotneededinfutureeditions.Inthatcasewemaywanttoreconsiderthesofttransitionapproachforexistingeditions.
0 commit comments