Commit Graph

7607 Commits

Author SHA1 Message Date
Gabriel Bjørnager Jensen
5efb3ef2da Update Unicode escapes; 2024-09-28 08:31:51 +02:00
Matthias Krüger
e76eb96a00
Rollup merge of #129087 - slanterns:option_get_or_insert_default, r=dtolnay
Stabilize `option_get_or_insert_default`

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

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

r? libs-api
2024-09-27 19:07:58 +02:00
Lukas Bergdoll
d17ba5d5c8 Apply review feedback 2024-09-27 11:31:56 +02:00
Lukas Bergdoll
5559ebe094 Apply round 1 of review comments 2024-09-27 11:31:56 +02:00
Lukas Bergdoll
d9449315ad Fix mistake in example 2024-09-27 11:31:56 +02:00
Lukas Bergdoll
a2c82f9b2b Improve Ord docs
- Makes wording more clear and re-structures some
  sections that can be overwhelming for some not
  already in the know.
- Adds examples of how *not* to implement Ord,
  inspired by various anti-patterns found in real
  world code.
2024-09-27 11:31:56 +02:00
Jubilee
1e882537d4
Rollup merge of #130875 - folkertdev:naked-asm-bootstrap, r=tgross35
update `compiler-builtins` to 0.1.126

this requires the addition of a bootstrap variant of the new `naked_asm!` macro

r? `@tgross35`

extracted from https://github.com/rust-lang/rust/pull/128651
2024-09-26 22:20:55 -07:00
Jubilee
98f567b35a
Rollup merge of #130313 - c410-f3r:unlock-rfc-2011, r=thomcc
[`cfg_match`] Generalize inputs

cc #115585

Changes the input type from `item` to `tt`, which makes the macro have the same functionality of `cfg_if`.

Also adds a test to ensure that `stmt_expr_attributes` is not triggered.
2024-09-26 22:20:53 -07:00
Guillaume Gomez
3d4d45f87b
Rollup merge of #130880 - RalfJung:const-hack, r=scottmcm
add missing FIXME(const-hack)

r? ```@scottmcm```
2024-09-27 00:43:35 +02:00
Guillaume Gomez
e65054633c
Rollup merge of #130845 - RalfJung:utf8chunk, r=tgross35
Utf8Chunks: add link to Utf8Chunk

It is currently surprisingly non-trivial to go from the `utf8_chunks` method to the docs of the `valid`/`invalid` methods used in the example. This should help.
2024-09-27 00:43:32 +02:00
Guillaume Gomez
8a827c77e3
Rollup merge of #130279 - theemathas:manually-drop-docs, r=thomcc,traviscross
Document subtleties of `ManuallyDrop`

After seeing #130140 and #130141, I figured that `ManuallyDrop` needs documentation explaining its subtleties, hence this PR.

See also https://github.com/rust-lang/unsafe-code-guidelines/issues/245
2024-09-27 00:43:30 +02:00
Ralf Jung
ef87a7f663 add missing FIXME(const-hack) 2024-09-26 15:42:37 +02:00
Urgau
1e24104587 Add [Option<T>; N]::transpose 2024-09-26 10:43:56 +02:00
Folkert de Vries
20c0067528 add a bootstrap variant of naked_asm 2024-09-26 09:54:00 +02:00
Scott McMurray
fd5aa07f4f Stabilize the map/value methods on ControlFlow
And fix the stability attribute on the `pub use` in `core::ops`.
2024-09-25 19:00:17 -07:00
Josh Stone
f4d9d1a0ea Use &raw in the standard library
Since the stabilization in #127679 has reached stage0, 1.82-beta, we can
start using `&raw` freely, and even the soft-deprecated `ptr::addr_of!`
and `ptr::addr_of_mut!` can stop allowing the unstable feature.

I intentionally did not change any documentation or tests, but the rest
of those macro uses are all now using `&raw const` or `&raw mut` in the
standard library.
2024-09-25 17:03:20 -07:00
Matthias Krüger
3a3352386c
Rollup merge of #130832 - RalfJung:sort-cfg-mess, r=workingjubilee
fix some cfg logic around optimize_for_size and 16-bit targets

Fixes https://github.com/rust-lang/rust/issues/130818.
Fixes https://github.com/rust-lang/rust/issues/129910.

There are still some warnings when building on a 16bit target:
```
warning: struct `AlignedStorage` is never constructed
   --> /home/r/src/rust/rustc.2/library/core/src/slice/sort/stable/mod.rs:135:8
    |
135 | struct AlignedStorage<T, const N: usize> {
    |        ^^^^^^^^^^^^^^
    |
    = note: `#[warn(dead_code)]` on by default

warning: associated items `new` and `as_uninit_slice_mut` are never used
   --> /home/r/src/rust/rustc.2/library/core/src/slice/sort/stable/mod.rs:141:8
    |
