about summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2023-05-02Use metavar `${count(x)}` instead of reimplementing itMaybe Waffle-9/+3
2023-05-02implement tuple<->array convertions via `From`Maybe Waffle-0/+40
2023-05-02rm diag item, use lang itemDeadbeef-1/+0
2023-05-02initial step towards implementing C string literalsDeadbeef-0/+1
2023-05-02Rollup merge of #108161 - WaffleLapkin:const_param_ty, r=BoxyUwUDylan DPC-52/+132
Add `ConstParamTy` trait This is a bit sketch, but idk. r? `@BoxyUwU` Yet to be done: - [x] ~~Figure out if it's okay to implement `StructuralEq` for primitives / possibly remove their special casing~~ (it should be okay, but maybe not in this PR...) - [ ] Maybe refactor the code a little bit - [x] Use a macro to make impls a bit nicer Future work: - [ ] Actually™ use the trait when checking if a `const` generic type is allowed - [ ] _Really_ refactor the surrounding code - [ ] Refactor `marker.rs` into multiple modules for each "theme" of markers
2023-05-02Rollup merge of #105076 - mina86:a, r=scottmcmDylan DPC-206/+273
Refactor core::char::EscapeDefault and co. structures 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-05-01Auto merge of #111066 - matthiaskrgr:rollup-4k6rj23, r=matthiaskrgrbors-1/+6
Rollup of 7 pull requests Successful merges: - #109540 (std docs: edit `PathBuf::set_file_name` example) - #110093 (Add 64-bit `time_t` support on 32-bit glibc Linux to `set_times`) - #110987 (update wasi_clock_time_api ref.) - #111038 (Leave promoteds untainted by errors when borrowck fails) - #111042 (Add `#[no_coverage]` to the test harness's `fn main`) - #111057 (Make sure the implementation of TcpStream::as_raw_fd is fully inlined) - #111065 (Explicitly document how Send and Sync relate to references) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2023-05-01Rollup merge of #111065 - est31:send_mut_ref, r=m-ou-seMatthias Krüger-1/+6
Explicitly document how Send and Sync relate to references Some of these relations were already mentioned in the text, but that Send is implemented for &mut impl Send was not mentioned, neither did the docs list when &T is Sync. Inspired by the discussion in #110961. [Proof](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=ed77bfc3c77ba664400ebc2734f500e6) based on `@lukas-code` 's [example](https://github.com/rust-lang/rust/pull/110961#discussion_r1181220662).
2023-05-01Explicitly document how Send and Sync relate to referencesest31-1/+6
Some of these relations were already mentioned in the text, but that Send is implemented for &mut impl Send was not mentioned, neither did the docs list when &T is Sync.
2023-05-01Auto merge of #111010 - scottmcm:mem-replace-simpler, r=WaffleLapkinbors-12/+35
Make `mem::replace` simpler in codegen Since they'd mentioned more intrinsics for simplifying stuff recently, r? `@WaffleLapkin` This is a continuation of me looking at foundational stuff that ends up with more instructions than it really needs. Specifically I noticed this one because `Range::next` isn't MIR-inlining, and one of the largest parts of it is a `replace::<usize>` that's a good dozen instructions instead of the two it could be. So this means that `ptr::write` with a `Copy` type no longer generates worse IR than manually dereferencing (well, at least in LLVM -- MIR still has bonus pointer casts), and in doing so means that we're finally down to just the two essential `memcpy`s when emitting `mem::replace` for a large type, rather than the bonus-`alloca` and three `memcpy`s we emitted before this ([or the 6 we currently emit in 1.69 stable](https://rust.godbolt.org/z/67W8on6nP)). That said, LLVM does _usually_ manage to optimize the extra code away. But it's still nice for it not to have to do as much, thanks to (for example) not going through an `alloca` when `replace`ing a primitive like a `usize`. (This is a new intrinsic, but one that's immediately lowered to existing MIR constructs, so not anything that MIRI or the codegen backends or MIR semantics needs to do work to handle.)
2023-05-01Fix `StructuralEq` impls for `&T`, `[T]` and `[T; N]`Maybe Waffle-3/+3
(`StructuralEq` is shallow for some reason...)
2023-04-30Codegen fewer instructions in `mem::replace`Scott McMurray-12/+35
2023-05-01Stabilize feature `cstr_is_empty`John Millikin-3/+2
2023-05-01Rollup merge of #110823 - compiler-errors:tweak-await-span, r=b-naberMatthias Krüger-0/+1
Tweak await span to not contain dot Fixes a discrepancy between method calls and await expressions where the latter are desugared to have a span that *contains* the dot (i.e. `.await`) but method call identifiers don't contain the dot. This leads to weird suggestions suggestions in borrowck -- see linked issue. Fixes #110761 This mostly touches a bunch of tests to tighten their `await` span.
2023-04-30Rollup merge of #111000 - JohnBobbo96:core_option_unneeded_function, r=jyn514Matthias Krüger-6/+2
Remove unneeded function call in `core::option`. r? `@jyn514`
2023-04-30a bit more usize::fromMichal Nazarewicz-1/+3
2023-04-30Auto merge of #110935 - scottmcm:always-ord, r=Mark-Simulacrumbors-8/+8
`inline(always)` for `lt`/`le`/`ge`/`gt` on integers and floats I happened to notice one of these not getting inlined as part of `Range::next` in <https://rust.godbolt.org/z/4WKWWxj1G> ```rust bb1: { StorageLive(_5); _6 = &mut _4; StorageLive(_21); StorageLive(_14); StorageLive(_15); _15 = &((*_6).0: usize); StorageLive(_16); _16 = &((*_6).1: usize); _14 = <usize as PartialOrd>::lt(move _15, move _16) -> bb7; } ``` So since a call for something that's just one instruction is never the right choice, `#[inline(always)]` seems appropriate, like we have it on things like the rotate methods on integers.
2023-04-30reviewMichal Nazarewicz-15/+15
2023-04-30Rollup merge of #110997 - scottmcm:slice-iter-comments, r=the8472Matthias Krüger-6/+20
Improve internal field comments on `slice::Iter(Mut)` I wrote these in a previous PR that I ended up withdrawing, so might as well submit them separately. `@bors` rollup=always
2023-04-29Remove unneeded function call in `core::option`.John Bobbo-6/+2
2023-04-29Improve internal field comments on `slice::Iter(Mut)`Scott McMurray-6/+20
I wrote these in a previous PR that I ended up withdrawing, so might as well submit them separately.
2023-04-29Rollup merge of #110958 - compiler-errors:stdlib-refinement, r=cuviperDylan DPC-6/+18
Make sure that some stdlib method signatures aren't accidental refinements In the process of implementing https://rust-lang.github.io/rfcs/3245-refined-impls.html, I found a bunch of stdlib implementations that accidentally "refined" their method signatures by dropping (unnecessary) bounds. This isn't currently a problem, but may become one if/when method signature refining is stabilized in the future. Shouldn't hurt to make these signatures a bit more accurate anyways. NOTE (just to be clear lol): This does not affect behavior at all, since we don't actually take advantage of refined implementations yet!
2023-04-28Make sure that signatures aren't accidental refinementsMichael Goulet-6/+18
2023-04-28handle cfg(bootstrap)Pietro Albini-290/+63
2023-04-28replace version placeholdersPietro Albini-39/+39
2023-04-28Auto merge of #110837 - scottmcm:offset-for-add, r=compiler-errorsbors-3/+41
Use MIR's `Offset` for pointer `add` too ~~Status: draft while waiting for #110822 to land, since this is built atop that.~~ ~~r? `@ghost~~` Canonical Rust code has mostly moved to `add`/`sub` on pointers, which take `usize`, instead of `offset` which takes `isize`. (And, relatedly, when `sub_ptr` was added it turned out it replaced every single in-tree use of `offset_from`, because `usize` is just so much more useful than `isize` in Rust.) Unfortunately, `intrinsics::offset` could only accept `*const` and `isize`, so there's a *huge* amount of type conversions back and forth being done. They're identity conversions in the backend, but still end up producing quite a lot of unhelpful MIR. This PR changes `intrinsics::offset` to accept `*const` *and* `*mut` along with `isize` *and* `usize`. Conveniently, the backends and CTFE already handle this, since MIR's `BinOp::Offset` [already supports all four combinations](https://github.com/rust-lang/rust/blob/adaac6b166df57ea5a20d56e4cce503b55aca927/compiler/rustc_const_eval/src/transform/validate.rs#L523-L528). To demonstrate the difference, I added some `mir-opt/pre-codegen/` tests around slice indexing. Here's the difference to `[T]::get_mut`, since it uses `<*mut _>::add` internally: ```diff `@@` -79,30 +70,21 `@@` fn slice_get_mut_usize(_1: &mut [u32], _2: usize) -> Option<&mut u32> { StorageLive(_12); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL StorageLive(_9); // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL _9 = _8 as *mut u32 (PtrToPtr); // scope 11 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - StorageLive(_13); // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - _13 = _2 as isize (IntToInt); // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - StorageLive(_14); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - StorageLive(_15); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - _15 = _9 as *const u32 (Pointer(MutToConstPointer)); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - _14 = Offset(move _15, _13); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - StorageDead(_15); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - _7 = move _14 as *mut u32 (PtrToPtr); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - StorageDead(_14); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - StorageDead(_13); // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + _7 = Offset(_9, _2); // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL StorageDead(_9); // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL StorageDead(_12); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL StorageDead(_11); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL ``` https://github.com/rust-lang/rust/pull/110837/commits/1c1c8e442add0f46905a57a25a6cba52b8b0c54d#diff-a841b6a4538657add3f39bc895744331453d0625e7aace128b1f604f0b63c8fdR80
2023-04-27`inline(always)` for `lt`/`le`/`ge`/`gt` on integers and floatsScott McMurray-8/+8
I happened to notice one of these not getting inlined as part of `Range::next` in <https://rust.godbolt.org/z/4WKWWxj1G> ```rust bb1: { StorageLive(_5); _6 = &mut _4; StorageLive(_21); StorageLive(_14); StorageLive(_15); _15 = &((*_6).0: usize); StorageLive(_16); _16 = &((*_6).1: usize); _14 = <usize as PartialOrd>::lt(move _15, move _16) -> bb7; } ``` So since a call for something this trivial is never the right choice, `#[inline(always)]` seems appropriate.
2023-04-27Also use `mir::Offset` for pointer `add`Scott McMurray-3/+41
2023-04-28Rollup merge of #110766 - m-ou-se:fmt-rt, r=jyn514Matthias Krüger-200/+200
More core::fmt::rt cleanup. - Removes the `V1` suffix from the `Argument` and `Flag` types. - Moves more of the format_args lang items into the `core::fmt::rt` module. (The only remaining lang item in `core::fmt` is `Arguments` itself, which is a public type.) Part of https://github.com/rust-lang/rust/issues/99012 Follow-up to https://github.com/rust-lang/rust/pull/110616
2023-04-27Don't call await a methodMichael Goulet-0/+1
2023-04-27Fix some marker implsMaybe Waffle-4/+4
2023-04-27Add FIXMEsMaybe Waffle-0/+2
2023-04-27Impl `StructuralEq` & `ConstParamTy` for `str`, `&T`, `[T; N]` and `[T]`Maybe Waffle-0/+9
2023-04-27Add a macro to conveniently implement marker traitsMaybe Waffle-108/+114
2023-04-27Remove `feature(const_param_ty_trait)`, use `adt_const_params` insteadMaybe Waffle-15/+15
2023-04-27Add a `ConstParamTy` traitMaybe Waffle-0/+34
2023-04-27pub -> pub(super).Mara Bos-1/+1
2023-04-27Implement `StructuralEq` for integers, `bool` and `char`Maybe Waffle-0/+29
(how did this work before??)
2023-04-27Auto merge of #110562 - ComputerDruid:riscv, r=tmandrybors-1/+4
Add definitions for riscv64gc-unknown-fuchsia To compile, also requires a libc update with https://github.com/rust-lang/libc/pull/3204
2023-04-26Rollup merge of #110819 - tamird:flattencompat-trustedlen, r=the8472Matthias Krüger-34/+28
simplify TrustedLen impls Implement on FlattenCompat and delegate from Flatten and FlatMap. /cc ``@the8472``
2023-04-26Rollup merge of #110419 - jsoref:spelling-library, r=jyn514Matthias Krüger-9/+9
Spelling library Split per https://github.com/rust-lang/rust/pull/110392 I can squash once people are happy w/ the changes. It's really uncommon for large sets of changes to be perfectly acceptable w/o at least some changes. I probably won't have time to respond until tomorrow or the next day
2023-04-26Implement midpoint for all unsigned NonZeroU{8,16,32,64,128,size}Loïc BRANSTETT-0/+37
2023-04-26Implement midpoint for all floating point f32 and f64Loïc BRANSTETT-0/+72
2023-04-26Implement midpoint for all signed and unsigned integersLoïc BRANSTETT-0/+98
2023-04-26Rollup merge of #108416 - pat-nel87:Issue-107957-black_box_docs, r=jyn514jyn-6/+3
black_box doc corrections for clarification - Issue #107957 Made a complete pass through the docs to help resolve https://github.com/rust-lang/rust/issues/107957 No code changes, just documentation `@rustbot` label +T-libs-api -T-libs
2023-04-26Spelling library/Josh Soref-9/+9
* advance * aligned * borrowed * calculate * debugable * debuggable * declarations * desugaring * documentation * enclave * ignorable * initialized * iterator * kaboom * monomorphization * nonexistent * optimizer * panicking * process * reentrant * rustonomicon * the * uninitialized Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-04-25Add definitions for riscv64gc-unknown-fuchsiaDan Johnson-1/+4
2023-04-25Rollup merge of #110649 - arlosi:fix_no_global_oom_handling, r=Mark-SimulacrumMatthias Krüger-1/+0
Fix no_global_oom_handling build `provide_sorted_batch` in core is incorrectly marked with `#[cfg(not(no_global_oom_handling))]` which prevents core from building with the cfg enabled. Nothing in `core` allocates memory (including this function). The `cfg` gate is incorrect. cc ``@dpaoliello`` r? ``@wesleywiser`` The cfg was added by #107191
2023-04-25simplify TrustedLen implsTamir Duberstein-34/+28
Implement on FlattenCompat and delegate from Flatten and FlatMap.
2023-04-25Auto merge of #110389 - mazong1123:add-shortcut-for-grisu3, r=Mark-Simulacrumbors-0/+16
Add shortcut for Grisu3 algorithm. While Grisu3 is way more faster for most numbers compare to Dragon4, the fall back to Dragon4 procedure for certain numbers could cause some performance regressions compare to use Dragon4 directly. Mitigating the regression caused by falling back is important for a largely used core library. In Grisu3 algorithm implementation, there's a shortcut to jump out earlier when the fractional or integrals cannot meet the requirement of requested digits. This could significantly improve the performance of converting floating number to string as it falls back even without starting trying the algorithm. The original idea is from the [.NET implementation](https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Number.Grisu3.cs#L602-L615) and the code was originally added in [this PR](https://github.com/dotnet/coreclr/pull/14646#issuecomment-350942050). This shortcut has been shipped long time ago and has been proved working. Fix #110129