Commit Graph

6652 Commits

Author SHA1 Message Date
León Orell Valerian Liehr
3873a74f8a
Rollup merge of #124307 - reitermarkus:escape-debug-size-hint-inline, r=joboet
Optimize character escaping.

Allow optimization of panicking branch in `EscapeDebug`, see https://github.com/rust-lang/rust/pull/121805.

r? `@joboet`
2024-05-15 14:21:37 +02:00
Jacob Pratt
74a78af0e2
Rollup merge of #116675 - joshlf:patch-10, r=scottmcm
[ptr] Document maximum allocation size

Partially addresses https://github.com/rust-lang/unsafe-code-guidelines/issues/465
2024-05-13 21:14:15 -04:00
Joshua Liebow-Feeser
293b5cb1ca [ptr] Document maximum allocation size 2024-05-13 11:14:45 -07:00
Joshua Liebow-Feeser
15df3d78e4
References must also be non-null 2024-05-11 12:08:19 -07:00
Joshua Liebow-Feeser
1cefaa7432
Relax slice safety requirements
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-11 11:50:20 -07:00
Matthias Krüger
6c3fce90cc
Rollup merge of #124954 - kpreid:fmterr, r=Nilstrieb
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-11 13:16:40 +02:00
Matthias Krüger
03ff775966
Rollup merge of #124928 - okaneco:trim_ascii, r=workingjubilee
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-11 13:16:40 +02:00
okaneco
9fb49faf40 Stabilize byte_slice_trim_ascii for &[u8]/&str
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-10 23:42:40 -04:00
Infinixius
781d737478
Fix typo in ManuallyDrop's documentation 2024-05-10 23:13:32 +00:00
bors
cf774742b6 Auto merge of #124863 - DaniPopes:from-str-radix-panic, r=Amanieu
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-10 11:48:15 +00:00
Matthias Krüger
f3f9f0c5e6
Rollup merge of #124551 - Swatinem:debug-str-bench, r=cuviper
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-10 07:30:19 +02:00
Kevin Reid
c21c5baad9 Document proper usage of fmt::Error and fmt()'s Result.
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-09 17:58:38 -07:00
Markus Reiter
4edf12d33e
Improve escape methods. 2024-05-09 17:04:30 +02:00
bors
ee9a9f84c5 Auto merge of #124793 - scottmcm:simplify-as-chunks, r=Nilstrieb
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-09 01:55:46 +00:00
bors
87293c9585 Auto merge of #124910 - matthiaskrgr:rollup-lo1uvdn, r=matthiaskrgr
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-08 21:47:34 +00:00
Markus Reiter
16981ba406
Avoid panicking branch in EscapeIterInner. 2024-05-08 21:52:32 +02:00
Markus Reiter
e3fc97be2b
Inline EscapeDebug::size_hint. 2024-05-08 21:52:31 +02:00
bors
ec1b69852f Auto merge of #124795 - scottmcm:simplify-slice-from-raw-parts, r=joboet
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-08 19:37:57 +00:00
Markus Reiter
bd8e565e16
Use generic NonZero. 2024-05-08 21:37:55 +02:00
Markus Reiter
767711b905
Use generic NonZero in examples. 2024-05-08 21:37:53 +02:00
Jubilee
ceb5ec3ad9
Rollup merge of #124838 - RalfJung:next_power_of_two, r=scottmcm
next_power_of_two: add a doctest to show what happens on 0
2024-05-08 00:37:11 -07:00
DaniPopes
eac37b6caf
from_str_radix: outline only the panic function 2024-05-08 00:20:06 +02:00
bors
cc8d9b6927 Auto merge of #124836 - tgross35:const-slice-last-chunk, r=BurntSushi
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-07 12:40:20 +00:00
Ralf Jung
776f182241 next_power_of_two: add a doctest to show what happens on 0 2024-05-07 10:48:04 +02:00
Trevor Gross
3488679768 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-07 03:03:44 -05:00
Trevor Spiteri
fac0a74450 f16::is_sign_{positive,negative} were feature-gated on f128 2024-05-06 23:36:47 +02:00
bors
fc47cf38e5 Auto merge of #123850 - tspiteri:f16_f128_consts, r=Amanieu
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-06 14:45:28 +00:00
Scott McMurray
61517dbbe6 Avoid a cast in ptr::slice_from_raw_parts(_mut)
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-06 01:53:54 -07:00
Scott McMurray
49af347653 Implement as_chunks with split_at_unchecked 2024-05-06 01:04:27 -07:00
Guillaume Gomez
4eedf7385b
Rollup merge of #124750 - ultrabear:ultrabear_softfloatdoc, r=workingjubilee
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-05 16:42:48 +02:00
Alex H
5aa2f9a208
Make f128 docs mention lack of any normal platform support
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-04 14:51:55 -07:00
Alex H
3ef25288a4
Make f16 and f128 docs clearer on platform support
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-04 14:51:35 -07:00
Alex H
e30ad6ff2c
Tgross feedback tweaks
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-04 14:51:13 -07:00
Matthias Krüger
a5cc1f663f
Rollup merge of #124699 - scottmcm:split_at_unchecked_should_use_unchecked, 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-04 18:36:38 +02:00
Matthias Krüger
5f4f4fbb98
Rollup merge of #124701 - scottmcm:unchecked_sub_docs, r=Nilstrieb
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-04 12:37:24 +02:00
Matthias Krüger
770567101c
Rollup merge of #124700 - scottmcm:unneeded_cast, r=Nilstrieb
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-04 12:37:24 +02:00
Matthias Krüger
ceb7b5e70e
Rollup merge of #124293 - oli-obk:miri_intrinsic_fallback_body, r=RalfJung
Let miri and const eval execute intrinsics' fallback bodies

