6
6
# Summary
7
7
[ summary ] : #summary
8
8
9
- Add a conservative form of abstract return types, aka ` impl Trait ` ,
10
- that will be compatible with most possible future extensions by
11
- initially being restricted to:
9
+ Add a conservative form of abstract return types, also known as `impl
10
+ Trait`, that will be compatible with most possible future extensions
11
+ by initially being restricted to:
12
12
13
13
- Only free-standing or inherent functions.
14
14
- Only return type position of a function.
@@ -175,7 +175,7 @@ and the *initial limitations* (which are likely to be lifted later).
175
175
- As far as the typesystem and the compiler is concerned , the return type
176
176
outside of the function would not be a entirely " new" type , nor would it be a
177
177
simple type alias . Rather , its semantics would be very similar to that of
178
- _generic type paramters_ inside a function , with small differences caused by
178
+ _generic type parameters_ inside a function , with small differences caused by
179
179
being an _output_ rather than an _input_ of the function .
180
180
181
181
- The type would be known to implement the specified traits .
@@ -189,7 +189,7 @@ and the *initial limitations* (which are likely to be lifted later).
189
189
non - local type checking becoming necessary .
190
190
191
191
- The return type has an identity based on all generic parameters the
192
- function body is parametrized by , and by the location of the function
192
+ function body is parameterized by , and by the location of the function
193
193
in the module system . This means type equality behaves like this :
194
194
195
195
```rust
@@ -211,7 +211,7 @@ and the *initial limitations* (which are likely to be lifted later).
211
211
212
212
- The code generation passes of the compiler would not draw a distinction
213
213
between the abstract return type and the underlying type , just like they don 't
214
- for generic paramters . This means :
214
+ for generic parameters . This means :
215
215
- The same trait code would be instantiated , for example , `-> impl Any `
216
216
would return the type id of the underlying type .
217
217
- Specialization would specialize based on the underlying type .
@@ -221,7 +221,7 @@ and the *initial limitations* (which are likely to be lifted later).
221
221
- `impl Trait ` may only be written within the return type of a freestanding or
222
222
inherent - impl function , not in trait definitions or any non - return type position . They may also not appear
223
223
in the return type of closure traits or function pointers ,
224
- unless these are themself part of a legal return type .
224
+ unless these are themselves part of a legal return type .
225
225
226
226
- Eventually , we will want to allow the feature to be used within traits , and
227
227
like in argument position as well (as an ergonomic improvement over today 's generics ).
@@ -262,7 +262,7 @@ was in fact the main focus of the
262
262
[blog post ](http : // aturon.github.io/blog/2015/09/28/impl-trait/) on `impl
263
263
Trait `. )
264
264
265
- The design as choosen in this RFC lies somewhat in between those two , since it
265
+ The design as chosen in this RFC lies somewhat in between those two , since it
266
266
allows OIBITs to leak through , and allows specialization to " see" the full type
267
267
being returned . That is , `impl Trait ` does not attempt to be a " tightly sealed"
268
268
abstraction boundary . The rationale for this design is a mixture of pragmatics
@@ -308,15 +308,15 @@ item-level API, but has been deemed worth it for the following reasons:
308
308
309
309
- Ergonomics : Trait objects already have the issue of explicitly needing to
310
310
declare `Send `/ `Sync `- ability , and not extending this problem to abstract
311
- return types is desireable . In practice , most uses of this feature would have
311
+ return types is desirable . In practice , most uses of this feature would have
312
312
to add explicit bounds for OIBITS if they wanted to be maximally usable .
313
313
314
314
- Low real change , since the situation already somewhat exists on structs with private fields :
315
315
- In both cases , a change to the private implementation might change whether a OIBIT is
316
316
implemented or not .
317
- - In both cases , the existence of OIBIT impls is not visible without doc tools
317
+ - In both cases , the existence of OIBIT impls is not visible without documentation tools
318
318
- In both cases , you can only assert the existence of OIBIT impls
319
- by adding explicit trait bounds either to the API or to the crate 's testsuite .
319
+ by adding explicit trait bounds either to the API or to the crate 's test suite .
320
320
321
321
In fact , a large part of the point of OIBITs in the first place was to cut
322
322
across abstraction barriers and provide information about a type without the
@@ -327,7 +327,7 @@ change a function with a abstract return type in a way that removes OIBIT impls,
327
327
which might be a problem . (As noted above , this is already the case for `struct `
328
328
definitions . )
329
329
330
- But since the number of used OIBITs is relatvly small , deducing the return type
330
+ But since the number of used OIBITs is relatively small , deducing the return type
331
331
in a function body and reasoning about whether such a breakage will occur has
332
332
been deemed as a manageable amount of work .
333
333
@@ -409,7 +409,7 @@ Because `impl Trait` defines a type tied to the concrete function body,
409
409
it does not make much sense to talk about it separately in a function signature ,
410
410
so the syntax is forbidden there .
411
411
412
- ### Compability with conditional trait bounds
412
+ ### Compatibility with conditional trait bounds
413
413
414
414
On valid critique for the existing `impl Trait ` proposal is that it does not
415
415
cover more complex scenarios , where the return type would implement
@@ -437,7 +437,7 @@ One important usecase of abstract return types is to use them in trait methods.
437
437
However , there is an issue with this, namely that in combinations with generic
438
438
trait methods, they are effectively equivalent to higher kinded types.
439
439
Which is an issue because Rust HKT story is not yet figured out, so
440
- any "accidential implementation" might cause unintended fallout.
440
+ any "accidental implementation" might cause unintended fallout.
441
441
442
442
HKT allows you to be generic over a type constructor, aka a
443
443
"thing with type parameters", and then instantiate them at some later point to
@@ -531,13 +531,13 @@ See the links in the motivation section for detailed analysis that we won't
531
531
repeat here .
532
532
533
533
But basically , without this feature certain things remain hard or impossible to do
534
- in Rust , like returning a efficiently usable type parametricised by
534
+ in Rust , like returning a efficiently usable type parameterized by
535
535
types private to a function body , for example an iterator adapter containing a closure .
536
536
537
537
# Unresolved questions
538
538
[unresolved ]: #unresolved - questions
539
539
540
- > What parts of the design are still TBD ?
540
+ > What parts of the design are still to be determined ?
541
541
542
542
The precise implementation details for OIBIT transparency are a bit unclear : in
543
543
general , it means that type checking may need to proceed in a particular order ,
0 commit comments