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

Docs for std::ptr::slice_from_raw_parts #120608

Merged
merged 1 commit into from
Mar 8, 2024
Merged

Conversation

kornelski
Copy link
Contributor

No description provided.

@rustbot
Copy link
Collaborator

rustbot commented Feb 3, 2024

r? @cuviper

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 3, 2024
@mgeier
Copy link
Contributor

mgeier commented Feb 3, 2024

Thanks @kornelski for this PR!

For reference, here's some discussion: https://users.rust-lang.org/t/missing-guidance-on-converting-ffi-ptr-length-to-slice/106048

Wouldn't it also be helpful to mention (or even recommend using) .as_ref().unwrap_or(&[])?

To me this was initially not obvious.

@kornelski
Copy link
Contributor Author

kornelski commented Feb 3, 2024

The examples use .as_ref().expect() to highlight the non-null requirement.

@mgeier
Copy link
Contributor

mgeier commented Feb 3, 2024

The examples use .as_ref().expect() to highlight the non-null requirement.

Yes, and I think that's helpful!

But it only illustrates the problem, not the solution.

@cuviper
Copy link
Member

cuviper commented Feb 11, 2024

But it only illustrates the problem, not the solution.

The solution is going to be domain-specific. In general, there is a distinction between non-existence and emptiness, so treating null as an empty slice is not necessarily the right thing to do. But maybe we can suggest it with that qualification, like "If you are converting from a context where null pointers are used for emptiness, then you may want .as_ref().unwrap_or(&[])."

@cuviper
Copy link
Member

cuviper commented Mar 8, 2024

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Mar 8, 2024

📌 Commit f4b65f5 has been approved by cuviper

It is now in the queue for this repository.

@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 Mar 8, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 8, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 8, 2024
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#118623 (Improve std::fs::read_to_string example)
 - rust-lang#119365 (Add asm goto support to `asm!`)
 - rust-lang#120608 (Docs for std::ptr::slice_from_raw_parts)
 - rust-lang#121885 (Move generic `NonZero` `rustc_layout_scalar_valid_range_start` attribute to inner type.)
 - rust-lang#121938 (Fix quadratic behavior of repeated vectored writes)
 - rust-lang#122099 (Add  `#[inline]` to `BTreeMap::new` constructor)
 - rust-lang#122143 (PassWrapper: update for llvm/llvm-project@a3319371970b)

Failed merges:

 - rust-lang#122076 (Tweak the way we protect in-place function arguments in interpreters)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 8, 2024
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#118623 (Improve std::fs::read_to_string example)
 - rust-lang#119365 (Add asm goto support to `asm!`)
 - rust-lang#120608 (Docs for std::ptr::slice_from_raw_parts)
 - rust-lang#121832 (Add new Tier-3 target: `loongarch64-unknown-linux-musl`)
 - rust-lang#121938 (Fix quadratic behavior of repeated vectored writes)
 - rust-lang#122099 (Add  `#[inline]` to `BTreeMap::new` constructor)
 - rust-lang#122103 (Make TAITs and ATPITs capture late-bound lifetimes in scope)
 - rust-lang#122143 (PassWrapper: update for llvm/llvm-project@a3319371970b)

Failed merges:

 - rust-lang#122076 (Tweak the way we protect in-place function arguments in interpreters)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit b1aca86 into rust-lang:master Mar 8, 2024
11 checks passed
@rustbot rustbot added this to the 1.78.0 milestone Mar 8, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 8, 2024
Rollup merge of rust-lang#120608 - kornelski:slice-ptr-doc, r=cuviper

Docs for std::ptr::slice_from_raw_parts
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 12, 2024
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Jun 12, 2024
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Jun 12, 2024
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Jun 12, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jun 12, 2024
Rollup merge of rust-lang#123374 - mgeier:doc-slice-from-raw-parts, r=scottmcm

DOC: Add FFI example for slice::from_raw_parts()

For some discussion, see https://users.rust-lang.org/t/missing-guidance-on-converting-ffi-ptr-length-to-slice/106048

See also rust-lang#120608.
@kornelski kornelski deleted the slice-ptr-doc branch August 14, 2024 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants