about summary refs log tree commit diff
path: root/src/libcore/ptr.rs
AgeCommit message (Collapse)AuthorLines
2019-05-25split core::ptr module into multiple filesRalf Jung-3125/+0
2019-05-22Allow null-pointer-optimized enums in FFI if their underlying representation ↵Michael Bradshaw-0/+1
is FFI safe This allows types like Option<NonZeroU8> to be used in FFI without triggering the improper_ctypes lint. This works by changing the is_repr_nullable_ptr function to consider an enum E to be FFI-safe if: - E has no explicit #[repr(...)]. - It only has two variants. - One of those variants is empty (meaning it has no fields). - The other variant has only one field. - That field is one of the following: - &T - &mut T - extern "C" fn - core::num::NonZero* - core::ptr::NonNull<T> - #[repr(transparent)] struct wrapper around one of the types in this list. - The size of E and its field are both known and are both the same size (implying E is participating in the nonnull optimization).
2019-05-20Rollup merge of #60972 - RalfJung:volatile, r=alexcrichtonMazdak Farrokhzad-6/+0
remove confusing remarks about mixed volatile and non-volatile accesses These comments were originally added by @ecstatic-morse in https://github.com/rust-lang/rust/commit/911d35f0bfd207112806eaec2763201dad06d1c7 and then later edited by me. The intention, I think, was to make sure people do both their reads and writes with these methods if the affected memory really is used for communication with external devices. However, [people read this as saying that mixed volatile/non-volatile accesses are UB](https://github.com/rust-lang/rust/issues/58599#issuecomment-493791130), which -- to my knowledge -- they are not. So better remove this. Cc @rkruppe @rust-lang/wg-unsafe-code-guidelines
2019-05-20elliminate mem::uninitialize from docs in libcoreRalf Jung-4/+4
2019-05-20remove confusing remarks about mixed volatile and non-volatile accessesRalf Jung-6/+0
2019-05-18fix copy-paste typo in docs for ptr::read_volatileBrent Kerby-1/+1
2019-05-12Auto merge of #60244 - SimonSapin:dangling, r=oli-obkbors-2/+0
const-stabilize NonNull::dangling and NonNull::cast
2019-05-10Auto merge of #60588 - cuviper:be-simd-swap, r=alexcrichtonbors-4/+1
Revert "Disable big-endian simd in swap_nonoverlapping_bytes" This reverts commit 77bd4dc65406ba3cedbc779e6f6280868231912e (#43159). Issue #42778 was formerly easy to reproduce on two big-endian targets, `powerpc64` and `s390x`, so we disabled SIMD on this function for all big-endian targets as a workaround. I have re-tested this code on `powerpc64` and `s390x`, each with the bundled LLVM 8 and with external LLVM 7 and LLVM 6, and the problems no longer appear. So it seems safe to remove this workaround, although I'm still a little uncomfortable that we never found a root-cause... Closes #42778. r? @arielb1
2019-05-07Add a `cast` method to raw pointers.Simon Sapin-0/+14
This is similar to `NonNull::cast`. Compared to the `as` operator (which has a wide range of meanings depending on the input and output types), a call to this method: * Can only go from a raw pointer to a raw pointer * Cannot change the pointer’s `const`ness … even when the pointed types are inferred based on context.
2019-05-06Revert "Disable big-endian simd in swap_nonoverlapping_bytes"Josh Stone-4/+1
This reverts commit 77bd4dc65406ba3cedbc779e6f6280868231912e. Issue #42778 was formerly easy to reproduce on two big-endian targets, `powerpc64` and `s390x`, so we disabled SIMD on this function for all big-endian targets as a workaround. I have re-tested this code on `powerpc64` and `s390x`, each with the bundled LLVM 8 and with external LLVM 7 and LLVM 6, and the problems no longer appear. So it seems safe to remove this workaround, although I'm still a little uncomfortable that we never found a root-cause...
2019-04-26Stabilize pointer::align_offsetChristopher Serr-4/+2
Closes #44488
2019-04-25ignore-tidy-filelength on all files with greater than 3000 linesvarkor-0/+2
2019-04-25const-stabilize NonNull::dangling and NonNull::castSimon Sapin-2/+0
2019-04-19libcore: deny more...Mazdak Farrokhzad-6/+6
2019-04-18libcore => 2018Taiki Endo-13/+13
2019-04-01stabilize ptr::hashAleksey Kladov-2/+1
closes #56286
2019-03-27Rollup merge of #59390 - czipperz:ptr_eq_smart_pointer, r=Centril,steveklabnikJosh Stone-2/+48
Make `ptr::eq` documentation mention fat-pointer behavior Resolves #59214
2019-03-27Rollup merge of #59284 - RalfJung:maybe-uninit, r=sfacklerJosh Stone-7/+7
adjust MaybeUninit API to discussions uninitialized -> uninit into_initialized -> assume_init read_initialized -> read set -> write
2019-03-27Minor rewordings and add `dyn` keywordChris Gregory-9/+9
2019-03-26Rollup merge of #59427 - czipperz:non_null_doc_links, r=Mark-SimulacrumGuillaume Gomez-2/+3
Link to PhantomData in NonNull documentation
2019-03-26bump bootstrap; adjust stage0 uses in core::ptr.Mazdak Farrokhzad-2/+2
2019-03-26adjust MaybeUninit API to discussionsRalf Jung-7/+7
uninitialized -> uninit into_initialized -> assume_init read_initialized -> read set -> write
2019-03-25Link to PhantomData in NonNull documentationChris Gregory-2/+3
2019-03-25Rework documentation into examplesChris Gregory-8/+46
2019-03-25Rework documentation to be about fat pointersChris Gregory-5/+9
2019-03-23Make `ptr::eq` documentation mention smart-pointer behaviorChris Gregory-0/+4
Resolves #59214
2019-03-13Rollup merge of #59130 - RalfJung:non-null, r=rkruppeMazdak Farrokhzad-0/+10
Note that NonNull does not launder shared references for mutation See https://users.rust-lang.org/t/relative-pointer-an-abstraction-to-build-movable-self-referential-types/26186/6
2019-03-12expandRalf Jung-1/+2
2019-03-12Note that NonNull does not launder shared references for mutationRalf Jung-0/+9
2019-03-09Use lifetime contravariance to elide more lifetimes in core+alloc+stdScott McMurray-8/+8
2019-03-09Rollup merge of #58750 - TimDiekmann:master, r=oli-obkMazdak Farrokhzad-3/+5
Make `Unique::as_ptr`, `NonNull::dangling` and `NonNull::cast` const
2019-02-28Make `Unique::as_ptr`, `NonNull::dangling` and `NonNull::cast` constTim-3/+5
Make `Unique::as_ptr` const without feature attribute as it's unstable Make `NonNull::dangling` and `NonNull::cast` const with `feature = "const_ptr_nonnull"`
2019-02-22avoid unnecessary use of MaybeUninit::get_ref, and expand comment on the othersRalf Jung-1/+1
2019-02-10libs: doc commentsAlexander Regueiro-3/+3
2019-02-10tests: doc commentsAlexander Regueiro-8/+8
2019-02-03some type-level docs for MaybeUninit; rename into_inner -> into_initializedRalf Jung-2/+2
2019-01-17Revert "Auto merge of #57670 - rust-lang:beta-next, r=Mark-Simulacrum"Pietro Albini-16/+0
This reverts commit 722b4d695964906807b12379577bce5ee3d23e08, reversing changes made to 956dba47d33fc8b2bdabcd50e5bfed264b570382.
2019-01-16allow unused warnings related to rustc_layout_scalar_valid_range_startPietro Albini-0/+16
2019-01-07Add link destination for `read-ownership`Dylan MacKenzie-0/+1
2018-12-28Removed aligned ZST requirement from docs of read_/write_unaligned.kennytm-2/+2
This is just a copy-paste error.
2018-12-26Remove the private generic NonZero<T> wrapper type.Simon Sapin-14/+15
Instead, use `#[rustc_layout_scalar_valid_range_start(1)]` directly on relevant libcore types.
2018-12-25Remove licensesMark Rousskov-10/+0
2018-12-16Rollup merge of #56706 - oli-obk:const_unsafe_fn, r=CentrilMazdak Farrokhzad-1/+1
Make `const unsafe fn` bodies `unsafe` r? @Centril Updated for tracking issue discussion https://github.com/rust-lang/rust/issues/55607#issuecomment-445882296
2018-12-15Rollup merge of #56751 - mbrubeck:hash, r=dtolnayPietro Albini-1/+1
Allow ptr::hash to accept fat pointers Fat pointers implement Hash since #45483. This is a follow-up to #56250.
2018-12-13Auto merge of #56161 - RalfJung:vecdeque-stacked-borrows, r=SimonSapinbors-4/+4
VecDeque: fix for stacked borrows `VecDeque` violates a version of stacked borrows where creating a shared reference is not enough to make a location *mutably accessible* from raw pointers (and I think that is the version we want). There are two problems: * Creating a `NonNull<T>` from `&mut T` goes through `&T` (inferred for a `_`), then `*const T`, then `NonNull<T>`. That means in this stricter version of Stacked Borrows, we cannot actually write to such a `NonNull` because it was created from a shared reference! This PR fixes that by going from `&mut T` to `*mut T` to `*const T`. * `VecDeque::drain` creates the `Drain` struct by *first* creating a `NonNull` from `self` (which is an `&mut VecDeque`), and *then* calling `self.buffer_as_mut_slice()`. The latter reborrows `self`, asserting that `self` is currently the unique pointer to access this `VecDeque`, and hence invalidating the `NonNull` that was created earlier. This PR fixes that by instead using `self.buffer_as_slice()`, which only performs read accesses and creates only shared references, meaning the raw pointer (`NonNull`) remains valid. It is possible that other methods on `VecDeque` do something similar, miri's test coverage of `VecDeque` is sparse to say the least. Cc @nikomatsakis @Gankro
2018-12-12Allow ptr::hash to accept fat pointersMatt Brubeck-1/+1
2018-12-11Make `const unsafe fn` bodies `unsafe`Oliver Scherer-1/+1
2018-12-08Rollup merge of #56602 - dwijnand:fix-ptr-hash-docs, r=CentrilMazdak Farrokhzad-2/+5
Fix the just-introduced ptr::hash docs Follow-up to #56250.
2018-12-07Various minor/cosmetic improvements to codeAlexander Regueiro-19/+19
2018-12-07grammarDale Wijnand-1/+1