Commit Graph

14482 Commits

Author SHA1 Message Date
许杰友 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
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
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
Matthias Krüger
be3ea1dfb0
Rollup merge of #123833 - dpaoliello:stdarch, r=Amanieu
Update stdarch submodule

`asm_experimental_arch` is required in `core` as we're now using unstable inline assembly when building Arm64EC.

Brings in the fix for <https://github.com/rust-lang/stdarch/issues/1555> (cc `@tslnc04).`

r? `@Amanieu`
2024-04-12 17:41:34 +02:00
Matthias Krüger
8c8692014b
Rollup merge of #123825 - saethlin:report-nounwind-panics, r=petrochenkov
Call the panic hook for non-unwind panics in proc-macros

As I suggested in https://github.com/rust-lang/rust/issues/123286#issuecomment-2030344815.

If a proc macro causes a non-unwinding panic, `proc_macro` isn't able to catch the unwind and report the panic as a compile error by passing control back to the compiler. Our only chance to produce any diagnostic is the panic hook, so we should call it.

This scenario has already existed, but has become a lot more interesting now that we're adding more UB-detecting panics to the standard library, and such panics do not unwind.
2024-04-12 17:41:34 +02:00
bors
bd71213cf0 Auto merge of #123846 - matthiaskrgr:rollup-85y28av, r=matthiaskrgr
Rollup of 3 pull requests

Successful merges:

 - #123796 (Remove unused cargo-platform dependency from tidy)
 - #123830 (Remove `From` impls for unstable types that break inference)
 - #123842 (fix typo in pin.rs)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-04-12 13:13:50 +00:00
Jiahao XU
4a6b1562b5
Update document for std::io::Error::downcast 2024-04-12 23:03:36 +10:00
kamaboko123
47c3ffa5d4 fix typo in library/std/src/lib.rs 2024-04-12 22:02:08 +09:00
Matthias Krüger
e256d5f2ee
Rollup merge of #123842 - ShockYoungCHN:master, r=scottmcm
fix typo in pin.rs

correct "implemts" to "implements".
2024-04-12 13:35:31 +02:00
Matthias Krüger
bcf24d6467
Rollup merge of #123830 - tgross35:f16-f128-from-inference-fix, r=Nilstrieb
Remove `From` impls for unstable types that break inference

Adding additional `From` implementations that fit `f32::from(<unaffixed float>)` broke inference. Remove these for now.

I added a test to make sure this doesn't quietly change in the future, even though the behavior is not technically guaranteed https://github.com/rust-lang/rust/issues/123824#issuecomment-2050628184

Fixes: <https://github.com/rust-lang/rust/issues/123824>
2024-04-12 13:35:30 +02:00
bors
7bdae134cb Auto merge of #123783 - tgross35:f16-f128-debug-impl, r=Amanieu
Add a `Debug` impl and some basic functions to `f16` and `f128`

`compiler_builtins` uses some convenience functions like `is_nan` and `is_sign_positive`. Add these, as well as a temporary implementation for `Debug` that prints the bit representation.
2024-04-12 11:11:50 +00:00
joboet
0f52cd0e71
core: get rid of USIZE_MARKER 2024-04-12 12:00:14 +02:00
bors
6bc9dcd7ec Auto merge of #123490 - niluxv:strict_prov_unwind_seh, r=Amanieu
Refactor `panic_unwind/seh.rs` pointer use

* `x86` now conforms to strict-provenance
* `x86_64` now uses the expose API (instead of `as` casts)
* changed `ptr_t` from a type alias to a `repr(transparent)` struct for some extra type-safety
* replaced the `ptr!` macro by methods on `ptr_t`, as there is now no reason (as far as I can see) anymore to use a macro

On `x86_64` pointers in SEH are represented by 32-bit offsets from `__ImageBase`, so we can't use a pointer type. It might be possible to leak the provenance into the FFI by using a `MaybeUninit<u32>` instead of a `u32`, but that is a bit more involved than using expose, and I'm not sure that would be worth it.
2024-04-12 06:38:26 +00:00
Yuanzhuo Yang
41ac5d93d6
fix pin.rs typo
correct "implemts" to "implements"
2024-04-12 01:28:58 -05:00
Matthias Krüger
3758e2ffa5
Rollup merge of #123826 - kornelski:one-in-a-quintillion, r=Amanieu
Move rare overflow error to a cold function

`scoped.spawn()` generates unnecessary inlined panic-formatting code for a branch that will never be taken.
2024-04-12 04:38:22 +02:00