Commit Graph

14498 Commits

Author SHA1 Message Date
David Tolnay
e480cabe3a
Fix empty-set symbol in comments 2024-04-16 18:19:27 -07:00
Guillaume Gomez
183c706305
Rollup merge of #123859 - krtab:uneeded_clone, r=cuviper
Remove uneeded clones now that TrustedStep implies Copy

This is a follow up to 11fa1764ee (from #112083)
2024-04-16 21:41:25 +02:00
Guillaume Gomez
1176134114
Rollup merge of #123811 - joboet:queue_em_up, r=ChrisDenton
Use queue-based `RwLock` on more platforms

This switches over Windows 7, SGX and Xous to the queue-based `RwLock` implementation added in #110211, thereby fixing #121949 for Windows 7 and partially resolving #114581 on SGX. TEEOS can't currently be switched because it doesn't have a good thread parking implementation.

CC `@roblabla` `@raoulstrackx` `@xobs` Could you help me test this, please?
r? `@ChrisDenton` the Windows stuff should be familiar to you
2024-04-16 21:41:25 +02:00
joboet
10b6ca139e
std: fix lint on SGX 2024-04-16 16:50:56 +02:00
Arthur Carcano
864eb7fa14 Remove uneeded clones now that TrustedStep implies Copy
This is a follow up to 11fa1764ee
2024-04-16 16:11:06 +02:00
Guillaume Gomez
1c8bdb93d9
Rollup merge of #123721 - madsmtm:fix-visionos, r=davidtwco
Various visionOS fixes

A few small mistakes was introduced in https://github.com/rust-lang/rust/pull/121419, probably after the rename from `xros` to `visionos`. See the commits for details.

CC `@agg23`

Since you reviewed https://github.com/rust-lang/rust/pull/121419
r? davidtwco
2024-04-16 15:19:13 +02:00
Hrvoje Niksic
d8745f9346 Update usage note on OpenOptions::append()
Avoid implying that concatenating data before passing it to `write()` (with
or without `BufWriter`) ensures atomicity.
2024-04-16 14:07:48 +02:00
Michael Goulet
27cb6bcb9b
Rollup merge of #123970 - risc0:erik/zkvm-fix-os-str, r=joboet
zkvm: fix references to `os_str` module

The `os_str` module has been moved to `sys`. This change fixes build issues by changing `use` to point to `crate::sys::os_str`.
2024-04-15 15:18:07 -04:00
bors
99d0186b1d Auto merge of #123968 - jieyouxu:rollup-1pnkxor, r=jieyouxu
Rollup of 12 pull requests

Successful merges:

 - #123423 (Distribute LLVM bitcode linker as a preview component)
 - #123548 (libtest: also measure time in Miri)
 - #123666 (Fix some typos in doc)
 - #123864 (Remove a HACK by instead inferring opaque types during expected/formal type checking)
 - #123896 (Migrate some diagnostics in `rustc_resolve` to session diagnostic)
 - #123919 (builtin-derive: tag → discriminant)
 - #123922 (Remove magic constants when using `base_n`.)
 - #123931 (Don't leak unnameable types in `-> _` recover)
 - #123933 (move the LargeAssignments lint logic into its own file)
 - #123934 (`rustc_data_structures::graph` mini refactor)
 - #123941 (Fix UB in LLVM FFI when passing zero or >1 bundle)
 - #123957 (disable create_dir_all_bare test on all(miri, windows))

r? `@ghost`
`@rustbot` modify labels: rollup
2024-04-15 16:46:59 +00:00
Erik Kaneda
ee0aea5f65
zkvm: fix references to os_str module
The `os_str` module has been moved to `sys`.
2024-04-15 09:32:21 -07:00
许杰友 Jieyou Xu (Joe)
723c0e23bc
Rollup merge of #123957 - RalfJung:create_dir_all_bare, r=joboet
disable create_dir_all_bare test on all(miri, windows)
2024-04-15 16:56:19 +01:00
许杰友 Jieyou Xu (Joe)
2074631732
Rollup merge of #123548 - RalfJung:what-is-time, r=joboet
libtest: also measure time in Miri

A long time ago we disabled timekeeping of the default test harness in Miri, as otherwise it would fail to run without `-Zmiri-disable-isolation`. However, since then Miri gained a "fake clock" that lets it present some deterministic notion of time when isolation is enabled.

So we could now let libtest do timekeeping again when running in Miri. That's nice as it can help detect tests that run too long. However it can also be confusing as the results with isolation can be quite different than the real time.

``@rust-lang/miri`` what do you think?
2024-04-15 16:56:14 +01:00
bors
023084804e Auto merge of #123937 - RalfJung:miri-link-section, r=oli-obk
Miri on Windows: run .CRT$XLB linker section on thread-end

Hopefully fixes https://github.com/rust-lang/rust/issues/123583

First commit is originally by `@bjorn3`

r? `@oli-obk`
Cc `@ChrisDenton`
2024-04-15 14:36:12 +00:00
bors
84e729a59f Auto merge of #123851 - NobodyXu:patch-1, r=BurntSushi
Update document for std::io::Error::downcast

Resolve concern raised by `@BurntSushi` https://github.com/rust-lang/rust/issues/99262#issuecomment-2042641813
2024-04-15 12:32:57 +00:00
Jiahao XU
05366ee270
Update doc for std::io::Error::downcast 2024-04-15 21:58:36 +10:00
Ralf Jung
24dac6cd45 disable create_dir_all_bare on all(miri, windows) 2024-04-15 10:15:14 +02:00
Ralf Jung
510720e9fc libtest: also measure time in Miri 2024-04-15 09:50:42 +02:00
bors
9db7a74525 Auto merge of #123928 - tbu-:pr_statx_enosys, r=workingjubilee
`statx` probe: `ENOSYS` might come from a faulty FUSE driver

Do the availability check regardless of the error returned from `statx`.

CC https://github.com/rust-lang/rust/pull/122079#discussion_r1564761281
2024-04-15 02:07:35 +00:00
Guillaume Gomez
32be7b7129
Rollup merge of #123915 - shenawy29:patch-1, r=Nilstrieb
improve documentation slightly regarding some pointer methods
2024-04-14 23:24:34 +02:00
Guillaume Gomez
fa483a4829
Rollup merge of #120900 - marcospb19:std-use-seek-stream-position, r=joshtriplett
std: use `stream_position` where applicable

by replacing `seek(SeekFrom::Current(0))` calls
2024-04-14 23:24:32 +02:00
Ralf Jung
5934aaaa97 Miri: run .CRT$XLB linker section on thread-end 2024-04-14 20:09:05 +02:00
Tobias Bucher
2325b81d04 statx probe: ENOSYS might come from a faulty FUSE driver
Do the availability check regardless of the error returned from `statx`.

CC https://github.com/rust-lang/rust/pull/122079#discussion_r1564761281
2024-04-14 17:04:41 +02:00
bors
a8a88fe524 Auto merge of #122268 - ChrisDenton:no-libc, r=Mark-Simulacrum
Link MSVC default lib in core

## The Problem

On Windows MSVC, Rust invokes the linker directly. This means only the objects and libraries Rust explicitly passes to the linker are used. In short, this is equivalent to passing `-nodefaultlibs`, `-nostartfiles`, etc for gnu compilers.

To compensate for this [the libc crate links to the necessary libraries](a0f5b4b213/src/windows/mod.rs (L258-L261)). The libc crate is then linked from std, thus when you use std you get the defaults back.or integrate with C/C++.

However, this has a few problems:

- For `no_std`, users are left to manually pass the default lib to the linker
- Whereas `std` has the opposite problem, using [`/nodefaultlib`](https://learn.microsoft.com/en-us/cpp/build/reference/nodefaultlib-ignore-libraries?view=msvc-170) doesn't work as expected because Rust treats them as normal libs. This is a particular problem when you want to use e.g. the debug CRT libraries in their place or integrate with C/C++..

## The solution

This PR fixes this in two ways:

- moves linking the default lib into `core`
- passes the lib to the linker using [`/defaultlib`](https://learn.microsoft.com/en-us/cpp/build/reference/defaultlib-specify-default-library?view=msvc-170). This allows users to override it in the normal way (i.e. with [`/nodefaultlib`](https://learn.microsoft.com/en-us/cpp/build/reference/nodefaultlib-ignore-libraries?view=msvc-170)).

This is more or less equivalent to what the MSVC C compiler does. You can see what this looks like in my second commit, which I'll reproduce here for convenience:

```rust
// In library/core
#[cfg(all(windows, target_env = "msvc"))]
#[link(
    name = "/defaultlib:msvcrt",
    modifiers = "+verbatim",
    cfg(not(target_feature = "crt-static"))
)]
#[link(name = "/defaultlib:libcmt", modifiers = "+verbatim", cfg(target_feature = "crt-static"))]
extern "C" {}
```

## Alternatives

- Add the above to `unwind` and `std` but not `core`
- The status quo
- Some other kind of compiler magic maybe

This bares some discussion so I've t-libs nominated it.
2024-04-14 13:28:21 +00:00
Mohamed El-Shenawy
5b8864ab80
improve documentation slightly regarding some pointer methods 2024-04-14 09:56:33 +02:00
Chris Denton
87e1dd0dfd
Move msvc libs to core 2024-04-14 07:11:53 +00:00
Chris Denton
b1f1039d8b
Replace libc::c_int with core::ffi::c_int
And remove the libc crate when it isn't needed
2024-04-14 07:11:51 +00:00
Matthias Krüger
2ba0c627de
Rollup merge of #123879 - beetrees:missing-unsafe, r=Mark-Simulacrum
Add missing `unsafe` to some internal `std` functions

Adds `unsafe` to a few internal functions that have safety requirements but were previously not marked as `unsafe`. Specifically:

- `std::sys::pal::unix:🧵:min_stack_size` needs to be `unsafe` as `__pthread_get_minstack` might dereference the passed pointer. All callers currently pass a valid initialised `libc::pthread_attr_t`.
- `std:🧵:Thread::new` (and `new_inner`) need to be `unsafe` as it requires the passed thread name to be valid UTF-8, otherwise `Thread::name` will trigger undefined behaviour. I've taken the opportunity to split out the unnamed thread case into a separate `new_unnamed` function to make the safety requirement clearer. All callers meet the safety requirement now that #123505 has been merged.
2024-04-14 09:01:58 +02:00
Matthias Krüger
2bec57d4a9
Rollup merge of #123875 - Ghamza-Jd:master, r=joboet
Doc: replace x with y for hexa-decimal fmt

I found it a bit unintuitive to know which is variable and which is the format string in `format!("{x:x}")`, so I switched it to `y`.
2024-04-14 09:01:58 +02:00
Matthias Krüger
0638780570
Rollup merge of #123779 - semarie:notgull-openbsd-socket, r=Mark-Simulacrum
OpenBSD fix long socket addresses

Original diff from ``@notgull`` in #118349, small changes from me.

on OpenBSD, getsockname(2) returns the actual size of the socket address, and  not the len of the content. Figure out the length for ourselves. see https://marc.info/?l=openbsd-bugs&m=170105481926736&w=2

Fixes #116523
2024-04-14 09:01:57 +02:00
Matthias Krüger
7c8c2f08e1
Rollup merge of #123651 - tgross35:thread-local-updates, r=Mark-Simulacrum
Thread local updates for idiomatic examples

Update thread local examples to make more idiomatic use of `Cell` for `Copy` types, `RefCell` for non-`Copy` types.

Also shrink the size of `unsafe` blocks, add `SAFETY` comments, and fix `clippy::redundant_closure_for_method_calls`.
2024-04-14 09:01:56 +02:00
bors
f3c6608861 Auto merge of #107462 - WaffleLapkin:from_iterator_for_tuple, r=dtolnay
Implement `FromIterator` for `(impl Default + Extend, impl Default + Extend)`

Similarly to how https://github.com/rust-lang/rust/pull/85835 implemented `Extend` for `(impl Extend, impl Extend)`:
```rust
impl<A, B, AE, BE> FromIterator<(AE, BE)> for (A, B)
where
    A: Default + Extend<AE>,
    B: Default + Extend<BE>,
{ ... }
```
2024-04-14 03:15:53 +00:00
bors
7ab5eb8fe7 Auto merge of #123819 - joboet:fmt_usize_marker, r=Mark-Simulacrum
Get rid of `USIZE_MARKER` in formatting infrastructure

An alternative to #123780.

The `USIZE_MARKER` function used to differentiate between placeholder and count arguments is never called anyway, so we can just replace the function-pointer-comparison hack with an `enum` and an `unreachable_unchecked`, hopefully without causing a regression.

CC `@RalfJung`
2024-04-14 00:03:53 +00:00
Matthias Krüger
360f9ed573
Rollup merge of #123876 - dpaoliello:backtrace, r=ChrisDenton
Update backtrace submodule

Fixes #123686
2024-04-13 16:42:05 +02:00
Matthias Krüger
c5bf34a3bf
Rollup merge of #123716 - Kriskras99:patch-2, r=Mark-Simulacrum
Update documentation of Path::to_path_buf and Path::ancestors

`Path::to_path_buf`
> Changes the example from using the qualified path of PathBuf with an import. This is what's done in all other Path/PathBuf examples and makes the code look a bit cleaner.

`Path::ancestors`
> If you take a quick glance at the documentation for Path::ancestors, the unwraps take the natural focus. Potentially indicating that ancestors might panic.
In the reworked version I've also moved the link with parent returning None and that the iterator will always yield &self to before the yield examples.

Feel free to cherry-pick the changes you like.
2024-04-13 16:42:05 +02:00
Jacob Pratt
0518ecc700
Rollup merge of #123868 - eduardosm:stabilize-slice_ptr_len, r=jhpratt
Stabilize (const_)slice_ptr_len and (const_)slice_ptr_is_empty_nonnull

Stabilized API:

```rust
impl<T> *mut [T] {
    pub const fn len(self) -> usize;
    pub const fn is_empty(self) -> bool;
}

impl<T> *const [T] {
    pub const fn len(self) -> usize;
    pub const fn is_empty(self) -> bool;
}

impl<T> NonNull<[T]> {
    pub const fn is_empty(self) -> bool;
}
```

FCP completed in tracking issue: https://github.com/rust-lang/rust/issues/71146
2024-04-13 00:18:46 -04:00
Jacob Pratt
8533144f97
Rollup merge of #123835 - saethlin:vec-from-nonnull, r=the8472
Avoid more NonNull-raw-NonNull roundtrips in Vec

r? the8472

The standard library in general has a lot of these round-trips from niched types to their raw innards and back. Such round-trips have overhead in debug builds since https://github.com/rust-lang/rust/pull/120594. I removed some such round-trips in that initial PR and I've been meaning to come back and hunt down more such examples (this is the last item on https://github.com/rust-lang/rust/issues/120848).
2024-04-13 00:18:46 -04:00
beetrees
126c762b85
Add missing unsafe to internal std:🧵:Thread creation functions 2024-04-13 02:08:21 +01:00
beetrees
53f55c6635
Add missing unsafe to internal function std::sys::pal::unix:🧵:min_stack_size 2024-04-13 01:16:28 +01:00
Daniel Paoliello
ed46e3ca65 Update backtrace submodule 2024-04-12 16:28:19 -07:00
Hamza Jadid
fa21dd4a97
chore: replace x with y for hexa-decimal fmt 2024-04-13 02:16:20 +03:00
Ben Kimock
f7d54fa6cb Avoid more NonNull-raw-NonNull roundtrips in Vec 2024-04-12 18:14:29 -04:00
Matthias Krüger
3026204e84
Rollup merge of #123867 - eduardosm:unsafe-fns, r=ChrisDenton
Add `unsafe` to two functions with safety invariants
2024-04-12 21:47:00 +02:00
Matthias Krüger
b5c3db162e
Rollup merge of #123858 - marijanp:fix-zkvm-cmath-path, r=joboet
zkvm: fix path to cmath in zkvm module

I don't know why the original author decided to use relative paths.

I think it would be better to use `use crate::sys::cmath;`

The according issue can be found here https://github.com/risc0/risc0/issues/1647
2024-04-12 21:47:00 +02:00
Matthias Krüger
fa4c219d91
Rollup merge of #123857 - devnexen:tcp_listener_update_backlog, r=ChrisDenton
std::net: TcpListener shrinks the backlog argument to 32 for Haiku.
2024-04-12 21:46:59 +02:00
Matthias Krüger
595a284872
Rollup merge of #123807 - joboet:sys_common_thread, r=jhpratt
Remove `sys_common::thread`

Part of #117276.

The stack size calculation isn't system-specific at all and can just live together with the rest of the spawn logic.
2024-04-12 21:46:58 +02:00
Eduardo Sánchez Muñoz
fb9e1f73b3 Stabilize (const_)slice_ptr_len and (const_)slice_ptr_is_empty_nonnull 2024-04-12 21:23:20 +02:00
Eduardo Sánchez Muñoz
a6ed319e1b Add unsafe to two functions with safety invariants 2024-04-12 21:13:44 +02:00
Marijan Petričević
861e213f87
zkvm: remove cmath
- Remove cmath from zkvm module since cmath was moved to sys and is
shared by all platforms (see #120109)
2024-04-12 11:30:12 -05:00
David Carlier
1ce559b690
std::net: TcpListener shrinks the backlog argument to 32 for Haiku. 2024-04-12 16:55:10 +01:00
Matthias Krüger
4393eab9ea
Rollup merge of #123852 - kamaboko123:fix_typo_in_std_lib_rs, r=lqd
fix typo in library/std/src/lib.rs

I found typo in literal.
I got an error by this typo when build std.

```
salacia@Vega:~/fat12rs$ cargo build -Zbuild-std
   Compiling compiler_builtins v0.1.108
   Compiling core v0.0.0 (/home/salacia/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
   Compiling libc v0.2.153
   Compiling memchr v2.5.0
   Compiling std v0.0.0 (/home/salacia/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std)
   Compiling rustc-std-workspace-core v1.99.0 (/home/salacia/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling alloc v0.0.0 (/home/salacia/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc)
   Compiling cfg-if v1.0.0
   Compiling unwind v0.0.0 (/home/salacia/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/unwind)
   Compiling adler v1.0.2
   Compiling rustc-demangle v0.1.23
   Compiling rustc-std-workspace-alloc v1.99.0 (/home/salacia/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-alloc)
   Compiling gimli v0.28.1
   Compiling object v0.32.2
   Compiling addr2line v0.21.0
   Compiling miniz_oxide v0.7.2
   Compiling std_detect v0.1.5 (/home/salacia/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/stdarch/crates/std_detect)
   Compiling hashbrown v0.14.3
   Compiling panic_abort v0.0.0 (/home/salacia/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/panic_abort)
   Compiling panic_unwind v0.0.0 (/home/salacia/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/panic_unwind)
error: expected `,`, found `.`
   --> /home/salacia/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/lib.rs:224:78
    |
224 |             `#![no_std]` or overriding this warning by enabling this feature".
    |                                                                              ^ expected `,`

error: could not compile `std` (lib) due to 1 previous error
:224:78
    |
224 |             `#![no_std]` or overriding this warning by enabling this feature".
    |                                                                              ^ expected `,`

error: could not compile `std` (lib) due to 1 previous error
```
2024-04-12 17:41:36 +02:00