Add `core::num::Complex`
tracking issue: https://github.com/rust-lang/rust/issues/154023
See also [#t-compiler > representing `_Complex`](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/representing.20.60_Complex.60/with/608308993). The RFC states that the `Complex` type should match the ABI of `_Complex` in C, but provides little detail on how to actually achieve this. We concluded that `repr(complex)` is probably the best approach. Like clang, that means we "desugar" the representation early: `_Complex` is not natively represented in LLVM IR.
I've derived the ABI from `clang` for 28 targets, a decent sample of what we actually support. For now I'm only actually testing `x86_64` because (as you'll see) updating the tests is quite labor-intensive. If we're happy with this direction I can fill more of them in, likely in a separate PR.
The libs side of the type is very bare-bones: I'm not as interested in that part. Others can fill in the various instances, methods, write tests for those, and improve the docs.
r? workingjubilee
std: don't clean up the main thread's altstack
Fixesrust-lang/rust#161018https://github.com/rust-lang/rust/pull/28069 added a call to what is now `rt::cleanup` to `process::exit`. `rt::cleanup` in turn calls the UNIX `stack_overflow::cleanup`, which frees the main thread's signal stack and uninstalls the current thread's signal handler in the assumption that the current thread is the main one – even though `process::exit` can be called from any thread.
This PR removes the main thread cleanup logic altogether, since, as the FIXME in `stack_overflow::cleanup` points out, it causes more issues than it is worth. This also means that stack overflows in TLS destructors will be caught on the main thread, partly addressing rust-lang/rust#111272.
std: map ERROR_NEGATIVE_SEEK to ErrorKind::InvalidInput on Windows
Windows error mapping doesn't have an arm for `ERROR_NEGATIVE_SEEK`, the code returned when using negative seek position, so it decodes to `ErrorKind::Uncategorized`.
On unix negative seek is `EINVAL`:
[> EINVAL whence is not valid. Or: the resulting file offset would be negative, or beyond the end of a seekable device.](https://www.man7.org/linux/man-pages/man2/lseek.2.html)
And is mapped to [InvalidInput](e64c8a664d/library/std/src/sys/io/error/unix.rs (L154)) error.
On Windows there is `ERROR_NEGATIVE_SEEK` [windows_sys.rs#L1829](e64c8a664d/library/std/src/sys/pal/windows/c/windows_sys.rs (L1829)).
The message on Windows would still be more specific and detailed for this error. Both messages come from the OS itself, so not sure if it could be addressed somehow. Looks like Unix has more coarse error codes than Windows, which uses more granular ones with more precise messages: `EINVAL` is shared across many syscalls, so its message is more general.
Windows:
`kind: InvalidInput, message: "An attempt was made to move the file pointer before the beginning of the file."`
Unix:
`kind: InvalidInput, message: "Invalid argument" `
Fixesrust-lang/rust#158246
r? libs
Couple of misc improvements to the unwind infrastructure
* Fix `_Unwind_Exception` size on Emscripten.
* Move a link block.
* Remove some manual dummy impls where there is already a dummy fallback.
Follow up to https://github.com/rust-lang/rust/pull/159785
doc changes to expect messages in process.rs
Reword expect messages in `library/std/src/process.rs` to follow style guide rust-lang/rust#96033
Example
```diff
- child.wait().expect("command wasn't running");
+ child.wait().expect("wait on child should succeed")
```
Issue: rust-lang/rust#159751
Enforce more library clippy lints in CI
Best reviewed commit by commit.
This is testing the waters for enforcing more clippy lints. I've chosen these ones because we mostly adhere to them already (at least in core/alloc/std) so we can reduce the noise in `./x clippy` by fixing or allowing the relatively few violations.
Windows error mapping doesn't have an arm for `ERROR_NEGATIVE_SEEK`,
the code returned when using negative seek position, so it
decodes to `ErrorKind::Uncategorized`. Unix already maps the equivalent
`EINVAL` to `InvalidInput`
This adds the missing arm, on Windows to match with Unix.
Ensure TLS accesses don't call the global allocator through panic
Fixesrust-lang/rust#160930
That issue is much more simple to fix than the other reentrancy issues, since only thread locals
use the TLS code. We can just replace all the assertions with their `rt` versions that do not
call the global allocator.
r? libs
std: Adjust cfgs again for TLS on WASI
This commit adjusts the changes made in rust-lang/rust#159733. A wasi-libc bug was discovered in rust-lang/rust#160828 which is present in certain situations which means that the changes in rust-lang/rust#159733 expose this bug. The purpose of this PR is to get wasip1/wasip2 targets fixed again while preserving a working implementation for wasip3. This upstream bug is already fixed in wasi-libc meaning that this PR won't be necessary once wasi-sdk-34 is published and used in rust-lang/rust. Until that time, however, this effectively reverts rust-lang/rust#159733 for wasip1/wasip2. The wasip3 target is Tier 3 still and requires wasi-sdk-34 anyway which is why that's left unchanged.
Closesrust-lang/rust#160828
Implement <OnceCell,OnceLock>::new_init
Tracking issues: rust-lang/rust#159859rust-lang/rust#159860
I'm not sure If I was supposed to add any other tests apart from the doc tests.
This commit adjusts the changes made in 159733. A wasi-libc bug was
discovered in 160828 which is present in certain situations which means
that the changes in 159733 expose this bug. The purpose of this PR is
to get wasip1/wasip2 targets fixed again while preserving a working
implementation for wasip3. This upstream bug is already fixed in
wasi-libc meaning that this PR won't be necessary once wasi-sdk-34 is
published and used in rust-lang/rust. Until that time, however, this
effectively reverts 159733 for wasip1/wasip2. The wasip3 target is Tier
3 still and requires wasi-sdk-34 anyway which is why that's left
unchanged.
Closes 160828
yk what we can do btree later
raaaaagh
pain and suffering
*unleaks your box* whats thiSegmentation fault (core dumped)
straight up testing it. and by it,
well, let's just say. "my allocator"
linked and listed
the unnecesary bits? gone. reduced to atoms
fix: build-std on 32 bit arm with 64 bit time
Infer target type of `tv_usec`.
The libc crate has support for building with 64 bit time on 32 bit
platforms, configurable currently via environment variable or cfg directives.
When building using 64 bit time, the tv_usec field will be aliased to `__suseconds64_t` instead of `suseconds_t` causing the `build-std` feature to not be able to build the standard library due to a type mismatch.
Adopting the same convention as in 1b29cfdbee/library/std/src/sys/net/connection/socket/solid.rs (L151) fixes the issue, supporting 64 bit time on 32 bit arm platforms.
Another option would be using cfg attributes for this but from what I can tell there are no existing such attributes for time bits in the std and they would essentially duplicate the ones already present in the libc crate e27c7f1e2b/build.rs (L16)
* fix: build-std on 32 bit arm with 64 bit time
The libc crate has support for building with 64 bit time on 32 bit
platforms using the `RUST_LIBC_UNSTABLE_GNU_TIME_BITS` environment
variable.
Convert the tv_usec field to i64 via `into` in this case since
`suseconds_t` is still defined as an i32 when this environment variable
is set.
* Use placeholder as target type
This allows us to rely on the compiler to infer the correct target type,
mirroring the approach used in `sys/net/connection/socket/solid.rs`.
Revive L4Re target
This revives the target for the L4Re OS. It changes the way, linking is done and adds aarch64 support and documentation including a maintainer for the target.
The update of the libc crate is necessary since only in 0.2.179 and higher is the fixed support for L4Re on uclibc.
Fixes the builds of rustc and library/std for the L4Re target OS.
A major change was done in linking binaries: The need for the L4Bender
tool was removed and linking parameters are now fully configured in the
rustc target config.
Cap socket send length to c_int::MAX on Apple targets
On Apple, `send`/`sendto` reject a length larger than `c_int::MAX` with `EINVAL` instead of doing a short send. The send length was only clamped to `wrlen_t::MAX` (a no-op on 64-bit unix), so writing more than `c_int::MAX` bytes to a socket failed on macOS.
Add a `MAX_SEND_LEN` cap (`c_int::MAX` on Apple, `wrlen_t::MAX` elsewhere), used in `write`, `send`, `send_to`, and `send_with_flags`.
Fixesrust-lang/rust#115325
[rustdoc] Do not take `doc(cfg())` into account when filtering doctests
Part of rust-lang/rust#147033.
Because it was using the `extract_cfg_from_attrs` common function, it was taking into account the `doc(cfg())` attributes the same as if they were a `cfg`.
I didn't mark this PR as "fix" because I didn't handle the case of the doctest not being marked as ignored because I'm not sure if we should revisit the fact that we ignore these doctests or if we should just mark them as ignored (because of `target_feature(enable = "...")`).
Setting @fmease as reviewer as they are likely the only one with context about this issue. 😆
r? @fmease
Update expect messages in tcp.rs doc examples to follow the style guide
Related issue: rust-lang/rust#159751
Rewords the `.expect(...)` messages in the `TcpStream`/`TcpListener` doc examples in `library/std/src/net/tcp.rs` to follow the "expect as precondition" style guide introduced in rust-lang/rust#96033.
Examples of the change:
- `"set_nodelay call failed"` → `"set_nodelay should succeed"`
- `"could not set TTL"` → `"set_ttl should succeed"`
- `"Cannot set non-blocking"` → `"set_nonblocking should succeed"`
19 doc-example messages updated, all in doc comments (`///`). Doc-only change, no behavior change.
Emit thumb code on VEX V5
This PR switches the default codegen for the VEX V5 target to emit Thumb-2 instructions, allowing for smaller binary sizes (on the programs I tested this change on, I saw a ~20% size decrease on average). The target is renamed to have the `thumb` prefix instead of the `arm` prefix because of the updated instruction set.
Since VEXos starts all programs in Arm32 mode, the program entrypoint is explicitly compiled as ARM code and now transitions to Thumb mode when calling `_start`.
Users can still use the updated target in Arm32 mode by specifying `-Ctarget-feature=-thumb-mode`.
cc @tropicaaal @Gavin-Niederman
std: move futex implementations into sys::sync::futex
Part of rust-lang/rust#117276.
Moves the futex primitives out of the per-platform `sys::pal` modules into a single `sys::sync::futex`, selected with `cfg_select!` the same way the other `sys::sync` backends are.
Every consumer of these primitives already lives in `sys::sync` (mutex, rwlock, once, condvar, thread_parking), so they now import `crate::sys::sync::futex` directly instead of reaching `crate::sys::futex` through the `pub use pal::*` glob.
I placed it under `sys::sync` rather than a top-level `sys::futex` because the futex API only backs the `sys::sync` primitives and sits next to the existing `sys::sync::thread_parking` backend.
Happy to place it to `sys::futex` if you would rather have it as a peer of the other feature modules.
The file moves are a separate commit, recorded in `.git-blame-ignore-revs` so blame skips the rename.
r? joboet
std: fix stack buffer overflow in Windows junction_point
The guard checked `data_len > u16::MAX`, allowing paths far larger than `PathBuffer` (a fixed 16384-element array), which the subsequent single `copy_from` then overflows. Bound against `MAXIMUM_REPARSE_DATA_BUFFER_SIZE` plus header instead, matching the kernel's limit.
The pages are demand-zero and never written, so the datagram test no
longer needs ~2 GiB of memory and its `#[ignore]` can go away. Keep a
`Vec`-backed copy for non-unix targets, where `mmap` isn't available.