about summary refs log tree commit diff
path: root/library/core
AgeCommit message (Collapse)AuthorLines
2024-05-12reverse condition in `uN::checked_sub`ivan-shrimp-3/+3
2024-05-11References must also be non-nullJoshua Liebow-Feeser-0/+1
2024-05-11Relax slice safety requirementsJoshua Liebow-Feeser-1/+1
Per https://github.com/rust-lang/rust/pull/116677#issuecomment-1945495786, the language as written promises too much. This PR relaxes the language to be consistent with current semantics. If and when #117945 is implemented, we can revert to the old language.
2024-05-11Add opt-for-size core lib feature flagDion Dokter-0/+2
2024-05-11Rollup merge of #124954 - kpreid:fmterr, r=NilstriebMatthias Krüger-15/+35
Document proper usage of `fmt::Error` and `fmt()`'s `Result`. I've seen several newcomers wonder why `fmt::Error` doesn't have any error detail information, or propose to return it in response to an error condition found inside a `impl fmt::Display for MyType`. That is incorrect, per [a lone paragraph of 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: every `fmt()` method, and `fmt::Error`. This PR is not intended to make any novel claims about `fmt`; only to repeat an existing one in places where it will be more visible.
2024-05-11Rollup merge of #124928 - okaneco:trim_ascii, r=workingjubileeMatthias Krüger-21/+15
Stabilize `byte_slice_trim_ascii` for `&[u8]`/`&str` Remove feature from documentation examples Update intra-doc link for `u8::is_ascii_whitespace` on `&[u8]` functions Closes #94035 FCP has successfully completed https://github.com/rust-lang/rust/issues/94035#issuecomment-2102690397
2024-05-10Stabilize `byte_slice_trim_ascii` for `&[u8]`/`&str`okaneco-21/+15
Remove feature from documentation examples Add rustc_const_stable attribute to stabilized functions Update intra-doc link for `u8::is_ascii_whitespace` on `&[u8]` functions
2024-05-10Fix typo in ManuallyDrop's documentationInfinixius-1/+1
2024-05-10Auto merge of #124863 - DaniPopes:from-str-radix-panic, r=Amanieubors-6/+6
from_str_radix: outline only the panic function In the `{integer}::from_str_radix` function, the radix check is labeled as `cold` and `inline(never)`, along with its corresponding panic. It probably was intended to apply these attributes only to the panic function.
2024-05-10Fix assertRenato Alves-1/+1
2024-05-10Rollup merge of #124551 - Swatinem:debug-str-bench, r=cuviperMatthias Krüger-0/+80
Add benchmarks for `impl Debug for str` In order to inform future perf improvements and prevent regressions, lets add some benchmarks that stress `impl Debug for str`. --- As I am currently working on improving the perf in https://github.com/rust-lang/rust/pull/121150, its nice to have these benchmarks. Writing them, I also saw that escapes are written out one char at a time, even though other parts of the code are already optimizing that via `as_str`, which I intend to do as well as a followup improvement. r? ``@cuviper`` ☝🏻 as you were also assigned to https://github.com/rust-lang/rust/pull/121150, CC ``@the8472`` if you want to steal the review :-)
2024-05-10Refactor examples and enhance documentation in result.rsRenato Alves-4/+8
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.