about summary refs log tree commit diff
path: root/library/core/tests
AgeCommit message (Collapse)AuthorLines
2022-04-08Rollup merge of #95579 - Cyborus04:slice_flatten, r=scottmcmDylan DPC-0/+17
Add `<[[T; N]]>::flatten{_mut}` Adds `flatten` to convert `&[[T; N]]` to `&[T]` (and `flatten_mut` for `&mut [[T; N]]` to `&mut [T]`)
2022-04-08add `<[[T; N]]>::flatten`, `<[[T; N]]>::flatten_mut`, and `Vec::<[T; ↵Cyborus04-0/+17
N]>::into_flattened`
2022-04-04from_u32(0) can just be default()Giles Cope-1/+47
2022-04-02Fix `array::IntoIter::fold` to use the optimized `Range::fold`Scott McMurray-0/+32
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-04-02Rollup merge of #95556 - declanvk:nonnull-provenance, r=dtolnayDylan DPC-0/+79
Implement provenance preserving methods on NonNull ### Description Add the `addr`, `with_addr`, `map_addr` methods to the `NonNull` type, and map the address type to `NonZeroUsize`. ### Motivation The `NonNull` type is useful for implementing pointer types which have the 0-niche. It is currently possible to implement these provenance preserving functions by calling `NonNull::as_ptr` and `new_unchecked`. The adding these methods makes it more ergonomic. ### Testing Added a unit test of a non-null tagged pointer type. This is based on some real code I have elsewhere, that currently routes the pointer through a `NonZeroUsize` and back out to produce a usable pointer. I wanted to produce an ideal version of the same tagged pointer struct that preserved pointer provenance. ### Related Extension of APIs proposed in #95228 . I can also split this out into a separate tracking issue if that is better (though I may need some pointers on how to do that).
2022-04-02Rollup merge of #95354 - dtolnay:rustc_const_stable, r=lcnrDylan DPC-1/+0
Handle rustc_const_stable attribute in library feature collector The library feature collector in [compiler/rustc_passes/src/lib_features.rs](https://github.com/rust-lang/rust/blob/551b4fa395fa588d91cbecfb0cdfe1baa02670cf/compiler/rustc_passes/src/lib_features.rs) has only been looking at `#[stable(…)]`, `#[unstable(…)]`, and `#[rustc_const_unstable(…)]` attributes, while ignoring `#[rustc_const_stable(…)]`. The consequences of this were: - When any const feature got stabilized (changing one or more `rustc_const_unstable` to `rustc_const_stable`), users who had previously enabled that unstable feature using `#![feature(…)]` would get told "unknown feature", rather than rustc's nicer "the feature … has been stable since … and no longer requires an attribute to enable". This can be seen in the way that https://github.com/rust-lang/rust/pull/93957#issuecomment-1079794660 failed after rebase: ```console error[E0635]: unknown feature `const_ptr_offset` --> $DIR/offset_from_ub.rs:1:35 | LL | #![feature(const_ptr_offset_from, const_ptr_offset)] | ^^^^^^^^^^^^^^^^ ``` - We weren't enforcing that a particular feature is either stable everywhere or unstable everywhere, and that a feature that has been stabilized has the same stabilization version everywhere, both of which we enforce for the other stability attributes. This PR updates the library feature collector to handle `rustc_const_stable`, and fixes places in the standard library and test suite where `rustc_const_stable` was being used in a way that does not meet the rules for a stability attribute.
2022-04-01Rollup merge of #95528 - RalfJung:miri-is-too-slow, r=scottmcmMatthias Krüger-0/+10
skip slow int_log tests in Miri Iterating over i16::MAX many things takes a long time in Miri, let's not do that. I added https://github.com/rust-lang/miri/pull/2044 on the Miri side to still give us some test coverage.
2022-04-01Implement provenance preserving method on NonNullDeclan Kelly-0/+79
**Description** Add the `addr`, `with_addr, `map_addr` methods to the `NonNull` type, and map the address type to `NonZeroUsize`. **Motiviation** The `NonNull` type is useful for implementing pointer types which have the 0-niche. It is currently possible to implement these provenance preserving functions by calling `NonNull::as_ptr` and `new_unchecked`. The addition of these methods simply make it more ergonomic to use. **Testing** Added a unit test of a nonnull tagged pointer type. This is based on some real code I have elsewhere, that currently routes the pointer through a `NonZeroUsize` and back out to produce a usable pointer.
2022-03-31Adjust feature names that disagree on const stabilization versionDavid Tolnay-1/+0
2022-03-31skip slow int_log tests in MiriRalf Jung-0/+10
2022-03-31ptr_metadata test: avoid ptr-to-int transmutesRalf Jung-5/+5
2022-03-27Debug print char 0 as '\0' rather than '\u{0}'David Tolnay-1/+1
2022-03-26add #[must_use] to functions of slice and its iterators.Jendrik-4/+4
2022-03-22Limit test_variadic_fnptr to unixbjorn3-1/+1
2022-03-20Don't declare test_variadic_fnptr with two conflicting signaturesbjorn3-6/+9
It is UB for LLVM and results in a compile error for Cranelift
2022-03-18Rollup merge of #95017 - zachs18:cmp_ordering_derive_eq, r=Dylan-DPCMatthias Krüger-0/+13
Derive Eq for std::cmp::Ordering, instead of using manual impl. This allows consts of type Ordering to be used in patterns, and with feature(adt_const_params) allows using `Ordering` as a const generic parameter. Currently, `std::cmp::Ordering` implements `Eq` using a manually written `impl Eq for Ordering {}`, instead of `derive(Eq)`. This means that it does not implement `StructuralEq`. This commit removes the manually written impl, and adds `derive(Eq)` to `Ordering`, so that it will implement `StructuralEq`.
2022-03-18Rollup merge of #94115 - scottmcm:iter-process-by-ref, r=yaahcMatthias Krüger-0/+24
Let `try_collect` take advantage of `try_fold` overrides No public API changes. With this change, `try_collect` (#94047) is no longer going through the `impl Iterator for &mut impl Iterator`, and thus will be able to use `try_fold` overrides instead of being forced through `next` for every element. Here's the test added, to see that it fails before this PR (once a new enough nightly is out): https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=462f2896f2fed2c238ee63ca1a7e7c56 This might as well go to the same person as my last `try_process` PR (#93572), so r? ``@yaahc``
2022-03-16Add test for StructuralEq for std::cmp::Ordering.Zachary S-0/+13
Added test in library/core/tests/cmp.rs that ensures that `const`s of type `Ordering`s can be used in patterns.
2022-03-13Auto merge of #94738 - Urgau:rustbuild-check-cfg-values, r=Mark-Simulacrumbors-2/+0
Enable conditional checking of values in the Rust codebase This pull-request enable conditional checking of (well known) values in the Rust codebase. Well known values were added in https://github.com/rust-lang/rust/pull/94362. All the `target_*` values are taken from all the built-in targets which is why some extra values were needed do be added as they are not (yet ?) defined in any built-in targets. r? `@Mark-Simulacrum`
2022-03-10Use implicit capture syntax in format_argsT-O-R-U-S-91/+91
This updates the standard library's documentation to use the new syntax. The documentation is worthwhile to update as it should be more idiomatic (particularly for features like this, which are nice for users to get acquainted with). The general codebase is likely more hassle than benefit to update: it'll hurt git blame, and generally updates can be done by folks updating the code if (and when) that makes things more readable with the new format. A few places in the compiler and library code are updated (mostly just due to already having been done when this commit was first authored).
2022-03-10Let `try_collect` take advantage of `try_fold` overridesScott McMurray-0/+24
Without this change it's going through `&mut impl Iterator`, which handles `?Sized` and thus currently can't forward generics. Here's the test added, to see that it fails before this PR (once a new enough nightly is out): https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=462f2896f2fed2c238ee63ca1a7e7c56
2022-03-09Rollup merge of #93057 - frengor:iter_collect_into, r=m-ou-seMatthias Krüger-0/+9
Add Iterator::collect_into This PR adds `Iterator::collect_into` as proposed by ``@cormacrelf`` in #48597 (see https://github.com/rust-lang/rust/pull/48597#issuecomment-842083688). Followup of #92982. This adds the following method to the Iterator trait: ```rust fn collect_into<E: Extend<Self::Item>>(self, collection: &mut E) -> &mut E ```
2022-03-09Remove unexpected #[cfg(target_pointer_width = "8")] in testsLoïc BRANSTETT-2/+0
2022-03-03Miri can run this test nowRalf Jung-2/+0
2022-03-03fix a warning when building core tests with cfg(miri)Ralf Jung-0/+2
2022-03-01Miri/CTFE: properly treat overflow in (signed) division/rem as UBRalf Jung-0/+10
2022-02-28Rollup merge of #89793 - ibraheemdev:from_ptr_range, r=m-ou-seMatthias Krüger-0/+23
Add `slice::{from_ptr_range, from_mut_ptr_range} ` Adds `slice::{from_ptr_range, from_mut_ptr_range}` as counterparts to `slice::{as_ptr_range, as_mut_ptr_range}`.
2022-02-27add `slice::{from_ptr_range, from_mut_ptr_range}`Ibraheem Ahmed-0/+23
2022-02-25Switch bootstrap cfgsMark Rousskov-4/+0
2022-02-20Add collect_intofren_gor-0/+9
2022-02-19Rollup merge of #93658 - cchiw:issue-77443-fix, r=joshtriplettMatthias Krüger-1/+1
Stabilize `#[cfg(panic = "...")]` [Stabilization PR](https://rustc-dev-guide.rust-lang.org/stabilization_guide.html#stabilization-pr) for #77443
2022-02-16Add a `try_collect()` helper method to `Iterator`Arthur Lafrance-0/+47
Tweaked `try_collect()` to accept more `Try` types Updated feature attribute for tracking issue
2022-02-14Write {ui,} tests for `pin_macro` and `pin!`Daniel Henry-Mantilla-0/+35
2022-02-13stabilize const_ptr_offsetSaltyKitkat-1/+0
2022-02-10added spaceCharisee-1/+1
2022-02-10add cfg_panic bootstrapCharisee-0/+6
2022-02-10remove mention of cfg_panic from library testsCharisee-6/+0
2022-02-10replace feature expression (cfg_panic) in lib and remove expression from testsCharisee-1/+1
Rebase commit
2022-02-09Stabilize cfg_target_has_atomicAmanieu d'Antras-1/+1
Closes #32976
2022-02-02add teststamaron-0/+24
2022-02-01Rollup merge of #91828 - oxalica:feat/waker-getters, r=dtolnayMatthias Krüger-0/+24
Implement `RawWaker` and `Waker` getters for underlying pointers implement #87021 New APIs: - `RawWaker::data(&self) -> *const ()` - `RawWaker::vtable(&self) -> &'static RawWakerVTable` - ~`Waker::as_raw_waker(&self) -> &RawWaker`~ `Waker::as_raw(&self) -> &RawWaker` This third one is an auxiliary function to make the two APIs above more useful. Since we can only get `&Waker` in `Future::poll`, without this, we need to `transmute` it into `&RawWaker` (relying on `repr(transparent)`) in order to access its data/vtable pointers. ~Not sure if it should be named `as_raw` or `as_raw_waker`. Seems we always use `as_<something-raw>` instead of just `as_raw`. But `as_raw_waker` seems not quite consistent with `Waker::from_raw`.~ As suggested in https://github.com/rust-lang/rust/pull/91828#discussion_r770729837, use `as_raw`.
2022-02-01Auto merge of #86988 - thomcc:chunky-splitz-says-no-checking, r=the8472bors-0/+102
Carefully remove bounds checks from some chunk iterator functions So, I was writing code that requires the equivalent of `rchunks(N).rev()` (which isn't the same as forward `chunks(N)` — in particular, if the buffer length is not a multiple of `N`, I must handle the "remainder" first). I happened to look at the codegen output of the function (I was actually interested in whether or not a nested loop was being unrolled — it was), and noticed that in the outer `rchunks(n).rev()` loop, LLVM seemed to be unable to remove the bounds checks from the iteration: https://rust.godbolt.org/z/Tnz4MYY8f (this panic was from the split_at in `RChunks::next_back`). After doing some experimentation, it seems all of the `next_back` in the non-exact chunk iterators have the issue: (`Chunks::next_back`, `RChunks::next_back`, `ChunksMut::next_back`, and `RChunksMut::next_back`)... Even worse, the forward `rchunks` iterators sometimes have the issue as well (... but only sometimes). For example https://rust.godbolt.org/z/oGhbqv53r has bounds checks, but if I uncomment the loop body, it manages to remove the check (which is bizarre, since I'd expect the opposite...). I suspect it's highly dependent on the surrounding code, so I decided to remove the bounds checks from them anyway. Overall, this change includes: - All `next_back` functions on the non-`Exact` iterators (e.g. `R?Chunks(Mut)?`). - All `next` functions on the non-exact rchunks iterators (e.g. `RChunks(Mut)?`). I wasn't able to catch any of the other chunk iterators failing to remove the bounds checks (I checked iterations over `r?chunks(_exact)?(_mut)?` with constant chunk sizes under `-O3`, `-Os`, and `-Oz`), which makes sense, since these were the cases where it was harder to prove the bounds check correct to remove... In fact, it took quite a bit of thinking to convince myself that using unchecked_ here was valid — so I'm not really surprised that LLVM had trouble (although compilers are slightly better at this sort of reasoning than humans). A consequence of that is the fact that the `// SAFETY` comment for these are... kinda long... --- I didn't do this for, or even think about it for, any of the other iteration methods; just `next` and `next_back` (where it mattered). If this PR is accepted, I'll file a follow up for someone (possibly me) to look at the others later (in particular, `nth`/`nth_back` looked like they had similar logic), but I wanted to do this now, as IMO `next`/`next_back` are the most important here, since they're what gets used by the iteration protocol. --- Note: While I don't expect this to impact performance directly, the panic is a side effect, which would otherwise not exist in these loops. That is, this could prevent the compiler from being able to move/remove/otherwise rework a loop over these iterators (as an example, it could not delete the code for a loop whose body computes a value which doesn't get used). Also, some like to be able to have confidence this code has no panicking branches in the optimized code, and "no bounds checks" is kinda part of the selling point of Rust's iterators anyway.
2022-01-31Improve test coverage of {Chunks,RChunks,RChunksMut}::{next,next_back}Thom Chiovoloni-0/+102
2022-01-31Auto merge of #93498 - matthiaskrgr:rollup-k5shwrc, r=matthiaskrgrbors-0/+27
Rollup of 8 pull requests Successful merges: - #90277 (Improve terminology around "after typeck") - #92918 (Allow eliding GATs in expression position) - #93039 (Don't suggest inaccessible fields) - #93155 (Switch pretty printer to block-based indentation) - #93214 (Respect doc(hidden) when suggesting available fields) - #93347 (Make `char::DecodeUtf16::size_hist` more precise) - #93392 (Clarify documentation on char::MAX) - #93444 (Fix some CSS warnings and errors from VS Code) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-01-31Rollup merge of #93480 - est31:remove_unstable_deprecated, r=Mark-SimulacrumMatthias Krüger-1/+0
Remove deprecated and unstable slice_partition_at_index functions They have been deprecated since commit 01ac5a97c90c26ac35ca9d65f685dd6701edfa3b which was part of the 1.49.0 release, so from the point of nightly, 11 releases ago.
2022-01-31Rollup merge of #93347 - WaffleLapkin:better_char_decode_utf16_size_hint, ↵Matthias Krüger-0/+27
r=dtolnay Make `char::DecodeUtf16::size_hist` more precise New implementation takes into account contents of `self.buf` and rounds lower bound up instead of down. Fixes #88762 Revival of #88763
2022-01-30Rollup merge of #92887 - pietroalbini:pa-bootstrap-update, r=Mark-SimulacrumEric Huss-3/+0
Bootstrap compiler update r? ``@Mark-Simulacrum``
2022-01-30Remove deprecated and unstable slice_partition_at_index functionsest31-1/+0
They have been deprecated since commit 01ac5a97c90c26ac35ca9d65f685dd6701edfa3b which was part of the 1.49.0 release, so from the point of nightly, 11 releases ago.
2022-01-30Fix an edge case in `chat::DecodeUtf16::size_hint`Maybe Waffle-0/+1
There are cases, when data in the buf might or might not be an error.
2022-01-29Rollup merge of #93236 - woppopo:const_nonnull_new, r=oli-obkMatthias Krüger-0/+17
Make `NonNull::new` `const` Tracking issue: #93235