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

Make EncodeWide implement FusedIterator #96397

Merged
merged 1 commit into from
Apr 28, 2022
Merged

Make EncodeWide implement FusedIterator #96397

merged 1 commit into from
Apr 28, 2022

Conversation

AronParker
Copy link
Contributor

EncodeUtf16 and EncodeWide currently serve similar purposes: They convert from UTF-8 to UTF-16 and WTF-8 to WTF-16, respectively. EncodeUtf16 wraps a &str, whereas EncodeWide wraps an &OsStr.

When Iteration has concluded, these iterators wrap an empty slice, which will forever yield None values. Hence, EncodeUtf16 rightfully implements FusedIterator. However, EncodeWide in contrast does not, even though it serves an almost identical purpose.

This PR attempts to fix that issue. I consider this change minor and non-controversial, hence why I have not added a RFC/FCP. Please let me know if the stability attribute is wrong or contains a wrong version number. Thanks in advance.

Fixes #96368

@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Apr 25, 2022
@rust-highfive
Copy link
Collaborator

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with r? rust-lang/libs-api @rustbot label +T-libs-api -T-libs to request review from a libs-api team reviewer. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@rust-highfive
Copy link
Collaborator

r? @joshtriplett

(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 Apr 25, 2022
@AronParker
Copy link
Contributor Author

r? rust-lang/libs-api @rustbot label +T-libs-api -T-libs

@rustbot rustbot added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 25, 2022
@ChrisDenton ChrisDenton added the needs-fcp This change is insta-stable, so needs a completed FCP to proceed. label Apr 25, 2022
@ChrisDenton
Copy link
Member

ChrisDenton commented Apr 25, 2022

As @scottmcm said, this is instantly stable so it does need to be signed off by the libs-api team. But I don't anticipate there being any concerns for reasons noted in the OP.

@dtolnay
Copy link
Member

dtolnay commented Apr 25, 2022

@rust-lang/libs-api:
@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented Apr 25, 2022

Team member @dtolnay has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Apr 25, 2022
@rfcbot
Copy link

rfcbot commented Apr 26, 2022

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot removed the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Apr 26, 2022
@dtolnay
Copy link
Member

dtolnay commented Apr 27, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Apr 27, 2022

📌 Commit fc6af81 has been approved by dtolnay

@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 Apr 27, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Apr 27, 2022
Make EncodeWide implement FusedIterator

[`EncodeUtf16`](https://doc.rust-lang.org/std/str/struct.EncodeUtf16.html) and [`EncodeWide`](https://doc.rust-lang.org/std/os/windows/ffi/struct.EncodeWide.html) currently serve similar purposes: They convert from UTF-8 to UTF-16 and WTF-8 to WTF-16, respectively. `EncodeUtf16` wraps a &str, whereas `EncodeWide` wraps an &OsStr.

When Iteration has concluded, these iterators wrap an empty slice, which will forever yield `None` values. Hence, `EncodeUtf16` rightfully implements `FusedIterator`. However, `EncodeWide` in contrast does not, even though it serves an almost identical purpose.

This PR attempts to fix that issue. I consider this change minor and non-controversial, hence why I have not added a RFC/FCP. Please let me know if the stability attribute is wrong or contains a wrong version number. Thanks in advance.

Fixes rust-lang#96368
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Apr 27, 2022
Make EncodeWide implement FusedIterator

[`EncodeUtf16`](https://doc.rust-lang.org/std/str/struct.EncodeUtf16.html) and [`EncodeWide`](https://doc.rust-lang.org/std/os/windows/ffi/struct.EncodeWide.html) currently serve similar purposes: They convert from UTF-8 to UTF-16 and WTF-8 to WTF-16, respectively. `EncodeUtf16` wraps a &str, whereas `EncodeWide` wraps an &OsStr.

When Iteration has concluded, these iterators wrap an empty slice, which will forever yield `None` values. Hence, `EncodeUtf16` rightfully implements `FusedIterator`. However, `EncodeWide` in contrast does not, even though it serves an almost identical purpose.

This PR attempts to fix that issue. I consider this change minor and non-controversial, hence why I have not added a RFC/FCP. Please let me know if the stability attribute is wrong or contains a wrong version number. Thanks in advance.

Fixes rust-lang#96368
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Apr 28, 2022
Make EncodeWide implement FusedIterator

[`EncodeUtf16`](https://doc.rust-lang.org/std/str/struct.EncodeUtf16.html) and [`EncodeWide`](https://doc.rust-lang.org/std/os/windows/ffi/struct.EncodeWide.html) currently serve similar purposes: They convert from UTF-8 to UTF-16 and WTF-8 to WTF-16, respectively. `EncodeUtf16` wraps a &str, whereas `EncodeWide` wraps an &OsStr.

When Iteration has concluded, these iterators wrap an empty slice, which will forever yield `None` values. Hence, `EncodeUtf16` rightfully implements `FusedIterator`. However, `EncodeWide` in contrast does not, even though it serves an almost identical purpose.

This PR attempts to fix that issue. I consider this change minor and non-controversial, hence why I have not added a RFC/FCP. Please let me know if the stability attribute is wrong or contains a wrong version number. Thanks in advance.

Fixes rust-lang#96368
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 28, 2022
Rollup of 7 pull requests

Successful merges:

 - rust-lang#96377 (make `fn() -> _ { .. }` suggestion MachineApplicable)
 - rust-lang#96397 (Make EncodeWide implement FusedIterator)
 - rust-lang#96421 (Less `NoDelim`)
 - rust-lang#96432 (not need `Option` for `dbg_scope`)
 - rust-lang#96466 (Better error messages when collecting into `[T; n]`)
 - rust-lang#96471 (replace let else with `?`)
 - rust-lang#96483 (Add missing `target_feature` to the list of well known cfg names)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit c4dd0d3 into rust-lang:master Apr 28, 2022
@rustbot rustbot added this to the 1.62.0 milestone Apr 28, 2022
@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels May 6, 2022
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label May 12, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 15, 2023
…or, r=dtolnay

Implement FusedIterator for DecodeUtf16 when the inner iterator does

I have just implemented an iterator that wraps `DecodeUtf16` and wanted to implement `FusedIterator` for my iterator when I noticed that `DecodeUtf16` currently doesn't implement `FusedIterator` at all.
A quick look at the code of `DecodeUtf16` revealed that `DecodeUtf16::next` only returns `None` when its inner iterator returns `None`:
https://github.com/rust-lang/rust/blob/3462f79e94f466a56ddaccfcdd3a3d44dd1dda9f/library/core/src/char/decode.rs#L45

As a result, we can implement `FusedIterator` for `DecodeUtf16` when the inner iterator does.

I'm following the example of rust-lang#96397 here and consider this change minor and non-controversial, which is why I haven't added an RFC. I have also added the required feature name (`"decode_utf16_fused_iterator"`), however without adding a chapter to the Rust Unstable book (same as rust-lang#96397).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. needs-fcp This change is insta-stable, so needs a completed FCP to proceed. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EncodeWide should implement FusedIterator
9 participants