Use better generic type parameter names for Extend and FromIterator - #161379
Open
steffahn wants to merge 3 commits into
Open
Use better generic type parameter names for Extend and FromIterator#161379steffahn wants to merge 3 commits into
Extend and FromIterator#161379steffahn wants to merge 3 commits into
Conversation
Collaborator
|
r? @JohnTitor rustbot has assigned @JohnTitor. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Member
Author
|
This failure might be spurious, for all I can tell, so let's retry. I might as well rebase now to reduce back the number of commits (integrating the previous two fixes for test failure with the respective change they correspond to) to trigger another run ^^ Edit: Yup, it was a spurious failure, the same test passed now. |
steffahn
force-pushed
the
extend_trait_param_name
branch
from
August 20, 2026 16:57
ae45a17 to
3060fe3
Compare
Extend trait's generic param name some other generics, tooExtend and FromIterator
JohnTitor
approved these changes
Aug 30, 2026
steffahn
force-pushed
the
extend_trait_param_name
branch
from
August 30, 2026 23:12
3060fe3 to
9bca736
Compare
Member
Author
|
@bors r=JohnTitor |
Contributor
|
@steffahn: 🔑 Insufficient privileges: not in review users |
Member
|
Oh sorry I thought you had, @bors r+ |
Contributor
jhpratt
added a commit
to jhpratt/rust
that referenced
this pull request
Aug 31, 2026
…r=JohnTitor
Use better generic type parameter names for `Extend` and `FromIterator`
Change
```rs
pub trait Extend<A> {
fn extend<T: IntoIterator<Item = A>>(&mut self, iter: T);
…
}
```
to
```rs
pub trait Extend<T> {
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I);
…
}
```
to be more consistent with common use of `T` as the item type in containers, and their `Extend` impls; and use `I` as the name for the `IntoIterator` type.
also do the basically the same thing for `FromIterator<A>`→`FromIterator<T>` as well
cases of these parameters in trait impls for the abovementioned traits.
These changes obviously don't change/break behavior of the traits and its users, but the improve the way the documentation of the traits renders (the improvement is the more sensible and more consistent names for the parameters). The only downside I'm aware of (besides that this is touching quite a few files..) is that this does affect some link anchor names in *some* cases. E.g.
```diff
- impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
+ impl<T, V: FromIterator<T>> FromIterator<Option<T>> for Option<V> {
```
would mean that [doc.rust-lang.org/core/iter/trait.FromIterator.html#impl-FromIterator<Option\<A>>-for-Option\<V>](https://doc.rust-lang.org/core/iter/trait.FromIterator.html#impl-FromIterator%3COption%3CA%3E%3E-for-Option%3CV%3E) no longer works, as it changes `…#impl-FromIterator<Option<A>>-for-Option<V>` to `…#impl-FromIterator<Option<T>>-for-Option<V>`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Okay, first some context:
When talking about the
Extendtrait in a recent meeting, it got really confusing to talk about properties of theExtendtrait for a moment because the naming convention on the trait was so weird. It's defined asExtend<A>and has a methodextend<T>. But most generic implementations of it look likeimpl<T> Extend<T> for …iterator-type…, calling the item typeT.I think
Tis quite sensible for the item type here, so let's change it in the trait definition as well!That means that
<T>for theextendmethod must go away.. what is that anyway? Yes, it't theIntoIteratorparameter that you extend with. Why isn't that justIanyway? Let's choose that! It will be more consistent with existing things likeimpl<I: Iterator> IntoIterator for Ifor instance. Or e.g. all of these… 🦀I've then also noticed
FromIteratorhas the same problem of calling the itemAand usingT: IntoIterator. Let's change that, too.....and then of course, there are a “handful” of implementations of these methods that did just copy the signature for
fn extend<T>orfn from_iter<T>, so I guess I'm fixing these as well.TL;DR:
Change
to
to be more consistent with common use of
Tas the item type in containers, and theirExtendimpls; and useIas the name for theIntoIteratortype.(first commit)
then also do the basically the same thing for
FromIterator<A>→FromIterator<T>as well(second commit)
Finally, adjust
a fewa lot of cases of these parameters in trait impls for the abovementioned traits.(third commit)
These changes obviously don't change/break behavior of the traits and its users, but the improve the way the documentation of the traits renders (the improvement is the more sensible and more consistent names for the parameters). The only downside I'm aware of (besides that this is touching quite a few files.. though I don't feel quite as strongly about all those impls needing change as about the trait definition itself) is that this does affect some link anchor names in some cases. E.g.
would mean that doc.rust-lang.org/core/iter/trait.FromIterator.html#impl-FromIterator<Option<A>>-for-Option<V> no longer works, as it changes
…#impl-FromIterator<Option<A>>-for-Option<V>to…#impl-FromIterator<Option<T>>-for-Option<V>