fixes https://github.com/rust-lang/miri/issues/3397

r? ``@RalfJung``
2024-05-04 12:37:22 +02:00
Scott McMurray
e1c833eb07 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-04 01:44:49 -07:00
Scott McMurray
b95d1b716f 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-04 01:25:39 -07:00
Scott McMurray
f1de4c16ee Use unchecked_sub in split_at 2024-05-04 00:54:21 -07:00
Ralf Jung
4e97c6c5c7 mark const_(de)allocate intrinsics as suitable for Miri 2024-05-04 08:40:42 +02:00
Michael Goulet
93ca906cb5
Rollup merge of #124678 - UserIsntAvailable:feat/stabilize-split-at-checked, 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-03 23:34:24 -04:00
UserIsntAvailable
4c286c7f9a feat: stabilize split_at_checked 2024-05-03 15:02:02 -04:00
Matthias Krüger
1ff247c404
Rollup merge of #124593 - GKFX:cstr-literals-in-api-docs, r=workingjubilee
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-03 20:33:46 +02:00
Matthias Krüger
4b913a2330
Rollup merge of #123815 - trueb2:patch-1, r=workingjubilee
Fix cannot usage in time.rs

Fix a small grammar error in usage of cannot in time.rs errors
2024-05-03 20:33:44 +02:00
Matthias Krüger
a296693376
Rollup merge of #122492 - GrigorenkoPV:ptr_as_ref_unchecked, r=workingjubilee
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-03 20:33:44 +02:00
Oli Scherer
821d23b329 Ensure miri only uses fallback bodies that have manually been vetted to preserve all UB that the native intrinsic would have 2024-05-03 09:16:57 +00:00
Matthias Krüger
e2a53441b9
Rollup merge of #124626 - RalfJung:const_eval_select, r=joboet
const_eval_select: add tracking issue
2024-05-03 06:04:23 +02:00
Matthias Krüger
e17a222a0a
Rollup merge of #123480 - Nadrieril:impl-all-derefpures, r=compiler-errors
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-03 06:04:19 +02:00
George Bateman
0e0042f16e
Update based on review 2024-05-02 21:29:13 +01:00