about summary refs log tree commit diff
path: root/library/core
AgeCommit message (Collapse)AuthorLines
2024-09-21Reword ManuallyDrop+Box interactionTim (Theemathas) Chirananthavat-2/+3
2024-09-20Auto merge of #130631 - GuillaumeGomez:rollup-jpgy1iv, r=GuillaumeGomezbors-2/+12
Rollup of 7 pull requests Successful merges: - #128209 (Remove macOS 10.10 dynamic linker bug workaround) - #130526 (Begin experimental support for pin reborrowing) - #130611 (Address diagnostics regression for `const_char_encode_utf8`.) - #130614 (Add arm64e-apple-tvos target) - #130617 (bail if there are too many non-region infer vars in the query response) - #130619 (Fix scraped examples height) - #130624 (Add `Vec::as_non_null`) r? `@ghost` `@rustbot` modify labels: rollup
2024-09-20Rollup merge of #130611 - bjoernager:const-char-encode-utf8, r=dtolnayGuillaume Gomez-2/+12
Address diagnostics regression for `const_char_encode_utf8`. Relevant tracking issue: #130512 This PR regains full diagnostics for non-const calls to `char::encode_utf8`.
2024-09-20Auto merge of #124895 - obeis:static-mut-hidden-ref, r=compiler-errorsbors-0/+2
Disallow hidden references to mutable static Closes #123060 Tracking: - https://github.com/rust-lang/rust/issues/123758
2024-09-20Address diagnostics regression for 'const_char_encode_utf8';Gabriel Bjørnager Jensen-2/+12
2024-09-19Rollup merge of #130553 - GnomedDev:remove-clippy-paths, r=compiler-errorsMatthias Krüger-0/+10
[Clippy] Get rid of most `std` `match_def_path` usage, swap to diagnostic items. Part of https://github.com/rust-lang/rust-clippy/issues/5393. This was going to remove all `std` paths, but `SeekFrom` has issues being cleanly replaced with a diagnostic item as the paths are for variants, which currently cannot be diagnostic items. This also, as a last step, categories the paths to help with future path removals.
2024-09-19Rollup merge of #128001 - Krappa322:master, r=scottmcmMatthias Krüger-26/+55
Improve documentation for <integer>::from_str_radix Two improvements to the documentation: - Document `-` as a valid character for signed integer destinations - Make the documentation even more clear that extra whitespace and non-digit characters is invalid. Many other languages, e.g. c++, are very permissive in string to integer routines and simply try to consume as much as they can, ignoring the rest. This is trying to make the transition for developers who are used to the conversion semantics in these languages a bit easier.
2024-09-19Add str.as_str() for easy dereferencing of Box<str>Kornel-0/+11
2024-09-19[Clippy] Swap `manual_strip` to use diagnostic items instead of pathsGnomedDev-0/+3
2024-09-19[Clippy] Swap `waker_clone_wake` to use diagnostic item instead of pathGnomedDev-0/+1
2024-09-19[Clippy] Swap `filter_map_bool_then` to use diagnostic item instead of pathGnomedDev-0/+1
2024-09-19[Clippy] Swap `manual_while_let_some` to use diagnostic items instead of pathsGnomedDev-0/+2
2024-09-19[Clippy] Swap `float_equality_without_abs` to use diagnostic items instead ↵GnomedDev-0/+2
of paths
2024-09-19[Clippy] Swap `lines_filter_map_ok` to use a diagnostic item instead of pathGnomedDev-0/+1
2024-09-19Auto merge of #130547 - workingjubilee:rollup-tw30khz, r=workingjubileebors-4/+5
Rollup of 3 pull requests Successful merges: - #130531 (Check params for unsafety in THIR) - #130533 (Never patterns constitute a read for unsafety) - #130542 (Stabilize const `MaybeUninit::as_mut_ptr`) r? `@ghost` `@rustbot` modify labels: rollup
2024-09-19Auto merge of #130511 - bjoernager:const-char-encode-utf8, r=dtolnaybors-18/+15
Support `char::encode_utf8` in const scenarios. This PR implements [`rust-lang/rfcs#3696`](https://github.com/rust-lang/rfcs/pull/3696/). This assumes [`const_slice_from_raw_parts_mut`](https://github.com/rust-lang/rust/issues/67456/).
2024-09-18run `x.py fmt`ultrabear-1/+4
2024-09-18remove feature attributes as const_maybe_uninit_as_mut_ptr is stabilizedultrabear-2/+0
2024-09-18stabilize `const_maybe_uninit_as_mut_ptr`ultrabear-2/+2
2024-09-18Mark and implement 'char::encode_utf8' as const.Gabriel Bjørnager Jensen-18/+15
2024-09-18Rollup merge of #130522 - GnomedDev:clippy-manual-retain-paths, ↵Jubilee-0/+5
r=compiler-errors [Clippy] Swap `manual_retain` to use diagnostic items instead of paths Part of https://github.com/rust-lang/rust-clippy/issues/5393, just a chore.
2024-09-18Rollup merge of #130476 - workingjubilee:more-lazy-methods-take-2, r=AmanieuJubilee-5/+142
Implement ACP 429: add `Lazy{Cell,Lock}::get[_mut]` and `force_mut` Tracking issue for `lazy_get`: https://github.com/rust-lang/rust/issues/129333
2024-09-18library: Call it really_init_mut to avoid name collisionsJubilee Young-2/+2
2024-09-18library: Destabilize Lazy{Cell,Lock}::{force,deref}_mutJubilee Young-14/+5
2024-09-18[Clippy] Swap `manual_retain` to use diagnostic items instead of pathsGnomedDev-0/+5
2024-09-18Auto merge of #129491 - StackOverflowExcept1on:master, r=m-ou-sebors-8/+8
Pass `fmt::Arguments` by reference to `PanicInfo` and `PanicMessage` Resolves #129330 For some reason after #115974 and #126732 optimizations applied to panic handler became worse and compiler stopped removing panic locations if they are not used in the panic message. This PR fixes that and maybe we can merge it into beta before rust 1.81 is released. Note: optimization only works with `lto = "fat"`. r? libs-api
2024-09-18Auto merge of #129845 - scottmcm:redo-layout, r=Noratriebbors-56/+110
Take more advantage of the `isize::MAX` limit in `Layout` Things like `padding_needed_for` are current implemented being super careful to handle things like `Layout::size` potentially being `usize::MAX`. But now that #95295 has happened, that's no longer a concern. It's possible to add two `Layout::size`s together without risking overflow now. So take advantage of that to remove a bunch of checked math that's not actually needed. For example, the round-up-and-add-next-size in `extend` doesn't need any overflow checks at all, just the final check for compatibility with the alignment. (And while I was doing that I made it all unstably const, because there's nothing in `Layout` that's fundamentally runtime-only.)
2024-09-17Take more advantage of the `isize::MAX` limit in `Layout`Scott McMurray-56/+110
Things like `padding_needed_for` are current implemented being super careful to handle things like `Layout::size` potentially being `usize::MAX`. But now that 95295 has happened, that's no longer a concern. It's possible to add two `Layout::size`s together without risking overflow now. So take advantage of that to remove a bunch of checked math that's not actually needed. For example, the round-up-and-add-next-size in `extend` doesn't need any overflow checks at all, just the final check for compatibility with the alignment. (And while I was doing that I made it all unstably const, because there's nothing in `Layout` that's fundamentally runtime-only.)
2024-09-17Remove uneeded PartialOrd bound in cmp::Ord::clampArthur Carcano-1/+0
There is a Self: PartialOrd bound in Ord::clamp, but it is already required by the trait itself. Likely a left-over from the const trait deletion in 76dbe2910465072f85e74d6f7115ec9e6803e8bf. Reported-by: @noeensarguet
2024-09-17Implement ACP 429: add `Lazy{Cell,Lock}::get[_mut]` and `force_mut`Chayim Refael Friedman-6/+152
In the implementation of `force_mut`, I chose performance over safety. For `LazyLock` this isn't really a choice; the code has to be unsafe. But for `LazyCell`, we can have a full-safe implementation, but it will be a bit less performant, so I went with the unsafe approach.
2024-09-17Auto merge of #130145 - fee1-dead-contrib:repeatn, r=lcnr,workingjubileebors-15/+69
`RepeatN`: use MaybeUninit Closes #130140. Closes #130141. Use `MaybeUninit` instead of `ManuallyDrop` for soundness.
2024-09-15Rollup merge of #127879 - kornelski:bad-pointer-printf, r=workingjubileeJubilee-2/+10
Document futility of printing temporary pointers In the user forum I've seen a few people trying to understand how borrowing and moves are implemented by peppering their code with printing of `{:p}` of references to variables and expressions. This is a bad idea. It gives misleading and confusing results, because of autoderef magic, printing pointers of temporaries on the stack, and/or causes LLVM to optimize code differently when values had their address exposed.
2024-09-16Auto merge of #130220 - RalfJung:float-classify, r=workingjubileebors-109/+31
simplify float::classify logic I played around with the float-classify test in the hope of triggering x87 bugs by strategically adding `black_box`, and still the exact expression `@beetrees` suggested [here](https://github.com/rust-lang/rust/pull/129835#issuecomment-2325661597) remains the only case I found where we get the wrong result on x87. Curiously, this bug only occurs when MIR optimizations are enabled -- probably the extra inlining that does is required for LLVM to hit the right "bad" case in the backend. But even for that case, it makes no difference whether `classify` is implemented in the simple bit-pattern-based version or the more complicated version we had before. Without even a single testcase that can distinguish our `classify` from the naive version, I suggest we switch to the naive version.
2024-09-15update docs for `catch_unwind` & related funcsKyle J Strand-5/+10
Documentation comments for `catch_unwind` and `thread::join` to indicate new behavioral guarantee when catching a foreign exception.
2024-09-15Rollup merge of #130339 - CAD97:unwind-choice, r=dtolnayMatthias Krüger-0/+25
Add `core::panic::abort_unwind` `abort_unwind` is like `catch_unwind` except that it aborts the process if it unwinds, using the `#[rustc_nounwind]` mechanism also used by `extern "C" fn` to abort unwinding. The docs attempt to make it clear when to (rarely) and when not to (usually) use the function. Although usage of the function is discouraged, having it available will help to normalize the experience when abort_unwind shims are hit, as opposed to the current ecosystem where there exist multiple common patterns for converting unwinding into a process abort. For further information and justification, see the linked ACP. - Tracking issue: https://github.com/rust-lang/rust/issues/130338 - ACP: https://github.com/rust-lang/libs-team/issues/441
2024-09-15simplify abort_unwindChristopher Durham-7/+2
Co-authored-by: David Tolnay <dtolnay@gmail.com>
2024-09-15Rollup merge of #130118 - RalfJung:unwrap_unchecked, r=NoratriebMatthias Krüger-1/+1
move Option::unwrap_unchecked into const_option feature gate That's where `unwrap` and `expect` are so IMO it makes more sense to group them together. Part of #91930, #67441
2024-09-15Rollup merge of #129195 - RalfJung:const-mut-refs, r=fee1-deadMatthias Krüger-6/+6
Stabilize `&mut` (and `*mut`) as well as `&Cell` (and `*const Cell`) in const This stabilizes `const_mut_refs` and `const_refs_to_cell`. That allows a bunch of new things in const contexts: - Mentioning `&mut` types - Creating `&mut` and `*mut` values - Creating `&T` and `*const T` values where `T` contains interior mutability - Dereferencing `&mut` and `*mut` values (both for reads and writes) The same rules as at runtime apply: mutating immutable data is UB. This includes mutation through pointers derived from shared references; the following is diagnosed with a hard error: ```rust #[allow(invalid_reference_casting)] const _: () = { let mut val = 15; let ptr = &val as *const i32 as *mut i32; unsafe { *ptr = 16; } }; ``` The main limitation that is enforced is that the final value of a const (or non-`mut` static) may not contain `&mut` values nor interior mutable `&` values. This is necessary because the memory those references point to becomes *read-only* when the constant is done computing, so (interior) mutable references to such memory would be pretty dangerous. We take a multi-layered approach here to ensuring no mutable references escape the initializer expression: - A static analysis rejects (interior) mutable references when the referee looks like it may outlive the current MIR body. - To be extra sure, this static check is complemented by a "safety net" of dynamic checks. ("Dynamic" in the sense of "running during/after const-evaluation, e.g. at runtime of this code" -- in contrast to "static" which works entirely by looking at the MIR without evaluating it.) - After the final value is computed, we do a type-driven traversal of the entire value, and if we find any `&mut` or interior-mutable `&` we error out. - However, the type-driven traversal cannot traverse `union` or raw pointers, so there is a second dynamic check where if the final value of the const contains any pointer that was not derived from a shared reference, we complain. This is currently a future-compat lint, but will become an ICE in #128543. On the off-chance that it's actually possible to trigger this lint on stable, I'd prefer if we could make it an ICE before stabilizing const_mut_refs, but it's not a hard blocker. This part of the "safety net" is only active for mutable references since with shared references, it has false positives. Altogether this should prevent people from leaking (interior) mutable references out of the const initializer. While updating the tests I learned that surprisingly, this code gets rejected: ```rust const _: Vec<i32> = { let mut x = Vec::<i32>::new(); //~ ERROR destructor of `Vec<i32>` cannot be evaluated at compile-time let r = &mut x; let y = x; y }; ``` The analysis that rejects destructors in `const` is very conservative when it sees an `&mut` being created to `x`, and then considers `x` to be always live. See [here](https://github.com/rust-lang/rust/issues/65394#issuecomment-541499219) for a longer explanation. `const_precise_live_drops` will solve this, so I consider this problem to be tracked by https://github.com/rust-lang/rust/issues/73255. Cc `@rust-lang/wg-const-eval` `@rust-lang/lang` Cc https://github.com/rust-lang/rust/issues/57349 Cc https://github.com/rust-lang/rust/issues/80384
2024-09-15also stabilize const_refs_to_cellRalf Jung-2/+2
2024-09-15const_refs_to_cell: dont let mutable references sneak past the interior ↵Ralf Jung-1/+1
mutability check
2024-09-15stabilize const_mut_refsRalf Jung-4/+4
2024-09-15Rollup merge of #130214 - RalfJung:zeroed, r=Mark-SimulacrumStuart Cook-0/+3
MaybeUninit::zeroed: mention that padding is not zeroed That should clarify cases like [this](https://github.com/rust-lang/rust/pull/129778#issuecomment-2342542847).
2024-09-14Rollup merge of #130268 - RalfJung:simd-shuffle-idx-vector, r=compiler-errorsLeón Orell Valerian Liehr-1/+1
simd_shuffle: require index argument to be a vector Remove some codegen hacks by forcing the SIMD shuffle `index` argument to be a vector, which means (thanks to https://github.com/rust-lang/rust/pull/128537) that it will automatically be passed as an immediate in LLVM. The only special-casing we still have is for the extra sanity-checks we add that ensure that the indices are all in-bounds. (And the GCC backend needs to do a bunch of work since the Rust intrinsic is modeled after what LLVM expects, which seems to be quite different from what GCC expects.) Fixes https://github.com/rust-lang/rust/issues/128738, see that issue for more context.
2024-09-14simd_shuffle: require index argument to be a vectorRalf Jung-1/+1
2024-09-14Rollup merge of #130053 - glowcoil:next_if-docs, r=jhprattStuart Cook-2/+2
fix doc comments for Peekable::next_if(_eq) Fix references to a nonexistent `consume` function in the doc comments for `Peekable::next_if` and `Peekable::next_if_eq`.
2024-09-14add core::panic::abort_unwindChristopher Durham-0/+30
2024-09-13RustfmtCaio-1/+1
2024-09-13[`cfg_match`] Generalize inputsCaio-5/+25
2024-09-13Fix awkward wording.Tim (Theemathas) Chirananthavat-10/+9
2024-09-13Address WaffleLapkin's commentsTim (Theemathas) Chirananthavat-9/+11