about summary refs log tree commit diff
path: root/src/libcore/ptr.rs
AgeCommit message (Collapse)AuthorLines
2018-11-12Auto merge of #55278 - Centril:constification-1, r=alexcrichtonbors-1/+1
Minor standard library constification This PR makes some bits of the standard library into `const fn`s. I've tried to be as aggressive as I possibly could in the constification. The list is rather small due to how restrictive `const fn` is at the moment. r? @oli-obk cc @rust-lang/libs Stable public APIs affected: + [x] `Cell::as_ptr` + [x] `UnsafeCell::get` + [x] `char::is_ascii` + [x] `iter::empty` + [x] `ManuallyDrop::{new, into_inner}` + [x] `RangeInclusive::{start, end}` + [x] `NonNull::as_ptr` + [x] `{[T], str}::as_ptr` + [x] `Duration::{as_secs, subsec_millis, subsec_micros, subsec_nanos}` + [x] `CStr::as_ptr` + [x] `Ipv4Addr::is_unspecified` + [x] `Ipv6Addr::new` + [x] `Ipv6Addr::octets` Unstable public APIs affected: + [x] `Duration::{as_millis, as_micros, as_nanos, as_float_secs}` + [x] `Wrapping::{count_ones, count_zeros, trailing_zeros, rotate_left, rotate_right, swap_bytes, reverse_bits, from_be, from_le, to_be, to_le, leading_zeros, is_positive, is_negative, leading_zeros}` + [x] `core::convert::identity` -------------------------- ## Removed from list in first pass: Stable public APIs affected: + [ ] `BTree{Map, Set}::{len, is_empty}` + [ ] `VecDeque::is_empty` + [ ] `String::{is_empty, len}` + [ ] `FromUtf8Error::utf8_error` + [ ] `Vec<T>::{is_empty, len}` + [ ] `Layout::size` + [ ] `DecodeUtf16Error::unpaired_surrogate` + [ ] `core::fmt::{fill, width, precision, sign_plus, sign_minus, alternate, sign_aware_zero_pad}` + [ ] `panic::Location::{file, line, column}` + [ ] `{ChunksExact, RChunksExact}::remainder` + [ ] `Utf8Error::valid_up_to` + [ ] `VacantEntry::key` + [ ] `NulError::nul_position` + [ ] `IntoStringError::utf8_error` + [ ] `IntoInnerError::error` + [ ] `io::Chain::get_ref` + [ ] `io::Take::{limit, get_ref}` + [ ] `SocketAddrV6::{flowinfo, scope_id}` + [ ] `PrefixComponent::{kind, as_os_str}` + [ ] `Path::{ancestors, display}` + [ ] `WaitTimeoutResult::timed_out` + [ ] `Receiver::{iter, try_iter}` + [ ] `thread::JoinHandle::thread` + [ ] `SystemTimeError::duration` Unstable public APIs affected: + [ ] `core::fmt::Arguments::new_v1` + [ ] `core::fmt::Arguments::new_v1_formatted` + [ ] `Pin::{get_ref, into_ref}` + [ ] `Utf8Lossy::chunks` + [ ] `LocalWaker::as_waker` + [ ] `panic::PanicInfo::{internal_constructor, message, location}` + [ ] `panic::Location::{internal_constructor }` ## Removed from list in 2nd pass: Stable public APIs affected: + [ ] `LinkedList::{new, iter, is_empty, len}` + [ ] `mem::forget` + [ ] `Cursor::{new, get_ref, position}` + [ ] `io::{empty, repeat, sink}` + [ ] `PoisonError::new` + [ ] `thread::Builder::new` + [ ] `process::Stdio::{piped, inherit, null}` Unstable public APIs affected: + [ ] `io::Initializer::{zeroing, should_initialize}`
2018-11-10Fix documentation typos.Bruce Mitchener-4/+4
2018-11-10revert making internal APIs const fn.Mazdak Farrokhzad-1/+1
2018-11-10constify parts of libcore.Mazdak Farrokhzad-2/+2
2018-11-01Replace CoerceSized trait with DispatchFromDynMichael Hewson-4/+4
Rename `CoerceSized` to `DispatchFromDyn`, and reverse the direction so that, for example, you write ``` impl<T: Unsize<U>, U> DispatchFromDyn<*const U> for *const T {} ``` instead of ``` impl<T: Unsize<U>, U> DispatchFromDyn<*const T> for *const U {} ``` this way the trait is really just a subset of `CoerceUnsized`. The checks in object_safety.rs are updated for the new trait, and some documentation and method names in there are updated for the new trait name — e.g. `receiver_is_coercible` is now called `receiver_is_dispatchable`. Since the trait now works in the opposite direction, some code had to updated here for that too. I did not update the error messages for invalid `CoerceSized` (now `DispatchFromDyn`) implementations, except to find/replace `CoerceSized` with `DispatchFromDyn`. Will ask for suggestions in the PR thread.
2018-11-01Add CoerceSized impls throughout libstdMichael Hewson-1/+7
This will make receiver types like `Rc<Self>` and `Pin<&mut Self>` object-safe.
2018-10-31Bump nightly to 1.32.0Alex Crichton-2/+2
* Also update the bootstrap compiler * Update cargo to 1.32.0 * Clean out stage0 annotations
2018-10-28Make a bunch of trivial methods of NonNull be `#[inline]`Nick Fitzgerald-0/+14
2018-10-23fix typos in various placesMatthias Krüger-1/+1
2018-10-14remove unnecessary emphasis in doc commentJan Niehusmann-2/+2
During review of the previous commit, @joshtriplett noticed that the emphasis on 'the same' is unnecessary. For consistency, remove it on the offset() functions, as well.
2018-10-14clarify pointer add/sub function safety concernsJan Niehusmann-4/+4
Ralf Jung made the same changes to the offset functions' documentation in commit fb089156. As add/sub just call offset, the same limitation applies here, as well. Removed emphasis on review request by @joshtriplett
2018-10-12Auto merge of #54534 - nagisa:align-offset-simplification, r=alexcrichtonbors-25/+12
Simplify implementation of align_offset slightly
2018-10-03Only promote calls to `#[rustc_promotable]` const fnsOliver Schneider-0/+2
2018-09-30Simplify implementation of align_offset slightlySimonas Kazlauskas-25/+12
2018-09-29Revert "Auto merge of #53508 - japaric:maybe-uninit, r=RalfJung"Ralf Jung-14/+18
This reverts commit c6e3d7fa3113aaa64602507f39d4627c427742ff, reversing changes made to 4591a245c7eec9f70d668982b1383cd2a6854af5.
2018-09-24Auto merge of #53783 - RalfJung:ptr-docs, r=alexcrichtonbors-513/+541
Rewrite docs for pointer methods This takes over https://github.com/rust-lang/rust/pull/51016 by @ecstatic-morse. They did most of the work, I just did some editing. However, I realized one problem: This updates the docs for the "free functions" in `core::ptr`, but it does not update the copies of these docs for the inherent methods of the `*const T` and `*mut T` types. These getting out-of-sync is certainly bad, but I also don't feel like copying all this stuff around. Instead, we should remove this redundancy. Any good ideas?
2018-09-22address Mark-Simulacrum commentsJorge Aparicio-2/+2
2018-09-22core: fix deprecated warningsJorge Aparicio-18/+14
2018-09-18clarify swapRalf Jung-5/+10
2018-09-17rearrange for clarityRalf Jung-41/+40
2018-09-17tweaksRalf Jung-1/+24
2018-09-10fix typosNicole Mazzuca-1/+1
2018-09-01remark on concurrency in validity sectionRalf Jung-0/+9
2018-09-01Valid raw pointersRalf Jung-1/+1
2018-08-31fix doctestsRalf Jung-1/+3
2018-08-31(un)alignedRalf Jung-2/+2
2018-08-31apply feedbackRalf Jung-7/+8
2018-08-31turn ptr type method docs into links to docs of free functions, to avoid ↵Ralf Jung-433/+44
duplication and inconsistency
2018-08-30fix exampleRalf Jung-2/+1
2018-08-30fix exampleRalf Jung-2/+3
2018-08-30improve volatile commentsRalf Jung-4/+4
2018-08-30address remaining remarks and add example for dropping unaligned dataRalf Jung-4/+32
2018-08-30apply commentsRalf Jung-12/+13
2018-08-30clarify ZST commentRalf Jung-10/+10
2018-08-29clarify that these are preliminary guaranteesRalf Jung-5/+4
2018-08-29edit docs a littleRalf Jung-24/+37
2018-08-29Resolve null/ZST conflict correctly (whoops)Dylan MacKenzie-4/+3
2018-08-29Add a list of known facts re: validityDylan MacKenzie-9/+26
Also rewrites the reads/writes section to be less reliant on `*const`, `*mut`
2018-08-29You can't make an omlette without breaking a few linksDylan MacKenzie-1/+1
2018-08-29Incorporate RalfJung's suggestionsDylan MacKenzie-28/+38
This splits "valid" into "valid for reads" and "valid for writes", and also adds the concept of operation size to validity. Now functions which operate on sequences state that e.g. pointer args must be "valid for reads of size x".
2018-08-29Redefine range validityDylan MacKenzie-8/+6
Uses `x.offset(i)` must be valid for all `i` in `0..count`.
2018-08-29Remove definiton of valid pointerDylan MacKenzie-7/+14
The enumerated list of conditions is replaced by an explanation that rust doesn't have a formal memory model. It does say that pointers created directly from references are guaranteed to be valid, and links to both the "Unsafe Code" section of the book and the "Undefined Behavior" section of the reference.
2018-08-29Fix off-by-one error when specifying a valid rangeDylan MacKenzie-2/+2
2018-08-29Reword module level docs re: alignmentDylan MacKenzie-4/+4
2018-08-29Update docs for `swap_nonoverlapping`Dylan MacKenzie-3/+19
They closely mirror the docs for `copy_nonoverlapping`
2018-08-29Fix unused variable warning in doctestDylan MacKenzie-0/+1
2018-08-29Fix failing doctestsDylan MacKenzie-3/+3
2018-08-29Mention alignment in top-level docsDylan MacKenzie-5/+11
This also removes the overlong link that failed tidy xD.
2018-08-29Rewrite docs for `std::ptr`Dylan MacKenzie-68/+351
- Add links to the GNU libc docs for `memmove`, `memcpy`, and `memset`, as well as internally linking to other functions in `std::ptr` - List invariants which, when violated, cause UB for all functions - Add example to `ptr::drop_in_place` and compares it to `ptr::read`. - Add examples which more closely mirror real world uses for the functions in `std::ptr`. Also, move the reimplementation of `mem::swap` to the examples of `ptr::read` and use a more interesting example for `copy_nonoverlapping`. - Change module level description - Define what constitutes a "valid" pointer. - Centralize discussion of ownership of bitwise copies in `ptr::read` and provide an example.
2018-08-22Rollup merge of #53574 - vorner:ptr_as_ref_unchecked, r=Mark-SimulacrumGuillaume Gomez-0/+30
Suggest direct raw-pointer dereference People often come looking for some kind of `as_ref_unchecked` method on raw pointers that would give them `&T` and not `Option<&T>` when they are sure the pointer is not NULL. There's no such method, but taking a reference of the dereferenced pointer accomplishes the same thing. Therefore, suggest using that, at the `as_ref` site ‒ it's a place people are likely going to look into.