Commit Graph

8223 Commits

Author SHA1 Message Date
Laine Taffin Altman
baa1cdde29
Docs for f16 and f128: correct a typo and add details 2025-02-02 19:48:57 -08:00
Matthias Krüger
961bf7ffa6
Rollup merge of #136434 - RalfJung:rustc_allowed_through_unstable_modules-deprecation-required, r=compiler-errors
rustc_allowed_through_unstable_modules: require deprecation message

This changes the `#[rustc_allowed_through_unstable_modules]` attribute so that a deprecation message (ideally directing people towards the stable path) is required.
2025-02-02 18:05:25 +01:00
Matthias Krüger
198384c8cc
Rollup merge of #136283 - hkBst:patch-31, r=workingjubilee
Update encode_utf16 to mention it is native endian

Fixes #83102
2025-02-02 18:05:22 +01:00
Matthias Krüger
48aede0773
Rollup merge of #134272 - RalfJung:destabilize-rustc_encodable_decodable, r=oli-obk
Remove rustc_encodable_decodable feature

This has been shown in future-compat reports since Rust 1.79 (https://github.com/rust-lang/rust/pull/116016), released June 2024. Let's see if crater still finds any issues.

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

Cc ``@rust-lang/libs-api``
2025-02-02 18:05:22 +01:00
Ralf Jung
3320e91575 rustc_allowed_through_unstable_modules: require deprecation message 2025-02-02 12:36:12 +01:00
Matthias Krüger
15a5f5f5e0
Rollup merge of #136364 - hkBst:ptr_cmp_docs, r=tgross35
document that ptr cmp is unsigned

Fixes #77497
2025-02-01 16:41:05 +01:00
Matthias Krüger
a56e85a827
Rollup merge of #136307 - WaffleLapkin:minminmin, r=scottmcm
Implement all mix/max functions in a (hopefully) more optimization amendable way

Previously the graph was like this:

```
min -> Ord::min -> min_by -> match on compare() (in these cases compare = Ord::cmp)
                                      ^
                                      |
                                 min_by_key
```
now it looks like this:
```
min -> Ord::min -> `<=` <- min_by_key

min_by -> `Ordering::is_le` of `compare()`
```
(`max*` and `minmax*` are the exact same, i.e. they also use `<=` and `is_le`)

I'm not sure how to test this, but it should probably be easier for the backend to optimize.

r? `@scottmcm`
cc https://github.com/rust-lang/rust/issues/115939#issuecomment-2622161134
2025-02-01 16:41:04 +01:00
Marijn Schouten
55dc6dbcf0 document ptr comparison being by address 2025-02-01 15:28:44 +01:00
Matthias Krüger
70894fed76
Rollup merge of #136351 - Darksonn:coerce-pointee-docs, r=compiler-errors
Add documentation for derive(CoercePointee)

Part of [RFC 3621][rfc] tracked by #123430. This text is heavily based on the guide-level explanation from the RFC.

``@rustbot`` label F-derive_coerce_pointee

[rfc]: https://rust-lang.github.io/rfcs/3621-derive-smart-pointer.html
2025-02-01 01:19:22 +01:00
Matthias Krüger
f90c321eb2
Rollup merge of #136163 - uellenberg:driftsort-off-by-one, r=Mark-Simulacrum
Fix off-by-one error causing slice::sort to abort the program

Fixes #136103.
Based on the analysis by ``@jonathan-gruber-jg`` and ``@orlp.``
2025-02-01 01:19:20 +01:00
bors
aa4cfd0809 Auto merge of #134424 - 1c3t3a:null-checks, r=saethlin
Insert null checks for pointer dereferences when debug assertions are enabled

Similar to how the alignment is already checked, this adds a check
for null pointer dereferences in debug mode. It is implemented similarly
to the alignment check as a `MirPass`.

This inserts checks in the same places as the `CheckAlignment` pass and additionally
also inserts checks for `Borrows`, so code like
```rust
let ptr: *const u32 = std::ptr::null();
let val: &u32 = unsafe { &*ptr };
```
will have a check inserted on dereference. This is done because null references
are UB. The alignment check doesn't cover these places, because in `&(*ptr).field`,
the exact requirement is that the final reference must be aligned. This is something to
consider further enhancements of the alignment check.

For now this is implemented as a separate `MirPass`, to make it easy to disable
this check if necessary.

This is related to a 2025H1 project goal for better UB checks in debug
mode: https://github.com/rust-lang/rust-project-goals/pull/177.

r? `@saethlin`
2025-01-31 15:56:53 +00:00
Alice Ryhl
209bb81483 Add documentation for derive(CoercePointee) 2025-01-31 11:37:41 +00:00
Bastian Kersting
b151b513ba Insert null checks for pointer dereferences when debug assertions are enabled
Similar to how the alignment is already checked, this adds a check
for null pointer dereferences in debug mode. It is implemented similarly
to the alignment check as a MirPass.

This is related to a 2025H1 project goal for better UB checks in debug
mode: https://github.com/rust-lang/rust-project-goals/pull/177.
2025-01-31 11:13:34 +00:00
Marijn Schouten
860476f6e0 Update encode_utf16 to mention it is native endian 2025-01-31 11:44:11 +01:00
bors
7f36543a48 Auto merge of #136332 - jhpratt:rollup-aa69d0e, r=jhpratt
Rollup of 9 pull requests

Successful merges:

 - #132156 (When encountering unexpected closure return type, point at return type/expression)
 - #133429 (Autodiff Upstreaming - rustc_codegen_ssa, rustc_middle)
 - #136281 (`rustc_hir_analysis` cleanups)
 - #136297 (Fix a typo in profile-guided-optimization.md)
 - #136300 (atomic: extend compare_and_swap migration docs)
 - #136310 (normalize `*.long-type.txt` paths for compare-mode tests)
 - #136312 (Disable `overflow_delimited_expr` in edition 2024)
 - #136313 (Filter out RPITITs when suggesting unconstrained assoc type on too many generics)
 - #136323 (Fix a typo in conventions.md)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-01-31 09:42:28 +00:00
Jacob Pratt
e2a73ab7ad
Rollup merge of #136300 - RalfJung:compare-and-swap, r=joboet
atomic: extend compare_and_swap migration docs

Fixes https://github.com/rust-lang/rust/issues/80486
2025-01-31 00:26:32 -05:00
Jacob Pratt
08dc8c931f
Rollup merge of #136296 - RalfJung:float-min-max, r=tgross35
float::min/max: mention the non-determinism around signed 0

Turns out this can actually produce different results on different machines [in practice](https://github.com/rust-lang/rust/issues/83984#issuecomment-2623859230); that seems worth documenting. I assume LLVM will happily const-fold these operations so so there could be different results for the same input even on the same machine, depending on whether things get const-folded or not.

`@nikic` I remember there was an LLVM soundness fix regarding scalar evolution for loops that had to recognize certain operations as non-deterministic... it seems to me that pass would also have to avoid predicting the result of `llvm.{min,max}num`, for the same reason?

r? `@tgross35`
Cc `@rust-lang/libs-api`

If this lands we should also make Miri non-deterministic here.

Fixes https://github.com/rust-lang/rust/issues/83984
2025-01-31 00:25:38 -05:00
Jacob Pratt
b249760c51
Rollup merge of #135414 - tgross35:stabilize-const_black_box, r=dtolnay
Stabilize `const_black_box`

This has been unstably const since #92226, but a tracking issue was never created. Per [discussion on Zulip][zulip], there should not be any blockers to making this const-stable. The function does not provide any functionality at compile time but does allow code reuse between const- and non-const functions, so stabilize it here.

[zulip]: https://rust-lang.zulipchat.com/#narrow/channel/146212-t-compiler.2Fconst-eval/topic/const_black_box
2025-01-31 00:25:34 -05:00
Waffle Lapkin
c5835cd648
implement all min/max fns in terms of </is_lt
`<` seems to be the "lucky one" for llvm
2025-01-31 05:45:12 +01:00
Waffle Lapkin
b20307b3e9
improve doc tests for (min/max/minmax).* functions
- add tests for `a == b` where missing
- try to make all the tests more similar
- try to use more illustrative test values
2025-01-31 05:30:32 +01:00
Matthias Krüger
410442f610
Rollup merge of #136271 - Sky9x:debug-maybeuninit-footgun, r=tgross35
Remove minor future footgun in `impl Debug for MaybeUninit`

No longer breaks if `MaybeUninit` moves modules (technically it could break if `MaybeUninit` were renamed but realistically that will never happen)

Debug impl originally added in #133282
2025-01-30 20:47:08 +01:00
Matthias Krüger
c32f2c7172
Rollup merge of #135852 - lukas-code:asyncfn-prelude-core, r=compiler-errors
Add `AsyncFn*` to `core` prelude

In https://github.com/rust-lang/rust/pull/132611 these got added to the `std` prelude only, which looks like an oversight.

r? libs-api
cc `@compiler-errors`
2025-01-30 20:47:05 +01:00
bors
a6434ef9c0 Auto merge of #134824 - niklasf:int_from_ascii, r=ibraheemdev
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.
2025-01-30 14:25:22 +00:00
Ralf Jung
46b7da8243 atomic: extend compare_and_swap migration docs 2025-01-30 14:40:08 +01:00
Ralf Jung
6b699ccee4 float::min/max: mention the non-determinism around signed 0 2025-01-30 13:44:13 +01:00
Stuart Cook
4059a796d5
Rollup merge of #136259 - hkBst:patch-30, r=thomcc
Cleanup docs for Allocator

This is an attempt to remove ungrammatical constructions and clean up the prose. I've sometimes had to try hard to understand what was being stated, so it is possible that I've misunderstood the original meaning. In particular, I did not see a difference between:
 - the borrow-checker lifetime of the allocator type itself.
 - as long as at least one of the allocator instance and all of its clones has not been dropped.
2025-01-30 14:25:07 +11:00
Stuart Cook
6ebe590e41
Rollup merge of #135847 - edwloef:slice_ptr_rotate_opt, r=scottmcm
optimize slice::ptr_rotate for small rotates

r? `@scottmcm`

This swaps the positions and numberings of algorithms 1 and 2 in `slice::ptr_rotate`, and pulls the entire outer loop into algorithm 3 since it was redundant for the first two. Effectively, `ptr_rotate` now always does the `memcpy`+`memmove`+`memcpy` sequence if the shifts fit into the stack buffer.
With this change, an `IndexMap`-style `move_index` function is optimized correctly.

Assembly comparisons:
- `move_index`, before: https://godbolt.org/z/Kr616KnYM
- `move_index`, after: https://godbolt.org/z/1aoov6j8h
- the code from `#89714`, before: https://godbolt.org/z/Y4zaPxEG6
- the code from `#89714`, after: https://godbolt.org/z/1dPx83axc

related to #89714
some relevant discussion in https://internals.rust-lang.org/t/idea-shift-move-to-efficiently-move-elements-in-a-vec/22184

Behavior tests pass locally. I can't get any consistent microbenchmark results on my machine, but the assembly diffs look promising.
2025-01-30 14:25:04 +11:00
Sky
b320e1741c
Remove minor future footgun in impl Debug for MaybeUninit
No longer breaks if `MaybeUninit` moves modules (technically it could break if `MaybeUninit` were renamed but realistically that will never happen)
2025-01-29 20:23:59 -05:00
Marijn Schouten
52519e145e Cleanup docs for Allocator 2025-01-29 20:15:49 +01:00
edwloef
fb3d1d0c4b
add inline attribute and codegen test 2025-01-29 19:34:19 +01:00
edwloef
311c3b71f0
split slice::ptr_rotate into three separate algorithms, to hopefully help inlining 2025-01-29 19:34:15 +01:00
uellenberg
1565254478 Fix off-by-one error causing driftsort to crash
Fixes #136103.
Based on the analysis by @jonathan-gruber-jg and @orlp.
2025-01-28 23:39:46 -08:00
León Orell Valerian Liehr
53f343f396
Rollup merge of #135625 - c410-f3r:cfg-match-foo-bar-baz, r=tgross35,jhpratt
[cfg_match] Document the use of expressions.

cc #115585

Adds documentation to this new feature introduced in #133720.
2025-01-29 03:12:18 +01:00
bors
bf1b174e7d Auto merge of #136203 - matthiaskrgr:rollup-1k0f44l, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #135869 (Make docs for AtomicUsize::from_mut platform-independent)
 - #135892 (-Znext-solver: "normalize" signature before checking it mentions self in `deduce_closure_signature`)
 - #136055 (Implement MIR const trait stability checks)
 - #136066 (Pass spans to `perform_locally_in_new_solver`)
 - #136071 ([Clippy] Add vec_reserve & vecdeque_reserve diagnostic items)
 - #136124 (Arbitrary self types v2: explain test.)
 - #136149 (Flip the `rustc-rayon`/`indexmap` dependency order)
 - #136173 (Update comments and sort target_arch in c_char_definition)
 - #136178 (Update username in build helper example)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-01-28 20:15:51 +00:00
Matthias Krüger
36b5c58ef8
Rollup merge of #136173 - taiki-e:c-char, r=tgross35
Update comments and sort target_arch in c_char_definition

Follow-up to https://github.com/rust-lang/rust/pull/132975.

- Clang's wrong default on MSP430 has been fixed in https://github.com/llvm/llvm-project/pull/115964, and will be included in LLVM 20, which will be used soon.
- Add a reference on Xtensa's default (from https://github.com/rust-lang/rust/pull/132975#issuecomment-2484645240).
- Fix link for Windows's default.
- Add a link to the discussion on L4Re (https://github.com/rust-lang/rust/pull/132975#issuecomment-2484645240)
- Sort `target_arch`. (now match with `target_arch`s in comments)

r? `@tgross35`
2025-01-28 18:17:30 +01:00
Matthias Krüger
6b4757b5de
Rollup merge of #135869 - hkBst:patch-12, r=Noratrieb
Make docs for AtomicUsize::from_mut platform-independent

fixes #133342
2025-01-28 18:17:22 +01:00
Matthias Krüger
448fa117f8
Rollup merge of #135886 - hkBst:patch-14, r=workingjubilee
Document purpose of closure in from_fn.rs more clearly

partial fix for #135087 together with https://github.com/rust-lang/rust/pull/135895
2025-01-28 14:23:23 +01:00
Matthias Krüger
da5e22de0a
Rollup merge of #133829 - GrigorenkoPV:fetch_update_infallible, r=Noratrieb
Implement `AtomicT::update` & `AtomicT::try_update`

ACP accepted in https://github.com/rust-lang/libs-team/issues/490

``@rustbot`` label +T-libs-api
2025-01-28 14:23:20 +01:00
Marijn Schouten
aa1f941116 Fix platform-specific doc string for AtomicUsize::from_mut to be platform-independent 2025-01-28 14:12:55 +01:00
Taiki Endo
ea70688f7d Update comments and sort target_arch in c_char_definition 2025-01-28 14:41:15 +09:00
Guillaume Gomez
314a695295
Rollup merge of #135807 - jhpratt:phantom-variance, r=Amanieu
Implement phantom variance markers

ACP accepted https://github.com/rust-lang/libs-team/issues/488

Tracking issue #135806
2025-01-27 15:38:24 +01:00
Guillaume Gomez
b7476f1784
Rollup merge of #135773 - hkBst:patch-10, r=tgross35
Clarify WindowsMut (Lending)Iterator

fixes #133628
2025-01-27 15:38:22 +01:00
Marijn Schouten
f630f7f410 Clarify WindowsMut (Lending)Iterator
fixes 133628
2025-01-27 10:53:58 +01:00
Trevor Gross
395f0c9ecd Stabilize const_black_box
This has been unstably const since [1], but a tracking issue was never
created. Per discussion on Zulip [2], there should not be any blockers
to making this const-stable. The function does not provide any
functionality at compile time but does allow code reuse between const-
and non-const functions, so stabilize it here.

[1]: https://github.com/rust-lang/rust/pull/92226
[2]: https://rust-lang.zulipchat.com/#narrow/channel/146212-t-compiler.2Fconst-eval/topic/const_black_box
2025-01-27 07:54:58 +00:00
bors
55459598c2 Auto merge of #136116 - fmease:rollup-c8pk3mj, r=fmease
Rollup of 8 pull requests

Successful merges:

 - #126604 (Uplift `clippy::double_neg` lint as `double_negations`)
 - #135158 (Add `TooGeneric` variant to `LayoutError` and emit `Unknown`)
 - #135635 (Move `std::io::pipe` code into its own file)
 - #136072 (add two old crash tests)
 - #136079 (compiler_fence: fix example)
 - #136091 (Add some tracing to core bootstrap logic)
 - #136097 (rustc_ast: replace some len-checks + indexing with slice patterns etc.)
 - #136101 (triagebot: set myself on vacation)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-01-27 06:54:42 +00:00
bors
633a3fe36d Auto merge of #135937 - bjorn3:separate_coretests_crate, r=jieyouxu,tgross35
Put the core unit tests in a separate coretests package

Having standard library tests in the same package as a standard library crate has bad side effects. It causes the test to have a dependency on a locally built standard library crate, while also indirectly depending on it through libtest. Currently this works out fine in the context of rust's build system as both copies are identical, but for example in cg_clif's tests I've found it basically impossible to compile both copies with the exact same compiler flags and thus the two copies would cause lang item conflicts.

This PR moves the tests of libcore to a separate package which doesn't depend on libcore, thus preventing the duplicate crates even when compiler flags don't exactly match between building the sysroot (for libtest) and building the test itself. The rest of the standard library crates do still have this issue however.
2025-01-27 03:57:37 +00:00
León Orell Valerian Liehr
bd2f6d7ee8
Rollup merge of #136079 - RalfJung:compiler-fence-example, r=jhpratt
compiler_fence: fix example

The old example was wrong, an acquire fence is required in the signal handler. To make the point more clear, I changed the "data" variable to use non-atomic accesses.

Fixes https://github.com/rust-lang/rust/issues/133014
2025-01-27 04:34:52 +01:00
Ralf Jung
9c972c0ea5 compiler_fence: fix example 2025-01-26 17:34:33 -07:00
Marijn Schouten
d3cd832dda Document purpose of closure in from_fn.rs more clearly 2025-01-26 13:43:55 +01:00
bors
15c6f7e1a3 Auto merge of #136087 - jhpratt:rollup-tam1mzn, r=jhpratt
Rollup of 7 pull requests

Successful merges:

 - #133631 (Support QNX 7.1 with `io-sock`+libstd and QNX 8.0 (`no_std` only))
 - #134358 (compiler: Set `target_abi = "ilp32e"` on all riscv32e targets)
 - #135812 (Fix GDB `OsString` provider on Windows )
 - #135842 (TRPL: more backward-compatible Edition changes)
 - #135946 (Remove extra whitespace from rustdoc breadcrumbs for copypasting)
 - #135953 (ci.py: check the return code in `run-local`)
 - #136019 (Add an `unchecked_div` alias to the `Div<NonZero<_>>` impls)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-01-26 12:10:05 +00:00