Skip to content

Convert std::vec::raw::{init_elem, copy_memory} to methods, and remove aliasing &[] and &mut[] #10996

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

Merged
merged 6 commits into from
Dec 17, 2013

Conversation

huonw
Copy link
Member

@huonw huonw commented Dec 16, 2013

The removal of the aliasing &mut[] and &[] from shift_opt also comes with its simplification.

The above also allows the use of copy_nonoverlapping_memory in [].copy_memory (I did an audit of each use of .copy_memory and std::vec::bytes::copy_memory, and I believe none of them are called with arguments can ever alias). This changes requires that unsafe code using copy_memory needs to respect the aliasing rules of &mut[].

Also, dramatically simplify it with some tasteful raw pointers, rather
than treating everything as a nail with `transmute`.
/// Copies data from `src` to `self`
///
/// Fails if `self` is shorter than `src`.
#[inline]
Copy link
Member

Choose a reason for hiding this comment

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

Why is there an #[inline] here?

Copy link
Member Author

Choose a reason for hiding this comment

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

You saw nothing... :p

(thanks)

docs for copy_memory.

&mut [u8] and &[u8] really shouldn't be overlapping at all (part of the
uniqueness/aliasing guarantee of &mut), so no point in encouraging it.
It is required that &mut[]s are disjoint from all other &(mut)[]s, so
this assumption is ok.
bors added a commit that referenced this pull request Dec 17, 2013
The removal of the aliasing &mut[] and &[] from `shift_opt` also comes with its simplification.

The above also allows the use of `copy_nonoverlapping_memory` in `[].copy_memory` (I did an audit of each use of `.copy_memory` and `std::vec::bytes::copy_memory`, and I believe none of them are called with arguments can ever alias). This changes requires that `unsafe` code using `copy_memory` **needs** to respect the aliasing rules of `&mut[]`.
@bors bors closed this Dec 17, 2013
@bors bors merged commit dd35570 into rust-lang:master Dec 17, 2013
@huonw huonw deleted the more-vec-raw branch February 25, 2014 05:28
flip1995 pushed a commit to flip1995/rust that referenced this pull request Jun 30, 2023
Lint `mem_forget` if any fields are `Drop`

Closes rust-lang#9298
I think this way of doing it (`needs_drop`) should be fine.

---

changelog: Enhancement: [`mem_forget`]: Now lints on types with fields that implement `Drop`
[rust-lang#10996](rust-lang/rust-clippy#10996)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants