about summary refs log tree commit diff
path: root/library/core
AgeCommit message (Collapse)AuthorLines
2023-03-25Correct typo (`back_box` -> `black_box`)Evie M-1/+1
2023-03-25Auto merge of #99929 - the8472:default-iters, r=scottmcmbors-0/+125
Implement Default for some alloc/core iterators Add `Default` impls to the following collection iterators: * slice::{Iter, IterMut} * binary_heap::IntoIter * btree::map::{Iter, IterMut, Keys, Values, Range, IntoIter, IntoKeys, IntoValues} * btree::set::{Iter, IntoIter, Range} * linked_list::IntoIter * vec::IntoIter and these adapters: * adapters::{Chain, Cloned, Copied, Rev, Enumerate, Flatten, Fuse, Rev} For iterators which are generic over allocators it only implements it for the global allocator because we can't conjure an allocator from nothing or would have to turn the allocator field into an `Option` just for this change. These changes will be insta-stable. ACP: https://github.com/rust-lang/libs-team/issues/77
2023-03-25Auto merge of #109546 - saethlin:inline-into, r=scottmcmbors-0/+1
Add #[inline] to the Into for From impl I was skimming through the standard library MIR and I noticed a handful of very suspicious `Into::into` calls in `alloc`. ~Since this is a trivial wrapper function, `#[inline(always)]` seems appropriate.;~ `#[inline]` works too and is a lot less spooky. r? `@thomcc`
2023-03-24Add #[inline] to the Into for From implBen Kimock-0/+1
2023-03-24Auto merge of #109216 - martingms:unicode-case-lut-shrink, r=Mark-Simulacrumbors-1794/+783
Shrink unicode case-mapping LUTs by 24k I was looking into the binary bloat of a small program using `str::to_lowercase` and `str::to_uppercase`, and noticed that the lookup tables used for case mapping had a lot of zero-bytes in them. The reason for this is that since some characters map to up to three other characters when lower or uppercased, the LUTs store a `[char; 3]` for each character. However, the vast majority of cases only map to a single new character, in other words most of the entries are e.g. `(lowerc, [upperc, '\0', '\0'])`. This PR introduces a new encoding scheme for these tables. The changes reduces the size of my test binary by about 24K. I've also done some `#[bench]`marks on unicode-heavy test data, and found that the performance of both `str::to_lowercase` and `str::to_uppercase` improves by up to 20%. These measurements are obviously very dependent on the character distribution of the data. Someone else will have to decide whether this more complex scheme is worth it or not, I was just goofing around a bit and here's what came out of it :man_shrugging: No hard feelings if this isn't wanted!
2023-03-24Rollup merge of #108924 - tmiasko:panic-immediate-abort, r=thomccMatthias Krüger-0/+3
panic_immediate_abort requires abort as a panic strategy 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-23A MIR transform that checks pointers are alignedBen Kimock-0/+14
2023-03-23Auto merge of #108442 - scottmcm:mir-transmute, r=oli-obkbors-0/+8
Add `CastKind::Transmute` to MIR ~~Nothing actually produces it in this commit, so I don't know how to test it, but it also means it shouldn't be possible for it to break anything.~~ Includes lowering `transmute` calls to it, so it's used. Zulip Conversation: <https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/Good.20first.20isssue/near/321849610>
2023-03-23Auto merge of #109503 - matthiaskrgr:rollup-cnp7kdd, r=matthiaskrgrbors-0/+1
Rollup of 9 pull requests Successful merges: - #108954 (rustdoc: handle generics better when matching notable traits) - #109203 (refactor/feat: refactor identifier parsing a bit) - #109213 (Eagerly intern and check CrateNum/StableCrateId collisions) - #109358 (rustc: Remove unused `Session` argument from some attribute functions) - #109359 (Update stdarch) - #109378 (Remove Ty::is_region_ptr) - #109423 (Use region-erased self type during IAT selection) - #109447 (new solver cleanup + implement coherence) - #109501 (make link clickable) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2023-03-22Add `CastKind::Transmute` to MIRScott McMurray-0/+8
Updates `interpret`, `codegen_ssa`, and `codegen_cranelift` to consume the new cast instead of the intrinsic. Includes `CastTransmute` for custom MIR building, to be able to test the extra UB.
2023-03-22Rollup merge of #109359 - Nilstrieb:bump-stdarch, r=AmanieuMatthias Krüger-0/+1
Update stdarch Bring the the `#![allow(internal_features)]` for #108955 r? `@Amanieu`
2023-03-22Auto merge of #109497 - matthiaskrgr:rollup-6txuxm0, r=matthiaskrgrbors-1/+16
Rollup of 10 pull requests Successful merges: - #109373 (Set LLVM `LLVM_UNREACHABLE_OPTIMIZE` to `OFF`) - #109392 (Custom MIR: Allow optional RET type annotation) - #109394 (adapt tests/codegen/vec-shrink-panik for LLVM 17) - #109412 (rustdoc: Add GUI test for "Auto-hide item contents for large items" setting) - #109452 (Ignore the vendor directory for tidy tests.) - #109457 (Remove comment about reusing rib allocations) - #109461 (rustdoc: remove redundant `.content` prefix from span/a colors) - #109477 (`HirId` to `LocalDefId` cleanup) - #109489 (More general captures) - #109494 (Do not feed param_env for RPITITs impl side) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2023-03-22Rollup merge of #109392 - cbeuw:composite-ret, r=JakobDegenMatthias Krüger-1/+16
Custom MIR: Allow optional RET type annotation This currently doesn't compile because the type of `RET` is inferred, which fails if RET is a composite type and fields are initialised separately. ```rust #![feature(custom_mir, core_intrinsics)] extern crate core; use core::intrinsics::mir::*; #[custom_mir(dialect = "runtime", phase = "optimized")] fn fn0() -> (i32, bool) { mir! ({ RET.0 = 0; RET.1 = true; Return() }) } ``` ``` error[E0282]: type annotations needed --> src/lib.rs:8:9 | 8 | RET.0 = 0; | ^^^ cannot infer type For more information about this error, try `rustc --explain E0282`. ``` This PR allows the user to manually specify the return type with `type RET = ...;` if required: ```rust #[custom_mir(dialect = "runtime", phase = "optimized")] fn fn0() -> (i32, bool) { mir! ( type RET = (i32, bool); { RET.0 = 0; RET.1 = true; Return() } ) } ``` The syntax is not optimal, I'm happy to see other suggestions. Ideally I wanted it to be a normal type annotation like `let RET: ...;`, but this runs into the multiple parsing options error during macro expansion, as it can be parsed as a normal `let` declaration as well. r? ```@oli-obk``` or ```@tmiasko``` or ```@JakobDegen```
2023-03-23Rollup merge of #109179 - llogiq:intrinsically-option-as-slice, r=eholkDylan DPC-72/+42
move Option::as_slice to intrinsic ````@scottmcm```` suggested on #109095 I use a direct approach of unpacking the operation in MIR lowering, so here's the implementation. cc ````@nikic```` as this should hopefully unblock #107224 (though perhaps other changes to the prior implementation, which I left for bootstrapping, are needed).
2023-03-23Rollup merge of #100311 - xfix:lines-fix-handling-of-bare-cr, r=ChrisDentonDylan DPC-7/+7
Fix handling of trailing bare CR in str::lines Continuing from #91191. Fixes #94435.
2023-03-21Rollup merge of #106434 - clubby789:document-sum-result, r=the8472nils-4/+42
Document `Iterator::sum/product` for Option/Result Closes #105266 We already document the similar behavior for `collect()` so I believe it makes sense to add this too. The Option/Result implementations *are* documented on their respective pages and the page for `Sum`, but buried amongst many other trait impls which doesn't make it very discoverable. `````@rustbot````` label +A-docs
2023-03-21Use hex literal for INDEX_MASKMartin Gammelsæter-1/+1
2023-03-21Auto merge of #108717 - TDecki:dec2flt-inline, r=thomccbors-1/+18
Add inlining annotations in `dec2flt`. Currently, the combination of `dec2flt` being generic and the `FromStr` implementaions containing inline anttributes causes massive amounts of assembly to be generated whenever these implementation are used. In addition, the assembly has calls to function which ought to be inlined, but they are not (even when using lto). This Pr fixes this.
2023-03-20Add example for `Option::product` and `Result::product`clubby789-4/+36
2023-03-20Add documentation for `type RET = ...`Andy Wang-0/+14
2023-03-20Allow optional RET type annotationAndy Wang-1/+2
2023-03-20Rollup merge of #109273 - WaffleLapkin:slice_is_sorted_by_array_windows, ↵Matthias Krüger-4/+2
r=scottmcm Make `slice::is_sorted_by` implementation nicer Just tweak implementation a little :) r? `@thomcc`
2023-03-20Rollup merge of #109353 - Nilstrieb:rustc-mir-building, r=compiler-errorsMatthias Krüger-1/+1
Fix wrong crate name in custom MIR docs
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/+86
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/+69
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-8/+30
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-16Update format_args!() test to account for inlining.Mara Bos-4/+4
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