summary refs log tree commit diff
path: root/src/libcore/ptr.rs
AgeCommit message (Collapse)AuthorLines
2018-03-29src/libcore/ptr.rs: Fix documentation for size of `Option<NonNull<T>>`Josh Triplett-1/+1
Seems more useful to say that it has the same size as `*mut T`.
2018-03-26Auto merge of #49297 - scottmcm:offset-from, r=dtolnaybors-2/+227
Introduce unsafe offset_from on pointers Adds intrinsics::exact_div to take advantage of the unsafe, which reduces the implementation from ```asm sub rcx, rdx mov rax, rcx sar rax, 63 shr rax, 62 lea rax, [rax + rcx] sar rax, 2 ret ``` down to ```asm sub rcx, rdx sar rcx, 2 mov rax, rcx ret ``` (for `*const i32`) See discussion on the `offset_to` tracking issue https://github.com/rust-lang/rust/issues/41079 Some open questions - Would you rather I split the intrinsic PR from the library PR? - Do we even want the safe version of the API? https://github.com/rust-lang/rust/issues/41079#issuecomment-374426786 I've added some text to its documentation that even if it's not UB, it's useless to use it between pointers into different objects. and todos - [x] ~~I need to make a codegen test~~ Done - [x] ~~Can the subtraction use nsw/nuw?~~ No, it can't https://github.com/rust-lang/rust/pull/49297#discussion_r176697574 - [x] ~~Should there be `usize` variants of this, like there are now `add` and `sub` that you almost always want over `offset`? For example, I imagine `sub_ptr` that returns `usize` and where it's UB if the distance is negative.~~ Can wait for later; C gives a signed result https://github.com/rust-lang/rust/issues/41079#issuecomment-375842235, so we might as well, and this existing to go with `offset` makes sense.
2018-03-24Fix doctest mutability copy-pastaScott McMurray-2/+2
2018-03-24Documentation and naming improvementsScott McMurray-15/+33
2018-03-23Introduce unsafe offset_from on pointersScott McMurray-0/+207
Adds intrinsics::exact_div to take advantage of the unsafe, which reduces the implementation from ```asm sub rcx, rdx mov rax, rcx sar rax, 63 shr rax, 62 lea rax, [rax + rcx] sar rax, 2 ret ``` down to ```asm sub rcx, rdx sar rcx, 2 mov rax, rcx ret ``` (for `*const i32`)
2018-03-17Remove deprecated unstable ptr::Shared type alias.Simon Sapin-5/+0
It has been deprecated for about one release cycle.
2018-03-17Stop using deprecated NonZero APIsSimon Sapin-10/+18
These will eventually be removed (though the NonZero<T> lang item will likely stay).
2018-03-17Deprecate core::nonzero in favor of ptr::NonNull and num::NonZero*Simon Sapin-2/+9
2018-03-02Stabilize Unsafe Pointer Methodstinaun-78/+30
also minor doc fixes. Closes #43941
2018-02-10Correct a few stability attributesOliver Middleton-2/+2
2018-01-22Add an unstable `cast<U>() -> NonNull<U>` method to `NonNull<T>`.Simon Sapin-0/+8
This is less verbose than going through raw pointers to cast with `as`.
2018-01-21Implement Eq, PartialEq, Ord, PartialOrd, and Hash for NonNull<_>Simon Sapin-0/+31
2018-01-21Move Debug for NonNull impl closer to other trait implsSimon Sapin-7/+7
2018-01-21NonNull ended up landing in 1.25Simon Sapin-18/+18
2018-01-20Rename NonNull::empty to dangling.Simon Sapin-1/+2
2018-01-20Preserve formatting options in Debug for NonNull/UniqueSimon Sapin-2/+2
2018-01-20Fix some doc-comment examples for earlier API refactorSimon Sapin-4/+4
https://github.com/rust-lang/rust/pull/41064
2018-01-20Stabilize std::ptr::NonNullSimon Sapin-15/+17
2018-01-20Remove a deprecated (renamed) and unstable method of NonNullSimon Sapin-7/+0
2018-01-20Mark Unique as perma-unstable, with the feature renamed to ptr_internals.Simon Sapin-15/+15
2018-01-20Replace Unique<T> with NonZero<T> in Alloc traitSimon Sapin-0/+7
2018-01-20Rename std::ptr::Shared to NonNullSimon Sapin-41/+46
`Shared` is now a deprecated `type` alias. CC https://github.com/rust-lang/rust/issues/27730#issuecomment-352800629
2018-01-20Implement Debug for ptr::Shared and ptr::Unique.Corey Farwell-2/+14
Fixes https://github.com/rust-lang/rust/issues/46755.
2017-12-25Auto merge of #46914 - mikeyhew:raw_pointer_self, r=arielb1bors-2/+2
Convert warning about `*const _` to a future-compat lint #46664 was merged before I could convert the soft warning about method lookup on `*const _` into a future-compatibility lint. This PR makes that change. fixes #46837 tracking issue for the future-compatibility lint: #46906 r? @arielb1
2017-12-23fix doctests in libcoreMichael Hewson-2/+2
2017-12-21docs: do not call integer overflows as underflowsTrevor Spiteri-8/+4
2017-12-16Move PhantomData<T> from Shared<T> to users of both Shared and #[may_dangle]Simon Sapin-23/+12
After discussing [1] today with @pnkfelix and @Gankro, we concluded that it’s ok for drop checking not to be much smarter than the current `#[may_dangle]` design which requires an explicit unsafe opt-in. [1] https://github.com/rust-lang/rust/issues/27730#issuecomment-316432083
2017-12-04Document behavior of `ptr::swap` with overlapping regions of memory.Corey Farwell-2/+40
Fixes https://github.com/rust-lang/rust/issues/44479.
2017-11-29Rollup merge of #46287 - SimonSapin:stable-constness, r=aturonkennytm-4/+0
Stabilize const-calling existing const-fns in std Fixes #46038
2017-11-26Stabilize const-calling existing const-fns in stdSimon Sapin-4/+0
Fixes #46038
2017-11-19Remove `T: Sized` on `ptr::is_null()`Josh Stone-13/+21
This reverts commit 604f049cd5060129cf14f7bd340d442811345ea8. This is purely a revert of cuviper's revert "Restore `T: Sized` on `ptr::is_null`". So double revert means this is code written by cuviper!
2017-11-07Auto merge of #44932 - cuviper:unsized-ptr-is_null, r=alexcrichtonbors-6/+12
Remove `T: Sized` on pointer `as_ref()` and `as_mut()` `NonZero::is_zero()` was already casting all pointers to thin `*mut u8` to check for null. The same test on unsized fat pointers can also be used with `as_ref()` and `as_mut()` to get fat references. (This PR formerly changed `is_null()` too, but checking just the data pointer is not obviously correct for trait objects, especially if `*const self` sorts of methods are ever allowed.)
2017-10-29Fix references to zero_memory and copy_memory in ptr docsFlorian Hartwig-9/+9
2017-10-26Bump to 1.23 and update bootstrapAlex Crichton-4/+4
This commit updates the bootstrap compiler, bumps the version to 1.23, updates Cargo, updates books, and updates crates.io dependencies
2017-10-20Fix most rendering warnings from switching to CommonMarksteveklabnik-6/+6
2017-10-10Restore `T: Sized` on `ptr::is_null`Josh Stone-21/+13
The exact semantics of `is_null` on unsized pointers are still debatable, especially for trait objects. It may be legal to call `*mut self` methods on a trait object someday, as with Go interfaces, so `is_null` might need to validate the vtable pointer too. For `as_ref` and `as_mut`, we're assuming that you cannot have a non-null data pointer with a null vtable, so casting the unsized check is fine.
2017-10-05Auto merge of #44943 - nivkner:fixme_fixup, r=dtolnaybors-2/+0
address some FIXME whose associated issues were marked as closed part of #44366
2017-09-30address some `FIXME`s whose associated issues were marked as closedNiv Kaminer-2/+0
remove FIXME(#13101) since `assert_receiver_is_total_eq` stays. remove FIXME(#19649) now that stability markers render. remove FIXME(#13642) now the benchmarks were moved. remove FIXME(#6220) now that floating points can be formatted. remove FIXME(#18248) and write tests for `Rc<str>` and `Rc<[u8]>` remove reference to irelevent issues in FIXME(#1697, #2178...) update FIXME(#5516) to point to getopts issue 7 update FIXME(#7771) to point to RFC 628 update FIXME(#19839) to point to issue 26925
2017-09-29Document that there are many possible null pointersJosh Stone-0/+10
2017-09-29Remove `T: Sized` on `ptr::is_null()`, `as_ref()`, `as_mut()`Josh Stone-7/+11
`NonZero::is_zero()` was already casting all pointers to thin `*mut u8` to check for null. It seems reasonable to apply that for `is_null()` in general, and then unsized fat pointers can also be used with `as_ref()` and `as_mut()` to get fat references.
2017-09-28Normalize spaces in lang attributes.Havvy-1/+1
2017-09-17Add `<*const T>::align_offset` and use it in `memchr`Oliver Schneider-1/+74
2017-09-16Auto merge of #43964 - Gankro:unsafe-reform, r=sfacklerbors-12/+1174
implement unsafe pointer methods I also cleaned up some existing documentation a bit here or there since I was doing so much auditing of it. Most notably I significantly rewrote the `offset` docs to clarify safety (`*const` and `*mut`'s offset docs had actually diverged).
2017-09-16change #![feature(const_fn)] to specific gatesAlex Burka-0/+6
2017-09-10implement unsafe pointer methodsAlexis Beingessner-12/+1174
2017-08-31Update bootstrap compilerAlex Crichton-27/+0
This commit updates the bootstrap compiler and clears out a number of #[cfg(stage0)] annotations and related business
2017-08-14Make `Clone` a lang item and generate builtin impls.scalexm-0/+3
Fixes #28229. Fixes #24000.
2017-08-13Addresses comments in PR #43836Alexey Tarasov-10/+8
- removes warnings introduced in changeset 0cd3587 - makes documentation more neat and grammatically correct
2017-08-12Follow up commit for the issue 39827Alexey Tarasov-0/+12
- updates documentation on volatile memory intrinsics, now the case of zero-sized types is mentioned explicitly. Volatile memory operations which doesn't affect memory at all are omitted in LLVM backend, e.g. if number of elements is zero or type used in generic specialisation is zero-sized, then LLVM intrinsic or related code is not generated. This was not explicitly documented before in Rust documentation and potentially could cause issues.
2017-07-22Fix unstable feature name for some impls for Unique<T>Simon Sapin-2/+2