Skip to content

Commit 2274ce3

Browse files
committed
Rename IntoIntIterator
1 parent 81fbad1 commit 2274ce3

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

text/0000-return-position-impl-trait-in-traits.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,26 @@ When you use `impl Trait` as the return type for a function within a trait defin
5050
Consider the following trait:
5151

5252
```rust
53-
trait IntoIntIterator {
53+
trait IntoNumIterator {
5454
fn into_int_iter(self) -> impl Iterator<Item = u32>;
5555
}
5656
```
5757

5858
The semantics of this are analogous to introducing a new associated type within the surrounding trait;
5959

6060
```rust
61-
trait IntoIntIterator { // desugared
62-
type IntoIntIter: Iterator<Item = u32>;
63-
fn into_int_iter(self) -> Self::IntoIntIter;
61+
trait IntoNumIterator { // desugared
62+
type IntoNumIter: Iterator<Item = u32>;
63+
fn into_int_iter(self) -> Self::IntoNumIter;
6464
}
6565
```
6666

6767
When using `-> impl Trait`, however, there is no associated type that users can name.
6868

69-
By default, the impl for a trait like `IntoIntIterator` must also use `impl Trait` in return position.
69+
By default, the impl for a trait like `IntoNumIterator` must also use `impl Trait` in return position.
7070

7171
```rust
72-
impl IntoIntIterator for Vec<u32> {
72+
impl IntoNumIterator for Vec<u32> {
7373
fn into_int_iter(self) -> impl Iterator<Item = u32> {
7474
self.into_iter()
7575
}
@@ -79,7 +79,7 @@ impl IntoIntIterator for Vec<u32> {
7979
It can, however, give a more specific type with `#[refine]`:[^refine]
8080

8181
```rust
82-
impl IntoIntIterator for Vec<u32> {
82+
impl IntoNumIterator for Vec<u32> {
8383
#[refine]
8484
fn into_int_iter(self) -> impl Iterator<Item = u32> + ExactSizeIterator {
8585
self.into_iter()
@@ -568,10 +568,10 @@ Not compatibly, no, because they would no longer have a named associated type. T
568568

569569
Generally yes, but all impls would have to be rewritten to include the definition of the associated type. In many cases, some form of type-alias impl trait (or impl trait in associated type values) would also be required.
570570

571-
For example, if we changed the `IntoIntIterator` trait from the motivation to use an explicit associated type..
571+
For example, if we changed the `IntoNumIterator` trait from the motivation to use an explicit associated type..
572572

573573
```rust
574-
trait IntoIntIterator {
574+
trait IntoNumIterator {
575575
type IntIter: Iterator<Item = u32>;
576576
fn into_iter(self) -> Self::IntIter;
577577
}
@@ -580,7 +580,7 @@ trait IntoIntIterator {
580580
...then impls like...
581581

582582
```rust
583-
impl IntoIntIterator for MyType {
583+
impl IntoNumIterator for MyType {
584584
fn into_int_iter(self) -> impl Iterator<Item = u32> {
585585
(0..self.len()).map(|x| x * 2)
586586
}
@@ -591,7 +591,7 @@ impl IntoIntIterator for MyType {
591591

592592
### Would there be any way to make it possible to migrate from `impl Trait` to a named associated type compatibly?
593593

594-
Potentially! There have been proposals to allow the values of associated types that appear in function return types to be inferred from the function declaration. So, using the example from the previous question, the impl for `IntoIntIterator` could infer the value of `IntIter` based on the return type of `into_int_iter`. This may be a good idea, but it is not proposed as part of this RFC.
594+
Potentially! There have been proposals to allow the values of associated types that appear in function return types to be inferred from the function declaration. So, using the example from the previous question, the impl for `IntoNumIterator` could infer the value of `IntIter` based on the return type of `into_int_iter`. This may be a good idea, but it is not proposed as part of this RFC.
595595

596596
### What about using an implicitly-defined associated type?
597597

@@ -657,7 +657,7 @@ There are a number of crates that do desugaring like this manually or with proce
657657

658658
### Naming return types
659659

660-
This RFC does not include a way for generic code to name or bound the result of `-> impl Trait` return types. This means, for example, that for the `IntoIntIterator` trait introduced in the motivation, it is not possible to write a function that takes a `T: IntoIntIterator` which returns an `ExactLenIterator`; for async functions, the most common time this comes up is code that wishes to take an async function that returns a `Send` future. We expect future RFCs will address these use cases.
660+
This RFC does not include a way for generic code to name or bound the result of `-> impl Trait` return types. This means, for example, that for the `IntoNumIterator` trait introduced in the motivation, it is not possible to write a function that takes a `T: IntoNumIterator` which returns an `ExactLenIterator`; for async functions, the most common time this comes up is code that wishes to take an async function that returns a `Send` future. We expect future RFCs will address these use cases.
661661

662662
### Dynamic dispatch
663663

0 commit comments

Comments
 (0)