-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add CStr::bytes iterator #104353
Add CStr::bytes iterator #104353
Conversation
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 Examples of
|
This comment has been minimized.
This comment has been minimized.
9759aad
to
b3c41f3
Compare
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. |
b3c41f3
to
1867de5
Compare
1867de5
to
8f2771f
Compare
Since the ACP was accepted, I removed the |
@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 |
@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. |
☔ 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 |
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. |
0a90d2d
to
a38a556
Compare
/// We could eventually expose this publicly, if we wanted. | ||
#[inline] | ||
#[must_use] | ||
const fn as_non_null_ptr(&self) -> NonNull<c_char> { | ||
NonNull::from(&self.inner).as_non_null_ptr() | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decided to put this because it seems like something we'd probably add in the future, but I don't really feel like doing an ACP for this right now. It felt reasonable enough to factor into its own method, at least.
I thought about why as_ptr
uses addr_of!
instead of a safe version (since, well, we require a reference to &self
to make this work, and thus any potential UB arguments don't make sense) and concluded that we don't need to here, but if I'm wrong about that, please let me know!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you're referring to -- CStr::as_ptr()
just calls the slice as_ptr()
, which is just a couple pointer casts. I only found addr_of!
used in Rc
/Arc::as_ptr
, and those are digging into a further heap allocation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, sorry, I totally mixed up the implementations for as_ptr
and to_bytes_with_nul
. The latter uses addr_of
to convert the slice into *const [u8]
instead of the existing method, but that's going to be unsafe anyway, so, it's fair.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, I don't see any reason it's needed there either, just a little bit shorter than it was with double pointer casts before addr_of!
. No matter.
@bors r+ rollup |
…iper 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`.
…iaskrgr Rollup of 12 pull requests Successful merges: - rust-lang#104353 (Add CStr::bytes iterator) - rust-lang#120699 (Document `TRACK_DIAGNOSTIC` calls.) - rust-lang#121207 (Add `-Z external-clangrt`) - rust-lang#122397 (Various cleanups around the const eval query providers) - rust-lang#122416 (Various style improvements to `rustc_lint::levels`) - rust-lang#122422 (compiletest: Allow `only-unix` in test headers) - rust-lang#122424 (fix: typos) - rust-lang#122425 (Increase timeout for new bors bot) - rust-lang#122426 (Fix StableMIR `WrappingRange::is_full` computation) - rust-lang#122430 (Generate link to `Local` in `hir::Let` documentation) - rust-lang#122434 (pattern analysis: rename a few types) - rust-lang#122437 (pattern analysis: remove `MaybeInfiniteInt::JustAfterMax`) r? `@ghost` `@rustbot` modify labels: rollup
…iper 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`.
…iper 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`.
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#104353 (Add CStr::bytes iterator) - rust-lang#120699 (Document `TRACK_DIAGNOSTIC` calls.) - rust-lang#120943 (Create some minimal HIR for associated opaque types) - rust-lang#121764 (Make incremental sessions identity no longer depend on the crate names provided by source code) - rust-lang#122375 (CFI: Break tests into smaller files) - rust-lang#122397 (Various cleanups around the const eval query providers) - rust-lang#122405 (Add methods to create StableMIR constant) - rust-lang#122416 (Various style improvements to `rustc_lint::levels`) - rust-lang#122440 (const-eval: organize and extend tests for required-consts) r? `@ghost` `@rustbot` modify labels: rollup
…iper 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`.
…iaskrgr Rollup of 11 pull requests Successful merges: - rust-lang#104353 (Add CStr::bytes iterator) - rust-lang#114038 (unix time module now return result) - rust-lang#119676 (rustdoc-search: search types by higher-order functions) - rust-lang#120699 (Document `TRACK_DIAGNOSTIC` calls.) - rust-lang#121899 (Document how removing a type's field can be bad and what to do instead) - rust-lang#121940 (Mention Register Size in `#[warn(asm_sub_register)]`) - rust-lang#122397 (Various cleanups around the const eval query providers) - rust-lang#122405 (Add methods to create StableMIR constant) - rust-lang#122416 (Various style improvements to `rustc_lint::levels`) - rust-lang#122440 (const-eval: organize and extend tests for required-consts) - rust-lang#122461 (fix unsoundness in Step::forward_unchecked for signed integers) r? `@ghost` `@rustbot` modify labels: rollup
…iper 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`.
…iper 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`.
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#104353 (Add CStr::bytes iterator) - rust-lang#119676 (rustdoc-search: search types by higher-order functions) - rust-lang#120699 (Document `TRACK_DIAGNOSTIC` calls.) - rust-lang#121899 (Document how removing a type's field can be bad and what to do instead) - rust-lang#122405 (Add methods to create StableMIR constant) - rust-lang#122416 (Various style improvements to `rustc_lint::levels`) - rust-lang#122421 (Improve `Step` docs) - rust-lang#122440 (const-eval: organize and extend tests for required-consts) - rust-lang#122461 (fix unsoundness in Step::forward_unchecked for signed integers) Failed merges: - rust-lang#122397 (Various cleanups around the const eval query providers) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#104353 - clarfonthey:cstr-bytes-iter, r=cuviper 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`.
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 ofcore::ffi::CStrBytes
.