140 | impl<T, const N: usize> AlignedStorage<T, N> {
    | -------------------------------------------- associated items in this implementation
141 |     fn new() -> Self {
    |        ^^^
...
145 |     fn as_uninit_slice_mut(&mut self) -> &mut [MaybeUninit<T>] {
    |        ^^^^^^^^^^^^^^^^^^^

warning: function `quicksort` is never used
  --> /home/r/src/rust/rustc.2/library/core/src/slice/sort/unstable/quicksort.rs:19:15
   |
19 | pub(crate) fn quicksort<'a, T, F>(
   |               ^^^^^^^^^

warning: `core` (lib) generated 3 warnings
```

However, the cfg stuff here is sufficiently messy that I didn't want to touch more of it. I think all `feature = "optimize_for_size"` should become `any(feature = "optimize_for_size", target_pointer_width = "16")` but I am not entirely certain. Warnings are fine, Miri will just ignore them.

Cc `@Voultapher`
2024-09-25 20:11:00 +02:00
Ralf Jung
8f1ed9b2e2 Utf8Chunks: add link to Utf8Chunk 2024-09-25 19:46:41 +02:00
Ralf Jung
1151eb1c84 fix some cfg logic around optimize_for_size and 16-bit targets 2024-09-25 15:21:08 +02:00
Gabriel Bjørnager Jensen
b466fa6db8 Add 'must_use' attribute to 'char::len_utf8' and 'char::len_utf16'; 2024-09-25 10:42:43 +02:00
bors
363ae41883 Auto merge of #129587 - Voultapher:opt-for-size-variants-of-sort-impls, r=cuviper
Add `optimize_for_size` 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.

Part of https://github.com/rust-lang/rust/issues/125612

r​? `@Kobzol`
2024-09-24 18:48:08 +00:00
bors
11e760b7f4 Auto merge of #130738 - bjoernager:const-make-ascii, r=jhpratt
Mark `make_ascii_uppercase` and `make_ascii_lowercase` in `[u8]` and `str` as const.

Relevant tracking issue: #130698

This PR extends #130697 and #130713 to the similar methods in byte slices (`[u8]`) and string slices (`str`).

For the `str` methods, this simply requires adding the `const` specifier to the function signatures. The `[u8]` methods, however, require (at least a temporary) reimplementation due to the use of iterators and `for` loops.
2024-09-24 08:52:12 +00:00
Gabriel Bjørnager Jensen
e723fe1713 Mark and implement 'make_ascii_uppercase' and 'make_ascii_lowercase' in '[u8]' and 'str' as const; 2024-09-24 08:50:40 +02:00
Michael Goulet
64aa4c6e25
Rollup merge of #130762 - RalfJung:const_intrinsic_copy, r=dtolnay
stabilize const_intrinsic_copy

Fixes https://github.com/rust-lang/rust/issues/80697

This stabilizes
```rust
mod ptr {
    pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
    pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize);
}

impl *const T {
    pub const unsafe fn copy_to(self, dest: *mut T, count: usize);
    pub const unsafe fn copy_to_nonoverlapping(self, dest: *mut T, count: usize);
}

impl *mut T {
    pub const unsafe fn copy_to(self, dest: *mut T, count: usize);
    pub const unsafe fn copy_to_nonoverlapping(self, dest: *mut T, count: usize);

    pub const unsafe fn copy_from(self, src: *const T, count: usize);
    pub const unsafe fn copy_from_nonoverlapping(self, src: *const T, count: usize);
}

impl <T> NonNull<T> {
    pub const unsafe fn copy_to(self, dest: NonNull<T>, count: usize);
    pub const unsafe fn copy_to_nonoverlapping(self, dest: NonNull<T>, count: usize);

    pub const unsafe fn copy_from(self, src: NonNull<T>, count: usize);
    pub const unsafe fn copy_from_nonoverlapping(self, src: NonNull<T>, count: usize);
}
```
In particular, this reverts https://github.com/rust-lang/rust/pull/117905, which reverted https://github.com/rust-lang/rust/pull/97276.

The `NonNull` methods are not listed in the tracking issue, they were added to this feature gate in https://github.com/rust-lang/rust/pull/124498. The existing [FCP](https://github.com/rust-lang/rust/issues/80697#issuecomment-1022585839) does not cover them. They are however entirely identical to the `*mut` methods and already stable outside `const`. ``@rust-lang/libs-api`` please let me know if FCP will be required for the `NonNull` methods.
2024-09-23 23:49:14 -04:00
Ralf Jung
2787179f53 stabilize const_intrinsic_copy 2024-09-23 22:12:54 +02:00
joboet
e94dd9b712
random: add tracking issue, address other comments 2024-09-23 10:36:16 +02:00
joboet
5c1c725724
std: implement the random feature
Implements the ACP https://github.com/rust-lang/libs-team/issues/393.
2024-09-23 10:29:51 +02:00
Matthias Krüger
8bb69b1861
Rollup merge of #130713 - bjoernager:const-char-make-ascii, r=Noratrieb
Mark `u8::make_ascii_uppercase` and `u8::make_ascii_lowercase` as const.

Relevant tracking issue: #130698

This PR extends #130697 by also marking the `make_ascii_uppercase` and `make_ascii_lowercase` methods in `u8` as const.

The `const_char_make_ascii` feature gate is additionally renamed to `const_make_ascii`.
2024-09-23 06:45:35 +02:00
Matthias Krüger
c1ccdb7d0c
Rollup merge of #130659 - bjoernager:const-char-encode-utf16, r=dtolnay
Support `char::encode_utf16` in const scenarios.

Relevant tracking issue: #130660

The method `char::encode_utf16` should be marked "const" to allow compile-time conversions.

This PR additionally rewrites the `encode_utf16_raw` function for better readability whilst also reducing the amount of unsafe code.

try-job: x86_64-msvc
2024-09-23 06:45:33 +02:00
Matthias Krüger
510fc3432e
Rollup merge of #129550 - kornelski:boxasstr, r=joshtriplett,dtolnay
Add str.as_str() for easy Deref to string slices

Working with `Box<str>` is cumbersome, because in places like `iter.filter()` it can end up being `&Box<str>` or even `&&Box<str>`, and such type doesn't always get auto-dereferenced as expected.

Dereferencing such box to `&str` requires ugly syntax like `&**boxed_str` or `&***boxed_str`, with the exact amount of `*`s.

`Box<str>` is [not easily comparable with other string types](https://github.com/rust-lang/rust/pull/129852) via `PartialEq`. `Box<str>` won't work for lookups in types like `HashSet<String>`, because `Borrow<String>` won't take types like `&Box<str>`. OTOH `set.contains(s.as_str())` works nicely regardless of levels of indirection.

`String` has a simple solution for this: the `as_str()` method, and `Box<str>` should too.
2024-09-23 06:45:32 +02:00
Michael Goulet
c682aa162b Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
Gabriel Bjørnager Jensen
2daf076fd8 Mark 'make_ascii_uppercase' and 'make_ascii_lowercase' in 'u8' as const; Rename 'const_char_make_ascii' feature gate to 'const_make_ascii'; 2024-09-22 19:54:35 +02:00
Guillaume Gomez
c43a9ea146
Rollup merge of #130692 - RalfJung:result-flatten, r=Noratrieb
make unstable Result::flatten a const fn

This method is still unstable (tracked at https://github.com/rust-lang/rust/issues/70142), but there's no reason I can see for it not to be const -- after all, `Option::flatten` is const. So let's make the `Result` one `const` as well, under the same feature gate.

Cc https://github.com/rust-lang/rust/issues/70142
2024-09-22 19:19:16 +02:00
Guillaume Gomez
cbf23960ea
Rollup merge of #130658 - EqualMa:patch-1, r=scottmcm
Fix docs of compare_bytes

The docs of `compare_bytes`. The return value is positive if <del>`right`</del> `left` is greater
2024-09-22 19:19:14 +02:00
bors
0af7f0f4c4 Auto merge of #130697 - bjoernager:const-char-make-ascii, r=dtolnay
Mark `char::make_ascii_uppercase` and `char::make_ascii_lowercase` as const.

Relevant tracking issue: #130698

The `make_ascii_uppercase` and `make_ascii_lowercase` methods in `char` should be marked "const."

With the stabilisation of [`const_mut_refs`](https://github.com/rust-lang/rust/issues/57349/), this simply requires adding the `const` specifier to the function signatures.
2024-09-22 13:55:07 +00:00
Gabriel Bjørnager Jensen
be9b3b459a Mark 'make_ascii_uppercase' and 'make_ascii_lowercase' in 'char' as const; 2024-09-22 14:26:29 +02:00
Ralf Jung
89c3cbafb8 make unstable Result::flatten a const fn 2024-09-22 08:40:25 +02:00
Gabriel Bjørnager Jensen
f48c5ec235 Mark and implement 'char::encode_utf16' as const; Rewrite 'encode_utf16_raw'; 2024-09-21 12:53:28 +02:00
EqualMa
d44a5fd00b
Fix docs of compare_bytes 2024-09-21 18:27:49 +08:00
Ralf Jung
b94f2931b3 ABI compatibility: mention Result guarantee 2024-09-21 09:17:31 +02:00
Tim (Theemathas) Chirananthavat
de2eba1826 Reword ManuallyDrop+Box interaction 2024-09-21 12:38:38 +07:00
bors
da889684c8 Auto merge of #130631 - GuillaumeGomez:rollup-jpgy1iv, r=GuillaumeGomez
Rollup of 7 pull requests

Successful merges:

 - #128209 (Remove macOS 10.10 dynamic linker bug workaround)
 - #130526 (Begin experimental support for pin reborrowing)
 - #130611 (Address diagnostics regression for `const_char_encode_utf8`.)
 - #130614 (Add arm64e-apple-tvos target)
 - #130617 (bail if there are too many non-region infer vars in the query response)
 - #130619 (Fix scraped examples height)
 - #130624 (Add `Vec::as_non_null`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-09-20 19:51:45 +00:00
Guillaume Gomez
2a3f353f04
Rollup merge of #130611 - bjoernager:const-char-encode-utf8, r=dtolnay
Address diagnostics regression for `const_char_encode_utf8`.

Relevant tracking issue: #130512

This PR regains full diagnostics for non-const calls to `char::encode_utf8`.
2024-09-20 19:46:38 +02:00
bors
5ba6db1b64 Auto merge of #124895 - obeis:static-mut-hidden-ref, r=compiler-errors
Disallow hidden references to mutable static

Closes #123060

Tracking:
- https://github.com/rust-lang/rust/issues/123758
2024-09-20 17:25:34 +00:00
Gabriel Bjørnager Jensen
bfadadf78f Address diagnostics regression for 'const_char_encode_utf8'; 2024-09-20 15:53:57 +02:00
Matthias Krüger
569153a432
Rollup merge of #130553 - GnomedDev:remove-clippy-paths, r=compiler-errors
[Clippy] Get rid of most `std` `match_def_path` usage, swap to diagnostic items.

Part of https://github.com/rust-lang/rust-clippy/issues/5393.

This was going to remove all `std` paths, but `SeekFrom` has issues being cleanly replaced with a diagnostic item as the paths are for variants, which currently cannot be diagnostic items.

This also, as a last step, categories the paths to help with future path removals.
2024-09-19 20:37:07 +02:00
Matthias Krüger
767ae2b33d
Rollup merge of #128001 - Krappa322:master, r=scottmcm
Improve documentation for <integer>::from_str_radix

Two improvements to the documentation:
- Document `-` as a valid character for signed integer destinations
- Make the documentation even more clear that extra whitespace and non-digit characters is invalid. Many other languages, e.g. c++, are very permissive in string to integer routines and simply try to consume as much as they can, ignoring the rest. This is trying to make the transition for developers who are used to the conversion semantics in these languages a bit easier.
2024-09-19 20:37:06 +02:00
Kornel
3dcb5a3962
Add str.as_str() for easy dereferencing of Box<str> 2024-09-19 16:25:56 +01:00
GnomedDev
5f42ae13c1
[Clippy] Swap manual_strip to use diagnostic items instead of paths 2024-09-19 13:13:43 +01:00
GnomedDev
372f68b6a6
[Clippy] Swap waker_clone_wake to use diagnostic item instead of path 2024-09-19 13:13:42 +01:00
GnomedDev
5b55270225
[Clippy] Swap filter_map_bool_then to use diagnostic item instead of path 2024-09-19 13:13:42 +01:00
GnomedDev
25da0e2e5d
[Clippy] Swap manual_while_let_some to use diagnostic items instead of paths 2024-09-19 13:13:42 +01:00
GnomedDev
c891082029
[Clippy] Swap float_equality_without_abs to use diagnostic items instead of paths 2024-09-19 13:13:20 +01:00
GnomedDev
3ebff28f80
[Clippy] Swap lines_filter_map_ok to use a diagnostic item instead of path 2024-09-19 08:26:41 +01:00
bors
b7b9453ea7 Auto merge of #130547 - workingjubilee:rollup-tw30khz, r=workingjubilee
Rollup of 3 pull requests

Successful merges:

 - #130531 (Check params for unsafety in THIR)
 - #130533 (Never patterns constitute a read for unsafety)
 - #130542 (Stabilize const `MaybeUninit::as_mut_ptr`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-09-19 06:58:55 +00:00
bors
f8192ba0d0 Auto merge of #130511 - bjoernager:const-char-encode-utf8, r=dtolnay
Support `char::encode_utf8` in const scenarios.

This PR implements [`rust-lang/rfcs#3696`](https://github.com/rust-lang/rfcs/pull/3696/).

This assumes [`const_slice_from_raw_parts_mut`](https://github.com/rust-lang/rust/issues/67456/).
2024-09-19 04:17:04 +00:00
ultrabear
b7ca2b6510
run x.py fmt 2024-09-18 20:49:53 -07:00
ultrabear
63f14b3a1e
remove feature attributes as const_maybe_uninit_as_mut_ptr is stabilized 2024-09-18 20:22:10 -07:00
ultrabear
7477f3eb35
stabilize const_maybe_uninit_as_mut_ptr 2024-09-18 20:22:02 -07:00
Gabriel Bjørnager Jensen
fb475e4759
Mark and implement 'char::encode_utf8' as const. 2024-09-18 14:56:01 -07:00
Jubilee
4bd9de5512
Rollup merge of #130522 - GnomedDev:clippy-manual-retain-paths, r=compiler-errors
[Clippy] Swap `manual_retain` to use diagnostic items instead of paths

Part of https://github.com/rust-lang/rust-clippy/issues/5393, just a chore.
2024-09-18 14:32:28 -07:00
Jubilee
12b59e52bc
Rollup merge of #130476 - workingjubilee:more-lazy-methods-take-2, r=Amanieu
Implement ACP 429: add `Lazy{Cell,Lock}::get[_mut]` and `force_mut`

Tracking issue for `lazy_get`: https://github.com/rust-lang/rust/issues/129333
2024-09-18 14:32:26 -07:00
Jubilee Young
f22797d3db library: Call it really_init_mut to avoid name collisions 2024-09-18 11:39:24 -07:00
Jubilee Young
d9cdb71497 library: Destabilize Lazy{Cell,Lock}::{force,deref}_mut 2024-09-18 11:39:21 -07:00
GnomedDev
a18564c198
[Clippy] Swap manual_retain to use diagnostic items instead of paths 2024-09-18 17:20:44 +01:00
bors
aaed38b2a6 Auto merge of #129491 - StackOverflowExcept1on:master, r=m-ou-se
Pass `fmt::Arguments` by reference to `PanicInfo` and `PanicMessage`

Resolves #129330

For some reason after #115974 and #126732 optimizations applied to panic handler became worse and compiler stopped removing panic locations if they are not used in the panic message. This PR fixes that and maybe we can merge it into beta before rust 1.81 is released.

Note: optimization only works with `lto = "fat"`.

r? libs-api
2024-09-18 11:57:31 +00:00
bors
f68c28b6ce Auto merge of #129845 - scottmcm:redo-layout, r=Noratrieb
Take more advantage of the `isize::MAX` limit in `Layout`

Things like `padding_needed_for` are current implemented being super careful to handle things like `Layout::size` potentially being `usize::MAX`.

But now that #95295 has happened, that's no longer a concern.  It's possible to add two `Layout::size`s together without risking overflow now.

So take advantage of that to remove a bunch of checked math that's not actually needed.  For example, the round-up-and-add-next-size in `extend` doesn't need any overflow checks at all, just the final check for compatibility with the alignment.

(And while I was doing that I made it all unstably const, because there's nothing in `Layout` that's fundamentally runtime-only.)
2024-09-18 07:05:14 +00:00
Scott McMurray
18ca8bf8ee Take more advantage of the isize::MAX limit in Layout
Things like `padding_needed_for` are current implemented being super careful to handle things like `Layout::size` potentially being `usize::MAX`.

But now that 95295 has happened, that's no longer a concern.  It's possible to add two `Layout::size`s together without risking overflow now.

So take advantage of that to remove a bunch of checked math that's not actually needed.  For example, the round-up-and-add-next-size in `extend` doesn't need any overflow checks at all, just the final check for compatibility with the alignment.

(And while I was doing that I made it all unstably const, because there's nothing in `Layout` that's fundamentally runtime-only.)
2024-09-17 20:05:57 -07:00
Arthur Carcano
0c9a17689a Remove uneeded PartialOrd bound in cmp::Ord::clamp
There is a Self: PartialOrd bound in Ord::clamp, but it is already
required by the trait itself. Likely a left-over from the const trait
deletion in 76dbe29104.

Reported-by: @noeensarguet
2024-09-17 21:16:12 +02:00
Chayim Refael Friedman
d0a2ca4867 Implement ACP 429: add Lazy{Cell,Lock}::get[_mut] and force_mut
In the implementation of `force_mut`, I chose performance over safety.
For `LazyLock` this isn't really a choice; the code has to be unsafe.
But for `LazyCell`, we can have a full-safe implementation, but it will
be a bit less performant, so I went with the unsafe approach.
2024-09-17 09:40:34 -07:00
bors
2e367d94f0 Auto merge of #130145 - fee1-dead-contrib:repeatn, r=lcnr,workingjubilee
`RepeatN`: use MaybeUninit

Closes #130140. Closes #130141.

Use `MaybeUninit` instead of `ManuallyDrop` for soundness.
2024-09-17 06:29:37 +00:00
Jubilee
0151cbe6e8
Rollup merge of #127879 - kornelski:bad-pointer-printf, r=workingjubilee
Document futility of printing temporary pointers

In the user forum I've seen a few people trying to understand how borrowing and moves are implemented by peppering their code with printing of `{:p}` of references to variables and expressions. This is a bad idea. It gives misleading and confusing results, because of autoderef magic, printing pointers of temporaries on the stack, and/or causes LLVM to optimize code differently when values had their address exposed.
2024-09-15 23:51:24 -07:00
bors
39b7669347 Auto merge of #130220 - RalfJung:float-classify, r=workingjubilee
simplify float::classify logic

I played around with the float-classify test in the hope of triggering x87 bugs by strategically adding `black_box`, and still the exact expression `@beetrees` suggested [here](https://github.com/rust-lang/rust/pull/129835#issuecomment-2325661597) remains the only case I found where we get the wrong result on x87. Curiously, this bug only occurs when MIR optimizations are enabled -- probably the extra inlining that does is required for LLVM to hit the right "bad" case in the backend. But even for that case, it makes no difference whether `classify` is implemented in the simple bit-pattern-based version or the more complicated version we had before.

Without even a single testcase that can distinguish our `classify` from the naive version, I suggest we switch to the naive version.
2024-09-16 03:36:03 +00:00
Kyle J Strand
249d3d2644 update docs for catch_unwind & related funcs
Documentation comments for `catch_unwind` and `thread::join` to indicate
new behavioral guarantee when catching a foreign exception.
2024-09-15 16:13:38 -06:00
Matthias Krüger
f0fb411969
Rollup merge of #130339 - CAD97:unwind-choice, r=dtolnay
Add `core::panic::abort_unwind`

`abort_unwind` is like `catch_unwind` except that it aborts the process if it unwinds, using the `#[rustc_nounwind]` mechanism also used by `extern "C" fn` to abort unwinding. The docs attempt to make it clear when to (rarely) and when not to (usually) use the function.

Although usage of the function is discouraged, having it available will help to normalize the experience when abort_unwind shims are hit, as opposed to the current ecosystem where there exist multiple common patterns for converting unwinding into a process abort.

For further information and justification, see the linked ACP.

- Tracking issue: https://github.com/rust-lang/rust/issues/130338
- ACP: https://github.com/rust-lang/libs-team/issues/441
2024-09-15 20:55:13 +02:00
Christopher Durham
42a44a04ee
simplify abort_unwind
Co-authored-by: David Tolnay <dtolnay@gmail.com>
2024-09-15 14:27:24 -04:00
Matthias Krüger
e267534b07
Rollup merge of #130118 - RalfJung:unwrap_unchecked, r=Noratrieb
move Option::unwrap_unchecked into const_option feature gate

That's where `unwrap` and `expect` are so IMO it makes more sense to group them together.

Part of #91930, #67441
2024-09-15 11:55:46 +02:00
Matthias Krüger
011289c9d4
Rollup merge of #129195 - RalfJung:const-mut-refs, r=fee1-dead
Stabilize `&mut` (and `*mut`) as well as `&Cell` (and `*const Cell`) in const

This stabilizes `const_mut_refs` and `const_refs_to_cell`. That allows a bunch of new things in const contexts:
- Mentioning `&mut` types
- Creating `&mut` and `*mut` values
- Creating `&T` and `*const T` values where `T` contains interior mutability
- Dereferencing `&mut` and `*mut` values (both for reads and writes)

The same rules as at runtime apply: mutating immutable data is UB. This includes mutation through pointers derived from shared references; the following is diagnosed with a hard error:
```rust
#[allow(invalid_reference_casting)]
const _: () = {
    let mut val = 15;
    let ptr = &val as *const i32 as *mut i32;
    unsafe { *ptr = 16; }
};
```

The main limitation that is enforced is that the final value of a const (or non-`mut` static) may not contain `&mut` values nor interior mutable `&` values. This is necessary because the memory those references point to becomes *read-only* when the constant is done computing, so (interior) mutable references to such memory would be pretty dangerous. We take a multi-layered approach here to ensuring no mutable references escape the initializer expression:
- A static analysis rejects (interior) mutable references when the referee looks like it may outlive the current MIR body.
- To be extra sure, this static check is complemented by a "safety net" of dynamic checks. ("Dynamic" in the sense of "running during/after const-evaluation, e.g. at runtime of this code" -- in contrast to "static" which works entirely by looking at the MIR without evaluating it.)
  - After the final value is computed, we do a type-driven traversal of the entire value, and if we find any `&mut` or interior-mutable `&` we error out.
  - However, the type-driven traversal cannot traverse `union` or raw pointers, so there is a second dynamic check where if the final value of the const contains any pointer that was not derived from a shared reference, we complain. This is currently a future-compat lint, but will become an ICE in #128543. On the off-chance that it's actually possible to trigger this lint on stable, I'd prefer if we could make it an ICE before stabilizing const_mut_refs, but it's not a hard blocker. This part of the "safety net" is only active for mutable references since with shared references, it has false positives.

Altogether this should prevent people from leaking (interior) mutable references out of the const initializer.

While updating the tests I learned that surprisingly, this code gets rejected:
```rust
const _: Vec<i32> = {
    let mut x = Vec::<i32>::new(); //~ ERROR destructor of `Vec<i32>` cannot be evaluated at compile-time
    let r = &mut x;
    let y = x;
    y
};
```
The analysis that rejects destructors in `const` is very conservative when it sees an `&mut` being created to `x`, and then considers `x` to be always live. See [here](https://github.com/rust-lang/rust/issues/65394#issuecomment-541499219) for a longer explanation. `const_precise_live_drops` will solve this, so I consider this problem to be tracked by https://github.com/rust-lang/rust/issues/73255.

Cc `@rust-lang/wg-const-eval` `@rust-lang/lang`
Cc https://github.com/rust-lang/rust/issues/57349
Cc https://github.com/rust-lang/rust/issues/80384
2024-09-15 11:55:45 +02:00
Ralf Jung
49316f871c also stabilize const_refs_to_cell 2024-09-15 10:20:47 +02:00
Ralf Jung
544a6a7df3 const_refs_to_cell: dont let mutable references sneak past the interior mutability check 2024-09-15 09:51:34 +02:00
Ralf Jung
3175cc2814 stabilize const_mut_refs 2024-09-15 09:51:32 +02:00
Stuart Cook
0648987532
Rollup merge of #130214 - RalfJung:zeroed, r=Mark-Simulacrum
MaybeUninit::zeroed: mention that padding is not zeroed

That should clarify cases like [this](https://github.com/rust-lang/rust/pull/129778#issuecomment-2342542847).
2024-09-15 12:14:56 +10:00
León Orell Valerian Liehr
a9dcd7f25d
Rollup merge of #130268 - RalfJung:simd-shuffle-idx-vector, r=compiler-errors
simd_shuffle: require index argument to be a vector

Remove some codegen hacks by forcing the SIMD shuffle `index` argument to be a vector, which means (thanks to https://github.com/rust-lang/rust/pull/128537) that it will automatically be passed as an immediate in LLVM. The only special-casing we still have is for the extra sanity-checks we add that ensure that the indices are all in-bounds. (And the GCC backend needs to do a bunch of work since the Rust intrinsic is modeled after what LLVM expects, which seems to be quite different from what GCC expects.)

Fixes https://github.com/rust-lang/rust/issues/128738, see that issue for more context.
2024-09-14 18:12:10 +02:00
Ralf Jung
60ee1b7ac6 simd_shuffle: require index argument to be a vector 2024-09-14 14:43:24 +02:00
Stuart Cook
c992f97cb1
Rollup merge of #130053 - glowcoil:next_if-docs, r=jhpratt
fix doc comments for Peekable::next_if(_eq)

Fix references to a nonexistent `consume` function in the doc comments for `Peekable::next_if` and `Peekable::next_if_eq`.
2024-09-14 20:22:40 +10:00
Christopher Durham
de66d3aa2b
add core::panic::abort_unwind 2024-09-14 01:34:05 -04:00
Caio
ae15032069 Rustfmt 2024-09-13 15:18:30 -03:00
Caio
561a6c5f11 [cfg_match] Generalize inputs 2024-09-13 15:00:33 -03:00
Tim (Theemathas) Chirananthavat
f604ed631b Fix awkward wording. 2024-09-13 22:02:07 +07:00
Tim (Theemathas) Chirananthavat
6fa092a102 Address WaffleLapkin's comments 2024-09-13 21:26:39 +07:00
Obei Sideg
3b0ce1bc33
Update tests for hidden references to mutable static 2024-09-13 14:10:56 +03:00
Matthias Krüger
4428d6f363
Rollup merge of #130101 - RalfJung:const-cleanup, r=fee1-dead
some const cleanup: remove unnecessary attributes, add const-hack indications

I learned that we use `FIXME(const-hack)` on top of the "const-hack" label. That seems much better since it marks the right place in the code and moves around with the code. So I went through the PRs with that label and added appropriate FIXMEs in the code. IMO this means we can then remove the label -- Cc ``@rust-lang/wg-const-eval.``

I also noticed some const stability attributes that don't do anything useful, and removed them.

r? ``@fee1-dead``
2024-09-12 19:03:41 +02:00
Tim (Theemathas) Chirananthavat
e2c9831388 Document subtleties of ManuallyDrop 2024-09-12 23:39:45 +07:00
Eduardo Sánchez Muñoz
e3c822df4e Stabilize const_float_classify 2024-09-12 17:45:58 +02:00
Ralf Jung
bc3d072206 also update the wrapping_ docs to use similar wording 2024-09-12 16:25:09 +02:00
Stuart Cook
c3d1be7c7f
Rollup merge of #130160 - Scripter17:fix-slice-first_mut-doc, r=Amanieu
Fix `slice::first_mut` docs

Changes `pointer` to `reference` since that's the actual type it returns.

`slice::last_mut` does correctly say "reference"
2024-09-12 20:37:16 +10:00
Ralf Jung
7f7c73bd9c simplify float::classify logic 2024-09-12 08:08:38 +02:00
bors
6c65d4f47f Auto merge of #130183 - Marcondiro:unicode-16.0.0, r=Manishearth
Bump Unicode to version 16.0.0

[Unicode 16.0.0 is out!](https://www.unicode.org/versions/Unicode16.0.0/)
This PR updates Unicode data embedded in `core`.
2024-09-12 02:00:55 +00:00
Ralf Jung
916eb130be various updates based on review 2024-09-11 22:41:25 +02:00
Ralf Jung
58350799a1 ptr::add/sub: these are *not* equivalent to offset(count as isize) 2024-09-11 16:38:52 +02:00
Ralf Jung
d4ac759542 MaybeUninit::zeroed: mention that padding is not zeroed 2024-09-11 08:08:39 +02:00
Ralf Jung
e556c136f3 clean up internal comments about float semantics
- remove an outdated FIXME
- add reference to floating-point semantics issue

Co-authored-by: Jubilee <workingjubilee@gmail.com>
2024-09-10 16:47:09 -07:00
Marcondiro
c8d9bd488a Bump unicode printable to version 16.0.0 2024-09-10 11:13:35 +02:00
Marcondiro
bdda4ec2f5 Bump unicode_data to version 16.0.0 2024-09-10 10:50:20 +02:00
bors
26b2b8d162 Auto merge of #130179 - workingjubilee:rollup-l78cv44, r=workingjubilee
Rollup of 11 pull requests

Successful merges:

 - #128316 (Stabilize most of `io_error_more`)
 - #129473 (use  `download-ci-llvm=true` in the default compiler config)
 - #129529 (Add test to build crates used by r-a on stable)
 - #129981 (Remove `serialized_bitcode` from `LtoModuleCodegen`.)
 - #130094 (Inform the solver if evaluation is concurrent)
 - #130132 ([illumos] enable SIGSEGV handler to detect stack overflows)
 - #130146 (bootstrap `naked_asm!` for `compiler-builtins`)
 - #130149 (Helper function for formatting with `LifetimeSuggestionPosition`)
 - #130152 (adapt a test for llvm 20)
 - #130162 (bump download-ci-llvm-stamp)
 - #130164 (move some const fn out of the const_ptr_as_ref feature)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-09-10 07:26:27 +00:00
Jubilee
9749a9801c
Rollup merge of #130164 - RalfJung:const_ptr_as_ref, r=dtolnay
move some const fn out of the const_ptr_as_ref feature

When a `const fn` is still `#[unstable]`, it should generally use the same feature to track its regular stability and const-stability. Then when that feature moves towards stabilization we can decide whether the const-ness can be stabilized as well, or whether it should be moved into a new feature.

Also, functions like `ptr::as_ref` (which returns an `Option<&mut T>`) require `is_null`, which is tricky and blocked on some design concerns (see #74939). So move those to the is_null feature gate, as they should be stabilized together with `ptr.is_null()`.

Affects #91822, #122034, #75402, https://github.com/rust-lang/rust/issues/74939
2024-09-09 19:20:39 -07:00
Jubilee
57273d82a8
Rollup merge of #130146 - folkertdev:bootstrap-naked-asm, r=Amanieu
bootstrap `naked_asm!` for `compiler-builtins`

tracking issue: https://github.com/rust-lang/rust/issues/90957
parent PR: https://github.com/rust-lang/rust/pull/128651

in this PR, `naked_asm!` is added as an alias for `asm!` with one difference: `options(noreturn)` is always enabled by `naked_asm!`. That makes it future-compatible for when `naked_asm!` starts disallowing `options(noreturn)` later.

The `naked_asm!` macro must be introduced first so that we can upgrade `compiler-builtins` to use it, and can then change the implementation of `naked_asm!` in https://github.com/rust-lang/rust/pull/128651

I've added some usages for `naked_asm!` in the tests, so we can be confident that it works, but I've left upgrading the whole test suite to the parent PR.

r? ``@Amanieu``
2024-09-09 19:20:38 -07:00
bors
304b7f801b Auto merge of #129778 - RalfJung:interp-lossy-typed-copy, r=saethlin
interpret: make typed copies lossy wrt provenance and padding

A "typed copy" in Rust can be a lossy process: when copying at type `usize` (or any other non-pointer type), if the original memory had any provenance, that provenance is lost. When copying at pointer type, if the original memory had partial provenance (i.e., not the same provenance for all bytes), that provenance is lost. When copying any type with padding, the contents of padding are lost.

This PR equips our validity-checking pass with the ability to reset provenance and padding according to those rules. Can be reviewed commit-by-commit. The first three commits are just preparation without any functional change.

Fixes https://github.com/rust-lang/miri/issues/845
Fixes https://github.com/rust-lang/miri/issues/2182
2024-09-10 02:18:51 +00:00
Ralf Jung
e10224a7c3 move const fn with a null check into const_ptr_is_null gate 2024-09-09 20:09:13 +02:00
Ralf Jung
720bd0dd6c move some const fn out of the const_ptr_as_ref feature 2024-09-09 19:59:16 +02:00
James C. Wise
99cad123ed
Fix slice::first_mut docs
pointer -> reference
2024-09-09 13:13:45 -04:00
okaneco
bc70fa2f22 Stabilize char::MIN 2024-09-09 11:48:12 -04:00
Ralf Jung
0a70924c21 fix UB in a test
also add an explicit test for the fact that a Option<WidePtr> has padding when it is None
2024-09-09 16:17:34 +02:00
Deadbeef
4c8b84ae82 RepeatN: use MaybeUninit 2024-09-09 19:30:48 +08:00
Folkert de Vries
02378997ea bootstrap naked_asm! for compiler-builtins
in this commit, `naked_asm!` is an alias for `asm!` with one difference: `options(noreturn)` is always enabled by `naked_asm!`. That makes it future-compatible for when `naked_asm!` starts disallowing `options(noreturn)` later.
2024-09-09 12:47:40 +02:00
Jubilee
2f1cf6feb0
Rollup merge of #130115 - eduardosm:needless-returns-libs, r=workingjubilee
Remove needless returns detected by clippy in libraries
2024-09-09 00:17:52 -07:00
Jubilee
fad44c424f
Rollup merge of #130107 - RalfJung:const-ptr-is-null, r=oli-obk
const: make ptr.is_null() stop execution on ambiguity

This seems better than saying `false` -- saying `false` is in fact actively unsound if `NonNull` then uses this to permit putting this pointer inside of it, but at runtime it turns out to be null.

Part of https://github.com/rust-lang/rust/issues/74939
Cc ```@rust-lang/wg-const-eval```
2024-09-09 00:17:51 -07:00
Jubilee
4a26f3b0ba
Rollup merge of #130090 - RalfJung:result-copied, r=Noratrieb
make Result::copied unstably const

The corresponding `Option::copied` is unstably const, so seems reasonable to do the same here.
2024-09-09 00:17:50 -07:00
Jubilee
38520aed18
Rollup merge of #130087 - RalfJung:option-const-iter, r=workingjubilee
remove 'const' from 'Option::iter'

This is kind of pointless to be a `const fn` since you can't do anything with the iterator. It is also the only `const fn iter*` in the entire standard library. It probably got constified when `~const` traits got added everywhere, and then was forgotten to be de-constified when that was undone.

The rest of the const_option feature seems like it can reasonably be stabilized, but this one IMO should not be stabilized, and it's not worth creating a new tracking issue.

Cc https://github.com/rust-lang/rust/issues/67441
2024-09-09 00:17:50 -07:00
Ralf Jung
7a3a317618 remove const_slice_index annotations, it never had a feature gate anyway 2024-09-08 23:08:43 +02:00
Ralf Jung
332fa6aa6e add FIXME(const-hack) 2024-09-08 23:08:40 +02:00
Ralf Jung
7ec01e453c move Option::unwrap_unchecked into const_option feature gate 2024-09-08 23:04:16 +02:00
Eduardo Sánchez Muñoz
5f3fdd14df Remove needless returns detected by clippy in libraries 2024-09-08 21:51:00 +02:00
Ralf Jung
11d51aae86 const: make ptr.is_null() stop execution on ambiguity 2024-09-08 19:07:46 +02:00
Ralf Jung
f7b4f4a73b Option, Result: put the &mut variants of 'copied' under the same feature as the '&' variants 2024-09-08 16:52:40 +02:00
bors
adf8d168af Auto merge of #130002 - orlp:better-div-floor-ceil, r=thomcc
better implementation of signed div_floor/ceil

Tracking issue for signed `div_floor`/`div_ceil`: https://github.com/rust-lang/rust/issues/88581.

This PR improves the implementation of those two functions by adding a better branchless algorithm. Side-by-side comparison of `i32::div_floor` on x86-64:

```asm
div_floor_new:                               div_floor_old:
        push    rax                                  push    rax
        test    esi, esi                             test    esi, esi
        je      .LBB0_3                              je      .LBB1_6
        mov     eax, esi                             mov     eax, esi
        not     eax                                  not     eax
        lea     ecx, [rdi - 2147483648]              lea     ecx, [rdi - 2147483648]
        or      ecx, eax                             or      ecx, eax
        je      .LBB0_2                              je      .LBB1_7
        mov     eax, edi                             mov     eax, edi
        cdq                                          cdq
        idiv    esi                                  idiv    esi
        xor     esi, edi                             test    edx, edx
        sar     esi, 31                              setg    cl
        test    edx, edx                             test    esi, esi
        cmove   esi, edx                             sets    dil
        add     eax, esi                             test    dil, cl
        pop     rcx                                  jne     .LBB1_4
        ret                                          test    edx, edx
.LBB0_3:                                             setns   cl
        lea     rdi, [rip + .L__unnamed_1]           test    esi, esi
        call    qword ptr [rip + panic...]          setle   dl
.LBB0_2:                                             or      dl, cl
        lea     rdi, [rip + .L__unnamed_1]           jne     .LBB1_5
        call    qword ptr [rip + panic...]   .LBB1_4:
                                                     dec     eax
                                             .LBB1_5:
                                                     pop     rcx
                                                     ret
                                             .LBB1_6:
                                                     lea     rdi, [rip + .L__unnamed_2]
                                                     call    qword ptr [rip + panic...]
                                             .LBB1_7:
                                                     lea     rdi, [rip + .L__unnamed_2]
                                                     call    qword ptr [rip + panic...]
```

And on Aarch64:

```asm
_div_floor_new:                                   _div_floor_old:
        stp     x29, x30, [sp, #-16]!                     stp     x29, x30, [sp, #-16]!
        mov     x29, sp                                   mov     x29, sp
        cbz     w1, LBB0_4                                cbz     w1, LBB1_9
        mov     w8, #-2147483648                          mov     x8, x0
        cmp     w0, w8                                    mov     w9, #-2147483648
        b.ne    LBB0_3                                    cmp     w0, w9
        cmn     w1, #1                                    b.ne    LBB1_3
        b.eq    LBB0_5                                    cmn     w1, #1
LBB0_3:                                                   b.eq    LBB1_10
        sdiv    w8, w0, w1                        LBB1_3:
        msub    w9, w8, w1, w0                            sdiv    w0, w8, w1
        eor     w10, w1, w0                               msub    w8, w0, w1, w8
        asr     w10, w10, #31                             tbz     w1, #31, LBB1_5
        cmp     w9, #0                                    cmp     w8, #0
        csel    w9, wzr, w10, eq                          b.gt    LBB1_7
        add     w0, w9, w8                        LBB1_5:
        ldp     x29, x30, [sp], #16                       cmp     w1, #1
        ret                                               b.lt    LBB1_8
LBB0_4:                                                   tbz     w8, #31, LBB1_8
        adrp    x0, l___unnamed_1@PAGE            LBB1_7:
        add     x0, x0, l___unnamed_1@PAGEOFF             sub     w0, w0, #1
        bl      panic...                          LBB1_8:
LBB0_5:                                                   ldp     x29, x30, [sp], #16
        adrp    x0, l___unnamed_1@PAGE                    ret
        add     x0, x0, l___unnamed_1@PAGEOFF     LBB1_9:
        bl      panic...                                  adrp    x0, l___unnamed_2@PAGE
                                                          add     x0, x0, l___unnamed_2@PAGEOFF
                                                          bl      panic...
                                                  LBB1_10:
                                                          adrp    x0, l___unnamed_2@PAGE
                                                          add     x0, x0, l___unnamed_2@PAGEOFF
                                                          bl      panic...
```
2024-09-08 13:54:02 +00:00
Ralf Jung
7f9a541059 remove pointless rustc_const_unstable on trait impls 2024-09-08 08:45:41 +02:00
Ralf Jung
3de6838238 add some FIXME(const-hack) 2024-09-08 08:30:28 +02:00
bors
878f49f5ff Auto merge of #130091 - matthiaskrgr:rollup-kalu1cs, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #126452 (Implement raw lifetimes and labels (`'r#ident`))
 - #129555 (stabilize const_float_bits_conv)
 - #129594 (explain the options bootstrap passes to curl)
 - #129677 (Don't build by-move body when async closure is tainted)
 - #129847 (Do not call query to compute coroutine layout for synthetic body of async closure)
 - #129869 (add a few more crashtests)
 - #130009 (rustdoc-search: allow trailing `Foo ->` arg search)
 - #130046 (str: make as_mut_ptr and as_bytes_mut unstably const)
 - #130047 (Win: Add dbghelp to the list of import libraries)
 - #130059 (Remove the unused  `llvm-skip-rebuild` option from x.py)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-09-07 23:02:03 +00:00
Matthias Krüger
c139dc6281
Rollup merge of #130046 - RalfJung:const_str_as_mut, r=dtolnay
str: make as_mut_ptr and as_bytes_mut unstably const

`@rust-lang/libs-api` the corresponding non-mutable methods are already const fn, so this seems pretty trivial. I hope this is small enough that it does not need an ACP? :)

I would like to get these stabilized ASAP because I want to avoid people doing `s.as_ptr().cast_mut()`, which is UB if they ever write to it, but is already const-stable.

TODO: create a tracking issue.
2024-09-07 23:30:14 +02:00
Matthias Krüger
3b2139bdb1
Rollup merge of #129555 - RalfJung:const_float_bits_conv, r=dtolnay
stabilize const_float_bits_conv

This stabilizes `const_float_bits_conv`, and thus fixes https://github.com/rust-lang/rust/issues/72447. With https://github.com/rust-lang/rust/pull/128596 having landed, this is entirely a libs-only question now.

```rust
impl f32 {
    pub const fn to_bits(self) -> u32;
    pub const fn from_bits(v: u32) -> Self;
    pub const fn to_be_bytes(self) -> [u8; 4];
    pub const fn to_le_bytes(self) -> [u8; 4]
    pub const fn to_ne_bytes(self) -> [u8; 4];
    pub const fn from_be_bytes(bytes: [u8; 4]) -> Self;
    pub const fn from_le_bytes(bytes: [u8; 4]) -> Self;
    pub const fn from_ne_bytes(bytes: [u8; 4]) -> Self;
}

impl f64 {
    pub const fn to_bits(self) -> u64;
    pub const fn from_bits(v: u64) -> Self;
    pub const fn to_be_bytes(self) -> [u8; 8];
    pub const fn to_le_bytes(self) -> [u8; 8]
    pub const fn to_ne_bytes(self) -> [u8; 8];
    pub const fn from_be_bytes(bytes: [u8; 8]) -> Self;
    pub const fn from_le_bytes(bytes: [u8; 8]) -> Self;
    pub const fn from_ne_bytes(bytes: [u8; 8]) -> Self;
}
````

Cc `@rust-lang/wg-const-eval` `@rust-lang/libs-api`
2024-09-07 23:30:11 +02:00
bors
12b26c13fb Auto merge of #129941 - BoxyUwU:bump-boostrap, r=albertlarsan68
Bump boostrap compiler to new beta

Accidentally left some comments on the update cfgs commit directly xd
2024-09-07 20:37:30 +00:00
Ralf Jung
03e0c8edb2 make Result::copied unstably const 2024-09-07 22:23:12 +02:00
Ralf Jung
f7d4da65c7 remove 'const' from 'Option::iter' 2024-09-07 21:41:28 +02:00
Ralf Jung
a8a7fd418e str: make as_mut_ptr and as_bytes_mut unstably const 2024-09-07 21:00:10 +02:00
Adam Sandberg Ericsson
896ccaa8ac restate GlobalAlloc method safety preconditions in terms of what the caller has to do for greater clarity 2024-09-07 15:21:52 +01:00
glowcoil
a5cbb5200d fix doc comments for Peekable::next_if(_eq)
Fix references to a nonexistent `consume` function in the doc comments
for `Peekable::next_if` and `Peekable::next_if_eq`.
2024-09-06 19:30:47 -05:00
bors
d678b81485 Auto merge of #129999 - matthiaskrgr:rollup-pzr9c8p, r=matthiaskrgr
Rollup of 11 pull requests

Successful merges:

 - #128919 (Add an internal lint that warns when accessing untracked data)
 - #129472 (fix ICE when `asm_const` and `const_refs_to_static` are combined)
 - #129653 (clarify that addr_of creates read-only pointers)
 - #129775 (bootstrap: Try to track down why `initial_libdir` sometimes fails)
 - #129939 (explain why Rvalue::Len still exists)
 - #129942 (copy rustc rustlib artifacts from ci-rustc)
 - #129943 (use the bootstrapped compiler for `test-float-parse` test)
 - #129944 (Add compat note for trait solver change)
 - #129947 (Add digit separators in `Duration` examples)
 - #129955 (Temporarily remove fmease from the review rotation)
 - #129957 (forward linker option to lint-docs)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-09-06 03:06:52 +00:00
Orson Peters
6b4ff514d9 better implementation of signed div_floor/ceil 2024-09-05 22:50:41 +02:00
Matthias Krüger
96719dbe32
Rollup merge of #129947 - LiterallyVoid:duration-docs-digit-separators, r=tgross35
Add digit separators in `Duration` examples

``@rustbot`` label A-docs
2024-09-05 19:43:50 +02:00
Matthias Krüger
85d15d292d
Rollup merge of #129653 - RalfJung:addr-of-read-only, r=scottmcm
clarify that addr_of creates read-only pointers

Stacked Borrows does make this UB, but Tree Borrows does not. This is tied up with https://github.com/rust-lang/rust/issues/56604 and other UCG discussions. Also see [this collection of links](https://github.com/Rust-for-Linux/linux/pull/950#discussion_r1104759431) where rustc treats `addr_of!` as a "non-mutating use".

So, let's better be careful for now.
2024-09-05 19:43:47 +02:00
Matthias Krüger
0db3932433
Rollup merge of #129938 - chancancode:patch-1, r=thomcc
Elaborate on deriving vs implementing `Copy`

I was reading this documentation and this wasn't immediately clear to me.

In my mind, it seemed obvious that a type can only claim to be `Copy` if the bits it is storing can be `Copy`, and in the case of a generic struct that can only be the case if `T: Copy`. So the bound added by the derive seemed necessary at all times, and I thought what the documentation was trying to say is that the custom implementation allows you to add _additional bounds_.

Of course what it was actually trying to point out is that just because you have a generic parameter `T`, it doesn't necessarily mean you are storing the bits of `T`. And if you aren't, it may be the case that your own bits can be copied regardless of whether the bits of `T` can be safely copied.

Thought it may be worth elaborating to make that a bit more clear. Haven't tested/didn't try to figure out how to render this locally. Mainly not sure if the `PhantomData` back link is going to just work or need some extra stuff, but I figured someone else probably could just tell.
2024-09-05 18:58:56 +02:00
Boxy
0091b8ab2a update cfgs 2024-09-05 17:24:01 +01:00
Matthias Krüger
c7c3ada95a
Rollup merge of #129919 - kevinmehall:waker-getters, r=dtolnay
Stabilize `waker_getters`

Tracking issue: #96992

FCP completed on the tracking issue a while ago. It's not clear whether the libs-api team wanted the `RawWaker` methods moved to `Waker` or went back to the current API after further discussion. `@Amanieu` [wrote "This is just waiting for someone to submit a stabilization PR."](https://github.com/rust-lang/rust/issues/96992#issuecomment-2213685218) so I'm doing just that in hopes of nudging this along.

Edit: Moved the `data` and `vtable` methods from `RawWaker` to `Waker` and added `Waker::new` per https://github.com/rust-lang/rust/issues/96992#issuecomment-1941998046

```rs
impl Waker {
  pub const unsafe fn new(data: *const (), vtable: &'static RawWakerVTable) -> Self;
  pub fn data(&self) -> *const ();
  pub fn vtable(&self) -> &'static RawWakerVTable;
}
```

Closes #96992
2024-09-05 03:47:44 +02:00
Matthias Krüger
3775e6bd9f
Rollup merge of #127021 - thesummer:1-add-target-support-for-rtems-arm-xilinx-zedboard, r=tgross35
Add target support for RTEMS Arm

# `armv7-rtems-eabihf`

This PR adds a new target for the RTEMS RTOS. To get things started it focuses on Xilinx/AMD Zynq-based targets, but in theory it should also support other armv7-based board support packages in the future.
Given that RTEMS has support for many POSIX functions it is mostly enabling corresponding unix features for the new target.
I also previously started a PR in libc (https://github.com/rust-lang/libc/pull/3561) to add the needed OS specific C-bindings and was told that a PR in this repo is needed first. I will update the PR to the newest version after approval here.
I will probably also need to change one line in the backtrace repo.

Current status is that I could compile rustc for the new target locally (with the updated libc and backtrace) and could compile binaries, link, and execute a simple "Hello World" RTEMS application for the target hardware.

> A proposed target or target-specific patch that substantially changes code shared with other targets (not just target-specific code) must be reviewed and approved by the appropriate team for that shared code before acceptance.

There should be no breaking changes for existing targets. Main changes are adding corresponding `cfg` switches for the RTEMS OS and adding the C binding in libc.

# Tier 3 target policy

> - A tier 3 target must have a designated developer or developers (the "target maintainers") on record to be CCed when issues arise regarding the target. (The mechanism to track and CC such developers may evolve over time.)

I will do the maintenance (for now) further members of the RTEMS community will most likely join once the first steps have been done.

> - Targets must use naming consistent with any existing targets; for instance, a target for the same CPU or OS as an existing Rust target should use the same name for that CPU or OS. Targets should normally use the same names and naming conventions as used elsewhere in the broader ecosystem beyond Rust (such as in other toolchains), unless they have a very good reason to diverge. Changing the name of a target can be highly disruptive, especially once the target reaches a higher tier, so getting the name right is important even for a tier 3 target.
>     - Target names should not introduce undue confusion or ambiguity unless absolutely necessary to maintain ecosystem compatibility. For example, if the name of the target makes people extremely likely to form incorrect beliefs about what it targets, the name should be changed or augmented to disambiguate it.
>     - If possible, use only letters, numbers, dashes and underscores for the name. Periods (`.`) are known to cause issues in Cargo.

The proposed triple is `armv7-rtems-eabihf`

> - Tier 3 targets may have unusual requirements to build or use, but must not create legal issues or impose onerous legal terms for the Rust project or for Rust developers or users.
>     - The target must not introduce license incompatibilities.
>     - Anything added to the Rust repository must be under the standard Rust license (`MIT OR Apache-2.0`).
>     - The target must not cause the Rust tools or libraries built for any other host (even when supporting cross-compilation to the target) to depend on any new dependency less permissive than the Rust licensing policy. This applies whether the dependency is a Rust crate that would require adding new license exceptions (as specified by the `tidy` tool in the rust-lang/rust repository), or whether the dependency is a native library or binary. In other words, the introduction of the target must not cause a user installing or running a version of Rust or the Rust tools to be subject to any new license requirements.
>     - Compiling, linking, and emitting functional binaries, libraries, or other code for the target (whether hosted on the target itself or cross-compiling from another target) must not depend on proprietary (non-FOSS) libraries. Host tools built for the target itself may depend on the ordinary runtime libraries supplied by the platform and commonly used by other applications built for the target, but those libraries must not be required for code generation for the target; cross-compilation to the target must not require such libraries at all. For instance, `rustc` built for the target may depend on a common proprietary C runtime library or console output library, but must not depend on a proprietary code generation library or code optimization library. Rust's license permits such combinations, but the Rust project has no interest in maintaining such combinations within the scope of Rust itself, even at tier 3.
>     - "onerous" here is an intentionally subjective term. At a minimum, "onerous" legal/licensing terms include but are _not_ limited to: non-disclosure requirements, non-compete requirements, contributor license agreements (CLAs) or equivalent, "non-commercial"/"research-only"/etc terms, requirements conditional on the employer or employment of any particular Rust developers, revocable terms, any requirements that create liability for the Rust project or its developers or users, or any requirements that adversely affect the livelihood or prospects of the Rust project or its developers or users.

The tools consists of the cross-compiler toolchain (gcc-based). The RTEMS kernel (BSD license) and parts of the driver stack of FreeBSD (BSD license). All tools are FOSS and publicly available here: https://gitlab.rtems.org/rtems
There are also no new features or dependencies introduced to the Rust code.

> - Neither this policy nor any decisions made regarding targets shall create any binding agreement or estoppel by any party. If any member of an approving Rust team serves as one of the maintainers of a target, or has any legal or employment requirement (explicit or implicit) that might affect their decisions regarding a target, they must recuse themselves from any approval decisions regarding the target's tier status, though they may otherwise participate in discussions.

N/A to me. I am not a reviewer nor Rust team member.

> - Tier 3 targets should attempt to implement as much of the standard libraries as possible and appropriate (`core` for most targets, `alloc` for targets that can support dynamic memory allocation, `std` for targets with an operating system or equivalent layer of system-provided functionality), but may leave some code unimplemented (either unavailable or stubbed out as appropriate), whether because the target makes it impossible to implement or challenging to implement. The authors of pull requests are not obligated to avoid calling any portions of the standard library on the basis of a tier 3 target not implementing those portions.

`core` and `std` compile. Some advanced features of the `std` lib might not work yet. However, the goal of this tier 3 target it to make it easier for other people to build and run test applications to better identify the unsupported features and work towards enabling them.

> - The target must provide documentation for the Rust community explaining how to build for the target, using cross-compilation if possible. If the target supports running binaries, or running tests (even if they do not pass), the documentation must explain how to run such binaries or tests for the target, using emulation if possible or dedicated hardware if necessary.

Building is described in platform support doc. Running simple unit tests works. Running the test suite of the stdlib is currently not that easy. Trying to work towards that after the this target has been added to the nightly.

> - Tier 3 targets must not impose burden on the authors of pull requests, or other developers in the community, to maintain the target. In particular, do not post comments (automated or manual) on a PR that derail or suggest a block on the PR based on a tier 3 target. Do not send automated messages or notifications (via any medium, including via ````@`)``` to a PR author or others involved with a PR regarding a tier 3 target, unless they have opted into such messages.

Understood.

>     - Backlinks such as those generated by the issue/PR tracker when linking to an issue or PR are not considered a violation of this policy, within reason. However, such messages (even on a separate repository) must not generate notifications to anyone involved with a PR who has not requested such notifications.

Ok

> - Patches adding or updating tier 3 targets must not break any existing tier 2 or tier 1 target, and must not knowingly break another tier 3 target without approval of either the compiler team or the maintainers of the other tier 3 target.
>     - In particular, this may come up when working on closely related targets, such as variations of the same architecture with different features. Avoid introducing unconditional uses of features that another variation of the target may not have; use conditional compilation or runtime detection, as appropriate, to let each target run code supported by that target.

I think, I didn't add any breaking changes for any existing targets (see the comment regarding features above).

> - Tier 3 targets must be able to produce assembly using at least one of rustc's supported backends from any host target.

Can produce assembly code via the llvm backend (tested on Linux).

>
> If a tier 3 target stops meeting these requirements, or the target maintainers no longer have interest or time, or the target shows no signs of activity and has not built for some time, or removing the target would improve the quality of the Rust codebase, we may post a PR to remove it; any such PR will be CCed to the target maintainers (and potentially other people who have previously worked on the target), to check potential interest in improving the situation.GIAt this tier, the Rust project provides no official support for a target, so we place minimal requirements on the introduction of targets.

Understood.

r? compiler-team
2024-09-05 03:47:40 +02:00
Lukas Bergdoll
5439198348 Use non-overlapping swap for inner heapsort loop
This regresses binary-size slightly for normal builds, but the important
release_lto_thin_opt_level_s config sees a small improvement in
binary-size and a larger types such as string and 1k see 2-3% run-time
improvements with this change.
2024-09-04 19:54:46 +02:00
Lukas Bergdoll
a0e4303ba2 Select tiny sorts for 16-bit platforms
Also skips stack alloc in stable sort if 16-bit target platform.
2024-09-04 19:53:56 +02:00
Lukas Bergdoll
adb0e27acd Shrink heapsort further by combining sift_down loops 2024-09-04 19:37:49 +02:00
Lukas Bergdoll
f2d4198d6e Drop bubble_sort
While using it results in slightly slammer binaries, it's not deemed
worth it to add yet another sort algorithm to the standard library.
select_nth_unstable has bigger binary-size problems.
2024-09-04 18:58:44 +02:00
Literally Void
e2484be0c7 docs: add digit separators in Duration examples 2024-09-03 16:01:33 -07:00