summary refs log tree commit diff
path: root/library
AgeCommit message (Collapse)AuthorLines
2023-03-03Add test for VecDeque::append ZST capacity overflowpommicket-0/+14
(cherry picked from commit 12f959ba39ad353ce07971aaf8cef564f86b068d)
2023-03-03Use checked_add in VecDeque::append for ZSTs to avoid overflowpommicket-1/+1
(cherry picked from commit 379b18bb0ab07e8f7ba04ca29ba52a1817cec1ce)
2023-03-03Disambiguate commentsMarkus Everling-2/+2
(cherry picked from commit 4a4f43e4e9b994c729a0506d921fe9734673a20a)
2023-03-03Fix `VecDeque::shrink_to` and add tests.Markus Everling-55/+104
This adds both a test specific to #108453 as well as an exhaustive test that goes through all possible combinations of head index, length and target capacity for a deque with capacity 16. (cherry picked from commit 9e22516877a2853c71456ef792fcbd9087fb905a)
2023-03-03Revert to using `RtlGenRandom`Chris Denton-103/+31
This is required due to `BCryptGenRandom` failing to load the necessary dll on some systems. (cherry picked from commit dfd0afb991d4bfbd6fdf86adb631e428c185ac89)
2023-01-24Set version placeholders to 1.68Mark Rousskov-9/+9
2023-01-21Rollup merge of #106144 - tgross35:patch-1, r=Mark-SimulacrumMichael Goulet-0/+69
Improve the documentation of `black_box` There don't seem to be many great resources on how `black_box` should be used, so I added some information here
2023-01-20Rollup merge of #104672 - Voultapher:unify-sort-modules, r=thomccMichael Goulet-310/+560
Unify stable and unstable sort implementations in same core module This moves the stable sort implementation to the core::slice::sort module. By virtue of being in core it can't access `Vec`. The two `Vec` used by merge sort, `buf` and `runs`, are modelled as custom types that implement the very limited required `Vec` interface with the help of provided allocation and free functions. This is done to allow future re-use of functions and logic between stable and unstable sort. Such as `insert_head`. This is in preparation of #100856 and #104116. It only moves code, it *doesn't* change any of the sort related logic. This unlocks the ability to share `insert_head`, `insert_tail`, `swap_if_less` `merge` and more. Tagging ````@Mark-Simulacrum```` I hope this allows progress on #100856, by moving `merge_sort` here I hope future changes will be easier to review.
2023-01-20Rollup merge of #107067 - tmiasko:custom-mir-storage-statements, r=oli-obkMatthias Krüger-0/+2
Custom MIR: Support storage statements r? `@oli-obk` `@JakobDegen`
2023-01-20Rollup merge of #107053 - devnexen:sigstringrepr_haiku, r=thomccMatthias Krüger-0/+2
signal update string representation for haiku.
2023-01-19Auto merge of #107064 - GuillaumeGomez:rollup-pbgu6r3, r=GuillaumeGomezbors-0/+5
Rollup of 5 pull requests Successful merges: - #105977 (Transform async `ResumeTy` in generator transform) - #106927 (make `CastError::NeedsDeref` create a `MachineApplicable` suggestion) - #106931 (document + UI test `E0208` and make its output more user-friendly) - #107027 (Remove extra removal from test path) - #107037 (Fix Dominators::rank_partial_cmp to match documentation) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2023-01-19Custom MIR: Support storage statementsTomasz Miąsko-0/+2
2023-01-19Auto merge of #106989 - clubby789:is-zero-num, r=scottmcmbors-1/+20
Implement `alloc::vec::IsZero` for `Option<$NUM>` types Fixes #106911 Mirrors the `NonZero$NUM` implementations with an additional `assert_zero_valid`. `None::<i32>` doesn't stricly satisfy `IsZero` but for the purpose of allocating we can produce more efficient codegen.
2023-01-19Transform async ResumeTy in generator transformArpad Borsos-0/+5
- Eliminates all the `get_context` calls that async lowering created. - Replace all `Local` `ResumeTy` types with `&mut Context<'_>`. The `Local`s that have their types replaced are: - The `resume` argument itself. - The argument to `get_context`. - The yielded value of a `yield`. The `ResumeTy` hides a `&mut Context<'_>` behind an unsafe raw pointer, and the `get_context` function is being used to convert that back to a `&mut Context<'_>`. Ideally the async lowering would not use the `ResumeTy`/`get_context` indirection, but rather directly use `&mut Context<'_>`, however that would currently lead to higher-kinded lifetime errors. See <https://github.com/rust-lang/rust/issues/105501>. The async lowering step and the type / lifetime inference / checking are still using the `ResumeTy` indirection for the time being, and that indirection is removed here. After this transform, the generator body only knows about `&mut Context<'_>`.
2023-01-18signal update string representation for haiku.David Carlier-0/+2
2023-01-18Update `IsZero` documentationclubby789-1/+2
2023-01-18Implement `alloc::vec::IsZero` for `Option<$NUM>` typesclubby789-0/+18
2023-01-18Rollup merge of #106950 - the8472:fix-splice-miri, r=cuviperDylan DPC-3/+9
Don't do pointer arithmetic on pointers to deallocated memory vec::Splice can invalidate the slice::Iter inside vec::Drain. So we replace them with dangling pointers which, unlike ones to deallocated memory, are allowed. Fixes miri test failures. Fixes https://github.com/rust-lang/miri/issues/2759
2023-01-18Rollup merge of #106441 - mllken:abstract-socket-noref, r=joshtriplettDylan DPC-2/+2
relax reference requirement on SocketAddrExt::from_abstract_name Reference: https://github.com/rust-lang/rust/issues/85410#issuecomment-1369544671
2023-01-18Rollup merge of #103702 - ↵Dylan DPC-48/+15
WaffleLapkin:lift-sized-bounds-from-pointer-methods-where-applicable, r=m-ou-se Lift `T: Sized` bounds from some `strict_provenance` pointer methods This PR removes requirement for `T` (pointee type) to be `Sized` to call `pointer::{addr, expose_addr, with_addr, map_addr}`. These functions don't use `T`'s size, so there is no reason for them to require this. Updated public API: cc ``@Gankra,`` #95228 r? libs-api
2023-01-18Rollup merge of #106997 - Sp00ph:introselect, r=scottmcmMatthias Krüger-0/+22
Add heapsort fallback in `select_nth_unstable` Addresses #102451 and #106933. `slice::select_nth_unstable` uses a quick select implementation based on the same pattern defeating quicksort algorithm that `slice::sort_unstable` uses. `slice::sort_unstable` uses a recursion limit and falls back to heapsort if there were too many bad pivot choices, to ensure O(n log n) worst case running time (known as introsort). However, `slice::select_nth_unstable` does not have such a fallback strategy, which leads to it having a worst case running time of O(n²) instead. #102451 links to a playground which generates pathological inputs that show this quadratic behavior. On my machine, a randomly generated slice of length `1 << 19` takes ~200µs to calculate its median, whereas a pathological input of the same length takes over 2.5s. This PR adds an iteration limit to `select_nth_unstable`, falling back to heapsort, which ensures an O(n log n) worst case running time (introselect). With this change, there was no noticable slowdown for the random input, but the same pathological input now takes only ~1.2ms. In the future it might be worth implementing something like Median of Medians or Fast Deterministic Selection instead, which guarantee O(n) running time for all possible inputs. I've left this as a `FIXME` for now and only implemented the heapsort fallback to minimize the needed code changes. I still think we should clarify in the `select_nth_unstable` docs that the worst case running time isn't currently O(n) (the original reason that #102451 was opened), but I think it's a lot better to be able to guarantee O(n log n) instead of O(n²) for the worst case.
2023-01-18Rollup merge of #106992 - joboet:alloc_remove_box_syntax, r=thomccMatthias Krüger-1/+0
Remove unused `#![feature(box_syntax)]` in `alloc`
2023-01-17Don't do pointer arithmetic on pointers to deallocated memoryThe 8472-3/+9
vec::Splice can invalidate the slice::Iter inside vec::Drain. So we replace them with dangling pointers which, unlike ones to deallocated memory, are allowed.
2023-01-17Rollup merge of #106889 - scottmcm:windows-mut, r=cuviperMatthias Krüger-0/+16
Mention the lack of `windows_mut` in `windows` This is a common request, going back to at least 2015 (#23783), so mention in the docs that it can't be done and offer a workaround using <https://doc.rust-lang.org/std/cell/struct.Cell.html#method.as_slice_of_cells>. (See also URLO threads like <https://internals.rust-lang.org/t/a-windows-mut-method-on-slice/16941/10?u=scottmcm>.)
2023-01-17Add heapsort fallback in `select_nth_unstable`Markus Everling-0/+22
2023-01-17refactor[alloc]: remove unused box syntax featurejoboet-1/+0
2023-01-17Rollup merge of #106922 - ChayimFriedman2:patch-5, r=workingjubileeDylan DPC-8/+6
Avoid unsafe code in `to_ascii_[lower/upper]case()`
2023-01-17Rollup merge of #106148 - chenyukang:yukang/fix-105061-unused, r=lcnrDylan DPC-4/+4
Fix unused_parens issue for higher ranked function pointers fixes #105061 r? `@lcnr`
2023-01-16Constify `TypeId` ordering implsonestacked-1/+2
2023-01-16Avoid unsafe code in `to_ascii_[lower/upper]case()`Chayim Refael Friedman-8/+6
2023-01-15Auto merge of #106393 - the8472:use-ptr-sub, r=scottmcmbors-23/+7
Simplify manual ptr arithmetic in slice::Iter with ptr_sub The old code was introduced in #61885, which predates the ptr_sub method and underlying intrinsic. The codegen test still passes. r? `@scottmcm`
2023-01-15replace manual ptr arithmetic with ptr_subThe 8472-23/+7
2023-01-15Auto merge of #105851 - dtolnay:peekmutleak, r=Mark-Simulacrumbors-10/+75
Leak amplification for peek_mut() to ensure BinaryHeap's invariant is always met In the libs-api team's discussion around #104210, some of the team had hesitations around exposing malformed BinaryHeaps of an element type whose Ord and Drop impls are trusted, and which does not contain interior mutability. For example in the context of this kind of code: ```rust use std::collections::BinaryHeap; use std::ops::Range; use std::slice; fn main() { let slice = &mut ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; let cut_points = BinaryHeap::from(vec![4, 2, 7]); println!("{:?}", chop(slice, cut_points)); } // This is a souped up slice::split_at_mut to split in arbitrary many places. // // usize's Ord impl is trusted, so 1 single bounds check guarantees all those // output slices are non-overlapping and in-bounds fn chop<T>(slice: &mut [T], mut cut_points: BinaryHeap<usize>) -> Vec<&mut [T]> { let mut vec = Vec::with_capacity(cut_points.len() + 1); let max = match cut_points.pop() { Some(max) => max, None => { vec.push(slice); return vec; } }; assert!(max <= slice.len()); let len = slice.len(); let ptr: *mut T = slice.as_mut_ptr(); let get_unchecked_mut = unsafe { |range: Range<usize>| &mut *slice::from_raw_parts_mut(ptr.add(range.start), range.len()) }; vec.push(get_unchecked_mut(max..len)); let mut end = max; while let Some(start) = cut_points.pop() { vec.push(get_unchecked_mut(start..end)); end = start; } vec.push(get_unchecked_mut(0..end)); vec } ``` ```console [['7', '8', '9'], ['4', '5', '6'], ['2', '3'], ['0', '1']] ``` In the current BinaryHeap API, `peek_mut()` is the only thing that makes the above function unsound. ```rust let slice = &mut ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; let mut cut_points = BinaryHeap::from(vec![4, 2, 7]); { let mut max = cut_points.peek_mut().unwrap(); *max = 0; std::mem::forget(max); } println!("{:?}", chop(slice, cut_points)); ``` ```console [['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], [], ['2', '3'], ['0', '1']] ``` Or worse: ```rust let slice = &mut ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; let mut cut_points = BinaryHeap::from(vec![100, 100]); { let mut max = cut_points.peek_mut().unwrap(); *max = 0; std::mem::forget(max); } println!("{:?}", chop(slice, cut_points)); ``` ```console [['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], [], ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '\u{1}', '\0', '?', '翾', '?', '翾', '\0', '\0', '?', '翾', '?', '翾', '?', '啿', '?', '啿', '?', '啿', '?', '啿', '?', '啿', '?', '翾', '\0', '\0', '񤬐', '啿', '\u{5}', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\u{8}', '\0', '`@',` '\0', '\u{1}', '\0', '?', '翾', '?', '翾', '?', '翾', ' thread 'main' panicked at 'index out of bounds: the len is 33 but the index is 33', library/core/src/unicode/unicode_data.rs:319:9 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` --- This PR makes `peek_mut()` use leak amplification (https://doc.rust-lang.org/1.66.0/nomicon/leaking.html#drain) to preserve the heap's invariant even in the situation that `PeekMut` gets leaked. I'll also follow up in the tracking issue of unstable `drain_sorted()` (#59278) and `retain()` (#71503).
2023-01-15Rollup merge of #106880 - tspiteri:borrowing-sub-typo, r=cuviperMatthias Krüger-1/+1
doc: fix typo
2023-01-15Rollup merge of #106867 - sunfishcode:sunfishcode/std-os-fd-stable-version, ↵Matthias Krüger-3/+3
r=m-ou-se Fix the stability attributes for `std::os::fd`. As `@bjorn3` pointed out [here], I used the wrong stability attribute in #98368 when making `std::os::fd` public. I set it to Rust 1.63, which was when io-safety was stabilized, but it should be Rust 1.66, which was when `std::os::fd` was stabilized. [here]: https://github.com/rust-lang/rust/pull/98368#discussion_r1063721420
2023-01-14Mention the lack of `windows_mut` in `windows`Scott McMurray-0/+16
2023-01-14Document guarantees about BinaryHeap invariantDavid Tolnay-1/+9
2023-01-14Leak amplification for peek_mut() to ensure BinaryHeap's invariant is always metDavid Tolnay-9/+46
2023-01-14Add test of leaking a binary_heap PeekMutDavid Tolnay-0/+20
2023-01-14doc: fix typoTrevor Spiteri-1/+1
2023-01-14Fix the stability attributes for `std::os::fd`.Dan Gohman-3/+3
As @bjorn3 pointed out [here], I used the wrong stability attribute in #98368 when making `std::os::fd` public. I set it to Rust 1.63, which was when io-safety was stabilized, but it should be Rust 1.66, which was when `std::os::fd` was stabilized. [here]: https://github.com/rust-lang/rust/pull/98368#discussion_r1063721420
2023-01-14Rollup merge of #106860 - anden3:doc-double-spaces, r=Dylan-DPCMatthias Krüger-71/+71
Remove various double spaces in the libraries. I was just pretty bothered by this when reading the source for a function, and was suggested to check if this happened elsewhere.
2023-01-14Rollup merge of #106661 - mjguzik:linux_statx, r=Mark-SimulacrumMatthias Krüger-27/+41
Stop probing for statx unless necessary As is the current toy program: fn main() -> std::io::Result<()> { use std::fs; let metadata = fs::metadata("foo.txt")?; assert!(!metadata.is_dir()); Ok(()) } ... observed under strace will issue: [snip] statx(0, NULL, AT_STATX_SYNC_AS_STAT, STATX_ALL, NULL) = -1 EFAULT (Bad address) statx(AT_FDCWD, "foo.txt", AT_STATX_SYNC_AS_STAT, STATX_ALL, {stx_mask=STATX_ALL|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0644, stx_size=0, ...}) = 0 While statx is not necessarily always present, checking for it can be delayed to the first error condition. Said condition may very well never happen, in which case the check got avoided altogether. Note this is still suboptimal as there still will be programs issuing it, but bulk of the problem is removed. Tested by forbidding the syscall for the binary and observing it correctly falls back to newfstatat. While here tidy up the commentary, in particular by denoting some problems with the current approach.
2023-01-14Rollup merge of #105526 - Xiretza:iter-from-generator-derive, r=scottmcmMatthias Krüger-4/+19
libcore: make result of iter::from_generator Clone `@rustbot` label +A-generators
2023-01-14Fix some missed double spaces.André Vennberg-5/+5
2023-01-14Remove various double spaces in source comments.André Vennberg-66/+66
2023-01-14fix issues in unused lintyukang-4/+4
2023-01-14Rollup merge of #106799 - scottmcm:remove-unused-generics, r=cuviperYuki Okushi-29/+29
Stop having unused lifetimes on some `impl`s See <https://doc.rust-lang.org/nightly/std/cmp/trait.PartialOrd.html#impl-PartialOrd%3COsStr%3E-for-PathBuf>, where these lifetimes show up even though they're not needed: ![image](https://user-images.githubusercontent.com/18526288/212257802-da275167-38f9-4e2c-aafc-d44f0fc6a7c6.png) With this PR, the unneeded lifetimes are no longer there: ![image](https://user-images.githubusercontent.com/18526288/212257938-0097c4bf-1247-4c91-8445-5bf0dde1b501.png)
2023-01-14Rollup merge of #106762 - WaffleLapkin:atomicptr+as_mut_ptr, r=m-ou-seYuki Okushi-2/+38
Add `AtomicPtr::as_mut_ptr` See https://github.com/rust-lang/rust/issues/66893#issuecomment-720125447 r? thomcc
2023-01-14Rollup merge of #106692 - eggyal:mv-binary_heap.rs-binary_heap/mod.rs, ↵Yuki Okushi-0/+0
r=Mark-Simulacrum mv binary_heap.rs binary_heap/mod.rs I confess this request is somewhat selfish, as it's made in order to ease synchronisation with my [copse](https://crates.io/crates/copse) crate (see eggyal/copse#6 for explanation). I wholly understand that such grounds may be insufficient to justify merging this request—but no harm in asking, right?