about summary refs log tree commit diff
path: root/library/core/tests
AgeCommit message (Collapse)AuthorLines
2022-07-13Stabilize `core::ffi:c_*` and rexport in `std::ffi`Josh Triplett-1/+0
This only stabilizes the base types, not the non-zero variants, since those have their own separate tracking issue and have not gone through FCP to stabilize.
2022-07-13Re-optimize `Layout::array`Scott McMurray-0/+44
This way it's one check instead of two, so hopefully it'll be better Nightly: ``` layout_array_i32: movq %rdi, %rax movl $4, %ecx mulq %rcx jo .LBB1_2 movabsq $9223372036854775805, %rcx cmpq %rcx, %rax jae .LBB1_2 movl $4, %edx retq .LBB1_2: … ``` This PR: ``` movq %rcx, %rax shrq $61, %rax jne .LBB2_1 shlq $2, %rcx movl $4, %edx movq %rcx, %rax retq .LBB2_1: … ```
2022-07-09Partially stabilize const_slice_from_raw_partsKonrad Borowski-1/+0
This doesn't stabilize methods working on mutable pointers.
2022-07-08revert changes to unicode stabilityJane Losare-Lusby-1/+1
2022-07-06Rollup merge of #96935 - thomcc:atomicptr-strict-prov, r=dtolnayGuillaume Gomez-0/+86
Allow arithmetic and certain bitwise ops on AtomicPtr This is mainly to support migrating from `AtomicUsize`, for the strict provenance experiment. This is a pretty dubious set of APIs, but it should be sufficient to allow code that's using `AtomicUsize` to manipulate a tagged pointer atomically. It's under a new feature gate, `#![feature(strict_provenance_atomic_ptr)]`, but I'm not sure if it needs its own tracking issue. I'm happy to make one, but it's not clear that it's needed. I'm unsure if it needs changes in the various non-LLVM backends. Because we just cast things to integers anyway (and were already doing so), I doubt it. API change proposal: https://github.com/rust-lang/libs-team/issues/60 Fixes #95492
2022-07-05core::any: replace some unstable generic types with impl TraitNick Cameron-11/+11
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2022-07-05Rollup merge of #97712 - RalfJung:untyped, r=scottmcmDylan DPC-0/+25
ptr::copy and ptr::swap are doing untyped copies The consensus in https://github.com/rust-lang/rust/issues/63159 seemed to be that these operations should be "untyped", i.e., they should treat the data as raw bytes, should work when these bytes violate the validity invariant of `T`, and should exactly preserve the initialization state of the bytes that are being copied. This is already somewhat implied by the description of "copying/swapping size*N bytes" (rather than "N instances of `T`"). The implementations mostly already work that way (well, for LLVM's intrinsics the documentation is not precise enough to say what exactly happens to poison, but if this ever gets clarified to something that would *not* perfectly preserve poison, then I strongly assume there will be some way to make a copy that *does* perfectly preserve poison). However, I had to adjust `swap_nonoverlapping`; after ``@scottmcm's`` [recent changes](https://github.com/rust-lang/rust/pull/94212), that one (sometimes) made a typed copy. (Note that `mem::swap`, which works on mutable references, is unchanged. It is documented as "swapping the values at two mutable locations", which to me strongly indicates that it is indeed typed. It is also safe and can rely on `&mut T` pointing to a valid `T` as part of its safety invariant.) On top of adding a test (that will be run by Miri), this PR then also adjusts the documentation to indeed stably promise the untyped semantics. I assume this means the PR has to go through t-libs (and maybe t-lang?) FCP. Fixes https://github.com/rust-lang/rust/issues/63159
2022-07-03Add size assert in transmute_copy5225225-0/+40
2022-07-03Fix slice::ChunksMut aliasingBen Kimock-0/+44
2022-07-01update cfg(bootstrap)sPietro Albini-10/+7
2022-07-01Rename AtomicPtr::fetch_{add,sub}{,_bytes}Thom Chiovoloni-10/+10
2022-07-01Allow arithmetic and certain bitwise ops on AtomicPtrThom Chiovoloni-0/+86
This is mainly to support migrating from AtomicUsize, for the strict provenance experiment. Fixes #95492
2022-06-27libcore tests: avoid int2ptr castsRalf Jung-19/+20
2022-06-21Add `Iterator::next_chunk`Ross MacArthur-0/+10
2022-06-17Stabilized Option::unzip()Chase Wilson-1/+0
2022-06-16Move/rename `lazy::{OnceCell, Lazy}` to `cell::{OnceCell, LazyCell}`Maybe Waffle-3/+2
2022-06-10Auto merge of #91970 - nrc:provide-any, r=scottmcmbors-0/+63
Add the Provider api to core::any This is an implementation of [RFC 3192](https://github.com/rust-lang/rfcs/pull/3192) ~~(which is yet to be merged, thus why this is a draft PR)~~. It adds an API for type-driven requests and provision of data from trait objects. A primary use case is for the `Error` trait, though that is not implemented in this PR. The only major difference to the RFC is that the functionality is added to the `any` module, rather than being in a sibling `provide_any` module (as discussed in the RFC thread). ~~Still todo: improve documentation on items, including adding examples.~~ cc `@yaahc`
2022-06-08Stabilize `const_intrinsic_copy`Yuki Okushi-1/+0
2022-06-07Use repr(C) when depending on struct layout in ptr testsBen Kimock-0/+1
2022-06-06Add some more testsNick Cameron-2/+42
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2022-06-06Modify the signature of the request_* methods so that trait_upcasting is not ↵Nick Cameron-3/+3
required Signed-off-by: Nick Cameron <nrc@ncameron.org>
2022-06-06Add the Provider api to core::anyNick Cameron-0/+23
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2022-06-05change ptr::swap methods to do untyped copiesRalf Jung-0/+25
2022-06-03test const_copy to make sure bytewise pointer copies are workingRalf Jung-0/+41
2022-05-30Implement carrying_add and borrowing_sub on signed numbersStovent-0/+49
2022-05-29Use Box::new() instead of box syntax in core testsest31-10/+13
2022-05-25Auto merge of #94954 - SimonSapin:null-thin3, r=yaahcbors-0/+12
Extend ptr::null and null_mut to all thin (including extern) types Fixes https://github.com/rust-lang/rust/issues/93959 This change was accepted in https://rust-lang.github.io/rfcs/2580-ptr-meta.html Note that this changes the signature of **stable** functions. The change should be backward-compatible, but it is **insta-stable** since it cannot (easily, at all?) be made available only through a `#![feature(…)]` opt-in. The RFC also proposed the same change for `NonNull::dangling`, which makes sense it terms of its signature but not in terms of its implementation. `dangling` uses `align_of()` as an address. But what `align_of()` should be for extern types or whether it should be allowed at all remains an open question. This commit depends on https://github.com/rust-lang/rust/pull/93977, which is not yet part of the bootstrap compiler. So `#[cfg]` is used to only apply the change in stage 1+. As far a I know bounds cannot be made conditional with `#[cfg]`, so the entire functions are duplicated. This is unfortunate but temporary. Since this duplication makes it less obvious in the diff, the new definitions differ in: * More permissive bounds (`Thin` instead of implied `Sized`) * Different implementation * Having `rustc_allow_const_fn_unstable(const_fn_trait_bound)` * Having `rustc_allow_const_fn_unstable(ptr_metadata)`
2022-05-22[RFC 2011] Library codeCaio-0/+39
2022-05-22Auto merge of #97265 - JohnTitor:rollup-kgthnjt, r=JohnTitorbors-2/+4
Rollup of 6 pull requests Successful merges: - #97144 (Fix rusty grammar in `std::error::Reporter` docs) - #97225 (Fix `Display` for `cell::{Ref,RefMut}`) - #97228 (Omit stdarch workspace from rust-src) - #97236 (Recover when resolution did not resolve lifetimes.) - #97245 (Fix typo in futex RwLock::write_contended.) - #97259 (Fix typo in Mir phase docs) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-05-20Fix `Display` for `cell::{Ref,RefMut}`Josh Stone-2/+4
These guards changed to pointers in #97027, but their `Display` was formatting that field directly, which made it show the raw pointer value. Now we go through `Deref` to display the real value again.
2022-05-20Stabilize core::array::from_fnCaio-2/+2
2022-05-18Stage-step cfgsMark Rousskov-2/+0
2022-05-14Auto merge of #95602 - scottmcm:faster-array-intoiter-fold, r=the8472bors-0/+32
Fix `array::IntoIter::fold` to use the optimized `Range::fold` It was using `Iterator::by_ref` in the implementation, which ended up pessimizing it enough that, for example, it didn't vectorize when we tried it in the <https://rust-lang.zulipchat.com/#narrow/stream/257879-project-portable-simd/topic/Reducing.20sum.20into.20wider.20types> conversation. Demonstration that the codegen test doesn't pass on the current nightly: <https://rust.godbolt.org/z/Taxev5eMn>
2022-05-13Extend ptr::null and null_mut to all thin (including extern) typesSimon Sapin-0/+12
Fixes https://github.com/rust-lang/rust/issues/93959 This change was accepted in https://rust-lang.github.io/rfcs/2580-ptr-meta.html Note that this changes the signature of **stable** functions. The change should be backward-compatible, but it is **insta-stable** since it cannot (easily, at all?) be made available only through a `#![feature(…)]` opt-in. The RFC also proposed the same change for `NonNull::dangling`, which makes sense it terms of its signature but not in terms of its implementation. `dangling` uses `align_of()` as an address. But what `align_of()` should be for extern types or whether it should be allowed at all remains an open question. This commit depends on https://github.com/rust-lang/rust/pull/93977, which is not yet part of the bootstrap compiler. So `#[cfg]` is used to only apply the change in stage 1+. As far a I know bounds cannot be made conditional with `#[cfg]`, so the entire functions are duplicated. This is unfortunate but temporary. Since this duplication makes it less obvious in the diff, the new definitions differ in: * More permissive bounds (`Thin` instead of implied `Sized`) * Different implementation * Having `rustc_allow_const_fn_unstable(ptr_metadata)`
2022-05-06Auto merge of #94598 - scottmcm:prefix-free-hasher-methods, r=Amanieubors-0/+5
Add a dedicated length-prefixing method to `Hasher` This accomplishes two main goals: - Make it clear who is responsible for prefix-freedom, including how they should do it - Make it feasible for a `Hasher` that *doesn't* care about Hash-DoS resistance to get better performance by not hashing lengths This does not change rustc-hash, since that's in an external crate, but that could potentially use it in future. Fixes #94026 r? rust-lang/libs --- The core of this change is the following two new methods on `Hasher`: ```rust pub trait Hasher { /// Writes a length prefix into this hasher, as part of being prefix-free. /// /// If you're implementing [`Hash`] for a custom collection, call this before /// writing its contents to this `Hasher`. That way /// `(collection![1, 2, 3], collection![4, 5])` and /// `(collection![1, 2], collection![3, 4, 5])` will provide different /// sequences of values to the `Hasher` /// /// The `impl<T> Hash for [T]` includes a call to this method, so if you're /// hashing a slice (or array or vector) via its `Hash::hash` method, /// you should **not** call this yourself. /// /// This method is only for providing domain separation. If you want to /// hash a `usize` that represents part of the *data*, then it's important /// that you pass it to [`Hasher::write_usize`] instead of to this method. /// /// # Examples /// /// ``` /// #![feature(hasher_prefixfree_extras)] /// # // Stubs to make the `impl` below pass the compiler /// # struct MyCollection<T>(Option<T>); /// # impl<T> MyCollection<T> { /// # fn len(&self) -> usize { todo!() } /// # } /// # impl<'a, T> IntoIterator for &'a MyCollection<T> { /// # type Item = T; /// # type IntoIter = std::iter::Empty<T>; /// # fn into_iter(self) -> Self::IntoIter { todo!() } /// # } /// /// use std::hash::{Hash, Hasher}; /// impl<T: Hash> Hash for MyCollection<T> { /// fn hash<H: Hasher>(&self, state: &mut H) { /// state.write_length_prefix(self.len()); /// for elt in self { /// elt.hash(state); /// } /// } /// } /// ``` /// /// # Note to Implementers /// /// If you've decided that your `Hasher` is willing to be susceptible to /// Hash-DoS attacks, then you might consider skipping hashing some or all /// of the `len` provided in the name of increased performance. #[inline] #[unstable(feature = "hasher_prefixfree_extras", issue = "88888888")] fn write_length_prefix(&mut self, len: usize) { self.write_usize(len); } /// Writes a single `str` into this hasher. /// /// If you're implementing [`Hash`], you generally do not need to call this, /// as the `impl Hash for str` does, so you can just use that. /// /// This includes the domain separator for prefix-freedom, so you should /// **not** call `Self::write_length_prefix` before calling this. /// /// # Note to Implementers /// /// The default implementation of this method includes a call to /// [`Self::write_length_prefix`], so if your implementation of `Hasher` /// doesn't care about prefix-freedom and you've thus overridden /// that method to do nothing, there's no need to override this one. /// /// This method is available to be overridden separately from the others /// as `str` being UTF-8 means that it never contains `0xFF` bytes, which /// can be used to provide prefix-freedom cheaper than hashing a length. /// /// For example, if your `Hasher` works byte-by-byte (perhaps by accumulating /// them into a buffer), then you can hash the bytes of the `str` followed /// by a single `0xFF` byte. /// /// If your `Hasher` works in chunks, you can also do this by being careful /// about how you pad partial chunks. If the chunks are padded with `0x00` /// bytes then just hashing an extra `0xFF` byte doesn't necessarily /// provide prefix-freedom, as `"ab"` and `"ab\u{0}"` would likely hash /// the same sequence of chunks. But if you pad with `0xFF` bytes instead, /// ensuring at least one padding byte, then it can often provide /// prefix-freedom cheaper than hashing the length would. #[inline] #[unstable(feature = "hasher_prefixfree_extras", issue = "88888888")] fn write_str(&mut self, s: &str) { self.write_length_prefix(s.len()); self.write(s.as_bytes()); } } ``` With updates to the `Hash` implementations for slices and containers to call `write_length_prefix` instead of `write_usize`. `write_str` defaults to using `write_length_prefix` since, as was pointed out in the issue, the `write_u8(0xFF)` approach is insufficient for hashers that work in chunks, as those would hash `"a\u{0}"` and `"a"` to the same thing. But since `SipHash` works byte-wise (there's an internal buffer to accumulate bytes until a full chunk is available) it overrides `write_str` to continue to use the add-non-UTF-8-byte approach. --- Compatibility: Because the default implementation of `write_length_prefix` calls `write_usize`, the changed hash implementation for slices will do the same thing the old one did on existing `Hasher`s.
2022-05-06Add a dedicated length-prefixing method to `Hasher`Scott McMurray-0/+5
This accomplishes two main goals: - Make it clear who is responsible for prefix-freedom, including how they should do it - Make it feasible for a `Hasher` that *doesn't* care about Hash-DoS resistance to get better performance by not hashing lengths This does not change rustc-hash, since that's in an external crate, but that could potentially use it in future.
2022-05-05Rollup merge of #95359 - jhpratt:int_roundings, r=joshtriplettMatthias Krüger-14/+14
Update `int_roundings` methods from feedback This updates `#![feature(int_roundings)]` (#88581) from feedback. All methods now take `NonZeroX`. The documentation makes clear that they panic in debug mode and wrap in release mode. r? `@joshtriplett` `@rustbot` label +T-libs +T-libs-api +S-waiting-on-review
2022-05-04Update `int_roundings` methods from feedbackJacob Pratt-14/+14
2022-05-04Stabilize `bool::then_some`Josh Triplett-1/+0
2022-04-26Rollup merge of #96149 - est31:remove_unused_macro_matchers, r=petrochenkovDylan DPC-12/+0
Remove unused macro rules Removes rules of internal macros that weren't triggered.
2022-04-18Auto merge of #92287 - JulianKnodt:slice_remainder, r=yaahcbors-0/+13
Add slice::remainder This adds a remainder function to the Slice iterator, so that a caller can access unused elements if iteration stops. Addresses #91733
2022-04-18Remove unused macro rulesest31-12/+0
2022-04-17Replace u8to64_le macro with u64::from_le_bytesest31-24/+2
The macro was a reimplementation of the function.
2022-04-17Add slice::remainderkadmin-0/+13
This adds a remainder function to the Slice iterator, so that a caller can access unused elements if iteration stops.
2022-04-12Auto merge of #95399 - gilescope:plan_b, r=scottmcmbors-1/+71
Faster parsing for lower numbers for radix up to 16 (cont.) ( Continuation of https://github.com/rust-lang/rust/pull/83371 ) With LingMan's change I think this is potentially ready.
2022-04-11better def of is signed in tests.Giles Cope-8/+2
2022-04-11fix Layout struct member naming styleliangyongrui-1/+1
2022-04-10Use Add, Sub, Mul traits instead of unsafeGiles Cope-1/+31
2022-04-09Rollup merge of #95361 - scottmcm:valid-align, r=Mark-SimulacrumDylan DPC-0/+18
Make non-power-of-two alignments a validity error in `Layout` Inspired by the zulip conversation about how `Layout` should better enforce `size <= isize::MAX as usize`, this uses an N-variant enum on N-bit platforms to require at the validity level that the existing invariant of "must be a power of two" is upheld. This was MIRI can catch it, and means there's a more-specific type for `Layout` to store than just `NonZeroUsize`. It's left as `pub(crate)` here; a future PR could consider giving it a tracking issue for non-internal usage.
2022-04-08Make non-power-of-two alignments a validity error in `Layout`Scott McMurray-0/+18
Inspired by the zulip conversation about how `Layout` should better enforce `size < isize::MAX as usize`, this uses an N-variant enum on N-bit platforms to require at the validity level that the existing invariant of "must be a power of two" is upheld. This was MIRI can catch it, and means there's a more-specific type for `Layout` to store than just `NonZeroUsize`.