about summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2024-05-09Document proper usage of `fmt::Error` and `fmt()`'s `Result`.Kevin Reid-15/+35
Documentation of these properties previously existed in a lone paragraph in the `fmt` module's documentation: <https://doc.rust-lang.org/1.78.0/std/fmt/index.html#formatting-traits> However, users looking to implement a formatting trait won't necessarily look there. Therefore, let's add the critical information (that formatting per se is infallible) to all the involved items.
2024-05-09Suggest borrowing on fn argument that is `impl AsRef`Esteban Küber-0/+1
When encountering a move conflict, on an expression that is `!Copy` passed as an argument to an `fn` that is `impl AsRef`, suggest borrowing the expression. ``` error[E0382]: use of moved value: `bar` --> f204.rs:14:15 | 12 | let bar = Bar; | --- move occurs because `bar` has type `Bar`, which does not implement the `Copy` trait 13 | foo(bar); | --- value moved here 14 | let baa = bar; | ^^^ value used here after move | help: borrow the value to avoid moving it | 13 | foo(&bar); | + ``` Fix #41708
2024-05-09Improve escape methods.Markus Reiter-40/+30
2024-05-09Auto merge of #124793 - scottmcm:simplify-as-chunks, r=Nilstriebbors-4/+8
Implement `as_chunks` with `split_at_unchecked` We were discussing various ways to do [this on Discord](https://discord.com/channels/273534239310479360/273541522815713281/1236946363120619521), and in the process I noticed that <https://rust.godbolt.org/z/1P16P37Go> is emitting a panic path inside `as_chunks`. It optimizes out in release, but we could just not do that in the first place. We're already doing unsafe code that depends on this value being calculated correctly, so might as well call `split_at_unchecked` instead of `split_at`.
2024-05-08Auto merge of #124910 - matthiaskrgr:rollup-lo1uvdn, r=matthiaskrgrbors-188/+186
Rollup of 8 pull requests Successful merges: - #123344 (Remove braces when fixing a nested use tree into a single item) - #124587 (Generic `NonZero` post-stabilization changes.) - #124775 (crashes: add lastest batch of crash tests) - #124869 (Make sure we don't deny macro vars w keyword names) - #124876 (Simplify `use crate::rustc_foo::bar` occurrences.) - #124892 (Update cc crate to v1.0.97) - #124903 (Ignore empty RUSTC_WRAPPER in bootstrap) - #124909 (Reapply the part of #124548 that bors forgot) r? `@ghost` `@rustbot` modify labels: rollup
2024-05-08Avoid panicking branch in `EscapeIterInner`.Markus Reiter-81/+137
2024-05-08Inline `EscapeDebug::size_hint`.Markus Reiter-0/+1
2024-05-08Auto merge of #124795 - scottmcm:simplify-slice-from-raw-parts, r=joboetbors-2/+2
Avoid a cast in `ptr::slice_from_raw_parts(_mut)` Casting to `*const ()` or `*mut ()` is no longer needed after https://github.com/rust-lang/rust/pull/123840 so let's make the MIR smaller (and more inline-able, as seen in the tests). If [ACP#362](https://github.com/rust-lang/libs-team/issues/362) goes through we can keep calling `ptr::from_raw_parts(_mut)` in these also without the cast, but that hasn't had any libs-api attention yet, so I'm not waiting on it.
2024-05-08Use generic `NonZero`.Markus Reiter-5/+5
2024-05-08Use generic `NonZero` in examples.Markus Reiter-183/+181
2024-05-08miri: rename intrinsic_fallback_checks_ub to intrinsic_fallback_is_specRalf Jung-5/+5
2024-05-08Rollup merge of #124838 - RalfJung:next_power_of_two, r=scottmcmJubilee-0/+1
next_power_of_two: add a doctest to show what happens on 0
2024-05-07use teletype on the attribute nameLokathor-1/+1
2024-05-07Some Result combinations work like an Option.Lokathor-0/+15
2024-05-08from_str_radix: outline only the panic functionDaniPopes-6/+6
2024-05-07Auto merge of #124836 - tgross35:const-slice-last-chunk, r=BurntSushibors-1/+1
Correct the const stabilization of `last_chunk` for slices `<[T]>::last_chunk` should have become const stable as part of <https://github.com/rust-lang/rust/pull/117561>. Update the const stability gate to reflect this.
2024-05-07next_power_of_two: add a doctest to show what happens on 0Ralf Jung-0/+1
2024-05-07Correct the const stabilization of `last_chunk` for slicesTrevor Gross-1/+1
`<[T]>::last_chunk` should have become const stable as part of <https://github.com/rust-lang/rust/pull/117561>. Update the const stability gate to reflect this.
2024-05-06f16::is_sign_{positive,negative} were feature-gated on f128Trevor Spiteri-2/+2
2024-05-06Auto merge of #123850 - tspiteri:f16_f128_consts, r=Amanieubors-4/+382
Add constants for f16 and f128 - Commit 1 adds associated constants for `f16`, excluding NaN and infinities as these are implemented using arithmetic for `f32` and `f64`. - Commit 2 adds associated constants for `f128`, excluding NaN and infinities. - Commit 3 adds constants in `std::f16::consts`. - Commit 4 adds constants in `std::f128::consts`.
2024-05-06Avoid a cast in `ptr::slice_from_raw_parts(_mut)`Scott McMurray-2/+2
Casting to `*const ()` or `*mut ()` just bloats the MIR, so let's not. If ACP#362 goes through we can keep calling `ptr::from_raw_parts(_mut)` in these also without the cast, but that hasn't had any libs-api attention yet, so I'm not waiting on it.
2024-05-06Implement `as_chunks` with `split_at_unchecked`Scott McMurray-4/+8
2024-05-05Rollup merge of #124750 - ultrabear:ultrabear_softfloatdoc, r=workingjubileeGuillaume Gomez-0/+12
Document That `f16` And `f128` Hardware Support is Limited (v2) This PR is identical to #123892, which was approved and merged but then removed from master by a force-push due to a [CI bug](https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra/topic/ci.20broken.3F). r? ghost Original PR description: --- This adds a small paragraph to the recently added f16 and f128 types explaining that hardware support may be limited, and that performance may suffer as a result of that. I mainly wrote this because I felt it may be useful to express in some form; as a launchpoint for readers of the documentation if they have issues with performance. I tried to word the documentation in a way that doesn't create false assumptions (that f16/f128 is too slow to use, for instance), removing the software implementation part could mislead people to thinking that f16/f128 is only available on some platforms, not all, so I believe it is important to keep in.\ "not all *major* platforms" is specifically said so as to not be redundant, because not all platforms implement many things, but the average rustacean is probably going to be using x86_64 or aarch64 derived ISA's, which is who this documentation is targeted towards. I'm not sure of the best way to word the documentation, or if it should even be added, but I feel like it may be useful to have (potentially in a reworded way, I'm not very confident in the current wording and cannot decide if that is because it is too vague to be useful or too specific to be generally correct).
2024-05-04Re-add `From<f16> for f64`beetrees-2/+3
2024-05-04Make f128 docs mention lack of any normal platform supportAlex H-5/+5
Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com> Update library/core/src/primitive_docs.rs Remove orphaned doc link and clean up grammar a bit Update library/core/src/primitive_docs.rs
2024-05-04Make f16 and f128 docs clearer on platform supportAlex H-4/+11
Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com> Update library/core/src/primitive_docs.rs Rewrite f16 and f128 hw support comments to match PR feedback I wrote RISC-V allcaps in all cases, and wrote amd64 lowercase in all cases, im not sure if either is the more correct way for either platform, thats just how I normally write them, if theres a precedent elsewhere it should probably be changed to match though. Update library/core/src/primitive_docs.rs Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com> Update library/core/src/primitive_docs.rs Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com> Update library/core/src/primitive_docs.rs
2024-05-04Tgross feedback tweaksAlex H-5/+4
Co-authored-by: Trevor Gross <t.gross35@gmail.com> Update library/core/src/primitive_docs.rs Co-authored-by: Trevor Gross <t.gross35@gmail.com> Update library/core/src/primitive_docs.rs
2024-05-04Rollup merge of #124699 - scottmcm:split_at_unchecked_should_use_unchecked, ↵Matthias Krüger-3/+8
r=Nilstrieb Use `unchecked_sub` in `split_at` LLVM currently isn't figuring it out on its own, even in the checked version where it hypothetically could. Before: <https://rust.godbolt.org/z/PEY38YrKs> ```llvm bb1: ; preds = %start %4 = getelementptr inbounds float, ptr %x.0, i64 %n %5 = sub i64 %x.1, %n ``` After: ```llvm bb1: ; preds = %start %4 = getelementptr inbounds float, ptr %x.0, i64 %n %5 = sub nuw i64 %x.1, %n ``` This is not using the wrapper because there's already a ubcheck covering it, so I don't want this to get a second one once #121571 lands. --- This is basically the same as #108763, since `split_at` is essentially doing two `get_unchecked`s.
2024-05-04Rollup merge of #124701 - scottmcm:unchecked_sub_docs, r=NilstriebMatthias Krüger-0/+25
Docs: suggest `uN::checked_sub` instead of check-then-unchecked As of #124114 it's exactly the same in codegen, so might as well not use `unsafe`. Note that this is only for *unsigned*, since the overflow conditions for `iN::checked_sub` are more complicated.
2024-05-04Rollup merge of #124700 - scottmcm:unneeded_cast, r=NilstriebMatthias Krüger-1/+1
Remove an unnecessary cast Very minor thing, obviously, but I randomly saw this unnecessary cast showing up in the UbChecks, so might as well get rid of it.
2024-05-04Rollup merge of #124293 - oli-obk:miri_intrinsic_fallback_body, r=RalfJungMatthias Krüger-2/+10
Let miri and const eval execute intrinsics' fallback bodies fixes https://github.com/rust-lang/miri/issues/3397 r? ``@RalfJung``
2024-05-04Docs: suggest `uN::checked_sub` instead of check-then-uncheckedScott McMurray-0/+25
As of 124114 it's exactly the same in codegen, so might as well not use `unsafe`. Note that this is only for *unsigned*, since the overflow conditions for `iN::checked_sub` are more complicated.
2024-05-04Remove an unnecessary castScott McMurray-1/+1
Very minor thing, obviously, but I randomly saw this unnecessary cast showing up in the UbChecks, so might as well get rid of it.
2024-05-04Use `unchecked_sub` in `split_at`Scott McMurray-3/+8
2024-05-04mark const_(de)allocate intrinsics as suitable for MiriRalf Jung-2/+7
2024-05-03Rollup merge of #124678 - UserIsntAvailable:feat/stabilize-split-at-checked, ↵Michael Goulet-15/+6
r=jhpratt Stabilize `split_at_checked` Closes #119128 For the const version of `slice::split_at_mut_checked`, I'm reusing the `const_slice_split_at_mut` feature flag (#101804). I don't if it okay to reuse tracking issues or if it preferred to create new ones...
2024-05-03feat: stabilize `split_at_checked`UserIsntAvailable-15/+6
2024-05-03Rollup merge of #124593 - GKFX:cstr-literals-in-api-docs, r=workingjubileeMatthias Krüger-13/+24
Describe and use CStr literals in CStr and CString docs Mention CStr literals in the description of both types, and use them in some of the code samples for CStr. This is intended to make C string literals more discoverable. Additionally, I don't think the orange "This example is not tested" warnings are very encouraging, so I have made the examples on `CStr` build.
2024-05-03Rollup merge of #123815 - trueb2:patch-1, r=workingjubileeMatthias Krüger-2/+2
Fix cannot usage in time.rs Fix a small grammar error in usage of cannot in time.rs errors
2024-05-03Rollup merge of #122492 - GrigorenkoPV:ptr_as_ref_unchecked, r=workingjubileeMatthias Krüger-0/+151
Implement ptr_as_ref_unchecked Implementation of #122034. Prefixed the feature name with `ptr_` for clarity. Linked const-unstability to #91822, so the post there should probably be updated to mentions the 3 new methods when/if this PR is merged.
2024-05-03Use `CURRENT_RUSTC_VERSION`Артём Павлов [Artyom Pavlov]-2/+2
2024-05-03Stabilize `div_duration`Артём Павлов [Artyom Pavlov]-4/+2
2024-05-03Ensure miri only uses fallback bodies that have manually been vetted to ↵Oli Scherer-0/+3
preserve all UB that the native intrinsic would have
2024-05-03Rollup merge of #124626 - RalfJung:const_eval_select, r=joboetMatthias Krüger-2/+1
const_eval_select: add tracking issue
2024-05-03Rollup merge of #123480 - Nadrieril:impl-all-derefpures, r=compiler-errorsMatthias Krüger-3/+15
deref patterns: impl `DerefPure` for more std types Context: [deref patterns](https://github.com/rust-lang/rust/issues/87121). The requirements of `DerefPure` aren't precise yet, but these types unambiguously satisfy them. Interestingly, a hypothetical `impl DerefMut for Cow` that does a `Clone` would *not* be eligible for `DerefPure` if we allow mixing deref patterns with normal patterns. If the following is exhaustive then the `DerefMut` would cause UB: ```rust match &mut Cow::Borrowed(&()) { Cow::Owned(_) => ..., // Doesn't match deref!(_x) if false => ..., // Causes the variant to switch to `Owned` Cow::Borrowed(_) => ..., // Doesn't match // We reach unreachable } ```
2024-05-02Update based on reviewGeorge Bateman-7/+7
2024-05-02const_eval_select: add tracking issueRalf Jung-2/+1
2024-05-02add constants in std::f128::constsTrevor Spiteri-1/+110
2024-05-02add constants in std::f16::constsTrevor Spiteri-1/+106
2024-05-02add f128 associated constantsTrevor Spiteri-1/+83
NaN and infinity are not included as they require arithmetic.