about summary refs log tree commit diff
path: root/library/core
AgeCommit message (Collapse)AuthorLines
2023-04-09Auto merge of #110101 - JohnTitor:rollup-ol20aw7, r=JohnTitorbors-0/+1
Rollup of 6 pull requests Successful merges: - #110058 (Remove `box_syntax` usage) - #110059 (ignore_git → omit_git_hash) - #110060 (Document that `&T` and `&mut T` are `Sync` if `T` is) - #110074 (Make the "codegen" profile of `config.toml` download and build llvm from source.) - #110086 (Add `max_line_length` to `.editorconfig`, matching rustfmt) - #110096 (Tweak tuple indexing suggestion) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2023-04-09Rollup merge of #110060 - WaffleLapkin:sync_refs, r=jyn514Yuki Okushi-0/+1
Document that `&T` and `&mut T` are `Sync` if `T` is Proof: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=fec8dc9ec36e873bf2962a2367d67045
2023-04-08Enforce that PointerLike requires a pointer-like ABIMichael Goulet-1/+1
2023-04-08Revert "Make the `Step` implementations const."Deadbeef-17/+7
This reverts commit 7bc67ef6e02d69023c6fb04c2258beab54ac22b8.
2023-04-08Revert "Mark DoubleEndedIterator as #[const_trait] using ↵Deadbeef-69/+9
rustc_do_not_const_check, implement const Iterator and DoubleEndedIterator for Range." This reverts commit 8a9d6bf4fd540b2a2882193cbd6232b86e5dcd7e.
2023-04-07The `wrapping_neg` example for unsigned types shouldn't use `i8`Scott McMurray-5/+4
2023-04-07Fix wrong type in docs: i16 -> u16Jörn Bethune-1/+1
@rustbot label +A-docs r? docs
2023-04-07Document that `&T` and `&mut T` are `Sync` if `T` isMaybe Waffle-0/+1
2023-04-07Avoid some manual slice length calculationScott McMurray-12/+4
No need for us to write the multiplication when `size_of_val` does exactly what we need.
2023-04-07Inline try_from and try_intoTomasz Miąsko-0/+2
To avoid link time dependency between core and compiler-builtins, when using opt-level that implicitly enables -Zshare-generics. While compiler-builtins should be compiled with -Zshare-generics disabled, the -Zbuild-std does not ensure this at the moment.
2023-04-06Stabilize is_some_andJonas Platte-8/+3
2023-04-05Refactor core::char::EscapeDefault and co. structuresMichal Nazarewicz-206/+271
Change core::char::{EscapeUnicode, EscapeDefault and EscapeDebug} structures from using a state machine to computing escaped sequence upfront and during iteration just going through the characters. This is arguably simpler since it’s easier to think about having a buffer and start..end range to iterate over rather than thinking about a state machine. This also harmonises implementation of aforementioned iterators and core::ascii::EscapeDefault struct. This is done by introducing a new helper EscapeIterInner struct which holds the buffer and offers simple methods for iterating over range. As a side effect, this probably optimises Display implementation for those types since rather than calling write_char repeatedly, write_str is invoked once. On 64-bit platforms, it also reduces size of some of the structs: | Struct | Before | After | |----------------------------+--------+-------+ | core::char::EscapeUnicode | 16 | 12 | | core::char::EscapeDefault | 16 | 12 | | core::char::EscapeDebug | 16 | 16 | My ulterior motive and reason why I started looking into this is addition of as_str method to the iterators. With this change this will became trivial. It’s also going to be trivial to implement DoubleEndedIterator if that’s ever desired.
2023-04-05Auto merge of #94786 - joshlf:patch-5, r=dtolnaybors-0/+7
Document NonZeroXxx layout guarantees Document that `NonZeroXxx` has the same layout and bit validity as `Xxx` with the exception of `0`.
2023-04-04Add links from `core::cmp` derives to their traitsclubby789-4/+7
2023-04-03Add links to <cell.rs>Sergey Kaunov-1/+1
`UnsafeCell` page could benefit too from having links to these most popular structs in the module.
2023-04-02Rollup merge of #109839 - sartak:iter-grammar, r=scottmcmNilstrieb-2/+2
Improve grammar of Iterator.partition_in_place This is my first PR against Rust, please let me know if there's anything I should be providing here! I didn't find any instructions specific to documentation grammar in the [std-dev guide](https://std-dev-guide.rust-lang.org/documentation/summary.html).
2023-04-01Auto merge of #109483 - joboet:optimize_lazycell, r=Mark-Simulacrumbors-11/+77
Optimize `LazyCell` size `LazyCell` can only store either the initializing function or the data it produces, so it does not need to reserve the space for both. Similar to #107329, but uses an `enum` instead of a `union`.
2023-04-01Improve grammar of Iterator.partition_in_placeShawn M Moore-2/+2
b9535c0b7d6 Auto merge of #109801 - aliemjay:test-implied-normalization, r=petrochenkov
2023-03-31Rollup merge of #109443 - GuillaumeGomez:doc-primitive-hard-error, r=notriddleGuillaume Gomez-25/+50
Move `doc(primitive)` future incompat warning to `invalid_doc_attributes` Fixes #88070. It's been a while since this was turned into a "future incompatible lint" so I think we can now turn it into a hard error without problem. r? `@jyn514`
2023-03-31Auto merge of #98112 - saethlin:mir-alignment-checks, r=oli-obkbors-0/+14
Insert alignment checks for pointer dereferences when debug assertions are enabled Closes https://github.com/rust-lang/rust/issues/54915 - [x] Jake tells me this sounds like a place to use `MirPatch`, but I can't figure out how to insert a new basic block with a new terminator in the middle of an existing basic block, using `MirPatch`. (if nobody else backs up this point I'm checking this as "not actually a good idea" because the code looks pretty clean to me after rearranging it a bit) - [x] Using `CastKind::PointerExposeAddress` is definitely wrong, we don't want to expose. Calling a function to get the pointer address seems quite excessive. ~I'll see if I can add a new `CastKind`.~ `CastKind::Transmute` to the rescue! - [x] Implement a more helpful panic message like slice bounds checking. r? `@oli-obk`
2023-03-30Replace doc(primitive) with rustc_doc_primitiveGuillaume Gomez-25/+50
2023-03-30add comment to `impl !Error for &str`Lukas Markeffsky-0/+1
2023-03-30fix typo and adjust commentjoboet-2/+2
Co-authored-by: Ralf Jung <post@ralfj.de>
2023-03-30core: use `pointer::write` to cleanup `LazyCell` initializationjoboet-8/+7
2023-03-30core: improve code documentation for `LazyCell`joboet-5/+24
2023-03-30core: optimize `LazyCell` sizejoboet-11/+59
2023-03-30Auto merge of #109769 - JohnTitor:rollup-7n2bnpg, r=JohnTitorbors-10/+10
Rollup of 7 pull requests Successful merges: - #106985 (Enhanced doucmentation of binary search methods for `slice` and `VecDeque` for unsorted instances) - #109509 (compiletest: Don't allow tests with overlapping prefix names) - #109719 (RELEASES: Add "Only support Android NDK 25 or newer" to 1.68.0) - #109748 (Don't ICE on `DiscriminantKind` projection in new solver) - #109749 (Canonicalize float var as float in new solver) - #109761 (Drop binutils on powerpc-unknown-freebsd) - #109766 (Fix title for openharmony.md) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2023-03-30Rollup merge of #106985 - jofas:106746-fix, r=ChrisDentonYuki Okushi-10/+10
Enhanced doucmentation of binary search methods for `slice` and `VecDeque` for unsorted instances Fixes #106746. Issue #106746 raises the concern that the binary search methods for slices and deques aren't explicit enough about the fact that they are only applicable to sorted slices/deques. I changed the explanation for these methods. I took the relatively harsh description of the behaviour of binary search on unsorted collections ("unspecified and meaningless") from the description of the [`partition_point`](https://doc.rust-lang.org/std/primitive.slice.html#method.partition_point) method: > If this slice is not partitioned, the returned result is unspecified and meaningless, as this method performs a kind of binary search.
2023-03-30removed deprecated markdown links from documentationjofas-3/+0
2023-03-29Em dashes are cooler than hyphens.Mara Bos-1/+1
2023-03-29Documentation updates to better share the purpose of OnceCell/OnceLockTrevor Gross-27/+72
2023-03-29Stabilize a portion of 'once_cell'Trevor Gross-39/+31
Move items not part of this stabilization to 'lazy_cell' or 'once_cell_try'
2023-03-29enhanced documentation of binary search methods for slice and VecDeque for ↵jofas-7/+10
unsorted instances
2023-03-28Auto merge of #108095 - soc:drop-contains, r=Amanieubors-93/+0
Drop unstable `Option::contains`, `Result::contains`, `Result::contains_err` This is a proposal to drop the three functions `Option::contains`, `Result::contains` and `Result::contains_err`. The discovery of `Option::is_some_with`/`Result::is_ok_with`/`Result::is_err_with` in https://github.com/rust-lang/rust/pull/93051 obviates the need for these methods (non-stabilization tracked in https://github.com/rust-lang/rust/issues/62358). An additional benefit of change is that it avoids spurious error messages in IDEs, when `contains` is supplied by a third-party library: ![option-result-unstable](https://user-images.githubusercontent.com/42493/219127961-13cb559e-6ee8-4449-8dc9-d28d07270ad5.png)
2023-03-28Auto merge of #109692 - Nilstrieb:rollup-hq65rps, r=Nilstriebbors-263/+292
Rollup of 8 pull requests Successful merges: - #91793 (socket ancillary data implementation for FreeBSD (from 13 and above).) - #92284 (Change advance(_back)_by to return the remainder instead of the number of processed elements) - #102472 (stop special-casing `'static` in evaluation) - #108480 (Use Rayon's TLV directly) - #109321 (Erase impl regions when checking for impossible to eagerly monomorphize items) - #109470 (Correctly substitute GAT's type used in `normalize_param_env` in `check_type_bounds`) - #109562 (Update ar_archive_writer to 0.1.3) - #109629 (remove obsolete `givens` from regionck) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2023-03-28Auto merge of #108080 - oli-obk:FnPtr-trait, r=lcnrbors-106/+176
Add a builtin `FnPtr` trait that is implemented for all function pointers r? `@ghost` Rebased version of https://github.com/rust-lang/rust/pull/99531 (plus adjustments mentioned in the PR). If perf is happy with this version, I would like to land it, even if the diagnostics fix in 9df8e1befb5031a5bf9d8dfe25170620642d3c59 only works for `FnPtr` specifically, and does not generally improve blanket impls.
2023-03-28Rollup merge of #92284 - the8472:simplify-advance-by, r=scottmcmnils-263/+292
Change advance(_back)_by to return the remainder instead of the number of processed elements When advance_by can't advance the iterator by the number of requested elements it now returns the amount by which it couldn't be advanced instead of the amount by which it did. This simplifies adapters like chain, flatten or cycle because the remainder doesn't have to be calculated as the difference between requested steps and completed steps anymore. Additionally switching from `Result<(), usize>` to `Result<(), NonZeroUsize>` reduces the size of the result and makes converting from/to a usize representing the number of remaining steps cheap.
2023-03-28Rollup merge of #109682 - clubby789:c-str-inline, r=scottmcmMatthias Krüger-0/+5
Add `#[inline]` to CStr trait implementations Fixes #109674 I noticed other usages of traits on `CStr` weren't being inlined, so also added hints to the other implementations
2023-03-28Add `#[inline]` to CStr trait implementationsclubby789-0/+5
2023-03-27Fix ASCII case commentclubby789-1/+1
2023-03-27update documentationThe 8472-8/+10
2023-03-27replace advance_by returning usize with Result<(), NonZeroUsize>The 8472-229/+286
2023-03-27Use the FnPtr trait to avoid implementing common traits via macrosOli Scherer-107/+162
2023-03-27Add a builtin `FnPtr` traitlcnr-0/+15
2023-03-27Change advance(_back)_by to return `usize` instead of `Result<(), usize>`The 8472-300/+270
A successful advance is now signalled by returning `0` and other values now represent the remaining number of steps that couldn't be advanced as opposed to the amount of steps that have been advanced during a partial advance_by. This simplifies adapters a bit, replacing some `match`/`if` with arithmetic. Whether this is beneficial overall depends on whether `advance_by` is mostly used as a building-block for other iterator methods and adapters or whether we also see uses by users where `Result` might be more useful.
2023-03-27Rollup merge of #97506 - JohnTitor:stabilize-nonnull-slice-from-raw-parts, ↵Matthias Krüger-8/+5
r=m-ou-se,the8472 Stabilize `nonnull_slice_from_raw_parts` FCP is done: https://github.com/rust-lang/rust/issues/71941#issuecomment-1100910416 Note that this doesn't const-stabilize `NonNull::slice_from_raw_parts` as `slice_from_raw_parts_mut` isn't const-stabilized yet. Given #67456 and #57349, it's not likely available soon, meanwhile, stabilizing only the feature makes some sense, I think. Closes #71941
2023-03-26Auto merge of #109357 - saethlin:inline-as-deref, r=thomccbors-0/+4
Add #[inline] to as_deref While working on https://github.com/rust-lang/rust/pull/109247 I found an `as_deref` call in the compiler that should have been inlined. This fixes the missing inlining (but doesn't address the perf issues I was chasing). r? `@thomcc`
2023-03-26Merge branch 'master' into Issue-107957-black_box_docspat-nel87-2171/+6686
2023-03-26Rollup merge of #109620 - eievui5:patch-1, r=compiler-errorsMatthias Krüger-1/+1
Correct typo (`back_box` -> `black_box`)
2023-03-26Auto merge of #105096 - LegionMammal978:copied-allocators, r=Amanieubors-3/+3
Clarify that copied allocators must behave the same Currently, the safety documentation for `Allocator` says that a cloned or moved allocator must behave the same as the original. However, it does not specify that a copied allocator must behave the same, and it's possible to construct an allocator that permits being moved or cloned, but sometimes produces a new allocator when copied. <details> <summary>Contrived example which results in a Miri error</summary> ```rust #![feature(allocator_api, once_cell, strict_provenance)] use std::{ alloc::{AllocError, Allocator, Global, Layout}, collections::HashMap, hint, marker::PhantomPinned, num::NonZeroUsize, pin::Pin, ptr::{addr_of, NonNull}, sync::{LazyLock, Mutex}, }; mod source_allocator { use super::*; // `SourceAllocator` has 3 states: // - invalid value: is_cloned == false, source != self.addr() // - source value: is_cloned == false, source == self.addr() // - cloned value: is_cloned == true pub struct SourceAllocator { is_cloned: bool, source: usize, _pin: PhantomPinned, } impl SourceAllocator { // Returns a pinned source value (pointing to itself). pub fn new_source() -> Pin<Box<Self>> { let mut b = Box::new(Self { is_cloned: false, source: 0, _pin: PhantomPinned, }); b.source = b.addr(); Box::into_pin(b) } fn addr(&self) -> usize { addr_of!(*self).addr() } // Invalid values point to source 0. // Source values point to themselves. // Cloned values point to their corresponding source. fn source(&self) -> usize { if self.is_cloned || self.addr() == self.source { self.source } else { 0 } } } // Copying an invalid value produces an invalid value. // Copying a source value produces an invalid value. // Copying a cloned value produces a cloned value with the same source. impl Copy for SourceAllocator {} // Cloning an invalid value produces an invalid value. // Cloning a source value produces a cloned value with that source. // Cloning a cloned value produces a cloned value with the same source. impl Clone for SourceAllocator { fn clone(&self) -> Self { if self.is_cloned || self.addr() != self.source { *self } else { Self { is_cloned: true, source: self.source, _pin: PhantomPinned, } } } } static SOURCE_MAP: LazyLock<Mutex<HashMap<NonZeroUsize, usize>>> = LazyLock::new(Default::default); // SAFETY: Wraps `Global`'s methods with additional tracking. // All invalid values share blocks with each other. // Each source value shares blocks with all cloned values pointing to it. // Cloning an allocator always produces a compatible allocator: // - Cloning an invalid value produces another invalid value. // - Cloning a source value produces a cloned value pointing to it. // - Cloning a cloned value produces another cloned value with the same source. // Moving an allocator always produces a compatible allocator: // - Invalid values remain invalid when moved. // - Source values cannot be moved, since they are always pinned to the heap. // - Cloned values keep the same source when moved. unsafe impl Allocator for SourceAllocator { fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> { let mut map = SOURCE_MAP.lock().unwrap(); let block = Global.allocate(layout)?; let block_addr = block.cast::<u8>().addr(); map.insert(block_addr, self.source()); Ok(block) } unsafe fn deallocate(&self, block: NonNull<u8>, layout: Layout) { let mut map = SOURCE_MAP.lock().unwrap(); let block_addr = block.addr(); // SAFETY: `block` came from an allocator that shares blocks with this allocator. if map.remove(&block_addr) != Some(self.source()) { hint::unreachable_unchecked() } Global.deallocate(block, layout) } } } use source_allocator::SourceAllocator; // SAFETY: `alloc1` and `alloc2` must share blocks. unsafe fn test_same(alloc1: &SourceAllocator, alloc2: &SourceAllocator) { let ptr = alloc1.allocate(Layout::new::<i32>()).unwrap(); alloc2.deallocate(ptr.cast(), Layout::new::<i32>()); } fn main() { let orig = &*SourceAllocator::new_source(); let orig_cloned1 = &orig.clone(); let orig_cloned2 = &orig.clone(); let copied = &{ *orig }; let copied_cloned1 = &copied.clone(); let copied_cloned2 = &copied.clone(); unsafe { test_same(orig, orig_cloned1); test_same(orig_cloned1, orig_cloned2); test_same(copied, copied_cloned1); test_same(copied_cloned1, copied_cloned2); test_same(orig, copied); // error } } ``` </details> This could result in issues in the future for algorithms that specialize on `Copy` types. Right now, nothing in the standard library that depends on `Allocator + Clone` is susceptible to this issue, but I still think it would make sense to specify that copying an allocator is always as valid as cloning it.