about summary refs log tree commit diff
path: root/library/core
AgeCommit message (Collapse)AuthorLines
2024-02-16Auto merge of #116385 - kornelski:maybe-rename, r=Amanieubors-21/+21
Rename MaybeUninit::write_slice A step to push #79995 forward. https://github.com/rust-lang/libs-team/issues/122 also suggested to make them inherent methods, but they can't be — they'd conflict with slice's regular methods.
2024-02-16Auto merge of #120500 - oli-obk:intrinsics2.0, r=WaffleLapkinbors-95/+98
Implement intrinsics with fallback bodies fixes #93145 (though we can port many more intrinsics) cc #63585 The way this works is that the backend logic for generating custom code for intrinsics has been made fallible. The only failure path is "this intrinsic is unknown". The `Instance` (that was `InstanceDef::Intrinsic`) then gets converted to `InstanceDef::Item`, which represents the fallback body. A regular function call to that body is then codegenned. This is currently implemented for * codegen_ssa (so llvm and gcc) * codegen_cranelift other backends will need to adjust, but they can just keep doing what they were doing if they prefer (though adding new intrinsics to the compiler will then require them to implement them, instead of getting the fallback body). cc `@scottmcm` `@WaffleLapkin` ### todo * [ ] miri support * [x] default intrinsic name to name of function instead of requiring it to be specified in attribute * [x] make sure that the bodies are always available (must be collected for metadata)
2024-02-16Auto merge of #120486 - reitermarkus:use-generic-nonzero, r=dtolnaybors-368/+358
Use generic `NonZero` internally. Tracking issue: https://github.com/rust-lang/rust/issues/120257
2024-02-16Rollup merge of #121155 - tspiteri:strict-doc-overflow, r=NilstriebGuillaume Gomez-0/+79
doc: add note about panicking examples for strict_overflow_ops The first commit adds a note before the panicking examples for strict_overflow_ops to make it clearer that the following examples should panic and why, without needing the reader to hover the mouse over the information icon. The second commit adds panicking examples for division by zero operations for strict division operations on unsigned numbers. The signed numbers already have two panicking examples each: one for division by zero and one for overflowing division (`MIN/-1`); this commit includes the division by zero examples for the unsigned numbers.
2024-02-16Rollup merge of #120971 - PizzasBear:patch-1, r=NilstriebGuillaume Gomez-1/+1
Fix comment in core/src/str/validations.rs Fix minor issue in the comment
2024-02-16Rollup merge of #120777 - Marcondiro:unicode15-1, r=ManishearthGuillaume Gomez-6/+6
Bump Unicode to version 15.1.0, regenerate tables r? ```@Manishearth```
2024-02-15doc: panicking division by zero examples for unsigned strict div opsTrevor Spiteri-0/+27
2024-02-15doc: add note before panicking examples for strict_overflow_opsTrevor Spiteri-0/+52
2024-02-15Add slice::try_rangeltdk-5/+56
2024-02-15Auto merge of #119863 - tmiasko:will-wake, r=m-ou-sebors-1/+3
Waker::will_wake: Compare vtable address instead of its content Optimize will_wake implementation by comparing vtable address instead of its content. The existing best practice to avoid false negatives from will_wake is to define a waker vtable as a static item. That approach continues to works with the new implementation. While this potentially changes the observable behaviour, the function is documented to work on a best-effort basis. The PartialEq impl for RawWaker remains as it was.
2024-02-15Add ASCII fast-path for `char::is_grapheme_extended`Arpad Borsos-1/+1
I discovered that `impl Debug for str` is quite slow because it ends up doing a `unicode_data::grapheme_extend::lookup` for each char, which ends up doing a binary search. This introduces a fast-path for ASCII chars which do not have this property. The `lookup` is thus completely gone from profiles.
2024-02-15Rollup merge of #121082 - peterjoel:atomic-docs, r=cuviperMatthias Krüger-2/+3
Clarified docs on non-atomic oprations on owned/mut refs to atomics I originally misinterpreted the documentation to mean that the compiler can/will automatically optimise away atomic operations whenever the data is owned or mutably referenced. On re-reading I think it is not technically incorrect, but specifically mentioning _how_ the atomic operations can be avoided also prevents this misunderstanding.
2024-02-15Rollup merge of #111106 - Stargateur:doc/format_args, r=m-ou-seMatthias Krüger-0/+8
Add known issue of let binding to format_args doc Simply add doc about https://github.com/rust-lang/rust/issues/92698. `@rustbot` label +T-rustdoc -T-libs r? `@GuillaumeGomez`
2024-02-15Replace `NonZero::<_>::new` with `NonZero::new`.Markus Reiter-117/+88
2024-02-15Use generic `NonZero` internally.Markus Reiter-352/+371
2024-02-14Clarified docs on non-atomic oprations on owned/mut refs to atomicsPeter Hall-2/+3
2024-02-14Rollup merge of #121024 - joseluis:feat-asciichar-default, r=scottmcmOli Scherer-1/+4
implement `Default` for `AsciiChar` This implements `Default` for `AsciiChar` in order to match `char`'s implementation. From all the different possible ways to do this I think the clearest one is to have both `char` and `AsciiChar` impls together. I've also updated the doc-comment of the default variant since rustdoc doesn't seem to indicate it otherwise. Probably the text could be improved, though. I couldn't find any similar examples in the codebase and suggestions are welcomed. r? `@scottmcm`
2024-02-14Rollup merge of #118890 - Amanieu:allocator-lifetime, r=Mark-SimulacrumOli Scherer-2/+8
Clarify the lifetimes of allocations returned by the `Allocator` trait The previous definition (accidentally) disallowed the implementation of stack-based allocators whose memory would become invalid once the lifetime of the allocator type ended. This also ensures the validity of the following blanket implementation: ```rust impl<A: Allocator> Allocator for &'_ A {} ```
2024-02-14Rollup merge of #116387 - kpreid:wake-doc, r=cuviperOli Scherer-3/+17
Additional doc links and explanation of `Wake`. This is intended to clarify: * That `Wake` exists and can be used instead of `RawWaker`. * How to construct a `Waker` when you are looking at `Wake` (which was previously only documented in the example).
2024-02-13Store core::str::CharSearcher::utf8_size as u8GnomedDev-11/+23
2024-02-13Add information about allocation lifetime to Allocator::allocateAmanieu d'Antras-0/+4
2024-02-13implement `Default` for `AsciiChar`joseLuís-1/+4
2024-02-12iterator.rs: remove "Basic usage" textTshepang Mbambo-40/+0
Only one example is given (for each method)
2024-02-12Support safe intrinsics with fallback bodiesOli Scherer-8/+4
Turn `is_val_statically_known` into such an intrinsic to demonstrate. It is perfectly safe to call after all.
2024-02-12Give const_deallocate a default bodyOli Scherer-14/+17
2024-02-12Teach llvm backend how to fall back to default bodiesOli Scherer-12/+16
2024-02-12Check signature of intrinsics with fallback bodiesOli Scherer-1/+1
2024-02-12Clarify the lifetimes of allocations returned by the `Allocator` traitAmanieu d'Antras-2/+4
The previous definition (accidentally) disallowed the implementation of stack-based allocators whose memory would become invalid once the lifetime of the allocator type ended. This also ensures the validity of the following blanket implementation: ```rust impl<A: Allocator> Allocator for &'_ A {} ```
2024-02-12Fix comment in core/src/str/validations.rsPizzasBear-1/+1
2024-02-12Implement intrinsics with fallback bodiesOli Scherer-69/+69
2024-02-11Rollup merge of #120888 - saethlin:unsafe-precondition-cleanup, r=RalfJungMatthias Krüger-38/+34
assert_unsafe_precondition cleanup I moved the polymorphic `is_nonoverlapping` into the `Cell` function that uses it and renamed `intrinsics::is_nonoverlapping_mono` to just `intrinsics::is_nonoverlapping`. We now also have some docs for `intrinsics::debug_assertions`. r? RalfJung
2024-02-11Rollup merge of #120880 - RalfJung:vtable-fnptr-partialeq, r=cuviperMatthias Krüger-0/+16
add note on comparing vtables / function pointers Fixes https://github.com/rust-lang/rust/issues/99388 Fixes https://github.com/rust-lang/rust/issues/117047
2024-02-11add comparison warning to RawWakerVTable as wellRalf Jung-0/+6
2024-02-11Auto merge of #120903 - matthiaskrgr:rollup-tmsuzth, r=matthiaskrgrbors-3/+51
Rollup of 9 pull requests Successful merges: - #119213 (simd intrinsics: add simd_shuffle_generic and other missing intrinsics) - #120272 (Suppress suggestions in derive macro) - #120773 (large_assignments: Allow moves into functions) - #120874 (Take empty `where` bounds into account when suggesting predicates) - #120882 (interpret/write_discriminant: when encoding niched variant, ensure the stored value matches) - #120883 (interpret: rename ReadExternStatic → ExternStatic) - #120890 (Adapt `llvm-has-rust-patches` validation to take `llvm-config` into account.) - #120895 (don't skip coercions for types with errors) - #120896 (Print kind of coroutine closure) r? `@ghost` `@rustbot` modify labels: rollup
2024-02-11Cleanup around the new assert_unsafe_preconditionBen Kimock-38/+34
Make the polymorphic is_nonoverlapping private Fix assert_unsafe_precondition doc typos Add docs for intrinsics::debug_assertions
2024-02-11Rollup merge of #120307 - djc:duration-constructors, r=Mark-SimulacrumMatthias Krüger-0/+164
core: add Duration constructors Add more `Duration` constructors. Tracking issue: #120301. These match similar convenience constructors available on both `chrono::Duration` and `time::Duration`. What's the best ordering for these with respect to the existing constructors?
2024-02-11Rollup merge of #119449 - Nilstrieb:library-clippy, r=cuviperMatthias Krüger-0/+12
Fix `clippy::correctness` in the library needs https://github.com/rust-lang/backtrace-rs/pull/579 to be complete for https://github.com/rust-lang/compiler-team/issues/709
2024-02-11Rollup merge of #119242 - BenWiederhake:dev-from-nanos, r=joshtriplettMatthias Krüger-0/+5
Suggest less bug-prone construction of Duration in docs std::time::Duration has a well-known quirk: Duration::as_nanos() returns u128 [1], but Duration::from_nanos() takes u64 [2]. So these methods cannot easily roundtrip [3]. It is not possible to simply accept u128 in from_nanos [4], because it requires breaking other API [5]. It seems to me that callers have basically only two options: 1. `Duration::from_nanos(d.as_nanos() as u64)`, which is the "obvious" and buggy approach. 2. `Duration::new(d.as_secs(), d.subsecs_nanos())`, which only becomes apparent after reading and digesting the entire Duration struct documentation. I suggest that the documentation of `from_nanos` is changed to make option 2 more easily discoverable. There are two major usecases for this: - "Weird math" operations that should not be supported directly by `Duration`, like squaring. - "Disconnected roundtrips", where the u128 value is passed through various other stack frames, and perhaps reconstructed into a Duration on a different machine. In both cases, it seems like a good idea to not tempt people into thinking "Eh, u64 is good enough, what could possibly go wrong!". That's why I want to add a note that points out the similarly-easy and *safe* way to reconstruct a Duration. [1] https://doc.rust-lang.org/stable/std/time/struct.Duration.html#method.as_nanos [2] https://doc.rust-lang.org/stable/std/time/struct.Duration.html#method.from_nanos [3] https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=fa6bab2b6b72f20c14b5243610ea1dde [4] https://github.com/rust-lang/rust/issues/103332 [5] https://github.com/rust-lang/rust/issues/51107#issuecomment-392353166
2024-02-11Rollup merge of #118307 - scottmcm:tuple-eq-simpler, r=joshtriplettMatthias Krüger-13/+1
Remove an unneeded helper from the tuple library code Thanks to https://github.com/rust-lang/rust/pull/107022, this is just what `==` does, so we don't need the helper here anymore.
2024-02-10Additional doc links and explanation of `Wake`.Kevin Reid-3/+17
This is intended to clarify: * That `Wake` exists and can be used instead of `RawWaker`. * How to construct a `Waker` when you are looking at `Wake` (which was previously only documented in the example).
2024-02-11Rollup merge of #119213 - RalfJung:simd_shuffle, r=workingjubileeMatthias Krüger-3/+51
simd intrinsics: add simd_shuffle_generic and other missing intrinsics Also tweak the simd_shuffle docs a bit. r? `@calebzulawski`
2024-02-10add note on comparing vtables / function pointersRalf Jung-0/+10
2024-02-10Rollup merge of #120823 - LegionMammal978:clarify-atomic-align, r=RalfJungMatthias Krüger-1/+10
Clarify that atomic and regular integers can differ in alignment The documentation for atomic integers says that they have the "same in-memory representation" as their underlying integers. This might be misconstrued as implying that they have the same layout. Therefore, clarify that atomic integers' alignment is equal to their size.
2024-02-10Rollup merge of #120764 - Alfriadox:master, r=m-ou-seMatthias Krüger-1/+14
Add documentation on `str::starts_with` Add documentation about a current footgun of `str::starts_with`
2024-02-10various docs tweaksRalf Jung-7/+7
2024-02-10simd_scatter: mention left-to-right orderRalf Jung-0/+3
2024-02-10add more missing simd intrinsicsRalf Jung-0/+32
2024-02-10simd intrinsics: add simd_shuffle_genericRalf Jung-3/+16
2024-02-10Stabilize slice_split_at_uncheckedDaniel Sedlak-7/+2
2024-02-10Auto merge of #120712 - compiler-errors:async-closures-harmonize, r=oli-obkbors-14/+37
Harmonize `AsyncFn` implementations, make async closures conditionally impl `Fn*` traits This PR implements several changes to the built-in and libcore-provided implementations of `Fn*` and `AsyncFn*` to address two problems: 1. async closures do not implement the `Fn*` family traits, leading to breakage: https://crater-reports.s3.amazonaws.com/pr-120361/index.html 2. *references* to async closures do not implement `AsyncFn*`, as a consequence of the existing blanket impls of the shape `AsyncFn for F where F: Fn, F::Output: Future`. In order to fix (1.), we implement `Fn` traits appropriately for async closures. It turns out that async closures can: * always implement `FnOnce`, meaning that they're drop-in compatible with `FnOnce`-bound combinators like `Option::map`. * conditionally implement `Fn`/`FnMut` if they have no captures, which means that existing usages of async closures should *probably* work without breakage (crater checking this: https://github.com/rust-lang/rust/pull/120712#issuecomment-1930587805). In order to fix (2.), we make all of the built-in callables implement `AsyncFn*` via built-in impls, and instead adjust the blanket impls for `AsyncFn*` provided by libcore to match the blanket impls for `Fn*`.