about summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2023-03-20Rollup merge of #109337 - frengor:collect_into_doc, r=scottmcmMatthias Krüger-4/+4
Improve `Iterator::collect_into` documentation This improves the examples in the documentation of `Iterator::collect_into`, replacing the usages of `println!` with `assert_eq!` as suggested on [IRLO](https://internals.rust-lang.org/t/18534/9).
2023-03-19Add `#![feature(generic_arg_infer)]` to core for stdarchNilstrieb-0/+1
2023-03-19Add #[inline] to as_derefBen Kimock-0/+4
2023-03-19Fix wrong crate name in custom MIR docsNilstrieb-1/+1
2023-03-19Rollup merge of #108973 - est31:pin_docs, r=Mark-SimulacrumDylan DPC-16/+19
Beautify pin! docs This makes pin docs a little bit less jargon-y and easier to read, by * splitting up the sentences * making them less interrupted by punctuation * turning the footnotes into paragraphs, as they contain useful information that shouldn't be hidden in footnotes. Footnotes also interrupt the read flow.
2023-03-19Rollup merge of #108829 - xfix:use-edition-2021-pat-in-matches, ↵Dylan DPC-2/+2
r=Mark-Simulacrum Use Edition 2021 :pat in matches macro This makes the macro syntax used in documentation more readable.
2023-03-19Rollup merge of #104100 - ink-feather-org:const_iter_range, r=the8472,fee1-deadDylan DPC-16/+45
Allow using `Range` as an `Iterator` in const contexts. ~~based on #102225 by `@fee1-dead~~`
2023-03-19Improve collect_into documentationfren_gor-4/+4
2023-03-18Rollup merge of #109287 - scottmcm:hash-slice-size-of-val, r=oli-obkMatthias Krüger-1/+1
Use `size_of_val` instead of manual calculation Very minor thing that I happened to notice in passing, but it's both shorter and [means it gets `mul nsw`](https://rust.godbolt.org/z/Y9KxYETv5), so why not.
2023-03-18Mark DoubleEndedIterator as #[const_trait] using rustc_do_not_const_check, ↵onestacked-9/+28
implement const Iterator and DoubleEndedIterator for Range.
2023-03-18move Option::as_slice to intrinsicAndre Bogus-72/+42
2023-03-17Use `size_of_val` instead of manual calculationScott McMurray-1/+1
Very minor thing that I happened to notice in passing, but it's both shorter and means it gets `mul nuw`, so why not.
2023-03-17Make the `Step` implementations const.onestacked-7/+17
2023-03-17Auto merge of #108862 - Mark-Simulacrum:bootstrap-bump, r=pietroalbinibors-71/+47
Bump bootstrap compiler to 1.69 beta r? `@pietroalbini`
2023-03-17Switch impls of `is_sorted_by` between slices and slice itersMaybe Waffle-2/+2
This makes a bit more sense — iter impl converts to slice first, while slice impl used to create iter, doing unnecessary conversions.
2023-03-17Make `slice::is_sorted_by` impl nicerMaybe Waffle-3/+1
2023-03-16Improve case mapping encoding schemeMartin Gammelsæter-1045/+779
The indices are encoded as `u32`s in the range of invalid `char`s, so that we know that if any mapping fails to parse as a `char` we should use the value for lookup in the multi-table. This avoids the second binary search in cases where a multi-`char` mapping is needed. Idea from @nikic
2023-03-16Beautify pin! docsest31-16/+19
This makes pin docs a little bit less jargon-y and easier to read, by * splitting up the sentences * making them less interrupted by punctuation * turning the footnotes into paragraphs, as they contain useful information that shouldn't be hidden in footnotes. Footnotes also interrupt the read flow. * other improvements and simplifications
2023-03-16Auto merge of #106824 - m-ou-se:format-args-flatten, r=oli-obkbors-4/+26
Flatten/inline format_args!() and (string and int) literal arguments into format_args!() Implements https://github.com/rust-lang/rust/issues/78356 Gated behind `-Zflatten-format-args=yes`. Part of #99012 This change inlines string literals, integer literals and nested format_args!() into format_args!() during ast lowering, making all of the following pairs result in equivalent hir: ```rust println!("Hello, {}!", "World"); println!("Hello, World!"); ``` ```rust println!("[info] {}", format_args!("error")); println!("[info] error"); ``` ```rust println!("[{}] {}", status, format_args!("error: {}", msg)); println!("[{}] error: {}", status, msg); ``` ```rust println!("{} + {} = {}", 1, 2, 1 + 2); println!("1 + 2 = {}", 1 + 2); ``` And so on. This is useful for macros. E.g. a `log::info!()` macro could just pass the tokens from the user directly into a `format_args!()` that gets efficiently flattened/inlined into a `format_args!("info: {}")`. It also means that `dbg!(x)` will have its file, line, and expression name inlined: ```rust eprintln!("[{}:{}] {} = {:#?}", file!(), line!(), stringify!(x), x); // before eprintln!("[example.rs:1] x = {:#?}", x); // after ``` Which can be nice in some cases, but also means a lot more unique static strings than before if dbg!() is used a lot.
2023-03-16Split unicode case LUTs in single and multi variantsMartin Gammelsæter-1682/+963
The majority of char case replacements are single char replacements, so storing them as [char; 3] wastes a lot of space. This commit splits the replacement tables for both `to_lower` and `to_upper` into two separate tables, one with single-character mappings and one with multi-character mappings. This reduces the binary size for programs using all of these tables with roughly 24K bytes.
2023-03-16Don't allow new const panic through format flattening.Mara Bos-4/+26
panic!("a {}", "b") is still not allowed in const, even if the hir flattens to panic!("a b").
2023-03-15unequal → not equalgimbles-3/+3
2023-03-15Skip serializing ascii chars in case LUTsMartin Gammelsæter-26/+0
Since ascii chars are already handled by a special case in the `to_lower` and `to_upper` functions, there's no need to waste space on them in the LUTs.
2023-03-15Bump to latest betaMark Rousskov-53/+29
2023-03-15Bump version placeholdersMark Rousskov-18/+18
2023-03-15Auto merge of #109035 - scottmcm:ptr-read-should-know-undef, ↵bors-14/+55
r=WaffleLapkin,JakobDegen Ensure `ptr::read` gets all the same LLVM `load` metadata that dereferencing does I was looking into `array::IntoIter` optimization, and noticed that it wasn't annotating the loads with `noundef` for simple things like `array::IntoIter<i32, N>`. Trying to narrow it down, it seems that was because `MaybeUninit::assume_init_read` isn't marking the load as initialized (<https://rust.godbolt.org/z/Mxd8TPTnv>), which is unfortunate since that's basically its reason to exist. The root cause is that `ptr::read` is currently implemented via the *untyped* `copy_nonoverlapping`, and thus the `load` doesn't get any type-aware metadata: no `noundef`, no `!range`. This PR solves that by lowering `ptr::read(p)` to `copy *p` in MIR, for which the backends already do the right thing. Fortuitiously, this also improves the IR we give to LLVM for things like `mem::replace`, and fixes a couple of long-standing bugs where `ptr::read` on `Copy` types was worse than `*`ing them. Zulip conversation: <https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Move.20array.3A.3AIntoIter.20to.20ManuallyDrop/near/341189936> cc `@erikdesjardins` `@JakobDegen` `@workingjubilee` `@the8472` Fixes #106369 Fixes #73258
2023-03-14Improved implementation and comments after code review feedbackScott McMurray-12/+10
2023-03-14Auto merge of #104833 - Swatinem:async-identity-future, r=compiler-errorsbors-5/+1
Remove `identity_future` indirection This was previously needed because the indirection used to hide some unexplained lifetime errors, which it turned out were related to the `min_choice` algorithm. Removing the indirection also solves a couple of cycle errors, large moves and makes async blocks support the `#[track_caller]`annotation. Fixes https://github.com/rust-lang/rust/issues/104826.
2023-03-13Rollup merge of #108419 - tgross35:atomic-as-ptr, r=m-ou-seMatthias Krüger-6/+7
Stabilize `atomic_as_ptr` Fixes #66893 This stabilizes the `as_ptr` methods for atomics. The stabilization feature gate used here is `atomic_as_ptr` which supersedes `atomic_mut_ptr` to match the change in https://github.com/rust-lang/rust/pull/107736. This needs FCP. New stable API: ```rust impl AtomicBool { pub const fn as_ptr(&self) -> *mut bool; } impl AtomicI32 { pub const fn as_ptr(&self) -> *mut i32; } // Includes all other atomic types impl<T> AtomicPtr<T> { pub const fn as_ptr(&self) -> *mut *mut T; } ``` r? libs-api ``@rustbot`` label +needs-fcp
2023-03-13add `#[doc(alias="flatmap")]` to `Option::and_then`Dante Broggi-0/+1
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-03-13Auto merge of #108623 - scottmcm:try-different-as-slice-impl, r=the8472bors-37/+83
Move `Option::as_slice` to an always-sound implementation This approach depends on CSE to not have any branches or selects when the guessed offset is correct -- which it always will be right now -- but to also be *sound* (just less efficient) if the layout algorithms change such that the guess is incorrect. The codegen test confirms that CSE handles this as expected, leaving the optimal codegen. cc JakobDegen #108545
2023-03-13Clarify stability guarantee for lifetimes in enum discriminantsMichael Krasnitski-0/+5
2023-03-12Clarify the text of some commentsScott McMurray-1/+5
2023-03-12Add a better approach comment in `ptr::read` to justify the intrinsicScott McMurray-11/+32
2023-03-11Move `Option::as_slice` to an always-sound implementationScott McMurray-37/+79
This approach depends on CSE to not have any branches or selects when the guessed offset is correct -- which it always will be right now -- but to also be *sound* (just less efficient) if the layout algorithms change such that the guess is incorrect.
2023-03-11`MaybeUninit::assume_init_read` should have `noundef` load metadataScott McMurray-6/+28
I was looking into `array::IntoIter` optimization, and noticed that it wasn't annotating the loads with `noundef` for simple things like `array::IntoIter<i32, N>`. Turned out to be a more general problem as `MaybeUninit::assume_init_read` isn't marking the load as initialized (<https://rust.godbolt.org/z/Mxd8TPTnv>), which is unfortunate since that's basically its reason to exist. This PR lowers `ptr::read(p)` to `copy *p` in MIR, which fortuitiously also improves the IR we give to LLVM for things like `mem::replace`.
2023-03-11Rollup merge of #106633 - c410-f3r:stabilize-nonzero_bits, r=dtolnayMatthias Krüger-12/+4
Stabilize `nonzero_min_max` ## Overall Stabilizes `nonzero_min_max` to allow the "infallible" construction of ordinary minimum and maximum `NonZero*` instances. The feature is fairly straightforward and already matured for some time in stable toolchains. ```rust let _ = NonZeroU8::MIN; let _ = NonZeroI32::MAX; ``` ## History * On 2022-01-25, implementation was [created](https://github.com/rust-lang/rust/pull/93293). ## Considerations * This report is fruit of the inanition observed after two unsuccessful attempts at getting feedback. * Other constant variants discussed at https://github.com/rust-lang/rust/issues/89065#issuecomment-923238190 are orthogonal to this feature. Fixes https://github.com/rust-lang/rust/issues/89065
2023-03-10improve doc test for UnsafeCell::raw_get and fix docs errorgftea-1/+3
2023-03-10Rollup merge of #106921 - madsmtm:cell-memory-layout, r=dtolnayMatthias Krüger-0/+6
Add documentation about the memory layout of `Cell` https://github.com/rust-lang/rust/pull/101717 guaranteed the memory layout of `UnsafeCell<T>`. This property (a guaranteed memory layout) can be useful to have on `Cell<T>` as well. (Note that `Cell<u8>` [already doesn't trigger the `improper_ctypes` lint](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=34af59ef60b96d8a8bdaec1d52cb5420) since it is `#[repr(transparent)]`). The concrete use-case is for the crate [`objc2`](https://github.com/madsmtm/objc2) to specify that `Cell<T>` is safe to use as an instance variable when `T` is. Fixes https://github.com/rust-lang/rust/issues/79303. --- I'm unsure if we should specify less, for example say that the `Cell` may have extra restrictions on when it may be accessed, or if that's implicit in the (deliberately minimal) way I've worded it here?
2023-03-10Rollup merge of #108964 - majaha:ptr_metadata_doc, r=workingjubileeMatthias Krüger-4/+4
Fix the docs for pointer method with_metadata_of The name of the argument to `{*const T, *mut T}::with_metadata_of` was changed from `val` to `meta` recently, but the docs weren't updated to match. Relevant pull request: #103701
2023-03-10Rollup merge of #108956 - Raekye:master, r=scottmcmMatthias Krüger-2/+2
Make ptr::from_ref and ptr::from_mut in #106116 const. As per https://github.com/rust-lang/rust/issues/106116#issuecomment-1462571833
2023-03-10Fix docs for ptr method with_metadata_of()Matt Harding-4/+4
2023-03-09Make ptr::from_ref and ptr::from_mut in #106116 const.Raekye-2/+2
2023-03-09Add examples section which demonstrates the behaviour (specifically the sign ↵bmoxb-0/+20
positive aspect)
2023-03-09Add missing comment for f64bmoxb-1/+2
2023-03-09Indicate that `0.0` refers to positive `0.0`bmoxb-2/+2
2023-03-09Document the resulting values produced when using `From<bool>` on floatsbmoxb-1/+2
2023-03-09Auto merge of #108920 - matthiaskrgr:rollup-qrr9a0u, r=matthiaskrgrbors-2/+1
Rollup of 8 pull requests Successful merges: - #108754 (Retry `pred_known_to_hold_modulo_regions` with fulfillment if ambiguous) - #108759 (1.41.1 supported 32-bit Apple targets) - #108839 (Canonicalize root var when making response from new solver) - #108856 (Remove DropAndReplace terminator) - #108882 (Tweak E0740) - #108898 (Set `LIBC_CHECK_CFG=1` when building Rust code in bootstrap) - #108911 (Improve rustdoc-gui/tester.js code a bit) - #108916 (Remove an unused return value in `rustc_hir_typeck`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2023-03-08panic_immediate_abort requires abort as a panic strategyTomasz Miąsko-0/+3
Guide `panic_immediate_abort` users away from `-Cpanic=unwind` and towards `-Cpanic=abort` to avoid an accidental use of the feature with the unwind strategy, e.g., on a targets where unwind is the default. The `-Cpanic=unwind` combination doesn't offer the same benefits, since the code would still be generated under the assumption that functions implemented in Rust can unwind.
2023-03-08Rollup merge of #108856 - Zeegomo:remove-drop-and-rep, r=tmiaskoMatthias Krüger-2/+1
Remove DropAndReplace terminator #107844 made DropAndReplace unused, let's remove it completely from the codebase.