about summary refs log tree commit diff
path: root/library/core
AgeCommit message (Collapse)AuthorLines
2023-06-07Auto merge of #96875 - SabrinaJewson:noop-waker, r=m-ou-sebors-0/+40
Add `task::Waker::noop` I have found myself reimplementing this function many times when I need a `Context` but don't have a runtime or `futures` to hand. Prior art: [`futures::task::noop_waker`](https://docs.rs/futures/0.3/futures/task/fn.noop_waker.html) and [`futures::task::noop_waker_ref`](https://docs.rs/futures/0.3/futures/task/fn.noop_waker_ref.html) Tracking issue: https://github.com/rust-lang/rust/issues/98286 Unresolved questions: 1. Should we also add `RawWaker::noop()`? (I don't think so, I can't think of a use case for it) 2. Should we also add `Context::noop()`? Depending on the future direction `Context` goes a "noop context" might not even make sense in future. 3. Should it be an associated constant instead? That would allow for `let cx = &mut Context::from_waker(&Waker::NOOP);` to work on one line which is pretty nice. I don't really know what the guideline is here. r? rust-lang/libs-api `@rustbot` label +T-libs-api -T-libs
2023-06-04Use 128 bits for TypeId hashThom Chiovoloni-3/+45
- Switch TypeId to 128 bits - Hack around the fact that tracing-subscriber dislikes how TypeId is hashed - Remove lowering of type_id128 from rustc_codegen_llvm - Remove unnecessary `type_id128` intrinsic (just change return type of `type_id`) - Only hash the lower 64 bits of the TypeId - Reword comment
2023-06-04Rollup merge of #109093 - Dante-Broggi:patch-2, r=joshtriplettMatthias Krüger-0/+1
add `#[doc(alias="flatmap")]` to `Option::and_then` I keep forgetting that rust calls this `and_then` and trying to search for `flatmap`. `and_then`'s docs even mention "Some languages call this operation flatmap", but it doesn't show up as a result in the search at `https://doc.rust-lang.org/std/?search=flatmap`
2023-06-03Rollup merge of #111702 - cgwalters:option-map-or-else-with-result, ↵Matthias Krüger-1/+20
r=Mark-Simulacrum Option::map_or_else: Show an example of integrating with Result Moving this from https://github.com/rust-lang/libs-team/issues/59 where an API addition was rejected. But I think it's valuable to add this example to the documentation at least.
2023-06-02Fix typo in `std::cell` module docsKourosh-1/+1
2023-06-01Stabilize 'const_cstr_methods'Trevor Gross-8/+10
2023-06-01Impl ConstParamTy for tuples, make PartialStructuralEq a supertrait tooMichael Goulet-3/+48
2023-06-01Require that const param tys implement ConstParamTyBoxy-0/+5
2023-06-01Rollup merge of #112141 - anna-singleton:issue-111655-fix, r=thomccDylan DPC-2/+1
remove reference to Into in ? operator core/std docs, fix #111655 remove the text stating that `?` uses `Into::into` and add text stating it uses `From::from` instead. This closes #111655.
2023-06-01Auto merge of #111567 - Urgau:uplift_cast_ref_to_mut, r=b-naberbors-0/+2
Uplift `clippy::cast_ref_to_mut` lint This PR aims at uplifting the `clippy::cast_ref_to_mut` lint into rustc. ## `cast_ref_to_mut` (deny-by-default) The `cast_ref_to_mut` lint checks for casts of `&T` to `&mut T` without using interior mutability. ### Example ```rust,compile_fail fn x(r: &i32) { unsafe { *(r as *const i32 as *mut i32) += 1; } } ``` ### Explanation Casting `&T` to `&mut T` without interior mutability is undefined behavior, as it's a violation of Rust reference aliasing requirements. ----- Mostly followed the instructions for uplifting a clippy lint described here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751 `@rustbot` label: +I-lang-nominated r? compiler ----- For Clippy: changelog: Moves: Uplifted `clippy::cast_ref_to_mut` into rustc
2023-05-31remove reference to Into in ? operator core/std docs, fix 111655anna-singleton-2/+1
2023-05-31Add diagnostic items for `ptr::cast_mut` and `ptr::from_ref` Urgau-0/+2
2023-05-31Rollup merge of #112103 - Mark-Simulacrum:bootstrap-update, r=clubby789Matthias Krüger-105/+37
Bootstrap update to 1.71 beta Best reviewed by-commit.
2023-05-31Rollup merge of #112096 - workingjubilee:array-unzip, r=scottmcmMatthias Krüger-23/+0
Remove array_zip `[T; N]::zip` is "eager" but most zips are mapped. This causes poor optimization in generated code. This is a fundamental design issue and "zip" is "prime real estate" in terms of function names, so let's free it up again. - FCP concluded in https://github.com/rust-lang/rust/issues/80094#issuecomment-1468300057 - Closes https://github.com/rust-lang/rust/issues/80094 - Closes https://github.com/rust-lang/rust/issues/103555 Could use review to make sure we aren't losing any essential codegen tests. r? `@scottmcm`
2023-05-30Bump to latest beta compilerMark Rousskov-78/+10
2023-05-30Swap out CURRENT_RUSTC_VERSION to 1.71.0Mark Rousskov-27/+27
2023-05-30Rollup merge of #111543 - Urgau:uplift_invalid_utf8_in_unchecked, r=WaffleLapkinNilstrieb-0/+4
Uplift `clippy::invalid_utf8_in_unchecked` lint This PR aims at uplifting the `clippy::invalid_utf8_in_unchecked` lint into two lints. ## `invalid_from_utf8_unchecked` (deny-by-default) The `invalid_from_utf8_unchecked` lint checks for calls to `std::str::from_utf8_unchecked` and `std::str::from_utf8_unchecked_mut` with an invalid UTF-8 literal. ### Example ```rust unsafe { std::str::from_utf8_unchecked(b"cl\x82ippy"); } ``` ### Explanation Creating such a `str` would result in undefined behavior as per documentation for `std::str::from_utf8_unchecked` and `std::str::from_utf8_unchecked_mut`. ## `invalid_from_utf8` (warn-by-default) The `invalid_from_utf8` lint checks for calls to `std::str::from_utf8` and `std::str::from_utf8_mut` with an invalid UTF-8 literal. ### Example ```rust std::str::from_utf8(b"ru\x82st"); ``` ### Explanation Trying to create such a `str` would always return an error as per documentation for `std::str::from_utf8` and `std::str::from_utf8_mut`. ----- Mostly followed the instructions for uplifting a clippy lint described here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751 ````@rustbot```` label: +I-lang-nominated r? compiler ----- For Clippy: changelog: Moves: Uplifted `clippy::invalid_utf8_in_unchecked` into rustc
2023-05-30Rollup merge of #107916 - reez12g:issue-107040, r=AmanieuNilstrieb-2/+3
fix comment on Allocator trait fixes https://github.com/rust-lang/rust/issues/107040
2023-05-30Remove array_zipJubilee Young-23/+0
`[T; N]::zip` is "eager" but most zips are mapped. This causes poor optimization in generated code. This is a fundamental design issue and "zip" is "prime real estate" in terms of function names, so let's free it up again.
2023-05-30fix comment on Allocator traitreez12g-2/+3
2023-05-29Make `TrustedStep` require `Copy`Scott McMurray-13/+14
All the implementations of the trait already are `Copy`, and this seems to be enough to simplify the implementations enough to make the MIR inliner willing to inline basics like `Range::next`.
2023-05-29Rollup merge of #112045 - Sp00ph:update_current_impl, r=AmanieuMatthias Krüger-2/+3
Followup to #111973 I somehow forgot to update the comment on `select_nth_unstable_by_key` in #111973, so this PR fixes that. r? `@Amanieu`
2023-05-28Update current impl comment for `select_nth_unstable_by_key`Markus Everling-2/+3
2023-05-28Update runtime guarantee for `select_nth_unstable`Markus Everling-6/+4
2023-05-27Rollup merge of #108630 - overlookmotel:realloc-docs-fix, r=AmanieuMatthias Krüger-1/+2
Fix docs for `alloc::realloc` Fixes #108546. Corrects the docs for `alloc::realloc` to bring the safety constraints into line with `Layout::from_size_align_unchecked`'s constraints.
2023-05-27Auto merge of #112016 - GuillaumeGomez:rollup-fhqn4i6, r=GuillaumeGomezbors-0/+4
Rollup of 6 pull requests Successful merges: - #111936 (Include test suite metadata in the build metrics) - #111952 (Remove DesugaringKind::Replace.) - #111966 (Add #[inline] to array TryFrom impls) - #111983 (Perform MIR type ops locally in new solver) - #111997 (Fix re-export of doc hidden macro not showing up) - #112014 (rustdoc: get unnormalized link destination for suggestions) r? `@ghost` `@rustbot` modify labels: rollup
2023-05-27Rollup merge of #111966 - saethlin:inline-slice-tryfrom, r=thomccGuillaume Gomez-0/+4
Add #[inline] to array TryFrom impls I was looking into https://github.com/rust-lang/rust/issues/111959 and I realized we don't have these. They seem like an uncontroversial addition. IMO this PR does not fix that issue. I think the bad codegen is being caused by some underlying deeper problem but this change might cause the MIR inliner to paper over it in this specific case. r? `@thomcc`
2023-05-27Auto merge of #111934 - scottmcm:stabilize-hash-one, r=Amanieubors-4/+1
Stabilize `BuildHasher::hash_one` FCP completed in https://github.com/rust-lang/rust/issues/86161#issuecomment-1561125732
2023-05-27Auto merge of #111928 - c410-f3r:dqewdas, r=eholkbors-1/+1
[RFC-2011] Expand more expressions cc #44838 Expands `if`, `let`, `match` and also makes `generic_assert_internals` an allowed feature when using `assert!`. `#![feature(generic_assert)]` is still needed to activate everything. ```rust #![feature(generic_assert)] fn fun(a: Option<i32>, b: Option<i32>, c: Option<i32>) { assert!( if a.is_some() { 1 } else { 2 } == 3 && if let Some(elem) = b { elem == 4 } else { false } && match c { Some(_) => true, None => false } ); } fn main() { fun(Some(1), None, Some(2)); } // Assertion failed: assert!( // if a.is_some() { 1 } else { 2 } == 3 // && if let Some(elem) = b { elem == 4 } else { false } // && match c { Some(_) => true, None => false } // ); // // With captures: // a = Some(1) // b = None // c = Some(2) ```
2023-05-27Rollup merge of #111973 - Sp00ph:update_current_impl, r=AmanieuMatthias Krüger-4/+6
Update current implementation comments for `select_nth_unstable` This more accurately reflects the actual implementation, as it hasn't been a simple quickselect since #106997. While it does say that the current implementation always runs in O(n), I don't think it should require an FCP as it doesn't guarantee linearity in general and only points out that the current implementation is in fact linear. r? `@Amanieu`
2023-05-27Add invalid_from_utf8 analogous to invalid_from_utf8_uncheckedUrgau-0/+2
2023-05-27Uplift clippy::invalid_utf8_in_unchecked as invalid_from_utf8_uncheckedUrgau-0/+2
2023-05-26Auto merge of #103291 - ink-feather-org:typeid_no_struct_match, r=dtolnaybors-1/+9
Remove structural match from `TypeId` As per https://github.com/rust-lang/rust/pull/99189#issuecomment-1203720442. > Removing the structural equality might make sense, but is a breaking change that'd require a libs-api FCP. https://github.com/rust-lang/rust/pull/99189#issuecomment-1197545482 > Landing this PR now (well, mainly the "remove structural equality" part) would unblock `const fn` `TypeId::of`, since we only postponed that because we were guaranteeing too much. See also #99189, #101698
2023-05-26Update current implementation comments for `select_nth_unstable`Markus Everling-4/+6
2023-05-25Add #[inline] to array TryFrom implsBen Kimock-0/+4
2023-05-25Rollup merge of #107522 - Sp00ph:introselect, r=AmanieuMichael Goulet-140/+311
Add Median of Medians fallback to introselect Fixes #102451. This PR is a follow up to #106997. It adds a Fast Deterministic Selection implementation as a fallback to the introselect algorithm used by `select_nth_unstable`. This allows it to guarantee O(n) worst case running time, while maintaining good performance in all cases. This would fix #102451, which was opened because the `select_nth_unstable` docs falsely claimed that it had O(n) worst case performance, even though it was actually quadratic in the worst case. #106997 improved the worst case complexity to O(n log n) by using heapsort as a fallback, and this PR further improves it to O(n) (this would also make #106933 unnecessary). It also improves the actual runtime if the fallback gets called: Using a pathological input of size `1 << 19` (see the playground link in #102451), calculating the median is roughly 3x faster using fast deterministic selection as a fallback than it is using heapsort. The downside to this is less code reuse between the sorting and selection algorithms, but I don't think it's that bad. The additional algorithms are ~250 LOC with no `unsafe` blocks (I tried using unsafe to avoid bounds checks but it didn't noticeably improve the performance). I also let it fuzz for a while against the current `select_nth_unstable` implementation to ensure correctness, and it seems to still fulfill all the necessary postconditions. cc `@scottmcm` who reviewed #106997
2023-05-25Remove structural match from `TypeId`.raldone01-1/+9
2023-05-24Stabilize `BuildHasher::hash_one`Scott McMurray-4/+1
2023-05-25Rollup merge of #95198 - clarfonthey:get_chunk, r=scottmcmMatthias Krüger-0/+258
Add slice::{split_,}{first,last}_chunk{,_mut} This adds to the existing tracking issue for `slice::array_chunks` (#74985) under a separate feature, `slice_get_chunk`. Currently, we have the existing `first`/`last` API for slices: ```rust impl [T] { pub const fn first(&self) -> Option<&T>; pub const fn first_mut(&mut self) -> Option<&mut T>; pub const fn last(&self) -> Option<&T>; pub const fn last_mut(&mut self) -> Option<&mut T>; pub const fn split_first(&self) -> Option<(&T, &[T])>; pub const fn split_first_mut(&mut self) -> Option<(&mut T, &mut [T])>; pub const fn split_last(&self) -> Option<(&T, &[T])>; pub const fn split_last_mut(&mut self) -> Option<(&mut T, &mut [T])>; } ``` This augments it with a `first_chunk`/`last_chunk` API that allows retrieving multiple elements at once: ```rust impl [T] { pub const fn first_chunk<const N: usize>(&self) -> Option<&[T; N]>; pub const fn first_chunk_mut<const N: usize>(&mut self) -> Option<&mut [T; N]>; pub const fn last_chunk<const N: usize>(&self) -> Option<&[T; N]>; pub const fn last_chunk_mut<const N: usize>(&mut self) -> Option<&mut [T; N]>; pub const fn split_first_chunk<const N: usize>(&self) -> Option<(&[T; N], &[T])>; pub const fn split_first_chunk_mut<const N: usize>(&mut self) -> Option<(&mut [T; N], &mut [T])>; pub const fn split_last_chunk<const N: usize>(&self) -> Option<(&[T; N], &[T])>; pub const fn split_last_chunk_mut<const N: usize>(&mut self) -> Option<(&mut [T; N], &mut [T])>; } ``` The code is based off of a copy of the existing API, with the documentation and examples properly modified. Currently, the most common way to perform these kinds of lookups with the existing methods is via `slice.as_chunks::<N>().0[0]` or the worse `slice.as_chunks::<N>().0[slice.len() - N]`, which is substantially less readable than `slice.first_chunk::<N>()` or `slice.last_chunk::<N>()`. ACP: https://github.com/rust-lang/libs-team/issues/69
2023-05-24[RFC-2011] Expand more expressionsCaio-1/+1
2023-05-24feat: implement `DoubleEndedSearcher` for `CharArray[Ref]Searcher`Jan-0/+4
2023-05-24Use helper functions for min/max_idxMarkus Everling-18/+28
2023-05-24Add Median of Medians fallback to introselectMarkus Everling-140/+301
2023-05-23const stabilize `NonNull::as_ref`Lukas Markeffsky-2/+3
2023-05-23Auto merge of #111807 - erikdesjardins:noalias, r=oli-obkbors-5/+11
[rustc_ty_utils] Treat `drop_in_place`'s *mut argument like &mut when adding LLVM attributes This resurrects PR #103614, which has sat idle for a while. This could probably use a new perf run, since we're on a new LLVM version now. r? `@oli-obk` cc `@RalfJung` --- LLVM can make use of the `noalias` parameter attribute on the parameter to `drop_in_place` in areas like argument promotion. Because the Rust compiler fully controls the code for `drop_in_place`, it can soundly deduce parameter attributes on it. In #103957, Miri was changed to retag `drop_in_place`'s argument as if it was `&mut`, matching this change.
2023-05-23Rollup merge of #111756 - Urgau:rename_drop_forget_copy_ref_lints, r=fee1-deadDylan DPC-1/+1
Rename `{drop,forget}_{copy,ref}` lints to more consistent naming This PR renames previous uplifted lints in https://github.com/rust-lang/rust/pull/109732 to more consistent naming. I followed the renaming done [here](https://github.com/rust-lang/rust/issues/53224) and also advocated in this [clippy issue](https://github.com/rust-lang/rust-clippy/issues/2845): - `drop_copy` to `dropping_copy_types` - `forget_copy` to `forgetting_copy_types` - `drop_ref` to `dropping_references` - `forget_ref` to `forgetting_references`
2023-05-23Rollup merge of #111612 - ChayimFriedman2:collect-into-slice-ref, r=petrochenkovDylan DPC-0/+10
Give better error when collecting into `&[T]` The detection of slice reference of `{integral}` in `rustc_on_unimplemented` is hacky, but a proper solution requires changing `FmtPrinter` to add a parameter to print integers as `{integral}` and I didn't want to change it just for `rustc_on_unimplemented`. I can do that if requested, though. I'm open to better wording; this is the best I could come up with.
2023-05-23Rollup merge of #111609 - LegionMammal978:internal-unsafe, r=thomccDylan DPC-24/+45
Mark internal functions and traits unsafe to reflect preconditions No semantics are changed in this PR; I only mark some functions and and a trait `unsafe` which already had implicit preconditions. Although it seems somewhat redundant for `numfmt::Part::Copy` to contain a `&[u8]` instead of a `&str`, given that all of its current consumers ultimately expect valid UTF-8. Is the type also intended to work for byte-slice formatting in the future?
2023-05-22Auto merge of #111711 - Jules-Bertholet:document-pin-layout, r=thomccbors-0/+2
Document `Pin` memory layout The fact that `Pin` is `#[repr(transparent)]` technically isn't documented anywhere currently. I don't see any reason why `Pin`'s layout would ever change, so this PR codifies it. `@rustbot` label +T-libs-api -T-libs +A-docs +A-layout +A-pin
2023-05-22Auto merge of #111835 - matthiaskrgr:rollup-qd4b2vu, r=matthiaskrgrbors-18/+8
Rollup of 2 pull requests Successful merges: - #111810 (Don't use inner macro in `marker_impls`) - #111826 (Render test messages from bootstrap) r? `@ghost` `@rustbot` modify labels: rollup