Skip to content

Improve the example for ptr::copy - #77385

Merged
bors merged 2 commits into
rust-lang:masterfrom
scottmcm:fix-77220
Oct 2, 2020
Merged

Improve the example for ptr::copy#77385
bors merged 2 commits into
rust-lang:masterfrom
scottmcm:fix-77220

Conversation

@scottmcm

Copy link
Copy Markdown
Member

Fixes#77220

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @KodrAus

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

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 1, 2020
@jyn514jyn514 added T-libs-api [DEPRECATED; DO NOT USE] A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools labels Oct 1, 2020
Comment threadlibrary/core/src/intrinsics.rs Outdated
@jyn514

Copy link
Copy Markdown
Member

@bors r+ rollup

@bors

bors commented Oct 1, 2020

Copy link
Copy Markdown
Collaborator

📌 Commit e58f3d3 has been approved by jyn514

@borsbors 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 Oct 1, 2020
///
/// /// # Safety:
/// /// * `ptr` must be correctly aligned for its type and non-zero.
/// /// * `ptr` must be valid for reads of `elts` contiguous objects of type `T`.

@pickfirepickfireOct 1, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I never heard of "contiguous objects"? Is this perhaps a new term? Also, s/of/for.

Suggested change
/// /// * `ptr` must be valid for reads of `elts` contiguous objects of type `T`.
/// /// * `ptr` must be valid for reads of `elts` contiguous objects for type `T`.

@jyn514jyn514Oct 1, 2020

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, contiguous is there but I never heard of contiguous objects. Try rg 'contiguous objects' in rust or https://github.com/rust-lang/rust/search?q=%22contiguous+objects%22

/// /// # Safety:
/// /// * `ptr` must be correctly aligned for its type and non-zero.
/// /// * `ptr` must be valid for reads of `elts` contiguous objects of type `T`.
/// /// * Those elements must not be used after calling this function unless `T: Copy`.

@pickfirepickfireOct 1, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this required? Is it only limited for Copy?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if these are not Copy you'll have a double-free. ptr::read does not drop or move the source buffer.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I guess that's true but should this be part of safety? I think it could be but I wonder if this should be here.

/// ```
/// use std::ptr;
///
/// /// # Safety:

@pickfirepickfireOct 1, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// /// # Safety:
/// /// # Safety
/// ///

We usually have a space after Safety for heading and don't have : at the end.

@JohnTitorJohnTitor mentioned this pull request Oct 1, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Oct 1, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 2, 2020
Rollup of 11 pull requests
Successful merges:
- rust-lang#76851 (Fix 'FIXME' about using NonZeroU32 instead of u32.)
- rust-lang#76979 (Improve std::sys::windows::compat)
- rust-lang#77111 (Stabilize slice_ptr_range.)
- rust-lang#77147 (Split sys_common::Mutex in StaticMutex and MovableMutex.)
- rust-lang#77312 (Remove outdated line from `publish_toolstate` hook)
- rust-lang#77362 (Fix is_absolute on WASI)
- rust-lang#77375 (rustc_metadata: Do not forget to encode inherent impls for foreign types)
- rust-lang#77385 (Improve the example for ptr::copy)
- rust-lang#77389 (Fix some clippy lints)
- rust-lang#77399 (BTreeMap: use Unique::from to avoid a cast where type information exists)
- rust-lang#77429 (Link `new` method in `DefautHasher`s doc)
Failed merges:
r? `@ghost`
@bors
bors merged commit 2e749ab into rust-lang:masterOct 2, 2020
@rustbotrustbot added this to the 1.48.0 milestone Oct 2, 2020
@scottmcm
scottmcm deleted the fix-77220 branch October 2, 2020 04:44
pickfire added a commit to pickfire/rust that referenced this pull request Oct 2, 2020
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsS-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-libs-api[DEPRECATED; DO NOT USE]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect unsafe code example in standard library

7 participants

@scottmcm@rust-highfive@jyn514@bors@pickfire@KodrAus@rustbot