Commit Graph

8223 Commits

Author SHA1 Message Date
Stuart Cook
fa6990c16e
Rollup merge of #134930 - RalfJung:ptr-docs-valid-access, r=jhpratt
ptr docs: make it clear that we are talking only about memory accesses

This should make it harder to take this sentence out of context and misunderstand it.
2024-12-31 14:12:46 +11:00
Stuart Cook
1200d3d733
Rollup merge of #134927 - DaniPopes:const-as_flattened_mut, r=scottmcm
Make slice::as_flattened_mut unstably const

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

Unblocked by const_mut_refs being stabilized: https://github.com/rust-lang/rust/pull/129195
2024-12-31 14:12:46 +11:00
LemonJ
d9ef419c90 fix doc for read write unaligned in zst operation 2024-12-31 10:59:13 +08:00
bors
4e5fec2f1e Auto merge of #134757 - RalfJung:const_swap, r=scottmcm
stabilize const_swap

libs-api FCP passed in https://github.com/rust-lang/rust/issues/83163.

However, I only just realized that this actually involves an intrinsic. The intrinsic could be implemented entirely with existing stable const functionality, but we choose to make it a primitive to be able to detect more UB. So nominating for `@rust-lang/lang`  to make sure they are aware; I leave it up to them whether they want to FCP this.

While at it I also renamed the intrinsic to make the "nonoverlapping" constraint more clear.

Fixes #83163
2024-12-30 23:46:42 +00:00
Ralf Jung
e36b4c95f4 ptr docs: make it clear that we are talking only about memory accesses 2024-12-30 19:28:03 +01:00
DaniPopes
26f523edfc
Make slice::as_flattened_mut unstably const
Tracking issue: https://github.com/rust-lang/rust/issues/95629

Unblocked by const_mut_refs being stabilized: https://github.com/rust-lang/rust/pull/129195
2024-12-30 18:16:49 +01:00
Mads Marquart
5966ba0424 Fix ptr::from_ref documentation example comment
The comment says that the expression involves no function call, but
that was only true for the example above, the example here _does_
contain a function call.
2024-12-30 00:26:47 +01:00
Geoffrey Thomas
0c2f4359fd
Fix sentence fragment in pin module docs
Looks like this was inadvertently dropped in 8241ca60. Restore the words from before that commit.
2024-12-28 22:21:04 -05:00
ltdk
f228458e30 Tidy up bigint mul methods 2024-12-27 22:01:51 -05:00
David Tolnay
9aebd28ca7
Rollup merge of #134823 - chloefeal:fix, r=tgross35,dtolnay
Fix typos

This PR focuses on correcting typos and improving clarity in documentation files. Thank you.
2024-12-27 18:43:03 -08:00
Niklas Fiekas
7d0518c380
Implement int_from_ascii (#134821)
Provides unstable `T::from_ascii()` and `T::from_ascii_radix()` for integer
types `T`, as drafted in tracking issue #134821.

To deduplicate documentation without additional macros, implementations of
`isize` and `usize` no longer delegate to equivalent integer types.
After #132870 they are inlined anyway.
2024-12-27 20:05:09 +01:00
Matthias Krüger
95e66ff8b4
Rollup merge of #133663 - scottmcm:carrying_mul_add, r=Amanieu
Add a compiler intrinsic to back `bigint_helper_methods`

cc https://github.com/rust-lang/rust/issues/85532

This adds a new `carrying_mul_add` intrinsic, to implement `wide_mul` and `carrying_mul`.

It has fallback MIR for all types -- including `u128`, which isn't currently supported on nightly -- so that it'll continue to work on all backends, including CTFE.

Then it's overridden in `cg_llvm` to use wider intermediate types, including `i256` for `u128::carrying_mul`.
2024-12-27 19:47:09 +01:00
Scott McMurray
4669c0d756 Override carrying_mul_add in cg_llvm 2024-12-27 08:17:40 -08:00
Scott McMurray
2c0c9123fc Move {widening, carrying}_mul to an intrinsic with fallback MIR
Including implementing it for `u128`, so it can be defined in `uint_impl!`.

This way it works for all backends, including CTFE.
2024-12-27 08:17:40 -08:00
chloefeal
e1b65be417
Fix typos
Signed-off-by: chloefeal <188809157+chloefeal@users.noreply.github.com>
2024-12-27 21:35:57 +08:00
许杰友 Jieyou Xu (Joe)
b9df376189
Rollup merge of #134606 - RalfJung:ptr-copy-docs, r=Mark-Simulacrum
ptr::copy: fix docs for the overlapping case

Fixes https://github.com/rust-lang/unsafe-code-guidelines/issues/549

As discussed in that issue, it doesn't make any sense for `copy` to read a byte via `src` after it was already written via `dst`. The entire point of this method is that is copies correctly even if they overlap, and that requires always reading any given location before writing it.

Cc `@rust-lang/opsem`
2024-12-27 20:44:11 +08:00
Jacob Pratt
c1447e3449
Rollup merge of #134791 - notriddle:notriddle/inline-ffi-error-types, r=tgross35
docs: inline `std::ffi::c_str` types to `std::ffi`

Rustdoc has no way to show that an item is stable, but only at a different path. `std::ffi::c_str::NulError` is not stable, but `std::ffi::NulError` is.

To avoid marking these types as unstable when someone just wants to follow a link from `CString`, inline them into their stable paths.

Fixes #134702

r? `@tgross35`
2024-12-26 21:56:51 -05:00
Jacob Pratt
0bfd367612
Rollup merge of #134782 - wtlin1228:docs/iter-rposition, r=Mark-Simulacrum
Update Code Example for `Iterator::rposition`

Added an additional assertion to the example to show the behavior of `iter.next_back` after using `iter.rposition`.
2024-12-26 21:56:50 -05:00
Michael Howell
fc8a541eaa docs: inline core::ffi::c_str types to core::ffi 2024-12-26 15:51:45 -07:00
Sebastian Hahn
10b23518c1 Impl FromIterator for tuples with arity 1-12 2024-12-26 08:47:49 +01:00
Sebastian Hahn
87e641a2a5 Fix formatting 2024-12-26 08:47:49 +01:00
wtlin1228
d0c1975e4b docs: update code example for Iterator#rposition 2024-12-26 13:56:45 +08:00
Ralf Jung
88b88f336b stabilize const_alloc_layout 2024-12-25 19:28:52 +01:00
Ralf Jung
7291b1eaf7 rename typed_swap → typed_swap_nonoverlapping 2024-12-25 10:53:03 +01:00
Ralf Jung
6de3a2e3a9 stabilize const_swap 2024-12-25 10:36:32 +01:00
oliveredget
be1d5dd494
chore: fix typos 2024-12-24 23:37:30 +08:00
Stuart Cook
bbd30b5476
Rollup merge of #134689 - RalfJung:ptr-swap-test, r=oli-obk
core: fix const ptr::swap_nonoverlapping when there are pointers at odd offsets

Ensure that the pointer gets swapped correctly even if it is not stored at an aligned offset. This rules out implementations that copy things in a `usize` loop -- so our implementation needs to be adjusted to avoid such a loop when running in const context.

Part of https://github.com/rust-lang/rust/issues/133668
2024-12-24 14:05:22 +11:00
Stuart Cook
0c93b279ea
Rollup merge of #134662 - ionicmc-rs:any-safety-docs, r=Amanieu
Fix safety docs for `dyn Any + Send {+ Sync}`

Fixes the `# Safety` docs for `dyn Any + Send`'s `downcast_{mut/ref}_unchecked` to show the direct instructions , where previously the would tell the user to find the docs on `dyn Any` themselves.

This also adds them for `downcast_{mut/ref}_unchecked` on `dyn Any + Send + Sync`
2024-12-24 14:05:22 +11:00
Ralf Jung
af1c8da172 core: fix const ptr::swap_nonoverlapping when there are pointers at odd offsets in the type 2024-12-23 16:24:45 +01:00
Matthias Krüger
95c33e303b
Rollup merge of #134363 - estebank:derive-default, r=SparrowLii
Use `#[derive(Default)]` instead of manual `impl` when possible

While working on #134175 I noticed a few manual `Default` `impl`s that could be `derive`d instead. These likely predate the existence of the `#[default]` attribute for `enum`s.
2024-12-23 14:44:20 +01:00
Trevor Gross
8fc4ba2ac1
Rollup merge of #134672 - Zalathar:revert-coverage-attr, r=wesleywiser
Revert stabilization of the `#[coverage(..)]` attribute

Due to a process mixup, the PR to stabilize the `#[coverage(..)]` attribute (#130766) was merged while there are still outstanding concerns. The default action in that situation is to revert, and the feature is not sufficiently urgent or uncontroversial to justify special treatment, so this PR reverts that stabilization.

---

- A key point that came up in offline discussions is that unlike most user-facing features, this one never had a proper RFC, so parts of the normal stabilization process that implicitly rely on an RFC break down in this case.
- As the implementor and de-facto owner of the feature in its current form, I would like to think that I made good choices in designing and implementing it, but I don't feel comfortable proceeding to stabilization without further scrutiny.
- There hasn't been a clear opportunity for T-compiler to weigh in or express concerns prior to stabilization.
- The stabilization PR cites a T-lang FCP that occurred in the tracking issue, but due to the messy design and implementation history (and lack of a clear RFC), it's unclear what that FCP approval actually represents in this case.
  - At the very least, we should not proceed without a clear statement from T-lang or the relevant members about the team's stance on this feature, especially in light of the other concerns listed here.
- The existing user-facing documentation doesn't clearly reflect which parts of the feature are stable commitments, and which parts are subject to change. And there doesn't appear to be a clear consensus anywhere about where that line is actually drawn, or whether the chosen boundary is acceptable to the relevant teams and individuals.
  - For example, the [stabilization report comment](https://github.com/rust-lang/rust/issues/84605#issuecomment-2166514660) mentions that some aspects are subject to change, but that text isn't consistent with my earlier comments, and there doesn't appear to have been any explicit discussion or approval process.
  - [The current reference text](https://github.com/rust-lang/reference/blob/4dfaa4f/src/attributes/coverage-instrumentation.md) doesn't mention this distinction at all, and instead simply describes the current implementation behaviour.
- When the implementation was changed to its current form, the associated user-facing error messages were not updated, so they still refer to the attribute only being allowed on functions and closures.
  - On its own, this might have been reasonable to fix-forward in the absence of other concerns, but the fact that it never came up earlier highlights the breakdown in process that has occurred here.

---

Apologies to everyone who was excited for this stabilization to land, but unfortunately it simply isn't ready yet.
2024-12-23 02:07:32 -05:00
Esteban Küber
1f82b45b6a Use #[derive(Default)] instead of manually implementing it 2024-12-23 03:01:29 +00:00
Zalathar
87c2f9a5be Revert "Auto merge of #130766 - clarfonthey:stable-coverage-attribute, r=wesleywiser"
This reverts commit 1d35638dc3, reversing
changes made to f23a80a4c2.
2024-12-23 12:30:37 +11:00
bors
908af5ba4a Auto merge of #134666 - matthiaskrgr:rollup-whe0chp, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #130289 (docs: Permissions.readonly() also ignores root user special permissions)
 - #134583 (docs: `transmute<&mut T, &mut MaybeUninit<T>>` is unsound when exposed to safe code)
 - #134611 (Align `{i686,x86_64}-win7-windows-msvc` to their parent targets)
 - #134629 (compiletest: Allow using a specific debugger when running debuginfo tests)
 - #134642 (Implement `PointerLike` for `isize`, `NonNull`, `Cell`, `UnsafeCell`, and `SyncUnsafeCell`.)
 - #134660 (Fix spacing of markdown code block fences in compiler rustdoc)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-12-23 01:18:40 +00:00
Matthias Krüger
c16f00cff6
Rollup merge of #134642 - kpreid:pointerlike-cell, r=compiler-errors
Implement `PointerLike` for `isize`, `NonNull`, `Cell`, `UnsafeCell`, and `SyncUnsafeCell`.

* Implementing `PointerLike` for `UnsafeCell` enables the possibility of interior mutable `dyn*` values. Since this means potentially exercising new codegen behavior, I added a test for it in `tests/ui/dyn-star/cell.rs`. Please let me know if there are further sorts of tests that should be written, or other care that should be taken with this change.

  It is unfortunately not possible without compiler changes to implement `PointerLike` for `Atomic*` types, since they are not `repr(transparent)` (and, in theory if not in practice, `AtomicUsize`'s alignment may be greater than that of an ordinary pointer or `usize`).

* Implementing `PointerLike` for `NonNull` is useful for pointer types which wrap `NonNull`.

* Implementing `PointerLike` for `isize` is just for completeness; I have no use cases in mind, but I cannot think of any reason not to do this.

* Tracking issue: #102425

`@rustbot` label +F-dyn_star
(there is no label or tracking issue for F-pointer_like_trait)
2024-12-22 21:59:27 +01:00
Matthias Krüger
6ade237b6c
Rollup merge of #134583 - Enselic:maybe-uninit-transmute, r=workingjubilee
docs: `transmute<&mut T, &mut MaybeUninit<T>>` is unsound when exposed to safe code

Closes #66699

On my system (Edit: And also in the [playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=90529e2a9900599cb759e4bfaa5b5efe)) the example program terminates with an unpredictable exit code:
```console
$ cargo +nightly build && target/debug/bin ; echo $?
255
$ cargo +nightly build && target/debug/bin ; echo $?
253
```

And miri considers the code to have undefined behavior:
```console
$ cargo +nightly miri run
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
  --> src/main.rs:12:24
   |
12 |     std::process::exit(*code); // UB! Accessing uninitialized memory
   |                        ^^^^^ using uninitialized data, but this operation requires initialized memory
   |
error: aborting due to 1 previous error
```
2024-12-22 21:59:24 +01:00
Caio
c89f0dc01d Adjust syntax 2024-12-22 17:12:42 -03:00
Mostafa Khaled
5a8d970e4f Fixes safety docs for dyn Any + Send {+ Sync} 2024-12-22 21:38:23 +02:00
Kevin Reid
5c04151c6c Implement PointerLike for isize, NonNull, Cell, UnsafeCell, and SyncUnsafeCell.
Implementing `PointerLike` for `UnsafeCell` enables the possibility of
interior mutable `dyn*` values. Since this means potentially exercising
new codegen behavior, I added a test for it in `tests/ui/dyn-star/cell.rs`.

Also updated UI tests to account for the `isize` implementation changing
error messages.
2024-12-22 11:18:56 -08:00
bors
e108481f74 Auto merge of #134330 - scottmcm:no-more-rvalue-len, r=matthewjasper
Delete `Rvalue::Len` 🎉

Everything's moved to `PtrMetadata`, so we can get rid of the `Len` variant now.

~~Depends on #134326, so draft until that lands~~ Ready!

r? mir
2024-12-22 18:49:18 +00:00
Marijn Schouten
5065a91d7f Improve prose around as_slice example of IterMut
I've removed the cryptic message about not being able to call `&mut self` methods while retaining a shared borrow of the iterator, such as `as_slice` produces. This is just normal borrowing rules and does not seem especially relevant here. I can whip up a replacement if someone thinks it has value.
2024-12-22 18:29:27 +01:00
bors
303e8bd768 Auto merge of #131193 - EFanZh:asserts-vec-len, r=the8472
Asserts the maximum value that can be returned from `Vec::len`

Currently, casting `Vec<i32>` to `Vec<u32>` takes O(1) time:

```rust
// See <https://godbolt.org/z/hxq3hnYKG> for assembly output.
pub fn cast(vec: Vec<i32>) -> Vec<u32> {
    vec.into_iter().map(|e| e as _).collect()
}
```

But the generated assembly is not the same as the identity function, which prevents us from casting `Vec<Vec<i32>>` to `Vec<Vec<u32>>` within O(1) time:

```rust
// See <https://godbolt.org/z/7n48bxd9f> for assembly output.
pub fn cast(vec: Vec<Vec<i32>>) -> Vec<Vec<u32>> {
    vec.into_iter()
        .map(|e| e.into_iter().map(|e| e as _).collect())
        .collect()
}
```

This change tries to fix the problem. You can see the comparison here: <https://godbolt.org/z/jdManrKvx>.
2024-12-22 16:09:16 +00:00
Scott McMurray
5ba54c9e31 Delete Rvalue::Len
Everything's moved to `PtrMetadata` instead.
2024-12-22 06:12:39 -08:00
Martin Nordholts
2305012e6a docs: transmute<&mut T, &mut MaybeUninit<T>> is unsound when exposed to safe code
In the playground the example program terminates with an unpredictable exit
code. The undefined behavior is also detected by miri:

    error: Undefined Behavior: using uninitialized data
2024-12-22 14:21:10 +01:00
Matthias Krüger
7f36ae400c
Rollup merge of #134602 - kpreid:pointerlike-doc, r=tgross35
Document `PointerLike` implementation restrictions.

Since <https://github.com/rust-lang/rust/pull/133226>, it is no longer automatically implemented, but must be manually implemented, with special restrictions. The documentation now (roughly) explains those special restrictions.

cc `@compiler-errors` (author of the previous PR)
2024-12-22 09:12:11 +01:00
bors
a2bcfae5c5 Auto merge of #134640 - matthiaskrgr:rollup-xlstm3o, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #134364 (Use E0665 for missing `#[default]` on enum and update doc)
 - #134601 (Support pretty-printing `dyn*` trait objects)
 - #134603 (Explain why a type is not eligible for `impl PointerLike`.)
 - #134618 (coroutine_clone: add comments)
 - #134630 (Use `&raw` for `ptr` primitive docs)
 - #134637 (Flatten effects directory now that it doesn't really test anything specific)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-12-22 05:29:45 +00:00
Matthias Krüger
9b4e40dcb8
Rollup merge of #134630 - fifty-six:master, r=workingjubilee
Use `&raw` for `ptr` primitive docs

Fixes the first item in #133024
2024-12-22 03:49:45 +01:00
bors
c1132470a6 Auto merge of #130733 - okaneco:is_ascii, r=scottmcm
Optimize `is_ascii` for `str` and `[u8]` further

Replace the existing optimized function with one that enables auto-vectorization.

This is especially beneficial on x86-64 as `pmovmskb` can be emitted with careful structuring of the code. The instruction can detect non-ASCII characters one vector register width at a time instead of the current `usize` at a time check.

The resulting implementation is completely safe.

`case00_libcore` is the current implementation, `case04_while_loop` is this PR.
```
benchmarks:
    ascii::is_ascii_slice::long::case00_libcore                             22.25/iter  +/- 1.09
    ascii::is_ascii_slice::long::case04_while_loop                           6.78/iter  +/- 0.92
    ascii::is_ascii_slice::medium::case00_libcore                            2.81/iter  +/- 0.39
    ascii::is_ascii_slice::medium::case04_while_loop                         1.56/iter  +/- 0.78
    ascii::is_ascii_slice::short::case00_libcore                             5.55/iter  +/- 0.85
    ascii::is_ascii_slice::short::case04_while_loop                          3.75/iter  +/- 0.22
    ascii::is_ascii_slice::unaligned_both_long::case00_libcore              26.59/iter  +/- 0.66
    ascii::is_ascii_slice::unaligned_both_long::case04_while_loop            5.78/iter  +/- 0.16
    ascii::is_ascii_slice::unaligned_both_medium::case00_libcore             2.97/iter  +/- 0.32
    ascii::is_ascii_slice::unaligned_both_medium::case04_while_loop          2.41/iter  +/- 0.10
    ascii::is_ascii_slice::unaligned_head_long::case00_libcore              23.71/iter  +/- 0.79
    ascii::is_ascii_slice::unaligned_head_long::case04_while_loop            7.83/iter  +/- 1.31
    ascii::is_ascii_slice::unaligned_head_medium::case00_libcore             3.69/iter  +/- 0.54
    ascii::is_ascii_slice::unaligned_head_medium::case04_while_loop          7.05/iter  +/- 0.32
    ascii::is_ascii_slice::unaligned_tail_long::case00_libcore              24.44/iter  +/- 1.41
    ascii::is_ascii_slice::unaligned_tail_long::case04_while_loop            5.12/iter  +/- 0.18
    ascii::is_ascii_slice::unaligned_tail_medium::case00_libcore             3.24/iter  +/- 0.40
    ascii::is_ascii_slice::unaligned_tail_medium::case04_while_loop          2.86/iter  +/- 0.14

```

`unaligned_head_medium` is the main regression in the benchmarks. It is a 32 byte string being sliced `bytes[1..]`.

The first commit can be used to run the benchmarks against the current core implementation.

Previous implementation was done in #74066

---

Two potential drawbacks of this implementation are that it increases instruction count and may regress other platforms/architectures. The benches here may also be too artificial to glean much insight from.
https://rust.godbolt.org/z/G9znGfY36
2024-12-22 02:44:13 +00:00
Matthias Krüger
3aedae24a2
Rollup merge of #134325 - theemathas:is_null-docs, r=RalfJung
Correctly document CTFE behavior of is_null and methods that call is_null.

The "panic in const if CTFE doesn't know the answer" behavior was discussed to be the desired behavior in #74939, and is currently how the function actually behaves.

I intentionally wrote this documentation to allow for the possibility that a panic might not occur even if the pointer is out of bounds, because of #133700 and other potential changes in the future.

This is beta-nominated since `const fn is_null` stabilization is in beta already but the docs there are wrong, and it seems better to have the docs be correct at the time of stabilization.
2024-12-21 22:16:02 +01:00
Yusuf Bham
466335205f Use &raw for ptr primitive docs 2024-12-21 15:47:44 -05:00
Tim (Theemathas) Chirananthavat
e6efbb210b Document CTFE behavior of methods that call is_null 2024-12-21 16:32:47 +07:00
Tim (Theemathas) Chirananthavat
93889172bc Correctly document is_null CTFE behavior.
The "panic in const if CTFE doesn't know the answer" behavior was discussed to be the desired behavior in #74939, and is currently how the function actually behaves.

I intentionally wrote this documentation to allow for the possibility that a panic might not occur even if the pointer is out of bounds, because of #133700 and other potential changes in the future.
2024-12-21 15:36:16 +07:00
Ralf Jung
526d29865c ptr::copy: fix docs for the overlapping case 2024-12-21 08:34:55 +01:00
Jacob Pratt
cc27e3f08b
Rollup merge of #134593 - kornelski:less-unwrap, r=jhpratt
Less unwrap() in documentation

I think the common use of `.unwrap()` in examples makes it overrepresented, looking like a more typical way of error handling than it really is in real programs.

Therefore, this PR changes a bunch of examples to use different error handling methods, primarily the `?` operator. Additionally, `unwrap()` docs warn that it might abort the program.
2024-12-21 01:18:43 -05:00
Jacob Pratt
c682d30337
Rollup merge of #134579 - hkBst:patch-6, r=jhpratt
Improve prose around into_slice example of IterMut

Having a part without modification and one with seems redundant, since `into_slice` is only called for the part without. I have brought the modification into the remaining part, although it perhaps does not add much (or only distracts?).
2024-12-21 01:18:42 -05:00
Jacob Pratt
91320f6eb8
Rollup merge of #134577 - hkBst:patch-5, r=jhpratt
Improve prose around `as_slice` example of Iter
2024-12-21 01:18:41 -05:00
Jacob Pratt
ba4f4f6a4f
Rollup merge of #134576 - hkBst:patch-4, r=jhpratt
Improve prose around basic examples of Iter and IterMut
2024-12-21 01:18:41 -05:00
Kevin Reid
da6616c54f Document PointerLike implementation restrictions. 2024-12-20 20:47:03 -08:00
Kornel
7b42bc0c79
Less unwrap() in documentation 2024-12-21 01:26:47 +00:00
Matthias Krüger
0b1834d66b
Rollup merge of #134573 - lukas-code:unimpl-dyn-pointerlike, r=compiler-errors
unimplement `PointerLike` for trait objects

Values of type `dyn* PointerLike` or `dyn PointerLike` are not pointer-like so these types should not implement `PointerLike`.

After https://github.com/rust-lang/rust/pull/133226, `PointerLike` allows user implementations, so we can't just mark it with `#[rustc_deny_explicit_impl(implement_via_object = false)]`. Instead, this PR splits the `#[rustc_deny_explicit_impl(implement_via_object = ...)]` attribute into two separate attributes `#[rustc_deny_explicit_impl]` and `#[rustc_do_not_implement_via_object]` so that we opt out of the automatic `impl PointerLike for dyn PointerLike` and still allow user implementations.

For traits that are marked with `#[do_not_implement_via_object]` but not `#[rustc_deny_explicit_impl]` I've also made it possible to add a manual `impl Trait for dyn Trait`. There is no immediate need for this, but it was one line to implement and seems nice to have.

fixes https://github.com/rust-lang/rust/issues/134545
fixes https://github.com/rust-lang/rust/issues/134543

r? `@compiler-errors`
2024-12-20 21:32:33 +01:00
Marijn Schouten
07ab203f34
Improve prose around into_slice example of IterMut 2024-12-20 19:57:20 +01:00
Marijn Schouten
3cfe66ab65
Improve prose around as_slice example of Iter 2024-12-20 19:19:34 +01:00
Marijn Schouten
a8e7a6c1d8
Improve prose around basic examples of Iter and IterMut 2024-12-20 18:55:48 +01:00
Marijn Schouten
496adcf36c
remove reference to dangling from slice::Iter
This aligns the comment with reality and with IterMut. Also dangling does not seem to take any arguments.
2024-12-20 18:20:40 +01:00
Lukas Markeffsky
159dba89ef fix PointerLike docs 2024-12-20 17:37:34 +01:00
Lukas Markeffsky
971a4f2d3b unimplement PointerLike for trait objects 2024-12-20 17:35:29 +01:00
Lukas Markeffsky
42c00cb647 split up #[rustc_deny_explicit_impl] attribute
This commit splits the `#[rustc_deny_explicit_impl(implement_via_object = ...)]` attribute
into two attributes `#[rustc_deny_explicit_impl]` and `#[rustc_do_not_implement_via_object]`.

This allows us to have special traits that can have user-defined impls but do not have the
automatic trait impl for trait objects (`impl Trait for dyn Trait`).
2024-12-20 16:57:14 +01:00
Jacob Pratt
ef47ba091d
Rollup merge of #134518 - hltj:typo-fix, r=tgross35
fix typos in the example code in the doc comments of `Ipv4Addr::from_bits()`, `Ipv6Addr::from_bits()` & `Ipv6Addr::to_bits()`
2024-12-20 01:36:48 -05:00
Jacob Pratt
1ec6d093b7
Rollup merge of #132830 - wr7:substr_range_documentation, r=tgross35
Rename `elem_offset` to `element_offset`

Tracking issue: #126769

Renames `slice::elem_offset` to `slice::element_offset` and improves the documentation of it and its related methods.

The current documentation can be misinterpreted (as explained [here](https://github.com/rust-lang/rust/issues/126769#issuecomment-2453363897)).
2024-12-20 01:36:46 -05:00
hltj
eef749819b fix typos in the example code in the doc comments of Ipv4Addr::from_bits(), Ipv6Addr::from_bits() & Ipv6Addr::to_bits() 2024-12-20 11:47:02 +08:00
Jacob Pratt
80cf85d584
Rollup merge of #134490 - hong9lol:typo, r=jhpratt
Fix typo in ptr/mod.rs

- Type: Document
- Description: I found a typo and want to fix it.
2024-12-18 21:38:12 -05:00
Jacob Pratt
e018796012
Rollup merge of #132056 - weiznich:diagnostic_do_not_recommend_final_tests, r=compiler-errors
Stabilize `#[diagnostic::do_not_recommend]`

This PR seeks to stabilize the `#[diagnostic::do_not_recommend]`attribute.

This attribute was first proposed as `#[do_not_recommend`] attribute in RFC 2397 (https://github.com/rust-lang/rfcs/pull/2397). It gives the crate authors the ability to not suggest to the compiler to not show certain traits in its error messages.

With the presence of the `#[diagnostic]` tool attribute namespace it was decided to move the attribute there, as that lowers the amount of guarantees the compiler needs to give about the exact way this influences error messages. It turns the attribute into a hint which can be ignored. In addition to the original proposed functionality this attribute now also hides the marked trait in help messages ("This trait is implemented by: ").

The attribute does not accept any argument and can only be placed on trait implementations. If it is placed somewhere else a lint warning is emitted and the attribute is otherwise ignored. If an argument is detected a lint warning is emitted and the argument is ignored. This follows the rules outlined by the diagnostic namespace.

This attribute allows crates like diesel to improve their error messages drastically. The most common example here is the following error message:

```
error[E0277]: the trait bound `&str: Expression` is not satisfied
  --> /home/weiznich/Documents/rust/rust/tests/ui/diagnostic_namespace/do_not_recommend.rs:53:15
   |
LL |     SelectInt.check("bar");
   |               ^^^^^ the trait `Expression` is not implemented for `&str`, which is required by `&str: AsExpression<Integer>`
   |
   = help: the following other types implement trait `Expression`:
             Bound<T>
             SelectInt
note: required for `&str` to implement `AsExpression<Integer>`
  --> /home/weiznich/Documents/rust/rust/tests/ui/diagnostic_namespace/do_not_recommend.rs:26:13
   |
LL | impl<T, ST> AsExpression<ST> for T
   |             ^^^^^^^^^^^^^^^^     ^
LL | where
LL |     T: Expression<SqlType = ST>,
   |        ------------------------ unsatisfied trait bound introduced here
```

By applying the new attribute to the wild card trait implementation of
`AsExpression` for `T: Expression` the error message becomes:

```
error[E0277]: the trait bound `&str: AsExpression<Integer>` is not satisfied
  --> $DIR/as_expression.rs:55:15
   |
LL |     SelectInt.check("bar");
   |               ^^^^^ the trait `AsExpression<Integer>` is not implemented for `&str`
   |
   = help: the trait `AsExpression<Text>` is implemented for `&str`
   = help: for that trait implementation, expected `Text`, found `Integer`
```

which makes it much easier for users to understand that they are facing a type mismatch.

Other explored example usages include:

* This standard library error message: https://github.com/rust-lang/rust/pull/128008
* That bevy derived example:
e1f3068995/tests/ui/diagnostic_namespace/do_not_recommend/supress_suggestions_in_help.rs (No
more tuple pyramids)

Fixes #51992

r? ``@compiler-errors``

This PR also adds a few more tests, makes sure that all the tests are run for the old and new trait solver and adds a check that the attribute does not contain arguments.
2024-12-18 21:38:08 -05:00
leejaehong
f8cd8c1c37 fix typo in ptr/mod.rs
Signed-off-by: leejaehong <jaehong2.lee@samsung.com>
2024-12-19 10:37:19 +09:00
bors
4ba4ac612d Auto merge of #134443 - joshtriplett:use-field-init-shorthand, r=lqd,tgross35,nnethercote
Use field init shorthand where possible

Field init shorthand allows writing initializers like `tcx: tcx` as
`tcx`. The compiler already uses it extensively. Fix the last few places
where it isn't yet used.

EDIT: this PR also updates `rustfmt.toml` to set
`use_field_init_shorthand = true`.
2024-12-18 19:16:15 +00:00
Jalil David Salamé Messina
20bff638bf
fix(LazyCell): documentation of get[_mut] was wrong
- `LazyCell::get`: said it was returning a **mutable** reference.
- `LazyCell::get_mut`: said it was returning a reference (the mutable
  was missing).
2024-12-18 09:43:02 +01:00
Georg Semmler
dd31713c53
Stabilize #[diagnostic::do_not_recommend]
This commit seeks to stabilize the `#[diagnostic::do_not_recommend]`
attribute.
This attribute was first proposed as `#[do_not_recommend`] attribute in
RFC 2397 (https://github.com/rust-lang/rfcs/pull/2397). It gives the
crate authors the ability to not suggest to the compiler to not show
certain traits in it's error messages. With the presence of the
`#[diagnostic]` tool attribute namespace it was decided to move the
attribute there, as that lowers the amount of guarantees the compiler
needs to give about the exact way this influences error messages. It
turns the attribute into a hint which can be ignored. In addition to the
original proposed functionality this attribute now also hides the marked
trait in help messages ("This trait is implemented by: ").
The attribute does not accept any argument and can only be placed on
trait implementations. If it is placed somewhere else a lint warning is
emitted and the attribute is otherwise ignored. If an argument is
detected a lint warning is emitted and the argument is ignored. This
follows the rules outlined by the diagnostic namespace.

This attribute allows crates like diesel to improve their error messages
drastically. The most common example here is the following error
message:

```
error[E0277]: the trait bound `&str: Expression` is not satisfied
  --> /home/weiznich/Documents/rust/rust/tests/ui/diagnostic_namespace/do_not_recommend.rs:53:15
   |
LL |     SelectInt.check("bar");
   |               ^^^^^ the trait `Expression` is not implemented for `&str`, which is required by `&str: AsExpression<Integer>`
   |
   = help: the following other types implement trait `Expression`:
             Bound<T>
             SelectInt
note: required for `&str` to implement `AsExpression<Integer>`
  --> /home/weiznich/Documents/rust/rust/tests/ui/diagnostic_namespace/do_not_recommend.rs:26:13
   |
LL | impl<T, ST> AsExpression<ST> for T
   |             ^^^^^^^^^^^^^^^^     ^
LL | where
LL |     T: Expression<SqlType = ST>,
   |        ------------------------ unsatisfied trait bound introduced here
```

By applying the new attribute to the wild card trait implementation of
`AsExpression` for `T: Expression` the error message becomes:

```
error[E0277]: the trait bound `&str: AsExpression<Integer>` is not satisfied
  --> $DIR/as_expression.rs:55:15
   |
LL |     SelectInt.check("bar");
   |               ^^^^^ the trait `AsExpression<Integer>` is not implemented for `&str`
   |
   = help: the trait `AsExpression<Text>` is implemented for `&str`
   = help: for that trait implementation, expected `Text`, found `Integer`
```

which makes it much easier for users to understand that they are facing
a type mismatch.

Other explored example usages included

* This standard library error message: https://github.com/rust-lang/rust/pull/128008
* That bevy derived example:
e1f3068995/tests/ui/diagnostic_namespace/do_not_recommend/supress_suggestions_in_help.rs (No
more tuple pyramids)

Fixes #51992
2024-12-18 07:10:53 +01:00
Josh Triplett
a105cd6066 Use field init shorthand where possible
Field init shorthand allows writing initializers like `tcx: tcx` as
`tcx`. The compiler already uses it extensively. Fix the last few places
where it isn't yet used.
2024-12-17 14:33:10 -08:00
Matthias Krüger
3b0df8c59f
Rollup merge of #134426 - hkBst:patch-3, r=lqd
Fix typo in uint_macros.rs
2024-12-17 22:34:44 +01:00
Marijn Schouten
c482b31195
Fix typo in uint_macros.rs 2024-12-17 14:43:22 +01:00
ltdk
cb487cc2fa Stabilize #[coverage] attribute 2024-12-16 21:07:06 -05:00
Matthias Krüger
d9ba4bf6fe
Rollup merge of #134277 - notriddle:notriddle/inline-into, r=GuillaumeGomez
rustdoc-search: handle `impl Into<X>` better

This PR fixes two bugs I ran into while searching the compiler docs:

- It omitted an `impl Trait` entry in the type signature field, producing `TyCtxt, , Symbol -> bool`
- It didn't let me search for `TyCtxt, DefId, Symbol -> bool` even though that's a perfectly good description of the function I was looking for (the function actually used `impl Into<DefId>`

r? ``@GuillaumeGomez`` cc ``@lolbinarycat``
2024-12-16 20:00:20 +01:00
Stuart Cook
b974187950
Rollup merge of #134310 - tkr-sh:master, r=Noratrieb
Add clarity to the examples of some `Vec` & `VecDeque` methods

In some `Vec` and `VecDeque` examples where elements are `i32`, examples can seem a bit confusing at first glance if a parameter of the method is an `usize`.

In this case, I think it's better to use `char` rather than `i32`.

> [!NOTE]
> It's already done in the implementation of `VecDeque::insert`

#### Difference

- `i32`
```rs
let mut v = vec![1, 2, 3];
assert_eq!(v.remove(1), 2);
assert_eq!(v, [1, 3]);
```
- `char`
```rs
let mut v = vec!['a', 'b', 'c'];
assert_eq!(v.remove(1), 'b');
assert_eq!(v, ['a', 'c']);
```

Even tho it's pretty minor, it's a nice to have.
2024-12-15 20:01:38 +11:00
EFanZh
b5ea631fbd Asserts the maximum value that can be returned from Vec::len 2024-12-15 15:44:56 +08:00
Matthias Krüger
9b9905593f
Rollup merge of #134022 - shahn:doc_clarify_extend_for_tuple_version, r=tgross35
Doc: Extend for tuples to be stabilized in 1.85.0

I assumed the RUSTC_CURRENT_VERSION would be replaced automatically, but it doesn't look like it on the nightly docs page. Sorry!
2024-12-14 23:56:31 +01:00
Sebastian Hahn
7717df2286 Correct spelling of CURRENT_RUSTC_VERSION
I mixed it up with RUSTC_CURRENT_VERSION unfortunately. Also improve the
formatting of the macro invocation slightly.
2024-12-14 21:40:11 +01:00
tkirishima
6d5c591405 Replace i32 by char in split_at & _unchecked 2024-12-14 14:25:55 +00:00
bors
f1ec5d64b3 Auto merge of #134296 - matthiaskrgr:rollup-o0sxozj, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #132150 (Fix powerpc64 big-endian FreeBSD ABI)
 - #133942 (Clarify how to use `black_box()`)
 - #134081 (Try to evaluate constants in legacy mangling)
 - #134192 (Remove `Lexer`'s dependency on `Parser`.)
 - #134208 (coverage: Tidy up creation of covmap and covfun records)
 - #134211 (On Neutrino QNX, reduce the need to set archiver via environment variables)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-12-14 13:06:18 +00:00
Matthias Krüger
8abb823520
Rollup merge of #133942 - BD103:black-box-docs, r=saethlin
Clarify how to use `black_box()`

Closes #133923.

r? libs
^ (I think that's the right group, this is my first time!)

This PR adds further clarification on the [`black_box()`](https://doc.rust-lang.org/stable/std/hint/fn.black_box.html) documentation. Specifically, it teaches _how_ to use it, instead of just _when_ to use it.

I tried my best to make it clear and accurate, but a lot of my information is sourced from https://github.com/rust-lang/rust-clippy/issues/12707 and [manually inspecting assembly](https://godbolt.org/). Please tell me if I got anything wrong!
2024-12-14 05:01:05 +01:00
Matthias Krüger
0b5003eaf0
Rollup merge of #134255 - bjoernager:master, r=Noratrieb
Update includes in `/library/core/src/error.rs`.

This PR removes the `crate::fmt::Result` include in `/library/core/src/error.rs`.

The main issue with this `use` statement is that it shadows the `Result` type from the prelude (i.e. `crate::result::Result`). This indirectly makes all docs references to `Result` in this module point to the wrong type (but only in `core::error` - not `std::error`, wherein this include isn't present to begin with).

Fixes: #134169
2024-12-14 04:09:34 +01:00
Michael Howell
246835eda4 rustdoc-search: let From and Into be unboxed 2024-12-13 11:05:30 -07:00
Matthias Krüger
8cce32ae2b
Rollup merge of #134229 - purplesyringa:provenance-docs, r=saethlin
Fix typos in docs on provenance

This is related to [strict provenance](https://github.com/rust-lang/rust/issues/95228).

Added a couple cross-refs, also replaced

> Create a pointer without provenance from just an address (see [`ptr::dangling`]).

with

> Create a pointer without provenance from just an address (see [`without_provenance`]).

as this method actually takes an address.
2024-12-13 17:25:31 +01:00
Matthias Krüger
5c9b227a3d
Rollup merge of #134140 - compiler-errors:unsafe-binders-ast, r=oli-obk
Add AST support for unsafe binders

I'm splitting up #130514 into pieces. It's impossible for me to keep up with a huge PR like that. I'll land type system support for this next, probably w/o MIR lowering, which will come later.

r? `@oli-obk`
cc `@BoxyUwU` and `@lcnr` who also may want to look at this, though this PR doesn't do too much yet
2024-12-13 17:25:31 +01:00
bors
4847d6a9d0 Auto merge of #134047 - saethlin:inline-fmt-rt, r=m-ou-se
Switch inline(always) in core/src/fmt/rt.rs to plain inline

I have a vague memory of these being instantiated a lot. Let's ask perf.

Looks like this is an improvement!
2024-12-13 12:04:04 +00:00
Gabriel Bjørnager Jensen
38eb608a43 Update includes in '/library/core/src/error.rs'; 2024-12-13 12:46:20 +01:00
Michael Goulet
c605c84be8 Stabilize async closures 2024-12-13 00:04:56 +00:00
Alisa Sireneva
6ce7ba4300 Fix typos in docs on provenance 2024-12-12 22:52:12 +03:00
BD103
7fb2fc01a5 feat: clarify how to use black_box()
Co-authored-by: Ben Kimock <kimockb@gmail.com>
2024-12-12 13:54:17 -05:00
Michael Goulet
3f97c6be8d Add unwrap_unsafe_binder and wrap_unsafe_binder macro operators 2024-12-12 16:29:40 +00:00
Matthias Krüger
10556598e5
Rollup merge of #134179 - zachs18:align_offset_mut_ptr_doc, r=workingjubilee
Remove outdated consteval note from `<*mut T>::align_offset` docs.
2024-12-12 08:07:04 +01:00
Matthias Krüger
90f6b27a93
Rollup merge of #134178 - ehuss:stabilize-2024-prelude, r=amanieu,traviscross,tgross35
Stabilize the Rust 2024 prelude

This stabilizes the `core::prelude::rust_2024` and `std::prelude::rust_2024` modules. I missed these in the #133349 stabilization.
2024-12-12 08:07:04 +01:00
Eric Huss
1bc58979a2 Stabilize the Rust 2024 prelude 2024-12-11 13:09:57 -08:00
bors
21fe748be1 Auto merge of #134177 - matthiaskrgr:rollup-hgp8q60, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #132975 (De-duplicate and improve definition of core::ffi::c_char)
 - #133598 (Change `GetManyMutError` to match T-libs-api decision)
 - #134148 (add comments in check_expr_field)
 - #134163 (coverage: Rearrange the code for embedding per-function coverage metadata)
 - #134165 (wasm(32|64): update alignment string)
 - #134170 (Subtree update of `rust-analyzer`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-12-11 19:06:46 +00:00
Matthias Krüger
2e60288ce0
Rollup merge of #133598 - ChayimFriedman2:get-many-mut-detailed-err, r=scottmcm
Change `GetManyMutError` to match T-libs-api decision

That is, differentiate between out-of-bounds and overlapping indices, and remove the generic parameter `N`.

I also exported `GetManyMutError` from `alloc` (and `std`), which was apparently forgotten.

Changing the error to carry additional details means LLVM no longer generates separate short-circuiting branches for the checks, instead it generates one branch at the end. I therefore changed the  code to use early returns to make LLVM generate jumps. Benchmark results between the approaches are somewhat mixed, but I chose this approach because it is significantly faster with ranges and also faster with `unwrap()`.

Benchmark (`jumps` refer to short-circuiting, `acc` is not short-circuiting):
```rust
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use my_crate::{get_many_check_valid_acc, get_many_check_valid_jumps, GetManyMutError};

mod externs {
    #[unsafe(no_mangle)]
    fn foo() {}
    #[unsafe(no_mangle)]
    fn bar() {}
    #[unsafe(no_mangle)]
    fn baz() {}
}

unsafe extern "C" {
    safe fn foo();
    safe fn bar();
    safe fn baz();
}

fn bench_method(c: &mut Criterion) {
    c.bench_function("jumps two usize", |b| {
        b.iter(|| get_many_check_valid_jumps(&[black_box(1), black_box(5)], black_box(10)))
    });
    c.bench_function("jumps two usize unwrap", |b| {
        b.iter(|| get_many_check_valid_jumps(&[black_box(1), black_box(5)], black_box(10)).unwrap())
    });
    c.bench_function("jumps two usize ok", |b| {
        b.iter(|| get_many_check_valid_jumps(&[black_box(1), black_box(5)], black_box(10)).ok())
    });
    c.bench_function("jumps three usize", |b| {
        b.iter(|| {
            get_many_check_valid_jumps(&[black_box(1), black_box(5), black_box(7)], black_box(10))
        })
    });
    c.bench_function("jumps three usize match", |b| {
        b.iter(|| {
            match get_many_check_valid_jumps(
                &[black_box(1), black_box(5), black_box(7)],
                black_box(10),
            ) {
                Err(GetManyMutError::IndexOutOfBounds) => foo(),
                Err(GetManyMutError::OverlappingIndices) => bar(),
                Ok(()) => baz(),
            }
        })
    });
    c.bench_function("jumps two Range", |b| {
        b.iter(|| {
            get_many_check_valid_jumps(
                &[black_box(1)..black_box(5), black_box(7)..black_box(8)],
                black_box(10),
            )
        })
    });
    c.bench_function("jumps two RangeInclusive", |b| {
        b.iter(|| {
            get_many_check_valid_jumps(
                &[black_box(1)..=black_box(5), black_box(7)..=black_box(8)],
                black_box(10),
            )
        })
    });

    c.bench_function("acc two usize", |b| {
        b.iter(|| get_many_check_valid_acc(&[black_box(1), black_box(5)], black_box(10)))
    });
    c.bench_function("acc two usize unwrap", |b| {
        b.iter(|| get_many_check_valid_acc(&[black_box(1), black_box(5)], black_box(10)).unwrap())
    });
    c.bench_function("acc two usize ok", |b| {
        b.iter(|| get_many_check_valid_acc(&[black_box(1), black_box(5)], black_box(10)).ok())
    });
    c.bench_function("acc three usize", |b| {
        b.iter(|| {
            get_many_check_valid_acc(&[black_box(1), black_box(5), black_box(7)], black_box(10))
        })
    });
    c.bench_function("acc three usize match", |b| {
        b.iter(|| {
            match get_many_check_valid_jumps(
                &[black_box(1), black_box(5), black_box(7)],
                black_box(10),
            ) {
                Err(GetManyMutError::IndexOutOfBounds) => foo(),
                Err(GetManyMutError::OverlappingIndices) => bar(),
                Ok(()) => baz(),
            }
        })
    });
    c.bench_function("acc two Range", |b| {
        b.iter(|| {
            get_many_check_valid_acc(
                &[black_box(1)..black_box(5), black_box(7)..black_box(8)],
                black_box(10),
            )
        })
    });
    c.bench_function("acc two RangeInclusive", |b| {
        b.iter(|| {
            get_many_check_valid_acc(
                &[black_box(1)..=black_box(5), black_box(7)..=black_box(8)],
                black_box(10),
            )
        })
    });
}

criterion_group!(benches, bench_method);
criterion_main!(benches);
```
Benchmark results:
```none
jumps two usize          time:   [586.44 ps 590.20 ps 594.50 ps]
jumps two usize unwrap   time:   [390.44 ps 393.63 ps 397.44 ps]
jumps two usize ok       time:   [585.52 ps 591.74 ps 599.38 ps]
jumps three usize        time:   [976.51 ps 983.79 ps 991.51 ps]
jumps three usize match  time:   [390.82 ps 393.80 ps 397.07 ps]
jumps two Range          time:   [1.2583 ns 1.2640 ns 1.2695 ns]
jumps two RangeInclusive time:   [1.2673 ns 1.2770 ns 1.2877 ns]
acc two usize            time:   [592.63 ps 596.44 ps 600.52 ps]
acc two usize unwrap     time:   [582.65 ps 587.07 ps 591.90 ps]
acc two usize ok         time:   [581.59 ps 587.82 ps 595.71 ps]
acc three usize          time:   [894.69 ps 901.23 ps 908.24 ps]
acc three usize match    time:   [392.68 ps 395.73 ps 399.17 ps]
acc two Range            time:   [1.5531 ns 1.5617 ns 1.5711 ns]
acc two RangeInclusive   time:   [1.5746 ns 1.5840 ns 1.5939 ns]
```
2024-12-11 20:00:14 +01:00
Matthias Krüger
fe516ef9f4
Rollup merge of #132975 - arichardson:ffi-c-char, r=tgross35
De-duplicate and improve definition of core::ffi::c_char

Instead of having a list of unsigned char targets for each OS, follow the logic Clang uses and instead set the value based on architecture with a special case for Darwin and Windows operating systems. This makes it easier to support new operating systems targeting Arm/AArch64 without having to modify this config statement for each new OS. The new list does not quite match Clang since I noticed a few bugs in the Clang implementation (https://github.com/llvm/llvm-project/issues/115957).

Fixes https://github.com/rust-lang/rust/issues/129945
Closes https://github.com/rust-lang/rust/pull/131319
2024-12-11 20:00:12 +01:00
Zachary S
6a8bc4bc6b Remove consteval note from <*mut T>::align_offset docs. 2024-12-11 12:56:12 -06:00
Jacob Pratt
43b4af5b77
Rollup merge of #134079 - tbu-:pr_doc_x8_to_from_xe_bytes, r=jhpratt
Add a note saying that `{u8,i8}::from_{be,le,ne}_bytes` is meaningless
2024-12-11 03:30:40 -05:00
Tobias Bucher
e37d7c0f15 Add a note saying that {u8,i8}::from_{be,le,ne}_bytes is meaningless 2024-12-11 02:18:17 +01:00
León Orell Valerian Liehr
e822dfc415
Rollup merge of #134116 - RalfJung:const_nonnull_new, r=jhpratt
stabilize const_nonnull_new

FCP passed in https://github.com/rust-lang/rust/issues/93235

Closes #93235
2024-12-10 20:16:06 +01:00
León Orell Valerian Liehr
f621be4ecc
Rollup merge of #134100 - eholk:noop-rustc-const-stable, r=dtolnay
Remove rustc_const_stable attribute on const NOOP

This was accidentally reintroduced while editing #133089.

r? dtolnay
2024-12-10 20:16:03 +01:00
Alex Richardson
dd3e98c58b Add references to the specific ABI documents
Expcept for L4RE and Xtensa these were obtained from #131319

I could not find an open link to the Xtensa documentation, but the
signedness was confirmed by on of the Xtensa developers in
https://github.com/llvm/llvm-project/pull/115967#issuecomment-2506292323

Co-authored-by: Taiki Endo <te316e89@gmail.com>
2024-12-10 08:33:29 -08:00
Alex Richardson
e8bcce77bb Remove l4re from the unsigned char operating system list
As noted in https://github.com/rust-lang/rust/pull/132975#issuecomment-2484645240,
the default for userland apps is to follow the architecture defaults, the
-funsigned-char flag only applies to kernel builds.
2024-12-10 08:33:29 -08:00
Alex Richardson
028ca8e616 De-duplicate and improve definition of core::ffi::c_char
Instead of having a list of unsigned char targets for each OS, follow the
logic Clang uses and instead set the value based on architecture with
a special case for Darwin and Windows operating systems. This makes it
easier to support new operating systems targeting Arm/AArch64 without
having to modify this config statement for each new OS. The new list does
not quite match Clang since I noticed a few bugs in the Clang
implementation (https://github.com/llvm/llvm-project/issues/115957).

Fixes: https://github.com/rust-lang/rust/issues/129945
2024-12-10 08:33:29 -08:00
Ralf Jung
a8d11ea20e stabilize const_nonnull_new 2024-12-10 11:29:01 +01:00
Eric Holk
b9afc78585
Remove rustc_const_stable attribute on const NOOP
This was accidentally reintroduced while editing #133089.
2024-12-09 15:08:30 -08:00
León Orell Valerian Liehr
e0f3db0056
Rollup merge of #134032 - snprajwal:fix-docs, r=joboet
docs: better examples for `std::ops::ControlFlow`

Fixes #133963. Lesson learnt, never force-push from a bare clone of a repo 💀
2024-12-09 23:39:04 +01:00
joboet
49d76b8d0e
core: use public method instead of instrinsic 2024-12-09 13:27:06 +01:00
Jonas Böttiger
13c77ba34d
core: improve comments
Co-authored-by: Yotam Ofek <yotam.ofek@gmail.com>
Co-authored-by: Hanna Kruppe <hanna.kruppe@gmail.com>
2024-12-09 13:22:39 +01:00
bors
1b3fb31675 Auto merge of #134052 - matthiaskrgr:rollup-puxwqrk, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #133567 (A bunch of cleanups)
 - #133789 (Add doc alias 'then_with' for `then` method on `bool`)
 - #133880 (Expand home_dir docs)
 - #134036 (crash tests: use individual mir opts instead of mir-opt-level where easily possible)
 - #134045 (Fix some triagebot mentions paths)
 - #134046 (Remove ignored tests for hangs w/ new solver)
 - #134050 (Miri subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-12-09 03:24:24 +00:00
Matthias Krüger
38cc868e21
Rollup merge of #133789 - rossmacarthur:then-with-doc-alias, r=Mark-Simulacrum
Add doc alias 'then_with' for `then` method on `bool`

I think its logical to search for this name since `Ordering::then_with` exists as well.
2024-12-09 01:56:32 +01:00
Ben Kimock
5f68526b31 Switch inline(always) in core/src/fmt/rt.rs to plain inline 2024-12-08 15:41:00 -05:00
aaishwarymishra@gmail.com
292fd0ffed Adds new intrinsic declaration
changes old intrinsic to new declaration
2024-12-08 19:46:45 +05:30
Prajwal S N
477b722fe1
docs: better examples for std::ops::ControlFlow
Signed-off-by: Prajwal S N <prajwalnadig21@gmail.com>
2024-12-08 18:21:15 +05:30
bors
9c707a8b76 Auto merge of #133978 - matthiaskrgr:rollup-6gh1iho, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #130209 (Stabilize `std::io::ErrorKind::CrossesDevices`)
 - #130254 (Stabilize `std::io::ErrorKind::QuotaExceeded`)
 - #132187 (Add Extend impls for tuples of arity 1 through 12)
 - #133875 (handle `--json-output` properly)
 - #133934 (Do not implement unsafe auto traits for types with unsafe fields)
 - #133954 (Hide errors whose suggestions would contain error constants or types)
 - #133960 (rustdoc: remove eq for clean::Attributes)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-12-07 09:38:00 +00:00
bors
75716b4510 Auto merge of #118159 - EliasHolzmann:formatting_options, r=m-ou-se
Implementation of `fmt::FormattingOptions`

Tracking issue: #118117

Public API:
```rust
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct FormattingOptions { … }
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Sign {
    Plus,
    Minus
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum DebugAsHex {
    Lower,
    Upper
}

impl FormattingOptions {
    pub fn new() -> Self;
    pub fn sign(&mut self, sign: Option<Sign>) -> &mut Self;
    pub fn sign_aware_zero_pad(&mut self, sign_aware_zero_pad: bool) -> &mut Self;
    pub fn alternate(&mut self, alternate: bool) -> &mut Self;
    pub fn fill(&mut self, fill: char) -> &mut Self;
    pub fn align(&mut self, alignment: Option<Alignment>) -> &mut Self;
    pub fn width(&mut self, width: Option<usize>) -> &mut Self;
    pub fn precision(&mut self, precision: Option<usize>) -> &mut Self;
    pub fn debug_as_hex(&mut self, debug_as_hex: Option<DebugAsHex>) -> &mut Self;

    pub fn get_sign(&self) -> Option<Sign>;
    pub fn get_sign_aware_zero_pad(&self) -> bool;
    pub fn get_alternate(&self) -> bool;
    pub fn get_fill(&self) -> char;
    pub fn get_align(&self) -> Option<Alignment>;
    pub fn get_width(&self) -> Option<usize>;
    pub fn get_precision(&self) -> Option<usize>;
    pub fn get_debug_as_hex(&self) -> Option<DebugAsHex>;

    pub fn create_formatter<'a>(self, write: &'a mut (dyn Write + 'a)) -> Formatter<'a>;
    }

impl<'a> Formatter<'a> {
    pub fn new(write: &'a mut (dyn Write + 'a), options: FormattingOptions) -> Self;
    pub fn with_options<'b>(&'b mut self, options: FormattingOptions) -> Formatter<'b>;
    pub fn sign(&self) -> Option<Sign>;

    pub fn options(&self) -> FormattingOptions;
}
```

Relevant changes from the public API in the tracking issue (I'm leaving out some stuff I consider obvious mistakes, like missing `#[derive(..)]`s and `pub` specifiers):

- `enum DebugAsHex`/`FormattingOptions::debug_as_hex`/`FormattingOptions::get_debug_as_hex`: To support `{:x?}` as well as `{:X?}`. I had completely missed these options in the ACP. I'm open for any and all bikeshedding, not married to the name.
- `fill`/`get_fill` now takes/returns `char` instead of `Option<char>`. This simply mirrors what `Formatter::fill` returns (with default being `' '`).
- Changed `zero_pad`/`get_zero_pad` to `sign_aware_zero_pad`/`get_sign_aware_zero_pad`. This also mirrors `Formatter::sign_aware_zero_pad`. While I'm not a fan of this quite verbose name, I do believe that having the interface of `Formatter` and `FormattingOptions` be compatible is more important.
- For the same reason, renamed `alignment`/`get_alignment` to `aling`/`get_align`.
- Deviating from my initial idea, `Formatter::with_options` returns a `Formatter` which has the lifetime of the `self` reference as its generic lifetime parameter (in the original API spec, the generic lifetime of the returned `Formatter` was the generic lifetime used by `self` instead). Otherwise, one could construct two `Formatter`s that both mutably borrow the same underlying buffer, which would be unsound. This solution still has performance benefits over simply using `Formatter::new`, so I believe it is worthwhile to keep this method.
2024-12-06 22:28:42 +00:00
Matthias Krüger
bfbbe95502
Rollup merge of #132187 - shahn:extend_more_tuples, r=dtolnay
Add Extend impls for tuples of arity 1 through 12
2024-12-06 21:21:05 +01:00
bors
8dc83770f7 Auto merge of #133089 - eholk:stabilize-noop-waker, r=dtolnay
Stabilize noop_waker

Tracking Issue: #98286

This is a handy feature that's been used widely in tests and example async code and it'd be nice to make it available to users.

cc `@rust-lang/wg-async`
2024-12-06 18:34:16 +00:00
joboet
69942f0132
core: implement bool::select_unpredictable 2024-12-06 15:07:50 +01:00
Guillaume Gomez
5a9c9ef541
Rollup merge of #133821 - Kobzol:replace-black-with-ruff, r=onur-ozkan
Replace black with ruff in `tidy`

`ruff` can both lint and format Python code (in fact, it should be a mostly drop-in replacement for `black` in terms of formatting), so it's not needed to use `black` anymore. This PR removes `black` and replaces it with `ruff`, to get rid of one Python dependency, and also to make Python formatting faster (although that's a small thing).

If we decide to merge this, we'll need to "reformat the world" - `ruff` is not perfectly compatible with `black`, and it also looks like `black` was actually ignoring some files before. I tried it locally (`./x test tidy --extra-checks=py:fmt --bless`) and it also reformatted some code in subtrees (e.g. `clippy` or `rustc_codegen_gcc`) - I'm not sure how to handle that.
2024-12-05 23:47:11 +01:00
Eric Holk
72ce1ab42f
Stabilize noop_waker
Co-authored-by: zachs18 <8355914+zachs18@users.noreply.github.com>
2024-12-05 14:14:17 -08:00
Elias Holzmann
31a5657109 Access members of FormattingOptions directly instead of via getters/setters 2024-12-05 21:48:36 +01:00
Elias Holzmann
2f9e0c984b Removed constness for methods receiving a &mut parameter
See https://github.com/rust-lang/rust/pull/118159#discussion_r1495760867
for context.
2024-12-05 21:48:36 +01:00
Elias Holzmann
245acf819d Added better reason for exposing flags and get_flags as unstable 2024-12-05 21:48:36 +01:00
Elias Holzmann
2fc260802c Formatted 2024-12-05 21:48:35 +01:00
Elias Holzmann
832a5f292f Refactored FormattingOptions to use a bitmask for storing flags 2024-12-05 21:48:35 +01:00
Elias Holzmann
5b236555d2 Revert "Turned public+unstable+hidden functions into private functions"
See https://github.com/rust-lang/rust/pull/118159#discussion_r1491842170 for
context.

This reverts commit 62078dffcc1aefd4d678df94bca06e7b864065bd.
2024-12-05 21:48:35 +01:00
Elias Holzmann
7eac57a395 Turned public+unstable+hidden functions into private functions 2024-12-05 21:48:35 +01:00
Elias Holzmann
b8b50aecc4 Made all fns const 2024-12-05 21:48:35 +01:00
Elias Holzmann
de073f42a8 impl Default for fmt::FormattingOptions 2024-12-05 21:48:35 +01:00
Elias Holzmann
a5a6d40791 Fixed copy+paste error in comment
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2024-12-05 21:48:35 +01:00
Elias Holzmann
ecdf48e2b1 fmt::FormattingOptions: Renamed alignment to align
Likewise for `get_alignment`. This is how the method is named on `Formatter`, I
want to keep it consistent.
2024-12-05 21:48:35 +01:00
Elias Holzmann
b0d3958e00 Formatter::with_options: Use different lifetimes
Formatter::with_options takes self as a mutable reference (`&'a mut
Formatter<'b>`). `'a` and `'b` need to be different lifetimes. Just taking `&'a
mut Formatter<'a>` and trusting in Rust being able to implicitely convert from
`&'a mut Formatter<'b>` if necessary (after all, `'a` must be smaller than `'b`
anyway) fails because `'b` is behind a *mutable* reference. For background on
on this behavior, see https://doc.rust-lang.org/nomicon/subtyping.html#variance.
2024-12-05 21:48:35 +01:00
Elias Holzmann
f17d13285c Added struct fmt::FormattingOptions
This allows to build custom `std::Formatter`s at runtime.

Also added some related enums and two related methods on `std::Formatter`.
2024-12-05 21:48:01 +01:00
Elias Holzmann
1d7984a132 Formatter: Access members via getter methods wherever possible
The idea behind this is to make implementing `fmt::FormattingOptions` (as well
as any future changes to `std::Formatter`) easier.

In theory, this might have a negative performance impact because of the
additional function calls. However, I strongly believe that those will be
inlined anyway, thereby producing assembly code that has comparable performance.
2024-12-05 21:47:13 +01:00
Jacob Pratt
f5f8a1f8ce
Rollup merge of #133844 - RalfJung:simd_relaxed_fma-nondet, r=workingjubilee
clarify simd_relaxed_fma non-determinism

This is the safer spec in the sense that it is more likely to be satisfied by the backend -- and if people are okay with a non-deterministic result, I assume they don't care whether it's the same choice across all lanes or not?

Cc ``@calebzulawski`` ``@workingjubilee``
2024-12-05 05:50:51 -05:00
Jacob Pratt
b5a7f41a87
Rollup merge of #127565 - esp-rs:xtensa-vaargs, r=workingjubilee
Teach rustc about the Xtensa VaListImpl

Following on from the target Xtensa target PRs (https://github.com/rust-lang/rust/pull/125141, https://github.com/rust-lang/rust/pull/126380), this PR teaches rustc about the structure of the VA list on the Xtensa arch, as well as adding the required lowering to be able to actually use it.
2024-12-05 05:50:50 -05:00
León Orell Valerian Liehr
44174d9213
Rollup merge of #133863 - oli-obk:push-pystoxvtvssx, r=lqd
Rename `core_pattern_type` and `core_pattern_types` lib feature  gates to `pattern_type_macro`

That's what the gates are actually gating, and the single char difference in naming was not helpful either

fixes #128987
2024-12-05 07:29:56 +01:00
León Orell Valerian Liehr
35ea48d588
Rollup merge of #118833 - Urgau:lint_function_pointer_comparisons, r=cjgillot
Add lint against function pointer comparisons

This is kind of a follow-up to https://github.com/rust-lang/rust/pull/117758 where we added a lint against wide pointer comparisons for being ambiguous and unreliable; well function pointer comparisons are also unreliable. We should IMO follow a similar logic and warn people about it.

-----

## `unpredictable_function_pointer_comparisons`

*warn-by-default*

The `unpredictable_function_pointer_comparisons` lint checks comparison of function pointer as the operands.

### Example

```rust
fn foo() {}
let a = foo as fn();

let _ = a == foo;
```

### Explanation

Function pointers comparisons do not produce meaningful result since they are never guaranteed to be unique and could vary between different code generation units. Furthermore different function could have the same address after being merged together.

----

This PR also uplift the very similar `clippy::fn_address_comparisons` lint, which only linted on if one of the operand was an `ty::FnDef` while this PR lints proposes to lint on all `ty::FnPtr` and `ty::FnDef`.

```@rustbot``` labels +I-lang-nominated

~~Edit: Blocked on https://github.com/rust-lang/libs-team/issues/323 being accepted and it's follow-up pr~~
2024-12-05 07:29:53 +01:00
Jakub Beránek
536516f949
Reformat Python code with ruff 2024-12-04 23:03:44 +01:00
Oli Scherer
f613636ae8 Rename core_pattern_type and core_pattern_types lib feature gates to pattern_type_macro
That's what the gates are actually gating, and the single char difference in naming was not helpful either
2024-12-04 16:16:24 +00:00
Ralf Jung
f4217f4296 clarify simd_relaxed_fma non-determinism 2024-12-04 08:39:19 +01:00
Matthias Krüger
68f8a53f12
Rollup merge of #133651 - scottmcm:nonnull-nonzero-no-field-projection, r=oli-obk
Update `NonZero` and `NonNull` to not field-project (per MCP#807)

https://github.com/rust-lang/compiler-team/issues/807#issuecomment-2506098540 was accepted, so this is the first PR towards moving the library to not using field projections into `[rustc_layout_scalar_valid_range_*]` types.

`NonZero` was already using `transmute` nearly everywhere, so there are very few changes to it.

`NonNull` needed more changes, but they're mostly simple, changing `.pointer` to `.as_ptr()`.

r? libs

cc #133324, which will tidy up some of the MIR from this a bit more, but isn't a blocker.
2024-12-04 05:42:07 +01:00
bors
3b382642ab Auto merge of #133818 - matthiaskrgr:rollup-iav1wq7, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #132937 (a release operation synchronizes with an acquire operation)
 - #133681 (improve TagEncoding::Niche docs, sanity check, and UB checks)
 - #133726 (Add `core::arch::breakpoint` and test)
 - #133768 (Remove `generic_associated_types_extended` feature gate)
 - #133811 ([AIX] change AIX default codemodel=large)
 - #133812 (Update wasm-component-ld to 0.5.11)
 - #133813 (compiletest: explain that UI tests are expected not to compile by default)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-12-04 00:47:09 +00:00
Matthias Krüger
e66e632479
Rollup merge of #133726 - joshtriplett:breakpoint, r=oli-obk
Add `core::arch::breakpoint` and test

Approved in [ACP 491](https://github.com/rust-lang/libs-team/issues/491).
2024-12-03 21:55:27 +01:00
Scott McMurray
7afce4f06a Update NonZero and NonNull to not field-project (per MCP807) 2024-12-03 11:13:34 -08:00
Matthias Krüger
b78ab2fdc1
Rollup merge of #133796 - TDecking:borrowing-sub, r=tgross35
Update the definition of `borrowing_sub`

Complementary PR to https://github.com/rust-lang/rust/pull/133674, which only updated `carrying_add`.
2024-12-03 17:27:11 +01:00
Matthias Krüger
f224ad85ff
Rollup merge of #133762 - RalfJung:const-size-of-val, r=workingjubilee
stabilize const_{size,align}_of_val

FCP passed [here](https://github.com/rust-lang/rust/issues/46571#issuecomment-2460285288).

Fixes https://github.com/rust-lang/rust/issues/46571.
2024-12-03 17:27:09 +01:00
Matthias Krüger
1ae6f4756e
Rollup merge of #133696 - RalfJung:const-hashmap, r=cuviper
stabilize const_collections_with_hasher and build_hasher_default_const_new

After a lot of preparatory work, finally we can stabilize creating `HashMap` in const context. :)

FCP for const_collections_with_hasher passed in https://github.com/rust-lang/rust/issues/102575.
Fixes https://github.com/rust-lang/rust/issues/102575.

FCP for build_hasher_default_const_new passed in https://github.com/rust-lang/rust/issues/123197.
Fixes https://github.com/rust-lang/rust/issues/123197.

Cc `@Amanieu`
Release notes: https://github.com/rust-lang/rust/issues/133347
2024-12-03 17:27:07 +01:00
Tobias Decking
8b7d3d3967
Update the definition of borrowing_sub
This ensures that it matches the one in `carrying_add`.
2024-12-03 15:31:00 +01:00
Brian J. Tarricone
059f6272c3 Teach rust core about Xtensa VaListImpl and add a custom lowering of vaarg for xtensa.
LLVM does not include an implementation of the va_arg instruction for
Xtensa. From what I understand, this is a conscious decision and
instead language frontends are encouraged to implement it themselves.
The rationale seems to be that loading values correctly requires
language and ABI-specific knowledge that LLVM lacks.

This is true of most architectures, and rustc already provides
implementation for a number of them. This commit extends the support to
include Xtensa.

See https://lists.llvm.org/pipermail/llvm-dev/2017-August/116337.html
for some discussion on the topic.

Unfortunately there does not seem to be a reference document for the
semantics of the va_list and va_arg on Xtensa. The most reliable source
is the GCC implementation, which this commit tries to follow. Clang also
provides its own compatible implementation.

This was tested for all the types that rustc allows in variadics.

Co-authored-by: Brian Tarricone <brian@tarricone.org>
Co-authored-by: Jonathan Bastien-Filiatrault <joe@x2a.org>
Co-authored-by: Paul Lietar <paul@lietar.net>
2024-12-03 10:54:08 +00:00
Josh Triplett
a030ffbe35 Add core::arch::breakpoint and test
Approved in [ACP 491](https://github.com/rust-lang/libs-team/issues/491).

Remove the `unsafe` on `core::intrinsics::breakpoint()`, since it's a
safe intrinsic to call and has no prerequisites.

(Thanks to @zachs18 for figuring out the `bootstrap`/`not(bootstrap)`
logic.)
2024-12-02 23:56:24 -08:00
Ross MacArthur
15feb5dc31
Add doc alias 'then_with' for then method on bool 2024-12-03 09:20:34 +02:00
Matthias Krüger
9709334061
Rollup merge of #133395 - calebzulawski:simd_relaxed_fma, r=workingjubilee
Add simd_relaxed_fma intrinsic

Adds compiler support for https://github.com/rust-lang/portable-simd/issues/387#issuecomment-2337169786

r? `@workingjubilee`

cc `@RalfJung` is this kind of nondeterminism a problem for miri/opsem?
2024-12-03 07:48:33 +01:00
Guillaume Gomez
73f225acf6
Rollup merge of #133763 - Urgau:f16-midpoint-const-feat, r=Amanieu
Fix `f16::midpoint` const feature gate

cc https://github.com/rust-lang/rust/pull/131784#discussion_r1866074470
2024-12-02 23:08:59 +01:00
Guillaume Gomez
e56e68541b
Rollup merge of #131713 - tgross35:stabilize-const_maybe_uninit_write, r=RalfJung,dtolnay
Stabilize `const_maybe_uninit_write`

Mark the following API const stable:

```rust
impl<T> MaybeUninit<T> {
    pub const fn write(&mut self, val: T) -> &mut T;
}
```

This depends on `const_mut_refs` and [`const_maybe_uninit_assume_init`](https://github.com/rust-lang/rust/issues/86722), both of which have recently been stabilized.

Closes: <https://github.com/rust-lang/rust/issues/63567>
2024-12-02 23:08:52 +01:00
Ralf Jung
2b88e4c716 stabilize const_{size,align}_of_val 2024-12-02 20:18:25 +01:00
Trevor Gross
c5fedc2267 Stabilize const_maybe_uninit_write
Mark the following API const stable:

    impl<T> MaybeUninit<T> {
        pub const fn write(&mut self, val: T) -> &mut T;
    }

This depends on `const_mut_refs` and `const_maybe_uninit_assume_init`,
both of which have recently been stabilized.

Tracking issue: <https://github.com/rust-lang/rust/issues/63567>
2024-12-02 14:06:56 -05:00
Urgau
7b06fcf559 Allow fn pointers comparisons lint in library 2024-12-02 18:43:37 +01:00
Urgau
72297d4272 Fix f16::midpoint const feature gate 2024-12-02 18:26:00 +01:00
Guillaume Gomez
1638a5514b
Rollup merge of #133743 - bjoernager:slice-as-array, r=joboet
Fix docs for `<[T]>::as_array`.

Tracking issue: #133508

This PR fixes a small typographical error in the docs entry for `<[T]>::as_array`.
2024-12-02 17:36:08 +01:00
Ralf Jung
3a9bc76f80 stabilize const_collections_with_hasher and build_hasher_default_const_new 2024-12-02 16:34:39 +01:00
bors
3bff51ea91 Auto merge of #133728 - jhpratt:rollup-k1i60pg, r=jhpratt
Rollup of 4 pull requests

Successful merges:

 - #133589 (Remove `hir::ArrayLen`)
 - #133672 (Remove a bunch of unnecessary const stability noise)
 - #133678 (Stabilize `ptr::fn_addr_eq`)
 - #133727 (Update mailmap)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-12-02 12:17:12 +00:00
Gabriel Bjørnager Jensen
b1ff3c8b92 Fix docs for '<[T]>::as_array'; 2024-12-02 10:38:40 +01:00
Jacob Pratt
10f3735a02
Rollup merge of #133678 - Urgau:stabilize-ptr_fn_addr_eq, r=jhpratt
Stabilize `ptr::fn_addr_eq`

This PR stabilize the `ptr::fn_addr_eq` function.

FCP completed in https://github.com/rust-lang/rust/issues/129322#issuecomment-2508304516
Closes https://github.com/rust-lang/rust/issues/129322
2024-12-01 22:10:24 -05:00
Jacob Pratt
8f7a10670f
Rollup merge of #133672 - RalfJung:const-stability-cleanup, r=jhpratt
Remove a bunch of unnecessary const stability noise
2024-12-01 22:10:23 -05:00
Jacob Pratt
5880752b9a
Rollup merge of #131784 - Urgau:stabilize-midpoint, r=dtolnay
Stabilize unsigned and float variants of `num_midpoint` feature

This PR proposes that we stabilize the unsigned variants of the [`num_midpoint`](https://github.com/rust-lang/rust/issues/110840#issue-1684506201) feature as well as the floats variants, since they are not subject to any unresolved questions, which is equivalent to doing `(a + b) / 2` (and `(a + b) >> 1`) in a sufficiently large number.

The stabilized API surface would be:

```rust
/// Calculates the middle point of `self` and `rhs`.
///
/// `midpoint(a, b)` is `(a + b) / 2` as if it were performed in a sufficiently-large unsigned integral type.
/// This implies that the result is always rounded towards negative infinity and that no overflow will ever occur.

impl u{8,16,32,64,128,size} {
    pub const fn midpoint(self, rhs: Self) -> Self;
}

impl NonZeroU{8,16,32,64,size} {
    pub const fn midpoint(self, rhs: Self) -> Self;
}

impl f{32,64} {
    pub const fn midpoint(self, rhs: Self) -> Self;
}
```

The signed variants `u{8,16,32,64,128,size}` would remain gated, until a decision is made about the rounding mode, in other words that the [unresolved questions](https://github.com/rust-lang/rust/issues/110840#issue-1684506201) are resolved.

cc `@rust-lang/libs-api`
cc `@scottmcm`
r? libs-api
2024-12-01 21:38:24 -05:00
Jacob Pratt
cb67512784
Rollup merge of #131416 - okaneco:const_copy, r=RalfJung
Mark `slice::copy_from_slice` unstably const

Tracking issue #131415

I used `const_eval_select` for runtime and const panic functions because const formatting isn't available yet.
2024-12-01 21:38:23 -05:00
okaneco
7f011a894f Mark slice::copy_from_slice unstably const 2024-12-01 16:39:56 -05:00
Matthias Krüger
2f00feb616
Rollup merge of #133674 - scottmcm:chain-carrying-add, r=Amanieu
Fix chaining `carrying_add`s

Something about the MIR lowering for `||` ended up breaking this, but it's fixed by changing the code to use `|` instead.

I also added an assembly test to ensure it *keeps* being [`adc`](https://www.felixcloutier.com/x86/adc).

cc https://github.com/rust-lang/rust/issues/85532#issuecomment-2495119815, which noticed this.
2024-12-01 14:30:11 +01:00
Matthias Krüger
3d18c3c414
Rollup merge of #133669 - RalfJung:const_swap_splitup, r=dtolnay
Move some functions out of const_swap feature gate

- `swap_unchecked` is still unstable as a regular fn, so that feature gate can also cover its constness.
- `swap_nonoverlapping` isn't ready to be stabilized yet, so make it a different feature gate.

Part of https://github.com/rust-lang/rust/issues/83163, https://github.com/rust-lang/rust/issues/88539, https://github.com/rust-lang/rust/issues/133668
2024-12-01 14:30:10 +01:00
Urgau
b88478f707 Stabilize unsigned num_midpoint feature 2024-12-01 11:28:53 +01:00
Matthias Krüger
3d365795fa
Rollup merge of #133686 - samueltardieu:push-xkxwxzxqokuu, r=compiler-errors
Add diagnostic item for `std::ops::ControlFlow`

This will be used in Clippy to detect useless conversions done through `ControlFlow::map_break()` and `ControlFlow::map_continue()`.
2024-12-01 08:15:25 +01:00
Samuel Tardieu
484c561d78 Add diagnostic item for std::ops::ControlFlow
This will be used in Clippy to detect useless conversions done through
`ControlFlow::map_break()` and `ControlFlow::map_continue()`.
2024-11-30 19:53:36 +01:00
bors
f981b2e27a Auto merge of #133659 - jieyouxu:rollup-576gh4p, r=jieyouxu
Rollup of 6 pull requests

Successful merges:

 - #131551 (Support input/output in vector registers of PowerPC inline assembly)
 - #132515 (Fix and undeprecate home_dir())
 - #132721 (CI: split x86_64-mingw job)
 - #133106 (changes old intrinsic declaration to new declaration)
 - #133496 (thread::available_parallelism for wasm32-wasip1-threads)
 - #133548 (Add `BTreeSet` entry APIs to match `HashSet`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-11-30 17:18:00 +00:00
Urgau
69c0326229 Stabilize ptr::fn_addr_eq 2024-11-30 16:15:47 +01:00
Ralf Jung
4ce2116aef get rid of a bunch of unnecessary rustc_const_unstable 2024-11-30 11:55:58 +01:00
Scott McMurray
9836196e3c Fix chaining carrying_adds
Something about the MIR lowering for `||` ended up breaking this, but it's fixed by changing the code to use `|` instead.

I also added an assembly test to ensure it *keeps* being `adc`.
2024-11-30 02:12:23 -08:00
Ralf Jung
2a05e5be4f add test for bytewise ptr::swap of a pointer 2024-11-30 10:42:17 +01:00
Ralf Jung
0dc94404ee remove a whole bunch of unnecessary const feature gates 2024-11-30 10:23:39 +01:00
Ralf Jung
ede5f0111d move swap_nonoverlapping constness to separate feature gate 2024-11-30 10:12:30 +01:00
Ralf Jung
23d9741be3 move slice::swap_unchecked constness to slice_swap_unchecked feature gate 2024-11-30 09:52:20 +01:00
许杰友 Jieyou Xu (Joe)
9e716c2788
Rollup merge of #133106 - BLANKatGITHUB:intrinsic, r=RalfJung
changes old intrinsic declaration to new declaration

This pr is for issue #132735

It changes old `extern "intrinsic"` code block with new declaration.

There are other blocks that use old declaration but as the changes needed in single block is quite large I do them in parts
2024-11-30 12:57:34 +08:00
许杰友 Jieyou Xu (Joe)
6512836be0
Rollup merge of #133625 - RalfJung:custom-mir-debug-info, r=compiler-errors
custom MIR: add doc comment for debuginfo

This is a revival of https://github.com/rust-lang/rust/pull/117015
2024-11-30 12:56:55 +08:00
bors
1fc691e6dd Auto merge of #133533 - BoxyUwU:bump-boostrap, r=jieyouxu,Mark-Simulacrum
Bump boostrap compiler to new beta

Currently failing due to something about the const stability checks and `panic!`. I'm not sure why though since I wasn't able to see any PRs merged in the past few days that would result in a `cfg(bootstrap)` that shouldn't be removed. cc `@RalfJung` #131349
2024-11-29 22:39:10 +00:00
Ralf Jung
6e449e18ad refine mir debuginfo docs 2024-11-29 14:01:53 +01:00
Camille GILLOT
c76f1f0b9b Doc comment custom MIR debuginfo.
and add a test for the constant case
2024-11-29 12:32:55 +01:00
Matthias Krüger
8ca5a907a5
Rollup merge of #133530 - timvisee:master, r=jhpratt
Use consistent wording in docs, use is zero instead of is 0

In documentation, wording of _"`rhs` is zero"_ and _"`rhs` is 0"_ is intermixed. This is especially visible [here](https://doc.rust-lang.org/std/primitive.usize.html#method.div_ceil).

This changes all occurrences to _"`rhs` is zero"_ for better readability.
2024-11-29 10:18:58 +01:00
Matthias Krüger
370fc13298
Rollup merge of #133466 - aksh1618:patch-1, r=thomcc
Fix typos in pin.rs
2024-11-29 10:18:56 +01:00
Chayim Refael Friedman
fa87a3e889 Change GetManyMutError to match T-libs-api decision
That is, differentiate between out-of-bounds and overlapping indices, and remove the generic parameter `N`.

I also exported `GetManyMutError` from `alloc` (and `std`), which was apparently forgotten.

Changing the error to carry additional details means LLVM no longer generates separate short-circuiting branches for the checks, instead it generates one branch at the end. I therefore changed the  code to use early returns to make LLVM generate jumps. Benchmark results between the approaches are somewhat mixed, but I chose this approach because it is significantly faster with ranges and also faster with `unwrap()`.
2024-11-28 23:34:47 +02:00
timvisee
89b20e95fd
Also use zero when referencing to capacity or length 2024-11-28 09:47:11 +01:00
timvisee
74cf503341
Use consistent wording in docs, use zero instead of 0 2024-11-28 09:39:33 +01:00