about summary refs log tree commit diff
path: root/src/libcore
AgeCommit message (Collapse)AuthorLines
2020-02-26Remove `sip::Hasher::short_write`.Nicholas Nethercote-46/+7
`sip::Hasher::short_write` is currently unused. It is called by `sip::Hasher::write_{u8,usize}`, but those methods are also unused, because `DefaultHasher`, `SipHasher` and `SipHasher13` don't implement any of the `write_xyz` methods, so all their write operations end up calling `sip::Hasher::write`. (I confirmed this by inserting a `panic!` in `sip::Hasher::short_write` and running the tests -- they all passed.) The alternative would be to add all the missing `write_xyz` methods. This does give some significant speed-ups, but it hurts compile times a little in some cases. See #69152 for details. This commit does the conservative thing and doesn't change existing behaviour.
2020-02-24Rollup merge of #69391 - memoryruins:memalias, r=Mark-SimulacrumDylan DPC-0/+2
Add rustdoc aliases to `ptr::copy` and `ptr::copy_nonoverlapping` This PR adds a [rustdoc alias](https://doc.rust-lang.org/nightly/rustdoc/unstable-features.html#add-aliases-for-an-item-in-documentation-search) to `ptr::copy` and `ptr::copy_nonoverlapping` using the commonly used terms `memcpy` and `memmove`. The motivation for this PR is to improve discoverability for these functions, since I've noticed users overlook these functions on multiple occasions (and they have thus reached for [libc](https://crates.io/crates/libc) without need). Currently std docs state: https://doc.rust-lang.org/nightly/std/ptr/fn.copy_nonoverlapping.html > `copy_nonoverlapping` is semantically equivalent to C's `memcpy`, but with the argument order swapped. https://doc.rust-lang.org/nightly/std/ptr/fn.copy.html > `copy` is semantically equivalent to C's `memmove`, but with the argument order swapped. #### search results before adding a rustdoc alias: ![screenshot 6517](https://user-images.githubusercontent.com/6868531/75102985-78fbb680-55c2-11ea-8e41-04979e6fa6f6.png) ![screenshot 6518](https://user-images.githubusercontent.com/6868531/75102984-78632000-55c2-11ea-9673-8822aae636d1.png) #### after adding `#[doc(alias = "memcpy")]` and `#[doc(alias = "memmove")]`: ![screenshot 6516](https://user-images.githubusercontent.com/6868531/75102986-78fbb680-55c2-11ea-93b9-1929be940043.png) ![screenshot 6515](https://user-images.githubusercontent.com/6868531/75102987-78fbb680-55c2-11ea-9861-ce8a77a0c3b9.png)
2020-02-24Address method commentsAndreas Molzer-3/+2
2020-02-24Rollup merge of #69386 - ↵Pietro Albini-1/+1
danielhenrymantilla:maybe_uninit_docs_replace_chunk_with_windows, r=Dylan-DPC Fix minor error in `MaybeUninit::get_mut()` doc example In the `MaybeUninit::get_mut()` example I wanted to assert that the slice was sorted and mistakenly used `.chunks(2)` rather than `.windows(2)` to assert it, as @ametisf pointed out in https://github.com/rust-lang/rust/pull/65948#issuecomment-589988183 . This fixes it.
2020-02-23Bump core::primitive to 1.43David Tolnay-18/+18
2020-02-24adjuste doc of `map_while`Waffle-10/+6
Fix doc of `Iterator::map_while` so it would be clearer that it isn't fused.
2020-02-22Add rustdoc aliases to `ptr::copy` and `ptr::copy_nonoverlapping`memoryruins-0/+2
2020-02-22Fix doc example for `MaybeUninit::get_mut()`Daniel Henry-Mantilla-1/+1
Suggested by @ametisf in https://github.com/rust-lang/rust/pull/65948#issuecomment-589988183 Co-Authored-By: Frantisek Fladung <fladufra@fel.cvut.cz>
2020-02-22Relax str::get_unchecked precondition to permit empty slicingridiculousfish-4/+4
Prior to this commit, `str` documented that `get_unchecked` had the precondition that "`begin` must come before `end`". This would appear to prohibit empty slices (i.e. begin == end). In practice, get_unchecked is called often with empty slices. Let's relax the precondition so as to allow them.
2020-02-22Rollup merge of #69354 - MichaelMcDonnell:duration_overflow_test, r=CentrilDylan DPC-0/+6
Test `Duration::new` panics on overflow A `Duration` is created from a second and nanoseconds variable. The documentation says: "This constructor will panic if the carry from the nanoseconds overflows the seconds counter". This was, however, not tested in the tests. I doubt the behavior will ever regress, but it is usually a good idea to test all documented behavior.
2020-02-22Rollup merge of #68984 - ecstatic-morse:const-u8-is-ascii, r=sfacklerDylan DPC-1/+2
Make `u8::is_ascii` a stable `const fn` `char::is_ascii` was already stabilized as `const fn` in #55278, so there is no reason for `u8::is_ascii` to go through an unstable period. cc @rust-lang/libs
2020-02-22Stabilize const for integer {to,from}_{be,le,ne}_bytes methodsTrevor Spiteri-13/+16
All of these functions can be implemented simply and naturally as const functions, e.g. u32::from_le_bytes can be implemented as (bytes[0] as u32) | (bytes[1] as u32) << 8 | (bytes[2] as u32) << 16 | (bytes[3] as u32) << 24 So stabilizing the constness will not expose that internally they are implemented using transmute which is not const in stable.
2020-02-22Auto merge of #69332 - nnethercote:revert-u8to64_le-changes, r=michaelwoeristerbors-1/+3
Revert `u8to64_le` changes from #68914. `SipHasher128`'s `u8to64_le` function was simplified in #68914. Unfortunately, the new version is slower, because it introduces `memcpy` calls with non-statically-known lengths. This commit reverts the change, and adds an explanatory comment (which is also added to `libcore/hash/sip.rs`). This barely affects `SipHasher128`'s speed because it doesn't use `u8to64_le` much, but it does result in `SipHasher128` once again being consistent with `libcore/hash/sip.rs`. r? @michaelwoerister
2020-02-22Auto merge of #67330 - golddranks:split_inclusive, r=kodrausbors-1/+421
Implement split_inclusive for slice and str # Overview * Implement `split_inclusive` for `slice` and `str` and `split_inclusive_mut` for `slice` * `split_inclusive` is a substring/subslice splitting iterator that includes the matched part in the iterated substrings as a terminator. * EDIT: The behaviour has now changed, as per @KodrAus 's input, to the same semantics with the `split_terminator` function. I updated the examples below. * Two examples below: ```Rust let data = "\nMäry häd ä little lämb\nLittle lämb\n"; let split: Vec<&str> = data.split_inclusive('\n').collect(); assert_eq!(split, ["\n", "Märy häd ä little lämb\n", "Little lämb\n"]); ``` ```Rust let uppercase_separated = "SheePSharKTurtlECaT"; let mut first_char = true; let split: Vec<&str> = uppercase_separated.split_inclusive(|c: char| { let split = !first_char && c.is_uppercase(); first_char = split; split }).collect(); assert_eq!(split, ["SheeP", "SharK", "TurtlE", "CaT"]); ``` # Justification for the API * I was surprised to find that stdlib currently only has splitting iterators that leave out the matched part. In my experience, wanting to leave a substring terminator as a part of the substring is a pretty common usecase. * This API is strictly more expressive than the standard `split` API: it's easy to get the behaviour of `split` by mapping a subslicing operation that drops the terminator. On the other hand it's impossible to derive this behaviour from `split` without using hacky and brittle `unsafe` code. The normal way to achieve this functionality would be implementing the iterator yourself. * Especially when dealing with mutable slices, the only way currently is to use `split_at_mut`. This API provides an ergonomic alternative that plays to the strengths of the iterating capabilities of Rust. (Using `split_at_mut` iteratively used to be a real pain before NLL, fortunately the situation is a bit better now.) # Discussion items * <s>Does it make sense to mimic `split_terminator` in that the final empty slice would be left off in case of the string/slice ending with a terminator? It might do, as this use case is naturally geared towards considering the matching part as a terminator instead of a separator.</s> * EDIT: The behaviour was changed to mimic `split_terminator`. * Does it make sense to have `split_inclusive_mut` for `&mut str`?
2020-02-21Test `Duration::new` panics on overflowMichael Mc Donnell-0/+6
A `Duration` is created from a second and nanoseconds variable. The documentation says: "This constructor will panic if the carry from the nanoseconds overflows the seconds counter". This was, however, not tested in the tests. I doubt the behavior will ever regress, but it is usually a good idea to test all documented behavior.
2020-02-21Revert `u8to64_le` changes from #68914.Nicholas Nethercote-1/+3
`SipHasher128`'s `u8to64_le` function was simplified in #68914. Unfortunately, the new version is slower, because it introduces `memcpy` calls with non-statically-known lengths. This commit reverts the change, and adds an explanatory comment (which is also added to `libcore/hash/sip.rs`). This barely affects `SipHasher128`'s speed because it doesn't use `u8to64_le` much, but it does result in `SipHasher128` once again being consistent with `libcore/hash/sip.rs`.
2020-02-20Rollup merge of #68978 - ecstatic-morse:const-int-pow, r=oli-obkDylan DPC-23/+49
Make integer exponentiation methods unstably const cc #53718 This makes the following inherent methods on integer primitives into unstable `const fn`: - `pow` - `checked_pow` - `wrapping_pow` - `overflowing_pow` - `saturating_pow` - `next_power_of_two` - `checked_next_power_of_two` - `wrapping_next_power_of_two` Only two changes were made to the implementation of these methods. First, I had to switch from the `?` operator, which is not yet implemented in a const context, to a `try_opt` macro. Second, `next_power_of_two` was using `ops::Add::add` (see the first commit) to "get overflow checks", so I switched to `#[rustc_inherit_overflow_checks]`. I'm not quite sure why the attribute wasn't used in the first place.
2020-02-20Auto merge of #69256 - nnethercote:misc-inlining, r=Centrilbors-1/+1
Miscellaneous inlining improvements These commits inline some hot functions that aren't currently inlined, for some speed wins. r? @Centril
2020-02-19Auto merge of #69241 - shahn:checked_add_revert, r=Mark-Simulacrum,lqdbors-5/+7
Revert "Remove `checked_add` in `Layout::repeat`" This fixes a a segfault in safe code, a stable regression. Reported in #69225. This reverts commit a983e0590a43ed8b0f60417828efd4e79b51f494.
2020-02-18Revert "Remove `checked_add` in `Layout::repeat`"Sebastian Hahn-5/+7
This fixes a a segfault in safe code, a stable regression. Reported in \#69225. This reverts commit a983e0590a43ed8b0f60417828efd4e79b51f494. Also adds a test for the expected behaviour.
2020-02-18Rollup merge of #69249 - LeSeulArtichaut:stabilize-logs-consts, r=sfacklerYuki Okushi-4/+4
Stabilize {f32, f64}::{LOG2_10, LOG10_2} Following the decision to stabilize `LOG2_10` and `LOG10_2` in https://github.com/rust-lang/rust/issues/50540#issuecomment-536627588. Closes #50540. r? @sfackler
2020-02-18Rollup merge of #68597 - ollie27:skip_nth_last, r=AmanieuYuki Okushi-13/+7
Simplify `Skip::nth` and `Skip::last` implementations The main improvement is to make `last` no longer recursive.
2020-02-18Always inline `run_utf8_validation`.Nicholas Nethercote-1/+1
It only has two call sites, and the one within `from_utf8` is hot within rustc itself.
2020-02-17Move the show_usize marker function to a staticMark Rousskov-7/+16
Currently, function items are always tagged unnamed_addr, which means that casting a function to a function pointer is not guaranteed to produce a deterministic address. However, once a function pointer is created, we do expect that to remain stable. So, this changes the show_usize function to a static containing a function pointer and uses that for comparisons. Notably, a *static* may have 'unstable' address, but the function pointer within it must be constant. Resolves issue 58320.
2020-02-17Move to using an extern type for opaquenessMark Rousskov-12/+4
This prevents accidental dereferences and so forth of the Void type, as well as cleaning up the error message to reference Opaque rather than the more complicated PhantomData type.
2020-02-17Drop unused argument to float functionsMark Rousskov-240/+224
2020-02-17Rollup merge of #68701 - amosonn:patch-2, r=RalfJungYuki Okushi-4/+15
Improve #Safety of various methods in core::ptr For `read`, `read_unaligned`,`read_volatile`, `replace`, and `drop_in_place`: - The value they point to must be properly initialized For `replace`, additionally: - The pointer must be readable
2020-02-17Rollup merge of #68495 - sdegutis:patch-1, r=Mark-SimulacrumYuki Okushi-1/+2
Updating str.chars docs to mention crates.io. This might spare someone else a little time searching the stdlib for unicode/grapheme support.
2020-02-16Stabilize {f32, f64}::{LOG2_10, LOG10_2}LeSeulArtichaut-4/+4
2020-02-16Improve documentation on iteratorsLeSeulArtichaut-2/+4
2020-02-16debug_assert a few more raw pointer methodsRalf Jung-5/+16
2020-02-16Improve #Safety of core::ptr::drop_in_placeAmos Onn-1/+4
Added missing conditions: - Valid for writes - Valid for destructing
2020-02-15Formatter::sign is &'static strMark Rousskov-21/+21
The contents were always UTF-8 anyway, and &str has an equivalent representation to &[u8], so this should not affect performance while removing unsafety at edges. It may be worth exploring a further adjustment that stores a single byte (instead of 16) as the contents are always "", "-", or "+".
2020-02-15Improve #Safety in various methods in core::ptrAmos Onn-0/+8
For all methods which read a value of type T, `read`, `read_unaligned`, `read_volatile` and `replace`, added missing constraint: The value they point to must be properly initialized
2020-02-15Improve #Safety of core::ptr::replaceAmos Onn-1/+1
Added missing condition: `dst` must be readable
2020-02-15Improve #Safety in various methods in core::ptrAmos Onn-2/+2
s/for reads and writes/for both ...
2020-02-14implement LowerExp and UpperExp for integersMax Blachman-0/+243
2020-02-12Add trait `Self` filtering to `rustc_on_unimplemented`Esteban Küber-4/+1
2020-02-12Account for `Pin::new(_)` and `Pin::new(Box::new(_))` when `Box::pin(_)` ↵Esteban Küber-0/+7
would be applicable
2020-02-12Add usage recommendation to old float constantsLinus Färnstrand-0/+28
2020-02-12Update float documentation to use associated constsLinus Färnstrand-22/+2
2020-02-12Add notice about using new consts in new code on int modulesLinus Färnstrand-0/+36
2020-02-12Add notice about using new consts in new code on float modulesLinus Färnstrand-0/+6
2020-02-12Remove uint_macros that was identical to int_macrosLinus Färnstrand-45/+13
2020-02-12Replace min/max_value() with MIN/MAX in integer docsLinus Färnstrand-52/+52
2020-02-12Use new preferred consts in int docsLinus Färnstrand-35/+13
2020-02-12Add "soft deprecation" notice to old MIN/MAX docsLinus Färnstrand-12/+41
2020-02-12Add "soft deprecation" notice to old min/max_value() docsLinus Färnstrand-40/+60
2020-02-12Stabilize assoc_int_constsLinus Färnstrand-37/+32
2020-02-12Add tracking number, adjust documentation wordingAndreas Molzer-4/+5