Skip to content
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

Use internal iteration in the Sum and Product impls of Result and Option #62459

Merged
merged 1 commit into from
Aug 6, 2019
Merged

Use internal iteration in the Sum and Product impls of Result and Option #62459

merged 1 commit into from
Aug 6, 2019

Conversation

timvermeulen
Copy link
Contributor

This PR adds internal iteration to the ResultShunt iterator type underlying the Sum and Product impls of Result. I had to change ResultShunt to hold a mutable reference to an error instead, similar to itertools::ProcessResults, in order to be able to pass the ResultShunt itself by value (which is necessary for internal iteration).

ResultShunt::process can unfortunately no longer be an associated function because that would make it generic over the lifetime of the error reference, which wouldn't work, so I turned it into the free function process_results.

I removed the OptionShunt type and forwarded the Sum and Product impls of Option to their respective impls of Result instead, to avoid having to repeat the internal iteration logic.

@rust-highfive
Copy link
Collaborator

r? @shepmaster

(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 Jul 7, 2019
@Centril
Copy link
Contributor

Centril commented Jul 7, 2019

r? @scottmcm

@rust-highfive rust-highfive assigned scottmcm and unassigned shepmaster Jul 7, 2019
@Stargateur
Copy link
Contributor

Stargateur commented Jul 23, 2019

look, like we are in conflict #62883

I tried to keep OptionShunt while delegate the implementation to ResultShunt do you think it's possible to make it compile #62883 (comment) ?

Also, are you sure your code doesn't slow done thing ? Why should take a reference to an error should be better ?

@shepmaster
Copy link
Member

Ping @scottmcm — probably worth reviewing both related PRs.

@timvermeulen
Copy link
Contributor Author

@Stargateur So it looks like my PR removes the duplication between OptionShunt and ResultShunt, while yours removes the duplication between those types and the two Adapter types used in the FromIterator impls? It seems to me like our PRs are totally compatible. If your PR is merged first, then I can still apply these changes to ResultShunt / OptionShunt, and I could implement Option::from_iter in terms of Result::from_iter. How does that sound?

@scottmcm
Copy link
Member

@timvermeulen Sounds like a good plan. I approved #62883, and will wait on your update here.

@bors
Copy link
Contributor

bors commented Jul 28, 2019

☔ The latest upstream changes (presumably #63057) made this pull request unmergeable. Please resolve the merge conflicts.

@timvermeulen
Copy link
Contributor Author

@scottmcm I updated my branch, it should now match what I described in my previous comment 🙂

@edmilsonefs
Copy link

Hey! This is a ping from triage, we would like to know if you @scottmcm could give us a few more minutes to update us from last changes made by @timbertson .

Thanks.

@scottmcm
Copy link
Member

scottmcm commented Aug 6, 2019

Very nice! Great to see the .by_ref() disappearing 🎉

@bors r+

@bors
Copy link
Contributor

bors commented Aug 6, 2019

📌 Commit 2e41ba8 has been approved by scottmcm

@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 Aug 6, 2019
@bors
Copy link
Contributor

bors commented Aug 6, 2019

⌛ Testing commit 2e41ba8 with merge c0832e47f4cc1f8b75a2239104899a0d28b7280c...

Centril added a commit to Centril/rust that referenced this pull request Aug 6, 2019
…eration, r=scottmcm

Use internal iteration in the Sum and Product impls of Result and Option

This PR adds internal iteration to the `ResultShunt` iterator type underlying the `Sum` and `Product` impls of `Result`. I had to change `ResultShunt` to hold a mutable reference to an error instead, similar to `itertools::ProcessResults`, in order to be able to pass the `ResultShunt` itself by value (which is necessary for internal iteration).

`ResultShunt::process` can unfortunately no longer be an associated function because that would make it generic over the lifetime of the error reference, which wouldn't work, so I turned it into the free function `process_results`.

I removed the `OptionShunt` type and forwarded the `Sum` and `Product` impls of `Option` to their respective impls of `Result` instead, to avoid having to repeat the internal iteration logic.
@Centril
Copy link
Contributor

Centril commented Aug 6, 2019

@bors retry rolled up.

@bors
Copy link
Contributor

bors commented Aug 6, 2019

⌛ Testing commit 2e41ba8 with merge 320ac879e9127dea1139438ed82ca841b89c4954...

Centril added a commit to Centril/rust that referenced this pull request Aug 6, 2019
…eration, r=scottmcm

Use internal iteration in the Sum and Product impls of Result and Option

This PR adds internal iteration to the `ResultShunt` iterator type underlying the `Sum` and `Product` impls of `Result`. I had to change `ResultShunt` to hold a mutable reference to an error instead, similar to `itertools::ProcessResults`, in order to be able to pass the `ResultShunt` itself by value (which is necessary for internal iteration).

`ResultShunt::process` can unfortunately no longer be an associated function because that would make it generic over the lifetime of the error reference, which wouldn't work, so I turned it into the free function `process_results`.

I removed the `OptionShunt` type and forwarded the `Sum` and `Product` impls of `Option` to their respective impls of `Result` instead, to avoid having to repeat the internal iteration logic.
@Centril
Copy link
Contributor

Centril commented Aug 6, 2019

@bors retry

bors added a commit that referenced this pull request Aug 6, 2019
Rollup of 6 pull requests

Successful merges:

 - #62459 (Use internal iteration in the Sum and Product impls of Result and Option)
 - #62821 (Not listed methods)
 - #62837 (Fix theme picker blur handler: always hide instead of switching)
 - #63286 (Replace error callback with Result)
 - #63296 (Deduplicate rustc_demangle in librustc_codegen_llvm)
 - #63298 (assume_init: warn about valid != safe)

Failed merges:

r? @ghost
@bors bors merged commit 2e41ba8 into rust-lang:master Aug 6, 2019
@bors
Copy link
Contributor

bors commented Aug 6, 2019

☔ The latest upstream changes (presumably #63328) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants