Commit graph

7514 commits

Author SHA1 Message Date
Matthias Krüger 27d7fb0cfa
Rollup merge of #129668 - coolreader18:fix-pin-set-regr, r=dtolnay
Fix Pin::set bounds regression

Fixes #129601

Fixes the regression from #129449, where changing the bounds of the impl block containing `Pin::set` changed the method resolution behavior.

```rust
struct A;
impl A {
    fn set(&self) {}
}

let a: Pin<&A>;
a.set();
// before:
// - checks <impl<Ptr: DerefMut> Pin<Ptr>>::set(): `&A` doesn't impl `DerefMut`
// - autorefs -> &A: resolves to A::set()
// now:
// - checks <impl<Ptr: Deref> Pin<Ptr>>::set(): `&A` impls `Deref`! resolves to Pin::set()
// - check method bounds: `&A` doesn't impl DerefMut: error
```

r? `@dtolnay`
2024-08-28 17:12:20 +02:00
Matthias Krüger 29188a54b3
Rollup merge of #129657 - jswrenn:transmute-name, r=compiler-errors
Rename `BikeshedIntrinsicFrom` to `TransmuteFrom`

As our implementation of MCP411 nears completion and we begin to solicit testing, it's no longer reasonable to expect testers to type or remember `BikeshedIntrinsicFrom`. The name degrades the ease-of-reading of documentation, and the overall experience of using compiler safe transmute.

Tentatively, we'll instead adopt `TransmuteFrom`.

This name seems to be the one most likely to be stabilized, after discussion on Zulip [1]. We may want to revisit the ordering of `Src` and `Dst` before stabilization, at which point we'd likely consider `TransmuteInto` or `Transmute`.

[1] https://rust-lang.zulipchat.com/#narrow/stream/216762-project-safe-transmute/topic/What.20should.20.60BikeshedIntrinsicFrom.60.20be.20named.3F

Tracking Issue: https://github.com/rust-lang/rust/issues/99571

r​? `@compiler-errors`
2024-08-28 17:12:18 +02:00
Matthias Krüger 015620869d
Rollup merge of #129551 - RalfJung:ub-checks-fallback, r=saethlin
ub_checks intrinsics: fall back to cfg(ub_checks)

Not sure why the fallback body uses `debug_assertions`, probably a leftover from when `cfg!(ub_checks)` did not exist yet?

r? `@saethlin`
2024-08-28 17:12:12 +02:00
Matthias Krüger 56ca2e23fe
Rollup merge of #129480 - lolbinarycat:euclid-docs, r=joboet
docs: correct panic conditions for rem_euclid and similar functions

fixes https://github.com/rust-lang/rust/issues/128857

also fixes the documentation for functions behind the `int_roundings` feature (#88581)
2024-08-28 17:12:12 +02:00
Ben Kimock 83de14c4ff Enable some ilog2 tests as well 2024-08-28 10:45:30 -04:00
bors ac77e88f7a Auto merge of #129589 - saethlin:improve-panic-immediate-abort, r=tgross35
Tweak some attributes to improve panic_immediate_abort

This is similar to https://github.com/rust-lang/rust/pull/117332; I did the same approach as before where I build a really big project with `-Zbuild-std -Zbuild-std-features=panic_immediate_abort` and grep its symbols for things that look panic-related.
2024-08-28 13:13:09 +00:00
Ralf Jung b5bd0fe48a addr_of on places derived from raw pointers should preserve permissions 2024-08-28 10:32:31 +02:00
Noa 0d6c9152fa
Fix Pin::set bounds regression 2024-08-27 16:32:46 -05:00
Matthias Krüger ac0cc709c3
Rollup merge of #129652 - RalfJung:ptr-to-ref, r=traviscross
fix Pointer to reference conversion docs

The aliasing rules documented in https://github.com/rust-lang/rust/pull/128157 are wrong, this fixes them.
2024-08-27 18:59:30 +02:00
Matthias Krüger 02491259c2
Rollup merge of #129645 - beetrees:fix-float-docs, r=tgross35
Fix typos in floating-point primitive type docs

Fixes a few typos. Also reflows the text of a couple of paragraphs in the source code to the standard line width to make the source easier to read (will have no effect on the rendered documentation).
2024-08-27 18:59:29 +02:00
Jack Wrenn 1ad218f3af safe transmute: Rename BikeshedIntrinsicFrom to TransmuteFrom
As our implementation of MCP411 nears completion and we begin to
solicit testing, it's no longer reasonable to expect testers to
type or remember `BikeshedIntrinsicFrom`. The name degrades the
ease-of-reading of documentation, and the overall experience of
using compiler safe transmute.

Tentatively, we'll instead adopt `TransmuteFrom`.

This name seems to be the one most likely to be stabilized, after
discussion on Zulip [1]. We may want to revisit the ordering of
`Src` and `Dst` before stabilization, at which point we'd likely
consider `TransmuteInto` or `Transmute`.

[1] https://rust-lang.zulipchat.com/#narrow/stream/216762-project-safe-transmute/topic/What.20should.20.60BikeshedIntrinsicFrom.60.20be.20named.3F
2024-08-27 14:05:54 +00:00
Ralf Jung ab4a743a38 fix Pointer to reference conversion docs 2024-08-27 12:28:43 +02:00
Ralf Jung 1ef4f5d924 clarify that addr_of creates read-only pointers 2024-08-27 12:21:35 +02:00
Lukas Bergdoll 7815d77ee0 Use last swap optimization in bubblesort 2024-08-27 10:10:29 +02:00
Trevor Gross 75ae913ec0
Rollup merge of #129559 - RalfJung:float-nan-semantics, r=thomcc
float types: document NaN bit pattern guarantees

Part of https://github.com/rust-lang/rust/issues/128288: document the guarantees we make for NaN bit patterns.

Cc ``@tgross35``
2024-08-27 01:46:53 -05:00
Trevor Gross d2ff033302
Rollup merge of #128731 - RalfJung:simd-shuffle-vector, r=workingjubilee
simd_shuffle intrinsic: allow argument to be passed as vector

See https://github.com/rust-lang/rust/issues/128738 for context.

I'd like to get rid of [this hack](6c0b89dfac/compiler/rustc_codegen_ssa/src/mir/block.rs (L922-L935)). https://github.com/rust-lang/rust/pull/128537 almost lets us do that since constant SIMD vectors will then be passed as immediate arguments. However, simd_shuffle for some reason actually takes an *array* as argument, not a vector, so the hack is still required to ensure that the array becomes an immediate (which then later stages of codegen convert into a vector, as that's what LLVM needs).

This PR prepares simd_shuffle to also support a vector as the `idx` argument. Once this lands, stdarch can hopefully be updated to pass `idx` as a vector, and then support for arrays can be removed, which finally lets us get rid of that hack.
2024-08-27 01:46:50 -05:00
beetrees d0548359b5
Reflow a couple of paragraphs in floating-point primitive docs 2024-08-27 05:26:28 +01:00
beetrees 969f9702da
Fix typos in floating-point primitive type docs 2024-08-27 05:25:34 +01:00
Matthias Krüger 29923b6801
Rollup merge of #129032 - jswrenn:transmute-method, r=compiler-errors
Document & implement the transmutation modeled by `BikeshedIntrinsicFrom`

Documents that `BikeshedIntrinsicFrom` models transmute-via-union, which is slightly more expressive than the transmute-via-cast implemented by `transmute_copy`. Additionally, we provide an implementation of transmute-via-union as a method on the `BikeshedIntrinsicFrom` trait with additional documentation on the boundary between trait invariants and caller obligations.

Whether or not transmute-via-union is the right kind of transmute to model remains up for discussion [1]. Regardless, it seems wise to document the present behavior.

[1] https://rust-lang.zulipchat.com/#narrow/stream/216762-project-safe-transmute/topic/What.20'kind'.20of.20transmute.20to.20model.3F/near/426331967

Tracking Issue: https://github.com/rust-lang/rust/issues/99571

r? `@compiler-errors`

cc `@scottmcm,` `@Lokathor`
2024-08-27 00:41:59 +02:00
Matthias Krüger c6ceb5be24
Rollup merge of #128157 - lolbinarycat:unify-ptr-ref-docs, r=cuviper
deduplicate and clarify rules for converting pointers to references

part of #124669
2024-08-27 00:41:58 +02:00
Josh Stone b11e0a883b
Apply suggestions from code review 2024-08-26 12:36:58 -07:00
Matthias Krüger b9dfb4d6f8
Rollup merge of #129592 - saethlin:core-cfg-test, r=tgross35
Remove cfg(test) from library/core

The diff here is very small with the ignore whitespace option.

`core` doesn't/can't have unit tests. All of its tests are just modules under `tests/`, so it has no use for `cfg(test)`, because the entire contents of `library/core/src` are only ever compiled with that cfg off, and the entire contents of `library/core/tests` are only ever compiled with that cfg on.

You can tell this is what's happening because we had `#[cfg(test)]` on a module declaration that has no source file.

I also deleted the extra `mod tests {` layer of nesting; there's no need to mention again in the module path that this is a module of tests. This exposes a name collision between the `u128` module of tests and `core::u128`. Fixed that by using `<u128>::MAX` like is done in the `check!` macro, which is what avoids this name ambiguity for the other types.
2024-08-26 17:25:33 +02:00
Matthias Krüger b1c9064071
Rollup merge of #129539 - oconnor663:poll_link, r=tgross35
link to Future::poll from the Poll docs

The most important thing about Poll is that Future::poll returns it, but previously the docs didn't emphasize this.
2024-08-26 17:25:32 +02:00
Matthias Krüger 68aff290fd
Rollup merge of #129377 - chorman0773:unbounded-shifts-impl, r=scottmcm
Add implementations for `unbounded_shl`/`unbounded_shr`

Tracking Issue: https://github.com/rust-lang/rust/issues/129375

This implements `unbounded_shl` and `unbounded_shr` under the feature gate `unbounded_shifts`
2024-08-26 17:25:31 +02:00
Ralf Jung 53d4544628 move per-target NaN info into a table 2024-08-26 17:20:40 +02:00
Ralf Jung fe2975076f float types: document NaN bit pattern guarantees 2024-08-26 17:20:40 +02:00
Lukas Bergdoll 8756ba56b0 Convert cfg blocks to cfg_if 2024-08-26 12:21:37 +02:00
Lukas Bergdoll 89c9a2908f Reduce code duplication by moving partition_lomuto_branchless_simple into quicksort module 2024-08-26 11:17:38 +02:00
bors f48062e7d0 Auto merge of #129595 - matthiaskrgr:rollup-4udn7nn, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #129288 (Use subtyping for `UnsafeFnPointer` coercion, too)
 - #129405 (Fixing span manipulation and indentation of the suggestion introduced by #126187)
 - #129518 (gitignore: ignore ICE reports regardless of directory)
 - #129519 (Remove redundant flags from `lower_ty_common` that can be inferred from the HIR)
 - #129525 (rustdoc: clean up tuple <-> primitive conversion docs)
 - #129526 (Use `FxHasher` on new solver unconditionally)
 - #129544 (Removes dead code from the compiler)
 - #129553 (add back test for stable-const-can-only-call-stable-const)
 - #129590 (Avoid taking reference of &TyKind)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-08-26 05:45:40 +00:00
Ben Kimock 4f3ef2ac90 Remove cfg(test) from library/core 2024-08-25 20:04:26 -04:00
Matthias Krüger aa26e1ad97
Rollup merge of #129525 - notriddle:notriddle/fake-variadic-tuple-array, r=GuillaumeGomez
rustdoc: clean up tuple <-> primitive conversion docs

This adds a minor missing feature to `fake_variadic`, so that it can render `impl From<(T,)> for [T; 1]` correctly.
2024-08-26 01:49:02 +02:00
bors 3f121b9461 Auto merge of #129488 - saethlin:alignment-precondition, r=workingjubilee
Enable Alignment::new_unchecked precondition check

Similar to what happened with https://github.com/rust-lang/rust/pull/126556, I think this has become palatable since https://github.com/rust-lang/rust/pull/126793.
2024-08-25 23:45:25 +00:00
Ben Kimock b1c2c78d29 Tweak some attributes to improve panic_immediate_abort 2024-08-25 14:52:53 -04:00
Lukas Bergdoll 13d7b546da Add binary-size optimized variants for stable and unstable sort as well as select_nth_unstable
- Stable sort uses a simple merge-sort that re-uses the existing - rather gnarly - merge function.
- Unstable sort jumps directly to the branchless heapsort fallback.
- select_nth_unstable jumps directly to the median_of_medians fallback, which is augmented with a
  custom tiny smallsort and partition impl.

Some code is duplicated but de-duplication would bring it's own problems. For example `swap_if_less`
is critical for performance, if the sorting networks don't inline it perf drops drastically,
however `#[inline(always)]` is also a poor fit, if the provided comparison function is huge,
it gives the compiler an out to only instantiate `swap_if_less` once and call it. Another aspect
that would suffer when making `swap_if_less` pub, is having to cfg out dozens of functions in
in smallsort module.
2024-08-25 20:47:01 +02:00
Jack O'Connor 3153b7d7b4 link to Future::poll from the Poll docs
The most important thing about Poll is that Future::poll returns it, but
previously the docs didn't emphasize this.
2024-08-25 08:35:06 -07:00
Matthias Krüger 9c59e97ded
Rollup merge of #129487 - GrigorenkoPV:repr_transparent_external_private_fields, r=compiler-errors
repr_transparent_external_private_fields: special-case some std types

Fixes #129470

```@rustbot``` label +A-lint +L-repr_transparent_external_private_fields
2024-08-25 16:51:05 +02:00
Ralf Jung a772db4206 ub_checks intrinsics: fall back to cfg(ub_checks) 2024-08-25 13:15:48 +02:00
bors 717aec0f8e Auto merge of #129521 - matthiaskrgr:rollup-uigv77m, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #128596 (stabilize const_fn_floating_point_arithmetic)
 - #129199 (make writes_through_immutable_pointer a hard error)
 - #129246 (Retroactively feature gate `ConstArgKind::Path`)
 - #129290 (Pin `cc` to 1.0.105)
 - #129323 (Implement `ptr::fn_addr_eq`)
 - #129500 (remove invalid `TyCompat` relation for effects)
 - #129501 (panicking: improve hint for Miri's RUST_BACKTRACE behavior)
 - #129505 (interpret: ImmTy: tighten sanity checks in offset logic)
 - #129510 (Fix `elided_named_lifetimes` in code)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-08-25 08:12:16 +00:00
Trevor Gross e96faab70b
Rollup merge of #129449 - coolreader18:pin-as_deref_mut-signature, r=dtolnay
Put Pin::as_deref_mut in impl Pin<Ptr> / rearrange Pin methods

Tracking issue: #86918

Based on the suggestion in https://github.com/rust-lang/rust/issues/86918#issuecomment-2189367582

> Some advantages:
>
>  * Synergy with the existing `as_ref` and `as_mut` signatures (stable since Rust 1.33)
>
>  * Lifetime elision reduces noise in the signature
>
>  * Turbofish less verbose: `Pin::<&mut T>::as_deref_mut` vs `Pin::<&mut Pin<&mut T>>::as_deref_mut`

The comment seemed to imply that `Pin::as_ref` and `Pin::as_mut` already share an impl block, which they don't. So, I rearranged it so that they do, and we can see which looks better in the docs.

<details><summary><b>Docs screenshots</b></summary>

Current nightly:
![image](https://github.com/user-attachments/assets/b432cb82-8f4b-48ae-bafc-2fe49d0ad48c)

`Pin::as_deref_mut` moved into the same block as `as_mut`:
![image](https://github.com/user-attachments/assets/f9b35722-6a88-4465-ad1c-28d8e91902ac)

`Pin::as_ref`, `as_mut`, and `as_deref_mut` all in the same block:
![image](https://github.com/user-attachments/assets/9a1b2bf0-70a6-4751-b13f-390f1d575244)

</details>

I think I like the last one the most; obviously I'm biased since I'm the one who rearranged it, but it doesn't make sense to me to have `as_ref` methods split up by an `into_inner` method.

r? dtolnay
2024-08-24 21:03:33 -05:00
Trevor Gross 198a68df1c
Rollup merge of #128735 - jieyouxu:pr-120176-revive, r=cjgillot
Add a special case for `CStr`/`CString` in the `improper_ctypes` lint

Revives #120176. Just needed to bless a test and fix an argument, but seemed reasonable to me otherwise.

Instead of saying to "consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct", we now tell users to "Use `*const ffi::c_char` instead, and pass the value from `CStr::as_ptr()`" when the type involved is a `CStr` or a `CString`.

The suggestion is not made for `&mut CString` or `*mut CString`.

r? ``````@cjgillot`````` (since you were the reviewer of the original PR #120176, but feel free to reroll)
2024-08-24 21:03:31 -05:00
Michael Howell 6df0ccf49e rustdoc: clean up tuple <-> primitive conversion docs
This adds a minor missing feature to `fake_variadic`,
so that it can render `impl From<(T,)> for [T; 1]` correctly.
2024-08-24 14:06:57 -07:00
Matthias Krüger 3f5d6b2e40
Rollup merge of #129500 - fee1-dead-contrib:fxrel, r=compiler-errors
remove invalid `TyCompat` relation for effects

if the current impl uses `Maybe` (`impl const`), the parent impl must use `Maybe` (`impl const`) as well.

I'd like to rename `TyCompat` to `Sub` which is probably clearer. But it would conflict with my other PR.

r? ``@rust-lang/project-const-traits``
2024-08-24 22:14:14 +02:00
Matthias Krüger 2c4338802a
Rollup merge of #129323 - Urgau:ptr_fn_addr_eq, r=Mark-Simulacrum
Implement `ptr::fn_addr_eq`

This PR implements https://github.com/rust-lang/libs-team/issues/323: `ptr::fn_addr_eq`.

r? libs
2024-08-24 22:14:13 +02:00
Matthias Krüger 0dfdea1c45
Rollup merge of #128596 - RalfJung:const_fn_floating_point_arithmetic, r=nnethercote
stabilize const_fn_floating_point_arithmetic

Part of https://github.com/rust-lang/rust/issues/128288
Fixes https://github.com/rust-lang/rust/issues/57241

The existing test `tests/ui/consts/const_let_eq_float.rs`  ([link](https://github.com/RalfJung/rust/blob/const_fn_floating_point_arithmetic/tests/ui/consts/const_let_eq_float.rs)) covers the basics, and also Miri has extensive tests covering the interpreter's float machinery. Also, that machinery can already be used on stable inside `const`/`static` initializers, just not inside `const fn`.

This was explicitly called out in https://github.com/rust-lang/rfcs/pull/3514 so in a sense t-lang just recently already FCP'd this, but let's hear from them whether they want another FCP for the stabilization here or whether that was covered by the FCP for the RFC.
Cc ``@rust-lang/lang``

### Open items

- [x] Update the Reference: https://github.com/rust-lang/reference/pull/1566
2024-08-24 22:14:11 +02:00
Pavel Grigorenko b9033bdd92 New #[rustc_pub_transparent] attribute 2024-08-24 23:05:37 +03:00
Deadbeef 378902e325 remove invalid TyCompat relation for effects 2024-08-24 14:24:21 +08:00
StackOverflowExcept1on c2fdb3435f
Pass fmt::Arguments by reference to PanicInfo and PanicMessage 2024-08-24 02:20:36 +03:00
Ben Kimock 5d98d20529 Enable Alignment::new_unchecked precondition check 2024-08-23 18:26:45 -04:00
Trevor Gross e76b7d029c Change f16 doctests in core to run on x86-64 linux
Since `f16` now works on x86 and x86-64, change doctests to use this
instead of aarch64. This is to make sure any changes get run in PR CI.
2024-08-23 14:21:57 -05:00
binarycat d7e7886b3c docs: correct panic conditions for rem_euclid and similar functions
fixes https://github.com/rust-lang/rust/issues/128857
2024-08-23 14:47:21 -04:00
Noa c65ef3d37c
Move into_inner_unchecked back to the bottom of the impl block 2024-08-23 13:06:26 -05:00
Noa b968b26c03
Put Pin::as_deref_mut in impl Pin<Ptr> 2024-08-23 12:45:05 -05:00
Jack Wrenn 2540070fd4 document & impl the transmutation modeled by BikeshedIntrinsicFrom
Documents that `BikeshedIntrinsicFrom` models transmute-via-union,
which is slightly more expressive than the transmute-via-cast
implemented by `transmute_copy`. Additionally, we provide an
implementation of transmute-via-union as a method on the
`BikeshedIntrinsicFrom` trait with additional documentation on
the boundary between trait invariants and caller obligations.

Whether or not transmute-via-union is the right kind of transmute
to model remains up for discussion [1]. Regardless, it seems wise
to document the present behavior.

[1] https://rust-lang.zulipchat.com/#narrow/stream/216762-project-safe-transmute/topic/What.20'kind'.20of.20transmute.20to.20model.3F/near/426331967
2024-08-23 14:37:36 +00:00
Guillaume Gomez 26672c93d5
Rollup merge of #129276 - eduardosm:stabilize-char_indices_offset, r=Amanieu
Stabilize feature `char_indices_offset`

Stabilized API:

```rust
impl CharIndices<'_> {
    pub fn offset(&self) -> usize;
}
```

Tracking issue: https://github.com/rust-lang/rust/issues/83871

Closes https://github.com/rust-lang/rust/issues/83871

I also attempted to improved the documentation to make it more clear that it returns the offset of the character that will be returned by the next call to `next()`.
2024-08-23 12:32:15 +02:00
binarycat 988bc1c654 fix typos in new pointer conversion docs 2024-08-22 14:25:54 -04:00
Connor Horman f4dc7830ed feat(core): Make unbounded_shl{l,r} unstably const and remove rustc_allow_const_fn_unstable 2024-08-22 10:28:48 +00:00
bors 8269be147b Auto merge of #129398 - matthiaskrgr:rollup-50l01ry, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #128432 (WASI: forbid `unsafe_op_in_unsafe_fn` for `std::{os, sys}`)
 - #129373 (Add missing module flags for CFI and KCFI sanitizers)
 - #129374 (Use `assert_unsafe_precondition!` in `AsciiChar::digit_unchecked`)
 - #129376 (Change `assert_unsafe_precondition` docs to refer to `check_language_ub`)
 - #129382 (Add `const_cell_into_inner` to `OnceCell`)
 - #129387 (Advise against removing the remaining Python scripts from `tests/run-make`)
 - #129388 (Do not rely on names to find lifetimes.)
 - #129395 (Pretty-print own args of existential projections (dyn-Trait w/ GAT constraints))

r? `@ghost`
`@rustbot` modify labels: rollup
2024-08-22 08:20:49 +00:00
Ralf Jung ebfa3e3f62 stabilize const_fn_floating_point_arithmetic 2024-08-22 08:25:54 +02:00
Matthias Krüger 28d4b8248e
Rollup merge of #129382 - tgross35:once-cell-const-into-inner, r=Noratrieb
Add `const_cell_into_inner` to `OnceCell`

`Cell` and `RefCell` have their `into_inner` methods const unstable. `OnceCell` has the same logic, so add it under the same gate.

Tracking issue: https://github.com/rust-lang/rust/issues/78729
2024-08-22 08:17:22 +02:00
Matthias Krüger ae58bbfbce
Rollup merge of #129376 - ChaiTRex:assert_unsafe_precondition_check_language_ub, r=workingjubilee,the8472
Change `assert_unsafe_precondition` docs to refer to `check_language_ub`
2024-08-22 08:17:21 +02:00
Matthias Krüger e7df7ba1e4
Rollup merge of #129374 - ChaiTRex:digit_unchecked_assert_unsafe_precondition, r=scottmcm
Use `assert_unsafe_precondition!` in `AsciiChar::digit_unchecked`
2024-08-22 08:17:20 +02:00
bors 739b1fdb15 Auto merge of #129365 - matthiaskrgr:rollup-ebwx6ya, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #127279 (use old ctx if has same expand environment during decode span)
 - #127945 (Implement `debug_more_non_exhaustive`)
 - #128941 ( Improve diagnostic-related lints: `untranslatable_diagnostic` & `diagnostic_outside_of_impl`)
 - #129070 (Point at explicit `'static` obligations on a trait)
 - #129187 (bootstrap: fix clean's remove_dir_all implementation)
 - #129231 (improve submodule updates)
 - #129264 (Update `library/Cargo.toml` in weekly job)
 - #129284 (rustdoc: animate the `:target` highlight)
 - #129302 (compiletest: use `std::fs::remove_dir_all` now that it is available)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-08-22 05:17:27 +00:00
Connor Horman 2cf48eaebc fix(core): Use correct operations/values in unbounded_shr doctests 2024-08-22 00:08:03 +00:00
Connor Horman 27b63b85ec chore: x fmt 2024-08-21 23:38:04 +00:00
Connor Horman 9907f617ab fix(core): Add #![feature(unbounded_shifts)] to doctests for unbounded_shr/unbounded_shl 2024-08-21 23:22:07 +00:00
Trevor Gross 81c00dde2b Add const_cell_into_inner to OnceCell
`Cell` and `RefCell` have their `into_inner` methods const unstable.
`OnceCell` has the same logic, so add it under the same gate.

Tracking issue: https://github.com/rust-lang/rust/issues/78729
2024-08-21 17:36:05 -05:00
Connor Horman 79cbb878c7 chore: x fmt and hopefully fix the tidy issue 2024-08-21 21:37:50 +00:00
Chai T. Rex c836739529 Change assert_unsafe_precondition docs to refer to check_language_ub 2024-08-21 17:35:54 -04:00
Connor Horman 38b5a2a67e chore: Also format the control flow 2024-08-21 21:23:25 +00:00
Connor Horman c89bae0ea8 Manually format functions and use rhs instead of v from my CE testing 2024-08-21 21:16:18 +00:00
Connor Horman 9b5a004bf8 feat(core): Add implementations for unbounded_shl/unbounded_shr 2024-08-21 20:57:50 +00:00
Chai T. Rex 191862d701 Use assert_unsafe_precondition! in AsciiChar::digit_unchecked 2024-08-21 16:26:35 -04:00
Matthias Krüger 3fb8faa653
Rollup merge of #129321 - krtab:float_sum, r=workingjubilee
Change neutral element of <fNN as iter::Sum> to neg_zero

The neutral element used to be positive zero, but +0 + -0 = +0 so -0 seems better indicated.
2024-08-21 21:58:28 +02:00
Matthias Krüger 65386c045e
Rollup merge of #127945 - tgross35:debug-more-non-exhaustive, r=Noratrieb
Implement `debug_more_non_exhaustive`

This implements the ACP at https://github.com/rust-lang/libs-team/issues/248, adding `.finish_non_exhaustive()` for `DebugTuple`, `DebugSet`, `DebugList`, and `DebugMap`.

Also used this as an opportunity to make some documentation and tests more readable by using raw strings instead of escaped quotes.

Tracking issue: https://github.com/rust-lang/rust/issues/127942
2024-08-21 19:35:10 +02:00
Matthias Krüger 349f29992b
Rollup merge of #129312 - tbu-:pr_str_not_impl_error, r=Noratrieb
Fix stability attribute of `impl !Error for &str`

It was introduced in bf7611d55e (#99917), which was included in Rust 1.65.0.
2024-08-21 18:15:03 +02:00
Tobias Bucher 123bb585f8 Fix stability attribute of impl !Error for &str
It was introduced in bf7611d55e (#99917),
which was included in Rust 1.65.0.
2024-08-21 16:21:40 +02:00
bors 982c6f8721 Auto merge of #126556 - saethlin:layout-precondition, r=joboet
Add a precondition check for Layout::from_size_align_unchecked

Ran into this while looking into https://github.com/rust-lang/miri/issues/3679. This is of course not the cause of the ICE, but the reproducer doesn't encounter a precondition check and it ought to.
2024-08-21 12:50:05 +00:00
Ben Kimock e6b0f27e00 Try to golf down the amount of code in Layout 2024-08-20 18:41:07 -04:00
Urgau 4325ac9652 Implement ptr::fn_addr_eq 2024-08-20 19:27:29 +02:00
Arthur Carcano 4908188518 Change neutral element of <fNN as iter::Sum> to neg_zero
The neutral element used to be positive zero, but +0 + -0 = +0 so
-0 seems better indicated.
2024-08-20 18:45:53 +02:00
Scott McMurray dfea11d620 Stabilize iter::repeat_n 2024-08-19 22:39:04 -07:00
Ben Kimock 7f5d282185 Add a precondition check for Layout::from_size_align_unchecked 2024-08-19 17:18:17 -04:00
Eduardo Sánchez Muñoz dbad758134 Stabilize feature char_indices_offset 2024-08-19 20:31:48 +02:00
Kornel 56fb89acee
Document futility of printing temporary pointers 2024-08-18 22:12:23 +01:00
Ralf Jung b8464961a2 soft-deprecate the addr_of macros 2024-08-18 19:46:53 +02:00
bors c6f81a452e Auto merge of #126877 - GrigorenkoPV:clone_to_uninit, r=dtolnay
CloneToUninit impls

As per #126799.

Also implements it for `Wtf8` and both versions of `os_str::Slice`.

Maybe it is worth to slap `#[inline]` on some of those impls.

r? `@dtolnay`
2024-08-17 11:39:08 +00:00
bors 426a60abc2 Auto merge of #128598 - RalfJung:float-comments, r=workingjubilee
float to/from bits and classify: update for float semantics RFC

With https://github.com/rust-lang/rfcs/pull/3514 having been accepted, it is clear that hardware which e.g. flushes subnormal to zero is just non-conformant from a Rust perspective -- this is a hardware bug, or maybe an LLVM backend bug (where LLVM doesn't lower floating-point ops in a way that they have the standardized behavior). So update the comments here to make it clear that we don't have to do any of this, we're just being nice.

Also remove the subnormal/NaN checks from the (unstable) const-version of to/from-bits; they are not needed since we decided with the aforementioned RFC that it is okay to get a different result at const-time and at run-time.

r? `@workingjubilee` since I think you wrote many of the comments I am editing here.
2024-08-17 09:13:13 +00:00
bors f24a6ba06f Auto merge of #106943 - mina86:exact_size_take_repeat, r=dtolnay
Implement DoubleEnded and ExactSize for Take<Repeat> and Take<RepeatWith>

Repeat iterator always returns the same element and behaves the same way
backwards and forwards.  Take iterator can trivially implement backwards
iteration over Repeat inner iterator by simply doing forwards iteration.

DoubleEndedIterator is not currently implemented for Take<Repeat<T>>
because Repeat doesn’t implement ExactSizeIterator which is a required
bound on DEI implementation for Take.

Similarly, since Repeat is an infinite iterator which never stops, Take
can trivially know how many elements it’s going to return.  This allows
implementing ExactSizeIterator on Take<Repeat<T>>.

While at it, observe that ExactSizeIterator can also be implemented for
Take<RepeatWhile<F>> so add that implementation too.  Since in contrast
to Repeat, RepeatWhile doesn’t guarante to always return the same value,
DoubleEndedIterator isn’t implemented.

Those changes render core::iter::repeat_n somewhat redundant.

Issue: https://github.com/rust-lang/rust/issues/104434
Issue: https://github.com/rust-lang/rust/issues/104729

- [ ] ACP: https://github.com/rust-lang/libs-team/issues/120 (this is actually ACP for repeat_n but this is nearly the same functionality so hijacking it so both approaches can be discussed in one place)
2024-08-17 01:46:24 +00:00
bors 67d09736ea Auto merge of #116528 - daxpedda:stabilize-ready-into-inner, r=dtolnay
Stabilize `Ready::into_inner()`

This PR stabilizes `Ready::into_inner()`.

Tracking issue: #101196.
Implementation PR: #101189.

Closes #101196.
2024-08-16 23:20:38 +00:00
Matthias Krüger 9d57e46f81
Rollup merge of #129086 - slanterns:is_none_or, r=dtolnay
Stabilize `is_none_or`

Closes: https://github.com/rust-lang/rust/issues/126383.

`@rustbot` label: +T-libs-api

r? libs-api
2024-08-16 19:58:58 +02:00
Ralf Jung 368a4c6808 float to/from bits and classify: update comments regarding non-conformant hardware 2024-08-16 10:11:36 +02:00
Jubilee f624f2d3f9
Rollup merge of #128064 - ijackson:noop-waker-doc, r=workingjubilee
Improve docs for Waker::noop and LocalWaker::noop

 * Add a warning about a likely misuse.  (See my commit message for longer rationale.)
 * Apply some probably-accidentally-omitted changes to `LocalWaker`'s docs
 * Add a comment about the clone-and-hack of the docs

I have used [semantic linefeeds](https://rhodesmill.org/brandon/2012/one-sentence-per-line/) for the docs formatting.
2024-08-15 18:44:15 -07:00
Ian Jackson 9a95573c2b Add cautionary paragraph about noop wakers.
Based on a suggestion from @kpreid, with some further editing.
2024-08-15 16:18:49 +01:00
Matthias Krüger cd1b42c3e9
Rollup merge of #128946 - orlp:faster-ip-hash, r=joboet
Hash Ipv*Addr as an integer

The `Ipv4Addr` and `Ipv6Addr` structs always have a fixed size, but directly derive `Hash`. This causes them to call the bytestring hasher implementation, which adds extra work for most hashers. This PR converts the internal representation to a fixed-width integer before passing to the hasher to prevent this.
2024-08-15 00:02:25 +02:00
Matthias Krüger 9938349c71
Rollup merge of #128925 - dingxiangfei2009:smart-ptr-helper-attr, r=compiler-errors
derive(SmartPointer): register helper attributes

Fix #128888

This PR enables built-in macros to register helper attributes, if any, to support correct name resolution in the correct lexical scope under the macros.

Also, `#[pointee]` is moved into the scope under `derive(SmartPointer)`.

cc `@Darksonn` `@davidtwco`
2024-08-15 00:02:25 +02:00
The 8472 6d8f0bd930 apply #[optimize(size)] to #[cold] ones and part of the panick machinery 2024-08-14 20:50:04 +02:00
许杰友 Jieyou Xu (Joe) 049b3e549e
Rollup merge of #128954 - zachs18:fromresidual-no-default, r=scottmcm
Explicitly specify type parameter on FromResidual for Option and ControlFlow.

~~Remove type parameter default `R = <Self as Try>::Residual` from `FromResidual`~~ _Specify default type parameter on `FromResidual` impls in the stdlib_ to work around https://github.com/rust-lang/rust/issues/99940 / https://github.com/rust-lang/rust/issues/87350 ~~as mentioned in https://github.com/rust-lang/rust/issues/84277#issuecomment-1773259264~~.

This does not completely fix the issue, but works around it for `Option` and `ControlFlow` specifically (`Result` does not have the issue since it already did not use the default parameter of `FromResidual`).

~~(Does this need an ACP or similar?)~~ ~~This probably needs at least an FCP since it changes the API described in [the RFC](https://github.com/rust-lang/rfcs/pull/3058). Not sure if T-lang, T-libs-api, T-libs, or some combination (The tracking issue is tagged T-lang, T-libs-api).~~ This probably doesn't need T-lang input, since it is not changing the API of `FromResidual` from the RFC? Maybe needs T-libs-api FCP?
2024-08-14 21:43:08 +08:00
许杰友 Jieyou Xu (Joe) 196d256b20
Rollup merge of #128570 - folkertdev:stabilize-asm-const, r=Amanieu
Stabilize `asm_const`

tracking issue: https://github.com/rust-lang/rust/issues/93332

reference PR: https://github.com/rust-lang/reference/pull/1556

this will probably require some CI wrangling (and a rebase), so let's get that over with even though the final required PR is not merged yet.

r? `@ghost`
2024-08-14 21:43:07 +08:00
Slanterns aec9116757
stabilize option_get_or_insert_default 2024-08-14 18:35:58 +08:00
Slanterns e2ec11502d
stabilize is_none_or 2024-08-14 18:28:40 +08:00
bors fbce03b195 Auto merge of #129060 - matthiaskrgr:rollup-s72gpif, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #122884 (Optimize integer `pow` by removing the exit branch)
 - #127857 (Allow to customize `// TODO:` comment for deprecated safe autofix)
 - #129034 (Add `#[must_use]` attribute to `Coroutine` trait)
 - #129049 (compiletest: Don't panic on unknown JSON-like output lines)
 - #129050 (Emit a warning instead of an error if `--generate-link-to-definition` is used with other output formats than HTML)
 - #129056 (Fix one usage of target triple in bootstrap)
 - #129058 (Add mw back to review rotation)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-08-14 06:43:26 +00:00
Matthias Krüger a4261a0bc0
Rollup merge of #129001 - cblh:fix/128713, r=Noratrieb
chore(lib): Enhance documentation for core::fmt::Formatter's write_fm…

fix: #128713
2024-08-14 05:05:52 +02:00
Folkert 8419c0956e stabilize asm_const 2024-08-13 23:18:31 +02:00
Matthias Krüger d4f5a89f6e
Rollup merge of #129034 - henryksloan:coroutine-must-use, r=joboet
Add `#[must_use]` attribute to `Coroutine` trait

[Coroutines tracking issue](https://github.com/rust-lang/rust/issues/43122)

Like closures (`FnOnce`, `AsyncFn`, etc.), coroutines are lazy and do nothing unless called (resumed). Closure traits like `FnOnce` have `#[must_use = "closures are lazy and do nothing unless called"]` to catch likely bugs for users of APIs that produce them. This PR adds such a `#[must_use]` attribute to `trait Coroutine`.
2024-08-13 21:11:13 +02:00
Matthias Krüger bc9c31df69
Rollup merge of #122884 - mzabaluev:pow-remove-exit-branch, r=Amanieu
Optimize integer `pow` by removing the exit branch

The branch at the end of the `pow` implementations is redundant with multiplication code already present in the loop. By rotating the exit check, this branch can be largely removed, improving code size and reducing instruction cache misses.

Testing on my machine (`x86_64`, 11th Gen Intel Core i5-1135G7 @ 2.40GHz), the `num::int_pow` benchmarks improve by some 40% for the unchecked operations and show some slight improvement for the checked operations as well.
2024-08-13 21:11:12 +02:00
Guillaume Gomez 475824d811 Mark location doctest as standalone since file information will not work in merged doctest file 2024-08-13 20:14:55 +02:00
Ralf Jung 194baa820d simd_shuffle intrinsic: allow argument to be passed as vector (not just as array) 2024-08-13 07:51:17 +02:00
Mikhail Zabaluev ac88b330b8 Revert to original loop for const pow exponents
Give LLVM the for original, optimizable loop in pow and wrapped_pow
functions in the case when the exponent is statically known.
2024-08-13 08:32:36 +03:00
bors 591ecb88df Auto merge of #128742 - RalfJung:miri-vtable-uniqueness, r=saethlin
miri: make vtable addresses not globally unique

Miri currently gives vtables a unique global address. That's not actually matching reality though. So this PR enables Miri to generate different addresses for the same type-trait pair.

To avoid generating an unbounded number of `AllocId` (and consuming unbounded amounts of memory), we use the "salt" technique that we also already use for giving constants non-unique addresses: the cache is keyed on a "salt" value n top of the actually relevant key, and Miri picks a random salt (currently in the range `0..16`) each time it needs to choose an `AllocId` for one of these globals -- that means we'll get up to 16 different addresses for each vtable. The salt scheme is integrated into the global allocation deduplication logic in `tcx`, and also used for functions and string literals. (So this also fixes the problem that casting the same function to a fn ptr over and over will consume unbounded memory.)

r? `@saethlin`
Fixes https://github.com/rust-lang/miri/issues/3737
2024-08-13 04:32:34 +00:00
Henry Sloan 1e445f48d4 Add must_use attribute to Coroutine trait 2024-08-12 19:27:57 -07:00
burlinchen c4333026a0 chore(lib): fmt core::fmt::Formatter's write_fmt method 2024-08-13 08:40:08 +08:00
Matthias Krüger 522d43673a
Rollup merge of #129017 - its-the-shrimp:core_fmt_from_fn, r=Noratrieb
Replace `std::fmt:FormatterFn` with `std::fmt::from_fn`

Modelled after the suggestion made in [this](https://github.com/rust-lang/rust/issues/117729#issuecomment-1837628559) comment, this should bring this functionality in line with the existing `array::from_fn` & `iter::from_fn`
2024-08-12 23:10:52 +02:00
Ding Xiang Fei 5534cb0a4a
derive(SmartPointer): register helper attributes 2024-08-13 04:26:48 +08:00
Zachary S 1b6df71192 Explicitly specify type parameter on FromResidual impls in stdlib.
To work around coherence issue. Also adds regression test.
2024-08-12 12:54:18 -05:00
schvv31n 027b19fa9b std::fmt::FormatterFn -> std::fmt::FromFn 2024-08-12 18:33:30 +01:00
Guillaume Gomez 095ca33bb6
Rollup merge of #128149 - RalfJung:nontemporal_store, r=jieyouxu,Amanieu,Jubilee
nontemporal_store: make sure that the intrinsic is truly just a hint

The `!nontemporal` flag for stores in LLVM *sounds* like it is just a hint, but actually, it is not -- at least on x86, non-temporal stores need very special treatment by the programmer or else the Rust memory model breaks down. LLVM still treats these stores as-if they were normal stores for optimizations, which is [highly dubious](https://github.com/llvm/llvm-project/issues/64521). Let's avoid all that dubiousness by making our own non-temporal stores be truly just a hint, which is possible on some targets (e.g. ARM). On all other targets, non-temporal stores become regular stores.

~~Blocked on https://github.com/rust-lang/stdarch/pull/1541 propagating to the rustc repo, to make sure the `_mm_stream` intrinsics are unaffected by this change.~~

Fixes https://github.com/rust-lang/rust/issues/114582
Cc `@Amanieu` `@workingjubilee`
2024-08-12 17:09:14 +02:00
burlinchen 72ef357ea3 chore(lib): Enhance documentation for core::fmt::Formatter's write_fmt method 2024-08-12 17:37:30 +08:00
Ralf Jung 4763d12207 ignore some vtable/fn ptr equality tests in Miri, their result is not fully predictable 2024-08-12 10:39:11 +02:00
joboet 8301dd4767
core: make documentation clearer, rename slice comparison specialization trait 2024-08-12 10:20:32 +02:00
bors 1d8f135b20 Auto merge of #128862 - cblh:fix/128855, r=scottmcm
fix:  #128855 Ensure `Guard`'s `drop` method is removed at `opt-level=s` for `…

fix: #128855

…Copy` types

Added `#[inline]` to the `drop` method in the `Guard` implementation to ensure that the method is removed by the compiler at optimization level `opt-level=s` for `Copy` types. This change aims to align the method's behavior with optimization expectations and ensure it does not affect performance.

r​? `@scottmcm`
2024-08-12 05:22:03 +00:00
bors 13f8a57cfb Auto merge of #126793 - saethlin:mono-rawvec, r=scottmcm
Apply "polymorphization at home" to RawVec

The idea here is to move all the logic in RawVec into functions with explicit size and alignment parameters. This should eliminate all the fussing about how tweaking RawVec code produces large swings in compile times.

This uncovered https://github.com/rust-lang/rust-clippy/issues/12979, so I've modified the relevant test in a way that tries to preserve the spirit of the test without tripping the ICE.
2024-08-12 01:47:06 +00:00
Orson Peters fce1decc3c Do not use unnecessary endian conversion. 2024-08-11 14:55:29 +02:00
Matthias Krüger 2c88eb9805
Rollup merge of #128882 - RalfJung:local-waker-will-wake, r=cuviper
make LocalWaker::will_wake consistent with Waker::will_wake

This mirrors https://github.com/rust-lang/rust/pull/119863 for `LocalWaker`. Looks like that got missed in the initial `LocalWaker` PR (https://github.com/rust-lang/rust/pull/118960).
2024-08-11 07:51:52 +02:00
Matthias Krüger e8f6819db7
Rollup merge of #120314 - mina86:i, r=Mark-Simulacrum
core: optimise Debug impl for ascii::Char

Rather than writing character at a time, optimise Debug implementation
for core::ascii::Char such that it writes the entire representation
with a single write_str call.

With that, add tests for Display and Debug.

Issue: https://github.com/rust-lang/rust/issues/110998
2024-08-11 07:51:49 +02:00
Orson Peters a04a1e464f Fix stability annotation and expand comment 2024-08-11 01:28:30 +02:00
Orson Peters ba62034430 Hash Ipv*Addr as an integer 2024-08-10 23:52:35 +02:00
bors 04ba50e823 Auto merge of #128927 - GuillaumeGomez:rollup-ei2lr0f, r=GuillaumeGomez
Rollup of 8 pull requests

Successful merges:

 - #128273 (Improve `Ord` violation help)
 - #128807 (run-make: explaing why fmt-write-bloat is ignore-windows)
 - #128903 (rustdoc-json-types `Discriminant`: fix typo)
 - #128905 (gitignore: Add Zed and Helix editors)
 - #128908 (diagnostics: do not warn when a lifetime bound infers itself)
 - #128909 (Fix dump-ice-to-disk for RUSTC_ICE=0 users)
 - #128910 (Differentiate between methods and associated functions in diagnostics)
 - #128923 ([rustdoc] Stop showing impl items for negative impls)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-08-10 15:13:38 +00:00
Guillaume Gomez 65875b2f5a
Rollup merge of #128273 - Voultapher:improve-ord-violation-help, r=workingjubilee
Improve `Ord` violation help

Recent experience in #128083 showed that the panic message when an Ord violation is detected by the new sort implementations can be confusing. So this PR aims to improve it, together with minor bug fixes in the doc comments for sort*, sort_unstable* and select_nth_unstable*.

Is it possible to get these changes into the 1.81 release? It doesn't change behavior and would greatly help when users encounter this panic for the first time, which they may after upgrading to 1.81.

Tagging `@orlp`
2024-08-10 16:23:51 +02:00
Nadrieril c256de2253 Update std and compiler 2024-08-10 12:07:17 +02:00
Ben Kimock d6c0ebef50 Polymorphize RawVec 2024-08-09 20:06:26 -04:00
Michal Nazarewicz 7d1de7f994 core: optimise Debug impl for ascii::Char
Rather than writing character at a time, optimise Debug implementation
for core::ascii::Char such that it writes the entire representation as
with a single write_str call.

With that, add tests for Display and Debug implementations.
2024-08-09 22:50:57 +02:00
Ralf Jung ae09340350 make LocalWaker::will_wake consistent with Waker::will_wake 2024-08-09 18:05:57 +02:00
Lukas Bergdoll 1be60b5d2b Fix linkchecker issue 2024-08-09 15:05:37 +02:00
burlinchen bca0c5f2a9 fix: Ensure Guard's drop method is removed at opt-level=s for Copy types
Added `#[inline]` to the `drop` method in the `Guard` implementation to ensure that the method is removed by the compiler at optimization level `opt-level=s` for `Copy` types. This change aims to align the method's behavior with optimization expectations and ensure it does not affect performance.
2024-08-09 11:10:30 +08:00
Matthias Krüger 127fbc8481
Rollup merge of #128749 - tgross35:float-inline, r=scottmcm
Mark `{f32,f64}::{next_up,next_down,midpoint}` inline

Most float functions are marked `#[inline]` so any float symbols used by these functions only need to be provided if the function itself is used. RFL recently noticed that `next_up`, `next_down`, and `midpoint` for `f32` and `f64` are not inline, which causes linker errors when building with certain configurations <https://lore.kernel.org/all/20240806150619.192882-1-ojeda@kernel.org/>.

Add the missing attributes so the symbols should no longer be required.
2024-08-08 18:57:02 +02:00
Matthias Krüger 3a9dd829d0
Rollup merge of #128306 - WiktorPrzetacznik:WiktorPrzetacznik-nonnull-alignoffset-update, r=Amanieu
Update NonNull::align_offset quarantees

This PR proposes to update [`NonNull::align_offset`](https://doc.rust-lang.org/stable/std/ptr/struct.NonNull.html#method.align_offset) guarantees, which should to be matched with [`ptr::align_offset`](https://doc.rust-lang.org/stable/std/primitive.pointer.html#method.align_offset-1)
(as `NonNull::align_offset` delegates to `ptr::align_offset`).

[PR #121201](https://github.com/rust-lang/rust/pull/121201) updated only `ptr::align_offset` docs.
2024-08-08 18:57:00 +02:00
ltdk 0257f42089 Add tracking issue to core-pattern-type 2024-08-07 20:43:05 -04:00
daxpedda 0732f7d5e1
Stabilize Ready::into_inner() 2024-08-08 00:18:19 +02:00
Trevor Gross 6b3feb49c6 Mark {f32,f64}::{next_up,next_down,midpoint} inline
Most float functions are marked `#[inline]` so any float symbols used by
these functions only need to be provided if the function itself is used.
RFL recently noticed that `next_up`, `next_down`, and `midpoint` for
`f32` and `f64` are not inline, which causes linker errors when building
with certain configurations [1].

Add the missing attributes so the symbols should no longer be required.

Cc: Gary Guo <gary@garyguo.net>
Reported-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/all/20240806150619.192882-1-ojeda@kernel.org/ [1]
2024-08-07 03:24:55 -05:00
Trevor Gross b3bfd66627
Rollup merge of #128417 - tgross35:f16-f128-math, r=dtolnay
Add `f16` and `f128` math functions

This adds intrinsics and math functions for `f16` and `f128` floating point types. Support is quite limited and some things are broken so tests don't run on many platforms, but this provides a starting point.
2024-08-06 22:17:32 -05:00
Matthias Krüger 16b251be10
Rollup merge of #125048 - dingxiangfei2009:stable-deref, r=amanieu
PinCoerceUnsized trait into core

cc ``@Darksonn`` ``@wedsonaf`` ``@ojeda``

This is a PR to introduce a `PinCoerceUnsized` trait in order to make trait impls generated by the proc-macro `#[derive(SmartPointer)]`, proposed by [RFC](e17e19ac7a/text/3621-derive-smart-pointer.md (pincoerceunsized-1)), sound. There you may find explanation, justification and discussion about the alternatives.

Note that we do not seek stabilization of this `PinCoerceUnsized` trait in the near future. The stabilisation of this trait does not block the eventual stabilization process of the `#[derive(SmartPointer)]` macro. Ideally, use of `DerefPure` is more preferrable except this will actually constitute a breaking change. `PinCoerceUnsized` emerges as a solution to the said soundness hole while avoiding the breaking change. More details on the `DerefPure` option have been described in this [section](e17e19ac7a/text/3621-derive-smart-pointer.md (derefpure)) of the RFC linked above.

Earlier discussion can be found in this [Zulip stream](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/Pin.20and.20soundness.20of.20unsizing.20coercions) and [rust-for-linux thread](https://rust-lang.zulipchat.com/#narrow/stream/425075-rust-for-linux/topic/.23.5Bderive.28SmartPointer.29.5D.20and.20pin.20unsoundness.20rfc.233621).

try-job: dist-various-2
2024-08-07 00:34:11 +02:00
Flying-Toast b335ec9ec8 Add a special case for CStr/CString in the improper_ctypes lint
Instead of saying to "consider adding a `#[repr(C)]` or
`#[repr(transparent)]` attribute to this struct", we now tell users to
"Use `*const ffi::c_char` instead, and pass the value from
`CStr::as_ptr()`" when the type involved is a `CStr` or a `CString`.

Co-authored-by: Jieyou Xu <jieyouxu@outlook.com>
2024-08-06 13:56:59 +00:00
Ralf Jung 212417b87f custom MIR: add support for tail calls 2024-08-05 18:23:14 +02:00
Ralf Jung 28e0907111 nontemporal_store: make sure that the intrinsic is truly just a hint 2024-08-05 10:57:14 +02:00
Matthias Krüger 74df517b90
Rollup merge of #128619 - glandium:last_chunk, r=scottmcm
Correct the const stabilization of `<[T]>::last_chunk`

`<[T]>::first_chunk` became const stable in 1.77, but `<[T]>::last_chunk` was left out. This was fixed in 3488679768, which reached stable in 1.80, making `<[T]>::last_chunk` const stable as of that version, but it is documented as being const stable as 1.77. While this is what should have happened, the documentation should reflect what actually did happen.
2024-08-05 08:22:24 +02:00
Matthias Krüger 1e951b70c7
Rollup merge of #128609 - swenson:smaller-faster-dragon, r=Amanieu
Remove unnecessary constants from flt2dec dragon

The "dragon" `flt2dec` algorithm uses multi-precision multiplication by (sometimes large) powers of 10. It has precomputed some values to help with these calculations.

BUT:

* There is no need to store powers of 10 and 2 * powers of 10: it is trivial to compute the second from the first.
* We can save a chunk of memory by storing powers of 5 instead of powers of 10 for the large powers (and just shifting as appropriate).
* This also slightly speeds up the routines (by ~1-3%) since the intermediate products are smaller and the shift is cheap.

In this PR, we remove the unnecessary constants and do the necessary adjustments.

Relevant benchmarks before (on my Threadripper 3970X, x86_64-unknown-linux-gnu):

```
num::flt2dec::bench_big_shortest                      137.92/iter   +/- 2.24
num::flt2dec::strategy:🐉:bench_big_exact_12   2135.28/iter  +/- 38.90
num::flt2dec::strategy:🐉:bench_big_exact_3     904.95/iter  +/- 10.58
num::flt2dec::strategy:🐉:bench_big_exact_inf 47230.33/iter +/- 320.84
num::flt2dec::strategy:🐉:bench_big_shortest   3915.05/iter  +/- 51.37
```

and after:

```
num::flt2dec::bench_big_shortest                      137.40/iter   +/- 2.03
num::flt2dec::strategy:🐉:bench_big_exact_12   2101.10/iter  +/- 25.63
num::flt2dec::strategy:🐉:bench_big_exact_3     873.86/iter   +/- 4.20
num::flt2dec::strategy:🐉:bench_big_exact_inf 47468.19/iter +/- 374.45
num::flt2dec::strategy:🐉:bench_big_shortest   3877.01/iter  +/- 45.74
```
2024-08-05 08:22:22 +02:00
Mike Hommey 70ab51f988 Correct the const stabilization of <[T]>::last_chunk
`<[T]>::first_chunk` became const stable in 1.77, but `<[T]>::last_chunk` was
left out. This was fixed in 3488679768, which reached stable in 1.80,
making `<[T]>::last_chunk` const stable as of that version, but it is
documented as being const stable as 1.77. While this is what should have
happened, the documentation should reflect what actually did happen.
2024-08-05 05:01:39 +09:00
Konippi 341511ad4e refactor: standardize duplicate processes in parser 2024-08-04 21:39:42 +09:00
Matthias Krüger c8a33f7e34
Rollup merge of #128526 - tshepang:patch-1, r=Amanieu
time.rs: remove "Basic usage text"

Only one example is given (for each method)
2024-08-04 11:32:34 +02:00
bors b389b0ab72 Auto merge of #128466 - sayantn:stdarch-update, r=tgross35
Update the stdarch submodule

cc `@tgross35` `@Amanieu`
r? `@tgross35`

try-job: dist-various-2
2024-08-04 02:11:27 +00:00
sayantn 2cde11f2d1 Chore: add x86_amx_intrinsics feature flag to core/lib.rs and remove issue-120720-reduce-nan.rs 2024-08-04 03:08:18 +05:30
Matthias Krüger 53a56190af
Rollup merge of #128530 - scottmcm:repeat-n-unchecked, r=joboet
Implement `UncheckedIterator` directly for `RepeatN`

This just pulls the code out of `next` into `next_unchecked`, rather than making the `Some` and `unwrap_unchecked`ing it.

And while I was touching it, I added a codegen test that `array::repeat` for something that's just `Clone`, not `Copy`, still ends up optimizing to the same thing as `[x; n]`: <https://rust.godbolt.org/z/YY3a5ajMW>.
2024-08-03 20:51:52 +02:00
Christopher Swenson 36a805939e Remove unnecessary constants from flt2dec dragon
The "dragon" `flt2dec` algorithm uses multi-precision multiplication by
(sometimes large) powers of 10. It has precomputed some values to help
with these calculations.

BUT:

* There is no need to store powers of 10 and 2 * powers of 10: it is
  trivial to compute the second from the first.
* We can save a chunk of memory by storing powers of 5 instead of powers
  of 10 for the large powers (and just shifting by 2 as appropriate).
* This also slightly speeds up the routines (by ~1-3%) since the
  intermediate products are smaller and the shift is cheap.

In this PR, we remove the unnecessary constants and do the necessary
adjustments.

Relevant benchmarks before (on my Threadripper 3970X, x86_64-unknown-linux-gnu):

```
num::flt2dec::bench_big_shortest                      137.92/iter   +/- 2.24
num::flt2dec::strategy:🐉:bench_big_exact_12   2135.28/iter  +/- 38.90
num::flt2dec::strategy:🐉:bench_big_exact_3     904.95/iter  +/- 10.58
num::flt2dec::strategy:🐉:bench_big_exact_inf 47230.33/iter +/- 320.84
num::flt2dec::strategy:🐉:bench_big_shortest   3915.05/iter  +/- 51.37
```

and after:

```
num::flt2dec::bench_big_shortest                      137.40/iter   +/- 2.03
num::flt2dec::strategy:🐉:bench_big_exact_12   2101.10/iter  +/- 25.63
num::flt2dec::strategy:🐉:bench_big_exact_3     873.86/iter   +/- 4.20
num::flt2dec::strategy:🐉:bench_big_exact_inf 47468.19/iter +/- 374.45
num::flt2dec::strategy:🐉:bench_big_shortest   3877.01/iter  +/- 45.74
```
2024-08-03 08:49:38 -07:00
Lukas Bergdoll 613155c96a Apply review comments to PartialOrd section 2024-08-03 15:10:27 +02:00
bors 1f47624f9a Auto merge of #128404 - compiler-errors:revert-dead-code-changes, r=pnkfelix
Revert recent changes to dead code analysis

This is a revert to recent changes to dead code analysis, namely:
* efdf219 Rollup merge of #128104 - mu001999-contrib:fix/128053, r=petrochenkov
* a70dc297a8 Rollup merge of #127017 - mu001999-contrib:dead/enhance, r=pnkfelix
* 31fe9628cf Rollup merge of #127107 - mu001999-contrib:dead/enhance-2, r=pnkfelix
* 2724aeaaeb Rollup merge of #126618 - mu001999-contrib:dead/enhance, r=pnkfelix
* 977c5fd419 Rollup merge of #126315 - mu001999-contrib:fix/126289, r=petrochenkov
* 13314df21b Rollup merge of #125572 - mu001999-contrib:dead/enhance, r=pnkfelix

There is an additional change stacked on top, which suppresses false-negatives that were masked by this work. I believe the functions that are touched in that code are legitimately unused functions and the types are not reachable since this `AnonPipe` type is not publically reachable -- please correct me if I'm wrong cc `@NobodyXu` who added these in ##127153.

Some of these reverts (#126315 and #126618) are only included because it makes the revert apply cleanly, and I think these changes were only done to fix follow-ups from the other PRs?

I apologize for the size of the PR and the churn that it has on the codebase (and for reverting `@mu001999's` work here), but I'm putting this PR up because I am concerned that we're making ad-hoc changes to fix bugs that are fallout of these PRs, and I'd like to see these changes reimplemented in a way that's more separable from the existing dead code pass. I am happy to review any code to reapply these changes in a more separable way.

cc `@mu001999`
r? `@pnkfelix`

Fixes #128272
Fixes #126169
2024-08-03 13:04:30 +00:00
Michael Goulet 5f5b4ee128 Revert "Rollup merge of #127107 - mu001999-contrib:dead/enhance-2, r=pnkfelix"
This reverts commit 31fe9628cf, reversing
changes made to f20307851e.
2024-08-03 07:57:31 -04:00
Matthias Krüger 8aa18290a4
Rollup merge of #126704 - sayantn:sha, r=Amanieu
Added SHA512, SM3, SM4 target-features and `sha512_sm_x86` feature gate

This is an effort towards #126624. This adds support for these 3 target-features and introduces the feature flag `sha512_sm_x86`, which would gate these target-features and the yet-to-be-implemented detection and intrinsics in stdarch.
2024-08-03 11:17:41 +02:00
bors 19326022d2 Auto merge of #128254 - Amanieu:orig-binary-search, r=tgross35
Rewrite binary search implementation

This PR builds on top of #128250, which should be merged first.

This restores the original binary search implementation from #45333 which has the nice property of having a loop count that only depends on the size of the slice. This, along with explicit conditional moves from #128250, means that the entire binary search loop can be perfectly predicted by the branch predictor.

Additionally, LLVM is able to unroll the loop when the slice length is known at compile-time. This results in a very compact code sequence of 3-4 instructions per binary search step and zero branches.

Fixes #53823
Fixes #115271
2024-08-02 08:20:35 +00:00
Scott McMurray 77ca30f195 Implement UncheckedIterator directly for RepeatN 2024-08-01 21:58:34 -07:00
Matthias Krüger 67fcb58347
Rollup merge of #128453 - RalfJung:raw_eq, r=saethlin
raw_eq: using it on bytes with provenance is not UB (outside const-eval)

The current behavior of raw_eq violates provenance monotonicity. See https://github.com/rust-lang/rust/pull/124921 for an explanation of provenance monotonicity. It is violated in raw_eq because comparing bytes without provenance is well-defined, but adding provenance makes the operation UB.

So remove the no-provenance requirement from raw_eq. However, the requirement stays in-place for compile-time invocations of raw_eq, that indeed cannot deal with provenance.

Cc `@rust-lang/opsem`
2024-08-02 06:43:43 +02:00
Tshepang Mbambo af79a6396c
time.rs: remove "Basic usage text"
Only one example is given (for each method)
2024-08-02 05:16:01 +02:00
sayantn 41b017ec99 Add the sha512, sm3 and sm4 target features
Add the feature in `core/lib.rs`
2024-08-02 02:29:15 +05:30
Trevor Gross 8e2ca0c9d5 Add a disclaimer about x86 f128 math functions
Due to a LLVM bug, `f128` math functions link successfully but LLVM
chooses the wrong symbols (`long double` symbols rather than those for
binary128).

Since this is a notable problem that may surprise a number of users, add
a note about it.

Link: https://github.com/llvm/llvm-project/issues/44744
2024-08-01 15:38:53 -04:00
Trevor Gross 43836421f8 Update comments for {f16, f32, f64, f128}::midpoint
Clarify what makes some operations not safe, and correct comment in the
default branch ("not safe" -> "safe").
2024-08-01 15:38:53 -04:00
Trevor Gross e18036c769 Add core functions for f16 and f128 that require math routines
`min`, `max`, and similar functions require external math routines. Add
these under the same gates as `std` math functions (`reliable_f16_math`
and `reliable_f128_math`).
2024-08-01 15:38:53 -04:00
Trevor Gross 82b40c4d8e Add math intrinsics for f16 and f128
These already exist in the compiler. Expose them in core so we can add
their library functions.
2024-08-01 15:36:15 -04:00
Matthias Krüger ca73b8b7a5
Rollup merge of #128497 - Bryanskiy:fix-dropck-doc, r=lcnr
fix dropck documentation for `[T;0]` special-case

fixes https://github.com/rust-lang/rust/issues/110288.

r? ``@lcnr``
2024-08-01 18:43:41 +02:00
Lukas Bergdoll eae7a186b2 Hide internal sort module 2024-08-01 17:37:07 +02:00
Bryanskiy c8a3cafc0f fix dropck documentation for [T;0] special-case 2024-08-01 17:44:14 +03:00
joboet 88fda58bf5
core: use compare_bytes for more slice element types 2024-08-01 14:41:35 +02:00
Ralf Jung f97aba2271 raw_eq: using it on bytes with provenance is not UB (outside const-eval) 2024-07-31 20:26:20 +02:00
Lukas Bergdoll afc404fdfc Apply review comments
- Use if the implementation of [`Ord`] for `T`
  language
- Link to total order wiki page
- Rework total order help and examples
- Improve language to be more precise and less
  prone to misunderstandings.
- Fix usage of `sort_unstable_by` in `sort_by`
  example
- Fix missing author mention
- Use more consistent example input for sort
- Use more idiomatic assert_eq! in examples
- Use more natural "comparison function" language
  instead of "comparator function"
2024-07-31 11:36:57 +02:00
Xiangfei Ding d495b84a9a
PinCoerceUnsized trait into core 2024-07-31 17:10:55 +08:00
bors f8060d282d Auto merge of #128083 - Mark-Simulacrum:bump-bootstrap, r=albertlarsan68
Bump bootstrap compiler to new beta

https://forge.rust-lang.org/release/process.html#master-bootstrap-update-t-2-day-tuesday
2024-07-30 17:49:08 +00:00
Amanieu d'Antras bb58488207 Rewrite binary search implementation
This restores the original binary search implementation from #45333
which has the nice property of having a loop count that only depends on
the size of the slice. This, along with explicit conditional moves
from #128250, means that the entire binary search loop can be perfectly
predicted by the branch predictor.

Additionally, LLVM is able to unroll the loop when the slice length is
known at compile-time. This results in a very compact code sequence of
3-4 instructions per binary search step and zero branches.

Fixes #53823
2024-07-30 17:07:56 +01:00
bors 710ce90fbe Auto merge of #128250 - Amanieu:select_unpredictable, r=nikic
Add `select_unpredictable` to force LLVM to use CMOV

Since https://reviews.llvm.org/D118118, LLVM will no longer turn CMOVs into branches if it comes from a `select` marked with an `unpredictable` metadata attribute.

This PR introduces `core::intrinsics::select_unpredictable` which emits such a `select` and uses it in the implementation of `binary_search_by`.
2024-07-30 03:22:27 +00:00
Pavel Grigorenko 110c273f4f CloneToUninit: use a private specialization trait
and move implementation details into a submodule
2024-07-29 20:44:43 +03:00
Pavel Grigorenko dbc13fb309 Sparkle some attributes over CloneToUninit stuff 2024-07-29 20:44:42 +03:00
Pavel Grigorenko ec921db289 impl CloneToUninit for str and CStr 2024-07-29 20:33:11 +03:00
George Bateman 23f46e5b99
Stabilize offset_of_nested 2024-07-29 17:50:12 +01:00
Matthias Krüger 8f7af88b33
Rollup merge of #128307 - ojeda:unescaped_backticks, r=GuillaumeGomez
Clean and enable `rustdoc::unescaped_backticks` for `core/alloc/std/test/proc_macro`

I am not sure if the lint is supposed to be "ready enough" (since it is `allow` by default), but it does catch a couple issues in `core` (`alloc`, `std`, `test` and `proc_macro` are already clean), so I propose making it `warn` in all the crates rendered in the website.

Cc: `@GuillaumeGomez`
2024-07-29 11:42:35 +02:00
Miguel Ojeda dc815df1e1 Warn on rustdoc::unescaped_backticks for core/alloc/std/test/proc_macro
They are all clean now, so enable the lint to keep them clean going forward.

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2024-07-29 00:58:45 +02:00
Miguel Ojeda cf87203f48 Remove spurious backticks detected by rustdoc::unescaped_backticks
There are only 3 cases across the crates rendered in the website (`core`,
`alloc`, `std`, `proc_macro` and `test`), and they are all in `core`.

Clean them up, so that the lint can be enabled in the next commit.

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2024-07-29 00:57:08 +02:00
Nicholas Nethercote 84ac80f192 Reformat use declarations.
The previous commit updated `rustfmt.toml` appropriately. This commit is
the outcome of running `x fmt --all` with the new formatting options.
2024-07-29 08:26:52 +10:00
Mark Rousskov 5eca36d27a step cfg(bootstrap) 2024-07-28 14:46:29 -04:00
Mark Rousskov e8644f85b8 Update CURRENT_RUSTC_VERSION 2024-07-28 14:46:29 -04:00
Guillaume Gomez eeb76ccaf0
Rollup merge of #128240 - mbrubeck:patch-3, r=joboet
Add links from `assert_eq!` docs to `debug_assert_eq!`, etc.

This adds information and links from the docs for the following macros to their debug-only versions:

* `assert_eq!`
* `assert_ne!`
* `assert_matches!`

This matches the existing documentation for the `assert!` macro.
2024-07-28 20:07:46 +02:00
Guillaume Gomez ee5956fd8a
Rollup merge of #128228 - slanterns:const_waker, r=dtolnay,oli-obk
Stabilize `const_waker`

Closes: https://github.com/rust-lang/rust/issues/102012.

For `local_waker` and `context_ext` related things, I just ~~moved them to dedicated feature gates and reused their own tracking issue (maybe it's better to open a new one later, but at least they should not be tracked under https://github.com/rust-lang/rust/issues/102012 from the beginning IMO.)~~ reused their own feature gates as suggested by ``@tgross35.``

``@rustbot`` label: +T-libs-api

r? libs-api
2024-07-28 20:07:46 +02:00
Guillaume Gomez 0e45047e81
Rollup merge of #128103 - folkertdev:unsigned-int-is-multiple-of, r=Amanieu
add `is_multiple_of` for unsigned integer types

tracking issue: https://github.com/rust-lang/rust/issues/128101

This adds the `.is_multiple_of` method on unsigned integers.

Returns `true` if `self` is an integer multiple of `rhs`, and false otherwise.

This function is equivalent to `self % rhs == 0`, except that it will not panic for `rhs == 0`. Instead, `0.is_multiple_of(0) == true`, and for any non-zero `n`, `n.is_multiple_of(0) == false`.
2024-07-28 20:07:45 +02:00
Guillaume Gomez 506a6317be
Rollup merge of #127765 - bitfield:fix_stdlib_doc_nits, r=dtolnay
Fix doc nits

Many tiny changes to stdlib doc comments to make them consistent (for example "Returns foo", rather than "Return foo"), adding missing periods, paragraph breaks, backticks for monospace style, and other minor nits.
2024-07-28 20:07:44 +02:00
Amanieu d'Antras 4f78f9fbb0 Force LLVM to use CMOV for binary search
Since https://reviews.llvm.org/D118118, LLVM will no longer turn CMOVs
into branches if it comes from a `select` marked with an `unpredictable`
metadata attribute.

This PR introduces `core::intrinsics::select_unpredictable` which emits
such a `select` and uses it in the implementation of `binary_search_by`.
2024-07-28 17:24:57 +01:00
Slanterns 0a6ebbaf2e
stabilize const_waker 2024-07-28 22:31:13 +08:00
Wiktor Przetacznik 3d7aa163d6
Update NonNull::align_offset quarantees
Update NonNull::align_offset quarantees, keeping it in sync with ptr::align_offset
2024-07-28 16:08:08 +02:00
Matthias Krüger 32f6534c91
Rollup merge of #128282 - pitaj:nonzero_bitwise, r=workingjubilee
bitwise and bytewise methods on `NonZero`

Implementation for `nonzero_bitwise`
Tracking issue #128281
ACP https://github.com/rust-lang/libs-team/issues/413
2024-07-28 08:57:18 +02:00
Matthias Krüger 99204047c9
Rollup merge of #128279 - slanterns:is_sorted, r=dtolnay
Stabilize `is_sorted`

Closes: https://github.com/rust-lang/rust/issues/53485.

~~Question: does~~ 8fe0c753f2/compiler/rustc_lint_defs/src/builtin.rs (L1986-L1994) ~~need a new example?~~
edit: It causes a test failure and needs to be changed anyway.

``@rustbot`` label: +T-libs-api

r? libs-api
2024-07-28 08:57:17 +02:00
Slanterns ec0b354092
stabilize is_sorted 2024-07-28 03:11:54 +08:00
Peter Jaszkowiak c9e408e3f8 bitwise and bytewise methods on NonZero 2024-07-27 13:06:03 -06:00
Trevor Gross 51734a8a6d
Rollup merge of #125897 - RalfJung:from-ref, r=Amanieu
from_ref, from_mut: clarify documentation

This was brought up [here](https://github.com/rust-lang/rust/issues/56604#issuecomment-2143193486). The domain of quantification is generally always constrained by the type in the type signature, and I am not sure it's always worth spelling that out explicitly as that makes things exceedingly verbose. But since this was explicitly brought up, let's clarify.
2024-07-27 13:32:56 -04:00
Lukas Bergdoll 00ce238885 Improve panic sections for sort*, sort_unstable* and select_nth_unstable*
- Move panic information into # Panics section
- Fix mentions of T: Ord that should be compare
- Add missing information
2024-07-27 16:48:42 +02:00
Lukas Bergdoll 644550f3de Improve panic message and surrounding documentation for Ord violations
The new sort implementations have the ability to
detect Ord violations in many cases. This commit
improves the message in a way that should help
users realize what went wrong in their program.
2024-07-27 16:47:10 +02:00
bors ad3c5a3301 Auto merge of #128255 - stepancheg:doc-shl, r=scottmcm
Document 0x10.checked_shl(BITS - 1) does not overflow

Not obvious.
2024-07-27 07:11:32 +00:00
bors a526d7ce45 Auto merge of #127946 - tgross35:fmt-builders-set-result, r=cuviper
Always set `result` during `finish()` in debug builders

Most functions for format builders set `self.result` after writing strings. This ensures that any further writing fails immediately rather than trying to write again.

A few `.finish()` methods and the `.finish_non_exhaustive` did have this same behavior, so update the remaining `.finish()` methods to make it consistent here.
2024-07-27 02:26:30 +00:00
Stepan Koltsov 723336d835 Document int.checked_shl(BITS - 1)
Not obvious.
2024-07-27 00:23:05 +01:00
Trevor Gross 8385f3b7ee
Rollup merge of #128235 - harryscholes:fix-iterator-filter-docs, r=tgross35
Fix `Iterator::filter` docs

Small fix to add code formatting around `Iterator::filter` `true` return type
2024-07-26 19:03:08 -04:00
Trevor Gross 86721a4c90
Rollup merge of #124941 - Skgland:stabilize-const-int-from-str, r=dtolnay
Stabilize const `{integer}::from_str_radix` i.e. `const_int_from_str`

This PR stabilizes the feature `const_int_from_str`.

- ACP Issue: rust-lang/libs-team#74
- Implementation PR: rust-lang/rust#99322
- Part of Tracking Issue: rust-lang/rust#59133

API Change Diff:

```diff
impl {integer} {
- pub       fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>;
+ pub const fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>;
}

impl ParseIntError {
- pub       fn kind(&self) -> &IntErrorKind;
+ pub const fn kind(&self) -> &IntErrorKind;
}
```
This makes it easier to parse integers at compile-time, e.g.
the example from the Tracking Issue:

```rust
env!("SOMETHING").parse::<usize>().unwrap()
```

could now be achived  with

```rust
match usize::from_str_radix(env!("SOMETHING"), 10) {
  Ok(val) => val,
  Err(err) => panic!("Invalid value for SOMETHING environment variable."),
}
```

rather than having to depend on a library that implements or manually implement the parsing at compile-time.

---

Checklist based on [Libs Stabilization Guide - When there's const involved](https://std-dev-guide.rust-lang.org/development/stabilization.html#when-theres-const-involved)

I am treating this as a [partial stabilization](https://std-dev-guide.rust-lang.org/development/stabilization.html#partial-stabilizations) as it shares a tracking issue (and is rather small), so directly opening the partial stabilization PR for the subset (feature `const_int_from_str`) being stabilized.

- [x] ping Constant Evaluation WG
- [x] no unsafe involved
- [x] no `#[allow_internal_unstable]`
- [ ] usage of `intrinsic::const_eval_select` rust-lang/rust#124625 in `from_str_radix_assert` to change the error message between compile-time and run-time
- [ ] [rust-labg/libs-api FCP](https://github.com/rust-lang/rust/pull/124941#issuecomment-2207021921)
2024-07-26 19:03:04 -04:00
Matt Brubeck 1c64fd3be8 Add links from assert_eq! docs to debug_assert_eq!, etc.
This adds information and links from the docs for the following macros to their debug-only versions:

* `assert_eq!`
* `assert_ne!`
* `assert_matches!`

This matches the existing documentation for the `assert!` macro.
2024-07-26 12:17:10 -07:00
Trevor Gross cc9da0b2ce Always set result during finish() in debug builders
Most functions for format builders set `self.result` after writing
strings. This ensures that any further writing fails immediately rather
than trying to write again.

A few `.finish()` methods did have this same behavior, so make it
consistent here.
2024-07-26 13:37:20 -04:00
harryscholes 130ce490f5 Fix docs 2024-07-26 16:09:17 +01:00
John Arundel a19472a93e Fix doc nits
Many tiny changes to stdlib doc comments to make them consistent (for example
"Returns foo", rather than "Return foo", per RFC1574), adding missing periods, paragraph
breaks, backticks for monospace style, and other minor nits.

https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md#appendix-a-full-conventions-text
2024-07-26 13:26:33 +01:00
Trevor Gross 97eade42f7
Rollup merge of #128170 - saethlin:clone-fn, r=compiler-errors
Make Clone::clone a lang item

I want to absorb all the logic for picking whether an Instance is LocalCopy or GloballyShared into one place. As part of this, I wanted to identify Clone shims inside `cross_crate_inlinable` and found that rather tricky. `@compiler-errors` suggested that I add a lang item for `Clone::clone` because that would produce other cleanups in the compiler.

That sounds good to me, but I have looked and I've only been able to find one.

r? compiler-errors
2024-07-26 02:20:31 -04:00
Matthias Krüger ba990ae8af
Rollup merge of #128150 - BoxyUwU:std_only_sized_const_params, r=workingjubilee
Stop using `unsized_const_parameters` in core/std

`feature(unsized_const_parameters)` is an incomplete feature and should not be used by core/std as it makes it can make it significantly harder to evolve the feature. It also just generally opens the possibility of introducing bugs on stable through std's backdoor.

The only usage of this feature in std is the `simd_shuffle_intrinsic` added in #119213. It doesn't seem to be used anywhere as far as I can tell so it is removed in this PR. All tests and codegen logic etc have been kept however.

r? `@workingjubilee`
2024-07-26 00:57:22 +02:00
Matthias Krüger ab2dd3aeb9
Rollup merge of #127950 - nnethercote:rustfmt-skip-on-use-decls, r=cuviper
Use `#[rustfmt::skip]` on some `use` groups to prevent reordering.

`use` declarations will be reformatted in #125443. Very rarely, there is a desire to force a group of `use` declarations together in a way that auto-formatting will break up. E.g. when you want a single comment to apply to a group. #126776 dealt with all of these in the codebase, ensuring that no comments intended for multiple `use` declarations would end up in the wrong place. But some people were unhappy with it.

This commit uses `#[rustfmt::skip]` to create these custom `use` groups in an idiomatic way for a few of the cases changed in #126776. This works because rustfmt treats any `use` item annotated with `#[rustfmt::skip]` as a barrier and won't reorder other `use` items around it.

r? `@cuviper`
2024-07-26 00:57:21 +02:00
Ben Kimock f4f57bfccb Make Clone::clone a lang item 2024-07-25 18:46:07 -04:00
Boxy 8174f9b44b Stop using unsized_const_parameters in core/std 2024-07-25 19:47:21 +01:00
binarycat 3877a7bcf3 clarify interactions with MaybeUninit and UnsafeCell 2024-07-25 12:14:20 -04:00
binarycat 1073f97ed8 remove duplicate explanations of the ptr to ref conversion rules 2024-07-25 12:14:18 -04:00
binarycat 7643ea5b9c create a new section on pointer to reference conversion
also start deduplicating the docs that are getting moved to this
section.
2024-07-25 12:14:18 -04:00
Pavel Grigorenko cf9816c17e CStr: derive PartialEq, Eq; add test for Ord 2024-07-25 14:18:40 +03:00
Matthias Krüger 07947f3773
Rollup merge of #128046 - GrigorenkoPV:90435, r=tgross35
Fix some `#[cfg_attr(not(doc), repr(..))]`

Now that #90435 seems to have been resolved.
2024-07-24 22:22:17 +02:00
Matthias Krüger 7fac549ff1
Rollup merge of #126042 - davidzeng0:master, r=Amanieu
Implement `unsigned_signed_diff`

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->
Implements https://github.com/rust-lang/rust/issues/126041
2024-07-24 22:22:15 +02:00
Matthias Krüger e342efe545
Rollup merge of #128120 - compiler-errors:async-fn-name, r=oli-obk
Gate `AsyncFn*` under `async_closure` feature

T-lang has not come to a consensus on the naming of async closure callable bounds, and as part of allowing the async closures RFC merge, we agreed to place `AsyncFn` under the same gate as `async Fn` so that these syntaxes can be evaluated in parallel.

See https://github.com/rust-lang/rfcs/pull/3668#issuecomment-2246435537

r? oli-obk
2024-07-24 18:00:40 +02:00
Matthias Krüger 34abb9647c
Rollup merge of #127733 - GrigorenkoPV:don't-forget, r=Amanieu
Replace some `mem::forget`'s with `ManuallyDrop`

              > but I would like to see a larger effort to replace all uses of `mem::forget`.

_Originally posted by `@saethlin` in https://github.com/rust-lang/rust/issues/127584#issuecomment-2226087767_

So,
r? `@saethlin`

Sorry, I have finished writing all of this before I got your response.
2024-07-24 18:00:39 +02:00
Matthias Krüger 720c6f19b7
Rollup merge of #127252 - fitzgen:edge-cases-for-bitwise-operations, r=m-ou-se
Add edge-case examples to `{count,leading,trailing}_{ones,zeros}` methods

Some architectures (i386) do not define a "count leading zeros" instruction, they define a "find first set bit" instruction (`bsf`) whose result is undefined when given zero (ie none of the bits are set). Of this family of bitwise operations, I always forget which of these things is potentially undefined for zero, and I'm also not 100% sure that Rust provides a hard guarantee for the results of these methods when given zero. So I figured there are others who have these same uncertainties, and it would be good to resolve them and answer the question via extending these doc examples/tests.

See https://en.wikipedia.org/wiki/Find_first_set#Hardware_support for more info on i386 and `bsf` on zero.
2024-07-24 18:00:36 +02:00
Matthias Krüger 130d15e23e
Rollup merge of #126152 - RalfJung:size_of_val_raw, r=saethlin
size_of_val_raw: for length 0 this is safe to call

For motivation, see https://github.com/rust-lang/unsafe-code-guidelines/issues/465, specifically around [here](https://github.com/rust-lang/unsafe-code-guidelines/issues/465#issuecomment-2136401114).
Cc `@rust-lang/opsem`
2024-07-24 18:00:35 +02:00
Matthias Krüger e56e886796
Rollup merge of #128043 - safinaskar:primitive, r=workingjubilee
Docs for core::primitive: mention that "core" can be shadowed, too, so we should write "::core"

``@rustbot`` label +A-docs
2024-07-24 05:05:33 +02:00
Matthias Krüger 6f696257cb
Rollup merge of #127481 - a1phyr:pattern_gat, r=Amanieu
Remove generic lifetime parameter of trait `Pattern`

Use a GAT for `Searcher` associated type because this trait is always implemented for every lifetime anyway.

cc #27721
2024-07-24 05:05:32 +02:00
Matthias Krüger d6080a1e2f
Rollup merge of #126770 - wr7:master, r=Amanieu
Add elem_offset and related methods

Implementation of #126769
2024-07-24 05:05:31 +02:00
Michael Goulet b82f878f03 Gate AsyncFn* under async_closure feature 2024-07-23 19:56:06 -04:00
wr7 557210c5c7 Add elem_offset and related methods 2024-07-23 18:22:29 -05:00
Askar Safin b8f7ed2394
library/core/src/primitive.rs: small doc fix
Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com>
2024-07-23 23:11:26 +03:00
Folkert aded725d6b
add is_multiple_of for unsigned integer types 2024-07-23 18:02:13 +02:00
Askar Safin b2e5ccef5e Docs for core::primitive: mention that "core" can be shadowed, too, so we should write "::core" 2024-07-23 05:14:16 +03:00
Ian Jackson c404406a87 LocalWaker docs: Make long-ago omitted but probably intended changes
In 6f8a944ba4, titled

  Change return type of unstable `Waker::noop()` from `Waker` to `&Waker`.

the summary line for Waker was changed:

  -    /// Creates a new `Waker` that does nothing when `wake` is called.
  +    /// Returns a reference to a `Waker` that does nothing when used.

and the sentence about clone was added.

LocalWaker's docs were not changed, even though the types were, but
there is no explanation for why not.  It seems like it was simply a
slip induced by the clone-and-hack.
2024-07-22 18:07:28 +01:00
Ian Jackson b18c7d85a9 Docs for Waker and LocalWaker: Add cross-refs in comment 2024-07-22 18:07:28 +01:00
Trevor Gross 8ee5e271ef
Rollup merge of #128008 - weiznich:fix/121521, r=lcnr
Start using `#[diagnostic::do_not_recommend]` in the standard library

This commit starts using `#[diagnostic::do_not_recommend]` in the standard library to improve some error messages. In this case we just hide a certain nightly only impl as suggested in #121521

The result in not perfect yet, but at least the `Yeet` suggestion is not shown anymore. I would consider that as a minor improvement.
2024-07-22 11:40:21 -05:00
Georg Semmler 00da9fc961
Start using #[diagnostic::do_not_recommend] in the standard library
This commit starts using `#[diagnostic::do_not_recommend]` in the
standard library to improve some error messages. In this case we just
hide a certain nightly only impl as suggested in #121521
2024-07-22 07:29:59 +02:00
Pavel Grigorenko b74f426e07 Fix some #[cfg_attr(not(doc), repr(..))]
Now that #90435 seems to have been resolved.
2024-07-22 01:10:06 +03:00
Trevor Gross 827970ebe9 Implement debug_more_non_exhaustive
Add a `.finish_non_exhaustive()` method to `DebugTuple`, `DebugSet`,
`DebugList`, and `DebugMap`. This indicates that the structures have
remaining items with `..`.

This implements the ACP at
<https://github.com/rust-lang/libs-team/issues/248>.
2024-07-21 12:05:02 -05:00
Trevor Gross 68fb25e2eb Make use of raw strings in core::fmt::builders
There are quite a few uses of escaped quotes. Turn these into raw
strings within documentation and tests to make things easier to read.
2024-07-21 12:05:02 -05:00
bors 9629b90b3f Auto merge of #127722 - BoxyUwU:new_adt_const_params_limitations, r=compiler-errors
Forbid borrows and unsized types from being used as the type of a const generic under `adt_const_params`

Fixes #112219
Fixes #112124
Fixes #112125

### Motivation

Currently the `adt_const_params` feature allows writing `Foo<const N: [u8]>` this is entirely useless as it is not possible to write an expression which evaluates to a type that is not `Sized`. In order to actually use unsized types in const generics they are typically written as `const N: &[u8]` which *is* possible to provide a value of.

Unfortunately allowing the types of const parameters to contain references is non trivial (#120961) as it introduces a number of difficult questions about how equality of references in the type system should behave. References in the types of const generics is largely only useful for using unsized types in const generics.

This PR introduces a new feature gate `unsized_const_parameters` and moves support for `const N: [u8]` and `const N: &...` from `adt_const_params` into it. The goal here hopefully is to experiment with allowing `const N: [u8]` to work without references and then eventually completely forbid references in const generics.

Splitting this out into a new feature gate means that stabilization of `adt_const_params` does not have to resolve #120961 which is the only remaining "big" blocker for the feature. Remaining issues after this are a few ICEs and naming bikeshed for `ConstParamTy`.

### Implementation

The implementation is slightly subtle here as we would like to ensure that a stabilization of `adt_const_params` is forwards compatible with any outcome of `unsized_const_parameters`. This is inherently tricky as we do not support unstable trait implementations and we determine whether a type is valid as the type of a const parameter via a trait bound.

There are a few constraints here:
- We would like to *allow for the possibility* of adding a `Sized` supertrait to `ConstParamTy` in the event that we wind up opting to not support unsized types and instead requiring people to write the 'sized version', e.g. `const N: [u8; M]` instead of `const N: [u8]`.
- Crates should be able to enable `unsized_const_parameters` and write trait implementations of `ConstParamTy` for `!Sized` types without downstream crates that only enable `adt_const_params` being able to observe this (required for std to be able to `impl<T> ConstParamTy for [T]`

Ultimately the way this is accomplished is via having two traits (sad), `ConstParamTy` and `UnsizedConstParamTy`. Depending on whether `unsized_const_parameters` is enabled or not we change which trait is used to check whether a type is allowed to be a const parameter.

Long term (when stabilizing `UnsizedConstParamTy`) it should be possible to completely merge these traits (and derive macros), only having a single `trait ConstParamTy` and `macro ConstParamTy`.

Under `adt_const_params` it is now illegal to directly refer to `ConstParamTy` it is only used as an internal impl detail by `derive(ConstParamTy)` and checking const parameters are well formed. This is necessary in order to ensure forwards compatibility with all possible future directions for `feature(unsized_const_parameters)`.

Generally the intuition here should be that `ConstParamTy` is the stable trait that everything uses, and `UnsizedConstParamTy` is that plus unstable implementations (well, I suppose `ConstParamTy` isn't stable yet :P).
2024-07-21 05:36:21 +00:00
bors ff4b39867e Auto merge of #127982 - matthiaskrgr:rollup-nzyvphj, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #127295 (CFI: Support provided methods on traits)
 - #127814 (`C-cmse-nonsecure-call`: improved error messages)
 - #127949 (fix: explain E0120 better cover cases when its raised)
 - #127966 (Use structured suggestions for unconstrained generic parameters on impl blocks)
 - #127976 (Lazy type aliases: Diagostics: Detect bivariant ty params that are only used recursively)
 - #127978 (Avoid ref when using format! for perf)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-19 18:40:33 +00:00
Matthias Krüger e28be0d168
Rollup merge of #127978 - nyurik:lib-refs, r=workingjubilee
Avoid ref when using format! for perf

Clean up a few minor refs in `format!` macro, as it has a performance cost. Apparently the compiler is unable to inline `format!("{}", &variable)`, and does a run-time double-reference instead (format macro already does one level referencing).  Inlining format args prevents accidental `&` misuse.
2024-07-19 20:03:58 +02:00
Yuri Astrakhan 91275b2c2b Avoid ref when using format! for perf
Clean up a few minor refs in `format!` macro, as it has a tiny perf
cost. A few more minor related cleanups.
2024-07-19 12:23:49 -04:00
ivan-shrimp 90bba8beb5 improve safety comment 2024-07-19 19:16:33 +08:00
ivan-shrimp eaaed00ff5 add NonZero<uN>::isqrt 2024-07-19 18:10:41 +08:00
Nicholas Nethercote c5dadd0408 Use #[rustfmt::skip] on some use groups to prevent reordering.
`use` declarations will be reformatted in #125443. Very rarely, there is
a desire to force a group of `use` declarations together in a way that
auto-formatting will break up. E.g. when you want a single comment to
apply to a group. #126776 dealt with all of these in the codebase,
ensuring that no comments intended for multiple `use` declarations would
end up in the wrong place. But some people were unhappy with it.

This commit uses `#[rustfmt::skip]` to create these custom `use` groups
in an idiomatic way for a few of the cases changed in #126776. This
works because rustfmt treats any `use` item annotated with
`#[rustfmt::skip]` as a barrier and won't reorder other `use` items
around it.
2024-07-19 13:26:48 +10:00
Matthias Krüger 6f7fa03a06
Rollup merge of #127748 - scottmcm:option_len, r=joboet
Use Option's discriminant as its size hint

I was looking at this in MIR after a question on discord, and noticed that it ends up with a switch in MIR (<https://rust.godbolt.org/z/3q4cYnnb3>), which it doesn't need because (as `Option::as_slice` uses) the discriminant is already the length.
2024-07-18 18:10:16 +02:00
Trevor Gross c36a39cd1f
Rollup merge of #127859 - RalfJung:ptr-dyn-metadata, r=scottmcm
ptr::metadata: avoid references to extern types

References to `extern types` are somewhat dubious entities, since generally we say that references must be dereferenceable for their size as determined via `size_of_val`, but with `extern type` that is an ill-defined statement. I'd like to make Miri warn for such cases since it interacts poorly with Stacked Borrows. To avoid warnings people can't fix, this requires not using references to `extern type` in the standard library, and I think `DynMetadata` is the only currently remaining use. so this changes `DynMetadata` to use a NonNull raw pointer instead. Given that the alignment was 1, this shouldn't really change anything meaningful.

I also updated a comment added by `@scottmcm` in https://github.com/rust-lang/rust/pull/125479, since I think the old comment is wrong. The `DynMetadata` type itself is not special, it is a normal aggregate. But computing field types for wide pointers (including references) is special.
2024-07-17 19:53:28 -05:00
Matthias Krüger 3ddfd97198
Rollup merge of #127337 - celinval:intrinsics-fallback, r=oli-obk
Move a few intrinsics to Rust abi

Move a few more intrinsic functions to the convention added in #121192. In the second commit, I added documentation about their safety requirements. Let me know if you would like me to move the second commit to a different PR.

Note: I kept the same signature of `pref_align_of`, but I was wondering why this function is considered unsafe?
2024-07-17 16:22:28 +02:00
Ralf Jung f9c0d3370f ptr::metadata: update comment on vtable_ptr work-around 2024-07-17 13:56:25 +02:00