Add CStr::bytes iterator
See rust-lang/libs-team#135 for an ACP.
Since rust-lang/libs-team#134 was also accepted, this type is now core::ffi::c_str::Bytes instead of core::ffi::CStrBytes.
r? @thomcc
(rustbot has picked a reviewer for you, use r? to override)
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 @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. 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
The job x86_64-gnu-llvm-13 failed! Check out the build log: (web) (plain)
Click to see the possible cause of the failure (guessed by this bot)
Compiling unwind v0.0.0 (/checkout/library/unwind)
error[E0412]: cannot find type `Bytes` in this scope
--> library/core/src/ffi/c_str.rs:608:28
|
608 | pub fn bytes(&self) -> Bytes<'_> {
|
help: consider importing this struct
|
1 | use crate::str::Bytes;
---
error[E0308]: mismatched types
--> library/core/src/ffi/c_str.rs:710:50
|
710 | ptr: unsafe { NonNull::new_unchecked(s.inner.as_ptr()) },
| ---------------------- ^^^^^^^^^^^^^^^^ types differ in mutability
| arguments to this function are incorrect
|
|
= note: expected raw pointer `*mut u8`
found raw pointer `*const i8`
--> library/core/src/ptr/non_null.rs:197:25
|
|
197 | pub const unsafe fn new_unchecked(ptr: *mut T) -> Self {
error[E0560]: struct `CStrBytes<'a>` has no field named `phantom`
|
|
711 | phantom: PhantomData,
| ^^^^^^^ `CStrBytes<'a>` does not have this field
|
= note: available fields are: `ptr`, `marker`
error[E0614]: type `NonNull<u8>` cannot be dereferenced
|
|
720 | unsafe { *self.ptr == 0 }
error[E0308]: mismatched types
--> library/core/src/ffi/c_str.rs:729:33
|
|
729 | unsafe { CStr::from_ptr(self.ptr.as_ptr()) }
| -------------- ^^^^^^^^^^^^^^^^^ expected `i8`, found `u8`
| |
| arguments to this function are incorrect
|
= note: expected raw pointer `*const i8`
found raw pointer `*mut u8`
--> library/core/src/ffi/c_str.rs:259:25
|
|
259 | pub const unsafe fn from_ptr<'a>(ptr: *const c_char) -> &'a CStr {
error[E0614]: type `NonNull<u8>` cannot be dereferenced
|
756 | let ret = *self.ptr;
| ^^^^^^^^^
This seems fairly reasonable to me. Can you file an ACP though?
Sounds reasonable to me! Filed those and replaced the description with a link back to the ACP.
Since the ACP was accepted, I removed the as_c_str and AsRef impl and opened a tracking issue. Adding the removed bits was mentioned as an unanswered question in the tracking issue since it was not accepted as part of the ACP.
@rustbot ready
(not sure if I can just do this, or if someone else will have to)
(edit: looks like I can, but it doesn't remove the S-waiting-on-ACP tag. someone else will have to do that)
@rustbot blocked
Going to open a PR in light of this ACP being accepted: rust-lang/libs-team#134
Then just make this depend on that one being merged first.
:umbrella: The latest upstream changes (presumably #114443) made this pull request unmergeable. Please resolve the merge conflicts.
I'm going to be away for a few months, so I'm rerolling my PRs so that folks don't have to wait for me. Sorry/thanks.
r? libs
r? libs
@rustbot author
(want to verify tests pass before I mark as ready; blocker has been merged)
@rustbot ready
Oh, I'm terrible with batching review comments, so, I get that. Will poke around the code in a bit to see what I can do.
@bors r+ rollup
:pushpin: Commit a38a556ceb4b65c397a47bcbe35d004bc9b8626f has been approved by cuviper
It is now in the queue for this repository.