Skip to content

Remove unnecessary SpecFromIter impls #85867

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

steffahn
Copy link
Member

Unless I’m missing something, these SpecFromIter<&'a T, …> for Vec<T> implementations were completely unused.

@rust-highfive
Copy link
Contributor

r? @Mark-Simulacrum

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 31, 2021
@Mark-Simulacrum
Copy link
Member

Unfortunate that these aren't statically detected but I guess that's true of all (trait) impls...

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 31, 2021
@bors
Copy link
Collaborator

bors commented May 31, 2021

⌛ Trying commit c902fdc with merge 81b35bb706dcef83a467dfb93f9415cea94a3b09...

@bors
Copy link
Collaborator

bors commented May 31, 2021

☀️ Try build successful - checks-actions
Build commit: 81b35bb706dcef83a467dfb93f9415cea94a3b09 (81b35bb706dcef83a467dfb93f9415cea94a3b09)

@rust-timer
Copy link
Collaborator

Queued 81b35bb706dcef83a467dfb93f9415cea94a3b09 with parent d9feaaa, future comparison URL.

@the8472
Copy link
Member

the8472 commented May 31, 2021

How did you determine that they're unused? They're specialization implementations, so they should be used for particular instances of an iterator. It looks like the last one is supposed to turn a [T].iter().collect() into [T].to_vec().

@the8472
Copy link
Member

the8472 commented May 31, 2021

The trait documentation would be outdated with this change

/// +-+-------------------------------+ +---------------------+
/// |SpecFromIter +---->+SpecFromIterNested |
/// |where I: | | |where I: |
/// | Iterator (default)----------+ | | Iterator (default) |
/// | vec::IntoIter | | | TrustedLen |
/// | SourceIterMarker---fallback-+ | | |
/// | slice::Iter | | |
/// | Iterator<Item = &Clone> | +---------------------+
/// +---------------------------------+
/// ```

@steffahn
Copy link
Member Author

steffahn commented May 31, 2021

How did you determine that they're unused?

There are impls of the form SpecFromIter<T, …> for Vec<T> and of the form SpecFromIter<&'a T, …> for Vec<T>. None of the first type of impl can ever overlap with any impl of the second type. I removed all the impls of the second form and std still compiles.

~/forks/rust/library @ master $ rg 'impl.*SpecFromIter<.*for' -A3
alloc/src/vec/source_iter_marker.rs
24:impl<T, I> SpecFromIter<T, I> for Vec<T>
25-where
26-    I: Iterator<Item = T> + SourceIterMarker,
27-{

alloc/src/vec/spec_from_iter.rs
31:impl<T, I> SpecFromIter<T, I> for Vec<T>
32-where
33-    I: Iterator<Item = T>,
34-{
--
40:impl<T> SpecFromIter<T, IntoIter<T>> for Vec<T> {
41-    fn from_iter(iterator: IntoIter<T>) -> Self {
42-        // A common case is passing a vector into a function which immediately
43-        // re-collects into a vector. We can short circuit this if the IntoIter
--
69:impl<'a, T: 'a, I> SpecFromIter<&'a T, I> for Vec<T>
70-where
71-    I: Iterator<Item = &'a T>,
72-    T: Clone,
--
83:impl<'a, T: 'a + Clone> SpecFromIter<&'a T, slice::Iter<'a, T>> for Vec<T> {
84-    #[cfg(not(test))]
85-    fn from_iter(iterator: slice::Iter<'a, T>) -> Self {
86-        iterator.as_slice().to_vec()

the last one is supposed to turn a [T].iter().collect() into […]

This doesn’t even compile.

@steffahn
Copy link
Member Author

steffahn commented May 31, 2021

The trait documentation would be outdated with this change

Good catch. I’ve added another commit changing those docs.

@the8472
Copy link
Member

the8472 commented May 31, 2021

Ah, I see. Looking through the history it looks this was originally used for the Extend<&'a T> implementation which shared some code with the FromIterator implementations which I then split into separate specializations but didn't clean up.
This would need an equivalent FromIterator<&'a T> implementation to be of any use and that doesn't exist.

👍

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (81b35bb706dcef83a467dfb93f9415cea94a3b09): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 31, 2021
@Mark-Simulacrum
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Jun 3, 2021

📌 Commit 5ea3e73 has been approved by Mark-Simulacrum

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 3, 2021
@bors
Copy link
Collaborator

bors commented Jun 3, 2021

⌛ Testing commit 5ea3e73 with merge f1cee2c...

@bors
Copy link
Collaborator

bors commented Jun 4, 2021

☀️ Test successful - checks-actions
Approved by: Mark-Simulacrum
Pushing f1cee2c to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jun 4, 2021
@bors bors merged commit f1cee2c into rust-lang:master Jun 4, 2021
@rustbot rustbot added this to the 1.54.0 milestone Jun 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants