about summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2023-05-09Fix incorrect implication of transmuting slicesThomas M. DuBuisson-1/+1
transmute<&[u8]> would be useful and as a beginner it is confusing to see documents casually confuse the types of &[u8] and [u8; SZ]
2023-05-09Rollup merge of #111282 - scottmcm:remove-unneeded-assumes, r=workingjubileeMatthias Krüger-10/+6
Remove some `assume`s from slice iterators that don't do anything Because the start pointer is iterators is already a `NonNull`, we emit the appropriate `!nonnull` metadata when loading the pointer to tell LLVM that it's non-null. Probably the best way to see that it's the metadata that's important (and not the `assume`) is to observe that LLVM actually *removes* the `assume` from the optimized IR: <https://rust.godbolt.org/z/KhE6G963n>. (I also checked that, yes, the if-not-ZST `assume` on `end` is still doing something: it's how there's a `!nonnull` metadata on its load, even though it's an ordinary raw pointer. The codegen test added in this PR fails if the other `assume` is removed.)
2023-05-09Rollup merge of #110770 - m-ou-se:fmt-temp-lifetime, r=oli-obkMatthias Krüger-0/+15
Limit lifetime of format_args!() with inlined args. Fixes #110769
2023-05-09Rollup merge of #97320 - usbalbin:stabilize_const_ptr_read, r=m-ou-seMatthias Krüger-8/+9
Stabilize const_ptr_read Stabilizes const_ptr_read, with tracking issue #80377
2023-05-09Auto merge of #111371 - compiler-errors:revert-110907, r=petrochenkovbors-6/+0
Revert "Populate effective visibilities in `rustc_privacy`" This reverts commit cff85f22f5030fbe7266d272da74a9e76160523c, cc #110907. It needs to be fixed, but there are too many issues being reported that I wanted to put up a revert until a proper fix can be committed. Fixes a ton of issues where private but still reachable impls were missing during codegen: Fixes #111320 Fixes #111321 Fixes #111334 Fixes #111357 Fixes #111368 Fixes #111373 Fixes #111377 Fixes #111386 Fixes #111387 `@bors` p=1 r? `@petrochenkov`
2023-05-09Limit lifetime of format_args!() with inlined args.Mara Bos-0/+15
2023-05-09Rollup merge of #110694 - est31:builtin, r=petrochenkovDylan DPC-3/+3
Implement builtin # syntax and use it for offset_of!(...) Add `builtin #` syntax to the parser, as well as a generic infrastructure to support both item and expression position builtin syntaxes. The PR also uses this infrastructure for the implementation of the `offset_of!` macro, added by #106934. cc `@petrochenkov` `@DrMeepster` cc #110680 `builtin #` tracking issue cc #106655 `offset_of!` tracking issue
2023-05-09Auto merge of #110027 - nbdd0121:dieting, r=m-ou-sebors-0/+9
Add `#[inline]` to functions that are never called This makes libcore binary size reduce by ~300 bytes. Not much, but these functions are never called so it doesn't make sense for them to get into the binary anyway.
2023-05-08Auto merge of #111296 - Sp00ph:const_gcd, r=nagisa,Mark-Simulacrumbors-37/+6
Always const-evaluate the GCD in `slice::align_to_offsets` Use an inline `const`-block to force the compiler to calculate the GCD at compile time, even in debug mode. This shouldn't affect the behavior of the program at all, but it drastically cuts down on the number of instructions emitted with optimizations disabled. With the current implementation, a single `slice::align_to` instantiation (specifically `<[u8]>::align_to::<u128>()`) generates 676 instructions (on x86-64). Forcing the GCD computation to be const cuts it down to 327 instructions, so just over 50% less. This is obviously not representative of actual runtime gains, but I still see it as a significant win as long as it doesn't degrade compile times. Not having to worry about LLVM const-evaluating the GCD function also allows it to use the textbook recursive euclidean algorithm instead of a much more complicated iterative implementation with multiple `unsafe`-blocks.
2023-05-08Revert "Populate effective visibilities in `rustc_privacy`"Michael Goulet-6/+0
This reverts commit cff85f22f5030fbe7266d272da74a9e76160523c.
2023-05-08Rollup merge of #111315 - Swatinem:rm-identitiy-future, r=Mark-SimulacrumYuki Okushi-7/+0
Remove `identity_future` from stdlib This function/lang_item was introduced in #104321 as a temporary workaround of future lowering. The usage and need for it went away in #104833. After a bootstrap update, the function itself can be removed from `std`.
2023-05-08Auto merge of #106621 - ozkanonur:enable-elided-lifetimes-for-doctests, ↵bors-46/+41
r=Mark-Simulacrum enable `rust_2018_idioms` lint group for doctests With this change, `rust_2018_idioms` lint group will be enabled for compiler/libstd doctests. Resolves #106086 Resolves #99144 Signed-off-by: ozkanonur <work@onurozkan.dev>
2023-05-07Auto merge of #111222 - scottmcm:constify-is_ascii, r=thomccbors-15/+61
Constify `[u8]::is_ascii` (unstably) UTF-8 checking in `const fn`-stabilized back in 1.63 (#97367), but apparently somehow ASCII checking was never const-ified, despite being simpler. New constness-tracking issue for `is_ascii`: #111090 I noticed this working on `ascii::Char`: #110998
2023-05-07Add `#[inline]` to functions that are never calledGary Guo-0/+9
2023-05-07Remove `identity_future` from stdlibArpad Borsos-7/+0
This function/lang_item was introduced in #104321 as a temporary workaround of future lowering. The usage and need for it went away in #104833. After a bootstrap update, the function itself can be removed from `std`.
2023-05-07Auto merge of #111125 - xfix:inline-socketaddr-methods, r=Mark-Simulacrumbors-0/+27
Inline SocketAddr methods
2023-05-06Tune the `is_ascii` implementation used for short slicesScott McMurray-10/+23
2023-05-07Rollup merge of #111301 - JohnBobbo96:cleanup_option_insert_methods, r=scottmcmYuki Okushi-4/+2
Remove calls to `mem::forget` and `mem::replace` in `Option::get_or_insert_with`. This removes the unneeded calls to `mem::forget` and `mem::replace` in `Option::get_or_insert_with`.
2023-05-07Rollup merge of #110094 - lukas-code:less-transmute, r=thomccYuki Okushi-13/+9
clean up `transmute`s in `core` * Use `transmute_unchecked` instead of `transmute_copy` for `MaybeUninit::transpose`. * Use manual transmute for `Option<Ordering>` → `i8`.
2023-05-06Remove unneeded calls to `mem::forget`John Bobbo-4/+2
and `mem::replace` in `Option::get_or_insert_with`.
2023-05-07enable `rust_2018_idioms` for doctestsozkanonur-46/+41
Signed-off-by: ozkanonur <work@onurozkan.dev>
2023-05-06Auto merge of #110907 - Bryanskiy:privacy_ef, r=petrochenkovbors-0/+6
Populate effective visibilities in 'rustc_privacy' Next part of RFC https://github.com/rust-lang/rust/issues/48054. r? `@petrochenkov`
2023-05-06Always const-eval the gcd in `slice::align_to_offsets`Markus Everling-37/+6
2023-05-06clean up transmutes in coreLukas Markeffsky-13/+9
2023-05-06Remove some `assume`s from slice iterators that don't do anythingScott McMurray-10/+6
2023-05-05Migrate offset_of from a macro to builtin # syntaxest31-3/+3
2023-05-05Stabilize const_ptr_readbors-8/+9
2023-05-05Auto merge of #111248 - Dylan-DPC:rollup-lbp0ui3, r=Dylan-DPCbors-1/+1
Rollup of 6 pull requests Successful merges: - #103056 (Fix `checked_{add,sub}_duration` incorrectly returning `None` when `other` has more than `i64::MAX` seconds) - #108801 (Implement RFC 3348, `c"foo"` literals) - #110773 (Reduce MIR dump file count for MIR-opt tests) - #110876 (Added default target cpu to `--print target-cpus` output and updated docs) - #111068 (Improve check-cfg implementation) - #111238 (btree_map: `Cursor{,Mut}::peek_prev` must agree) Failed merges: - #110694 (Implement builtin # syntax and use it for offset_of!(...)) r? `@ghost` `@rustbot` modify labels: rollup
2023-05-05Populate effective visibilities in `rustc_privacy`Bryanskiy-0/+6
2023-05-05Rollup merge of #108801 - fee1-dead-contrib:c-str, r=compiler-errorsDylan DPC-1/+1
Implement RFC 3348, `c"foo"` literals RFC: https://github.com/rust-lang/rfcs/pull/3348 Tracking issue: #105723
2023-05-05Auto merge of #111113 - scottmcm:assume-align-offset, r=thomccbors-4/+11
`assume` the runtime range of `align_offset` Found when I saw code with `align_to` having extraneous checks. Demo that LLVM can't do this today: <https://rust.godbolt.org/z/6dnG749bq> (It's filed as https://github.com/llvm/llvm-project/issues/62502.)
2023-05-05`assume` the runtime range of `align_offset`Scott McMurray-4/+11
Found when I saw code with `align_to` having extraneous checks.
2023-05-05Rollup merge of #111213 - WaffleLapkin:fixup_dates, r=scottmcmYuki Okushi-2/+2
Fixup "since" dates for `array_tuple_conv` feature Fixes a mistake from #97594
2023-05-05Stabilize feature `nonzero_negation_ops`John Millikin-18/+12
2023-05-04Add an example that depends on `is_ascii` in a `const`Scott McMurray-0/+13
2023-05-04Constify `[u8]::is_ascii` (unstably)Scott McMurray-15/+35
UTF-8 checking in `const fn`-stabilized back in 1.63, but apparently somehow ASCII checking was never const-ified, despite being simpler.
2023-05-04Fixup "since" dates for `array_tuple_conv` featureMaybe Waffle-2/+2
2023-05-04Rollup merge of #111186 - jmillikin:nonzero-is-positive, r=dtolnayMatthias Krüger-0/+26
Add `is_positive` method for signed non-zero integers. ACP: https://github.com/rust-lang/libs-team/issues/105
2023-05-04Rollup merge of #111009 - scottmcm:ascii-char, r=BurntSushiMatthias Krüger-1/+674
Add `ascii::Char` (ACP#179) ACP second: https://github.com/rust-lang/libs-team/issues/179#issuecomment-1527900570 New tracking issue: https://github.com/rust-lang/rust/issues/110998 For now this is an `enum` as `@kupiakos` [suggested](https://github.com/rust-lang/libs-team/issues/179#issuecomment-1527959724), with the variants under a different feature flag. There's lots more things that could be added here, and place for further doc updates, but this seems like a plausible starting point PR. I've gone through and put an `as_ascii` next to every `is_ascii`: on `u8`, `char`, `[u8]`, and `str`. As a demonstration, made a commit updating some formatting code to use this: https://github.com/scottmcm/rust/commit/ascii-char-in-fmt (I don't want to include that in this PR, though, because that brings in perf questions that don't exist if this is just adding new unstable APIs.)
2023-05-04Optimize `Iterator` implementation for `&mut impl Iterator + Sized`Benoît du Garreau-0/+130
2023-05-04Add `is_positive` method for signed non-zero integers.John Millikin-0/+26
2023-05-03Add the basic `ascii::Char` typeScott McMurray-1/+674
2023-05-03Rollup merge of #111127 - xfix:const-slice-flatten, r=scottmcmManish Goregaokar-1/+1
Constify slice flatten method ACP: https://github.com/rust-lang/libs-team/issues/218
2023-05-03Rollup merge of #105452 - rcvalle:rust-cfi-3, r=bjorn3Manish Goregaokar-0/+1
Add cross-language LLVM CFI support to the Rust compiler This PR adds cross-language LLVM Control Flow Integrity (CFI) support to the Rust compiler by adding the `-Zsanitizer-cfi-normalize-integers` option to be used with Clang `-fsanitize-cfi-icall-normalize-integers` for normalizing integer types (see https://reviews.llvm.org/D139395). It provides forward-edge control flow protection for C or C++ and Rust -compiled code "mixed binaries" (i.e., for when C or C++ and Rust -compiled code share the same virtual address space). For more information about LLVM CFI and cross-language LLVM CFI support for the Rust compiler, see design document in the tracking issue #89653. Cross-language LLVM CFI can be enabled with -Zsanitizer=cfi and -Zsanitizer-cfi-normalize-integers, and requires proper (i.e., non-rustc) LTO (i.e., -Clinker-plugin-lto). Thank you again, ``@bjorn3,`` ``@nikic,`` ``@samitolvanen,`` and the Rust community for all the help!
2023-05-03Rollup merge of #97594 - WaffleLapkin:array_tuple_conv, r=ChrisDentonManish Goregaokar-0/+40
Implement tuple<->array convertions via `From` This PR adds the following impls that convert between homogeneous tuples and arrays of the corresponding lengths: ```rust impl<T> From<[T; 1]> for (T,) { ... } impl<T> From<[T; 2]> for (T, T) { ... } /* ... */ impl<T> From<[T; 12]> for (T, T, T, T, T, T, T, T, T, T, T, T) { ... } impl<T> From<(T,)> for [T; 1] { ... } impl<T> From<(T, T)> for [T; 2] { ... } /* ... */ impl<T> From<(T, T, T, T, T, T, T, T, T, T, T, T)> for [T; 12] { ... } ``` IMO these are quite uncontroversial but note that they are, just like any other trait impls, insta-stable.
2023-05-03Add cross-language LLVM CFI support to the Rust compilerRamon de C Valle-0/+1
This commit adds cross-language LLVM Control Flow Integrity (CFI) support to the Rust compiler by adding the `-Zsanitizer-cfi-normalize-integers` option to be used with Clang `-fsanitize-cfi-icall-normalize-integers` for normalizing integer types (see https://reviews.llvm.org/D139395). It provides forward-edge control flow protection for C or C++ and Rust -compiled code "mixed binaries" (i.e., for when C or C++ and Rust -compiled code share the same virtual address space). For more information about LLVM CFI and cross-language LLVM CFI support for the Rust compiler, see design document in the tracking issue #89653. Cross-language LLVM CFI can be enabled with -Zsanitizer=cfi and -Zsanitizer-cfi-normalize-integers, and requires proper (i.e., non-rustc) LTO (i.e., -Clinker-plugin-lto).
2023-05-03Mention array<->tuple convs in docsMaybe Waffle-0/+20
2023-05-03Constify slice flatten methodKonrad Borowski-1/+1
2023-05-03Inline SocketAddr methodsKonrad Borowski-0/+27
2023-05-02Remove `[]` <-> `()` `From` convertionsMaybe Waffle-14/+0
... with this convertions some tests fail :(