Commit Graph

6163 Commits

Author SHA1 Message Date
Stefan Lankes
d39dc0ab23 switch also the default implementation for read_vectored 2024-05-20 21:44:04 +02:00
Tobias Bucher
20fd725172 Document platform-specifics for Read and Write of File 2024-05-20 21:21:53 +02:00
Stefan Lankes
c170bf9927 switch to the default implementation of write_vectored 2024-05-20 19:24:11 +02:00
Ben Kimock
aa31281f2d Remove Windows dependency on libc 2024-05-20 11:13:31 -04:00
Benoît du Garreau
a197ff3259 Address review comments 2024-05-20 17:00:11 +02:00
bors
f092f73c11 Auto merge of #124560 - madsmtm:update-libc, r=Mark-Simulacrum
Update libc to 0.2.155

Motivation: To fix `-Zbuild-std` / Xargo for visionOS targets.

EDIT: Blocked on ~https://github.com/rust-lang/libc/issues/3608 / https://github.com/rust-lang/libc/pull/3609~ ~https://github.com/rust-lang/libc/pull/3682 and https://github.com/rust-lang/libc/pull/3690~ No longer blocked.
2024-05-20 05:50:24 +00:00
Mads Marquart
38ad851603 Make NULL check in argument parsing the same on all unix platforms 2024-05-20 04:54:27 +02:00
Matthias Krüger
c5b8c7c3b0
Rollup merge of #124992 - foresterre:example/is-terminal, r=ChrisDenton
Add example to IsTerminal::is_terminal
2024-05-19 22:50:55 +02:00
Martijn
0b6baf6130 Add example to IsTerminal::is_terminal 2024-05-19 20:00:02 +02:00
Michael Goulet
f848505c40
Rollup merge of #124304 - hermit-os:fuse, r=joboet
revise the interpretation of ReadDir for HermitOS

HermitOS supports getdents64. As under Linux, the dirent64 entry `d_off` is not longer used, because its definition is not clear. Instead of `d_off` the entry `d_reclen` is used to determine the end of the dirent64 entry.

In addition, take up `@workingjubilee`  suggestion from the discussions in rust-lang/rust#115984 to increase the readability.

Hermit is a tier 3 platform and this PR changes only files, wich are related to the tier 3 platform.
2024-05-19 11:04:07 -04:00
Michael Goulet
0f923a48c5
Rollup merge of #123709 - tgross35:windows-cmd-docs-update, r=ChrisDenton
Update documentation related to the recent cmd.exe fix

Fix some grammar nits, change `bat` (extension) -> `batch` (file), and make line wrapping more consistent.
2024-05-19 11:04:07 -04:00
Mads Marquart
abd5d0e37b Add NULL check in argument parsing on Apple platforms 2024-05-19 04:19:15 +02:00
Ralf Jung
dde1134c6d android: use posix_memalign for aligned allocations 2024-05-18 12:49:01 +02:00
Mads Marquart
74012d5200 Update libc to 0.2.155 2024-05-18 00:48:57 +02:00
Mads Marquart
8f18e4fe4b Use _NSGetArgc/_NSGetArgv on iOS/tvOS/watchOS/visionOS
If we're comfortable using `_NSGetEnviron` from `crt_externs.h`, there shouldn't be an issue with using these either, and then we can merge with the macOS implementation.

This also fixes two test cases on Mac Catalyst:
- `tests/ui/command/command-argv0.rs`, maybe because `[[NSProcessInfo processInfo] arguments]` somehow converts the name of the first argument?
- `tests/ui/env-funky-keys.rs` since we no longer link to Foundation.
2024-05-17 22:11:51 +02:00
Mads Marquart
6016bad063 Use _NSGetEnviron instead of environ on iOS/tvOS/watchOS/visionOS
This should be slightly more correct, and matches the implementation in other programming languages:
- [Python's `os.environ`](https://github.com/python/cpython/blob/v3.12.3/Modules/posixmodule.c#L1562-L1566).
- [Swift's `Darwin.environ`](https://github.com/apple/swift-corelibs-foundation/blob/swift-5.10-RELEASE/CoreFoundation/Base.subproj/CFPlatform.c#L1811-L1812), though that library is bundled on the system, so they can change it if they want.
- [Dart/Flutter](https://github.com/dart-lang/sdk/blob/3.4.0/runtime/bin/platform_macos.cc#L205-L234), doesn't support environment variables on iOS.
- Node seems to not be entirely consistent with it:
  - [`process.c`](https://github.com/nodejs/node/blob/v22.1.0/deps/uv/src/unix/process.c#L38).
  - [`unix/core.c`](https://github.com/nodejs/node/blob/v22.1.0/deps/uv/src/unix/core.c#L59).
- [.NET/Xamarin](https://github.com/dotnet/runtime/blob/v8.0.5/src/native/libs/configure.cmake#L1099-L1106).
- [OpenJDK](https://github.com/openjdk/jdk/blob/jdk-23%2B22/src/java.base/unix/native/libjava/ProcessEnvironment_md.c#L31-L33).
2024-05-17 22:11:50 +02:00
Trevor Gross
7685734384 Add powi to f16 and f128
This will unblock adding support to compiler_builtins
(<https://github.com/rust-lang/compiler-builtins/pull/614>), which will
then unblock adding tests for these new functions.
2024-05-16 15:41:06 -05:00
León Orell Valerian Liehr
c5b17ec9d2
Rollup merge of #125003 - RalfJung:aligned_alloc, r=cuviper
avoid using aligned_alloc; posix_memalign is better-behaved

Also there's no reason why wasi should be different than all the other Unixes here.
2024-05-15 22:01:18 +02:00
Ralf Jung
5cc020d3df avoid using aligned_alloc; posix_memalign is better-behaved 2024-05-14 19:32:11 +02:00
Benoît du Garreau
cfb04795a1 Fix read_exact and read_buf_exact for &[u8] and io:Cursor 2024-05-14 16:16:33 +02:00
Matthias Krüger
b0cbd4e5f3
Rollup merge of #123817 - slanterns:seek_relative, r=dtolnay
Stabilize `seek_seek_relative`

This PR stabilizes `seek_seek_relative`:

```rust
// std::io::Seek

trait Seek {
    fn seek_relative(&mut self, offset: i64) -> Result<()>;
}
```

<br>

Tracking issue: https://github.com/rust-lang/rust/issues/117374.
Implementation PR: https://github.com/rust-lang/rust/pull/116750.

FCPs already completed in the tracking issue.

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

r? libs-api
2024-05-13 20:29:18 +02:00
Josh Triplett
a5a60d75a8 Add size_of, size_of_val, align_of, and align_of_val to the prelude
Many, many projects use `size_of` to get the size of a type. However,
it's also often equally easy to hardcode a size (e.g. `8` instead of
`size_of::<u64>()`). Minimizing friction in the use of `size_of` helps
ensure that people use it and make code more self-documenting.

The name `size_of` is unambiguous: the name alone, without any prefix or
path, is self-explanatory and unmistakeable for any other functionality.
Adding it to the prelude cannot produce any name conflicts, as any local
definition will silently shadow the one from the prelude. Thus, we don't
need to wait for a new edition prelude to add it.

Add `size_of_val`, `align_of`, and `align_of_val` as well, with similar
justification: widely useful, self-explanatory, unmistakeable for
anything else, won't produce conflicts.
2024-05-13 15:11:28 +02:00
Tobias Bucher
700b3ea61b Panic if PathBuf::set_extension would add a path separator
This is likely never intended and potentially a security vulnerability
if it happens.

I'd guess that it's mostly literal strings that are passed to this
function in practice, so I'm guessing this doesn't break anyone.

CC #125060
2024-05-13 15:08:34 +02:00
bors
b71fa82d78 Auto merge of #124798 - devnexen:illumos_memalign_fix, r=RalfJung
std::alloc: use posix_memalign instead of memalign on solarish

`memalign` on Solarish requires the alignment to be at least the size of a pointer, which we did not honor. `posix_memalign` also requires that, but that code path already takes care of this requirement.

close GH-124787
2024-05-12 11:22:40 +00:00
bors
4fd98a4b1b Auto merge of #125012 - RalfJung:format-error, r=Mark-Simulacrum,workingjubilee
io::Write::write_fmt: panic if the formatter fails when the stream does not fail

Follow-up to https://github.com/rust-lang/rust/pull/124954
2024-05-12 08:34:32 +00:00
David Carlier
1e232fea1b std::alloc: using posix_memalign instead of memalign on solarish.
simpler code path since small alignments are already taking care of.
close GH-124787
2024-05-11 18:08:35 +00:00
Mark Rousskov
3aa16f0d2f Pin libc back to 0.2.153 2024-05-11 10:25:37 -04:00
Ralf Jung
e00f27b7be io::Write::write_fmt: panic if the formatter fails when the stream does not fail 2024-05-11 15:13:18 +02:00
Dion Dokter
579266a6be Add flag to std and alloc too 2024-05-11 14:20:03 +02:00
Matthias Krüger
f73f266657
Rollup merge of #124766 - devnexen:getrandom_solarish, r=Mark-Simulacrum
std::rand: adding solaris/illumos for getrandom support.

To help solarish support for miri https://https://github.com/rust-lang/miri/issues/3567
2024-05-11 08:00:15 +02:00
Jubilee
037c62a196
Rollup merge of #124788 - madsmtm:reduce-target_os-macos, r=workingjubilee
Convert instances of `target_os = "macos"` to `target_vendor = "apple"`

https://github.com/rust-lang/rust/pull/124491 migrated towards using `target_vendor = "apple"` more, as there's very little difference between iOS, tvOS, watchOS and visionOS. In that PR, I only did the changes where the standard library already had fixes for iOS, that I could confidently apply to the other targets.

However, there's actually also not that big of a gap between macOS and the aforementioned platforms - so in this PR, I've gone through a few of the instances of `target_os = "macos"` and replaced it with `target_vendor = "apple"` to improve support on those platforms, see the commits for details.

r? workingjubilee

CC `@thomcc` `@simlay` (do tell me if I should stop pinging you on these Apple PRs)

`@rustbot` label O-apple
2024-05-08 00:37:10 -07:00
Jubilee
40926fdc19
Rollup merge of #124782 - anatawa12:docs-create-new-already-exists, r=workingjubilee
add note about `AlreadyExists` to `create_new`

Fixes #119244
2024-05-08 00:37:10 -07:00
Jubilee
bc42f25b04
Rollup merge of #124470 - devnexen:no_sigpipe_fbsd, r=workingjubilee
std::net: Socket::new_raw now set to SO_NOSIGPIPE on freebsd.
2024-05-08 00:37:09 -07:00
Matthias Krüger
44cbf7d853
Rollup merge of #124520 - tbu-:pr_create_dir_all_doc, r=Amanieu
Document that `create_dir_all` calls `mkdir`/`CreateDirW` multiple times
2024-05-06 18:50:34 +02:00
David Carlier
1d45f47d24 std::rand: adding solaris/illumos for getrandom support.
To help solarish support for miri https://rust-lang/miri/issues/3567
2024-05-06 13:31:58 +00:00
bors
8cef37dbb6 Auto merge of #124497 - rytheo:move-std-tests-to-library, r=workingjubilee
Move some stdlib tests from `tests/ui` to `library/std/tests`

Related to #99417
2024-05-06 09:53:24 +00:00
Mads Marquart
ff41c99bb8 iOS/tvOS/watchOS/visionOS: Improve File Debug impl
This uses `libc::fcntl`, which, while not explicitly marked as available
in the headers, is already used by `File::sync_all` and `File::sync_data`
on these platforms, so should be fine to use here as well.
2024-05-06 09:14:38 +02:00
Mads Marquart
28622c9e52 iOS/tvOS/watchOS/visionOS: Fix reading large files
Tested in the iOS simulator with something like:
```
let mut buf = vec![0; c_int::MAX as usize - 1 + 2];
let read_bytes = f.read(&mut buf).unwrap();
```
2024-05-06 08:08:15 +02:00
Mads Marquart
53bd38b7c5 iOS/tvOS/watchOS: Fix alloc w. large alignment on older versions
Tested on an old MacBook and the iOS simulator.
2024-05-06 08:08:15 +02:00
Mads Marquart
aa606bb246 iOS/tvOS/watchOS/visionOS: Set the main thread name
Tested in the iOS simulator that the thread name is not set by default,
and that setting it improves the debugging experience in lldb / Xcode.
2024-05-06 08:08:15 +02:00
anatawa12
81f5175868
Apply suggestions from code review
Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com>
2024-05-06 12:16:31 +09:00
Mads Marquart
c64889c537 iOS/tvOS/watchOS/visionOS: Default to kernel-defined backlog in listen
This behavior is defined in general for the XNU kernel, not just macOS:
https://github.com/apple-oss-distributions/xnu/blob/rel/xnu-10002/bsd/kern/uipc_socket.c
2024-05-06 04:22:23 +02:00
anatawa12
ab066ae329
add note about AlreadyExists to create_new 2024-05-06 09:52:13 +09:00
Ryan Lowe
1bec124ab8 Rename test for issue 21058 2024-05-05 10:47:12 -04:00
Mads Marquart
fa22863f1b Fix unwinding on 32-bit watchOS ARM
The code is written in a way to support 32-bit iOS and tvOS ARM devices,
for future compatibility even though we currently only have a target for
32-bit iOS ARM.
2024-05-05 15:41:55 +02:00
Matthias Krüger
4577b1a7d3
Rollup merge of #124721 - ids1024:netbsd-32-bit-ulong, r=workingjubilee
library/std: Fix build for NetBSD targets with 32-bit `c_long`

This fixes building `std` for targets like `mipsel-unknown-netbsd`.

If `c_long` is an `i64`, this conversion works with `Into`. But if it's an `i32`, this failed to convert a `u32` to an `i32`.
2024-05-04 22:27:34 +02:00
Ian Douglas Scott
7dc27d596b library/std: Fix build for NetBSD targets with 32-bit c_long
This fixes building `std` for targets like `mipsel-unknown-netbsd`.

If `c_long` is an `i64`, this conversion works with `Into`. But if it's
an `i32`, this failed to convert a `u32` to an `i32`.
2024-05-04 11:27:21 -07:00
Matthias Krüger
00bc2a425c
Rollup merge of #122441 - a1phyr:improve_read_impls, r=ChrisDenton
Improve several `Read` implementations

- `read_to_end` and `read_to_string` for `Cursor`
- Error on OOM in `read_to_string` of `&[u8]` and `VecDeque<u8>`
- Avoid making the slices contiguous in `VecDeque::read_to_string`
- ~`read_exact` and (unstable) `read_buf_exact` for `Take`~
- ~`read_buf` for `UnixStream` and `&UnixStream`~ (moved to #123084)
- `read_to_end` for `ChildStdErr`
2024-05-04 18:36:37 +02:00
Matthias Krüger
cc51f91455
Rollup merge of #124159 - joboet:move_pal_thread_parking, r=ChrisDenton
Move thread parking to `sys::sync`

Part of #117276.

I'll leave the platform-specific API abstractions in `sys::pal`, as per the initial proposal. I'm not entirely sure whether we'll want to keep it that way, but that remains to be seen.

r? ``@ChrisDenton`` (if you have time)
2024-05-04 12:37:21 +02:00
Matthias Krüger
b8fa047398
Rollup merge of #123356 - joboet:set_current_size, r=ChrisDenton
Reduce code size of `thread::set_current`

#123265 introduced a rather large binary size regression, because it added an `unwrap()` call on a `Result<(), Thread>`, which in turn pulled its rather heavy `Debug` implementation. This PR fixes this by readding the `rtassert!` that was removed.
2024-05-04 12:37:20 +02:00
Michael Goulet
9dfd527c6f
Rollup merge of #124480 - Enselic:on-broken-pipe, r=jieyouxu
Change `SIGPIPE` ui from `#[unix_sigpipe = "..."]` to `-Zon-broken-pipe=...`

In the stabilization [attempt](https://github.com/rust-lang/rust/pull/120832) of `#[unix_sigpipe = "sig_dfl"]`, a concern was [raised ](https://github.com/rust-lang/rust/pull/120832#issuecomment-2007394609) related to using a language attribute for the feature: Long term, we want `fn lang_start()` to be definable by any crate, not just libstd. Having a special language attribute in that case becomes awkward.

So as a first step towards the next stabilization attempt, this PR changes the `#[unix_sigpipe = "..."]` attribute to a compiler flag `-Zon-broken-pipe=...` to remove that concern, since now the language is not "contaminated" by this feature.

Another point was [also raised](https://github.com/rust-lang/rust/pull/120832#issuecomment-1987023484), namely that the ui should not leak **how** it does things, but rather what the **end effect** is. The new flag uses the proposed naming. This is of course something that can be iterated on further before stabilization.

Tracking issue: https://github.com/rust-lang/rust/issues/97889
2024-05-03 23:34:22 -04:00
Matthias Krüger
8e3f61b9f9
Rollup merge of #124059 - RalfJung:default_alloc_error_hook, r=workingjubilee
default_alloc_error_hook: explain difference to default __rdl_oom in alloc

Though I'm not sure if that is really the reason that this code is duplicated. On no_std it may already be possible to call user-defined code on allocation failure.
2024-05-03 20:33:45 +02:00
Ralf Jung
3f6703bbd8 default_alloc_error_hook: explain difference to default __rdl_oom in alloc 2024-05-03 19:12:33 +02:00
Matthias Krüger
a7f4a2edc6
Rollup merge of #124649 - Meziu:master, r=ChrisDenton
Fix HorizonOS build broken by #124210

HorizonOS (for the Tier-3 target `armv6k-nintendo-3ds`) does not support `dirfd()`, as many other similar targets.
2024-05-03 15:26:11 +02:00
Andrea Ciliberti
bdf1eae360 Horizon OS: dirfd unavailable 2024-05-03 10:09:28 +02:00
Matthias Krüger
c412751d19
Rollup merge of #124609 - RalfJung:float-precision, r=cuviper
variable-precision float operations can differ depending on optimization levels

Follow-up to https://github.com/rust-lang/rust/pull/121793 and https://github.com/rust-lang/rust/pull/118217 that accounts for optimizations changing the precision of these functions.

Fixes https://github.com/rust-lang/rust/issues/109118
Fixes https://github.com/rust-lang/rust/issues/71355
2024-05-03 06:04:22 +02:00
Matthias Krüger
bd6276c95e
Rollup merge of #124604 - Enselic:std-gimli-symbolize, r=workingjubilee
library/std: Remove unused `gimli-symbolize` feature

library/backtrace also declares a feature called `gimli-symbolize` which appear used, but the feature in std with the same name is unused, so remove it.
2024-05-03 06:04:21 +02:00
Matthias Krüger
9ab5cfd91e
Rollup merge of #124412 - RalfJung:io-safety, r=Amanieu
io safety: update Unix explanation to use `Arc`

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

Cc ```@jsgf```
2024-05-03 06:04:19 +02:00
Martin Nordholts
cde0cde151 Change SIGPIPE ui from #[unix_sigpipe = "..."] to -Zon-broken-pipe=...
In the stabilization attempt of `#[unix_sigpipe = "sig_dfl"]`, a concern
was raised related to using a language attribute for the feature: Long
term, we want `fn lang_start()` to be definable by any crate, not just
libstd. Having a special language attribute in that case becomes
awkward.

So as a first step towards towards the next stabilization attempt, this
PR changes the `#[unix_sigpipe = "..."]` attribute to a compiler flag
`-Zon-broken-pipe=...` to remove that concern, since now the language
is not "contaminated" by this feature.

Another point was also raised, namely that the ui should not leak
**how** it does things, but rather what the **end effect** is. The new
flag uses the proposed naming. This is of course something that can be
iterated on further before stabilization.
2024-05-02 19:48:29 +02:00
Ralf Jung
ff2ff97904 variable-precision float operations behave non-deterministically 2024-05-02 18:57:30 +02:00
joboet
a56fd370fc
std: move thread parking to sys::sync 2024-05-02 12:38:26 +02:00
Martin Nordholts
9af3b1eff4 library/std: Remove unused gimli-symbolize feature
library/backtrace also declares a feature called `gimli-symbolize` which
appear used, but the feature in std with the same name is unused, so
remove it.
2024-05-02 06:51:17 +02:00
Mark Rousskov
a64f941611 Step bootstrap cfgs 2024-05-01 22:19:11 -04:00
Mark Rousskov
bd7d328807 Replace version placeholders for 1.79 2024-05-01 21:01:51 -04:00
bors
2e88e9e7d0 Auto merge of #124491 - madsmtm:target_vendor-apple, r=workingjubilee
Use `target_vendor = "apple"` instead of `target_os = "..."`

Use `target_vendor = "apple"` instead of `all(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "visionos")`.

The apple targets are quite close to being identical, with iOS, tvOS, watchOS and visionOS being even closer, so using `target_vendor` when possible makes it clearer when something is actually OS-specific, or just Apple-specific.
Note that `target_vendor` will [be deprecated in the future](https://github.com/rust-lang/rust/issues/100343), but not before an alternative (like `target_family = "apple"`) is available.

While doing this, I found various inconsistencies and small mistakes in the standard library, see the commits for details. Will follow-up with an extra PR for a similar issue that need a bit more discussion. EDIT: https://github.com/rust-lang/rust/pull/124494

Since you've talked about using `target_vendor = "apple"` in the past:
r? workingjubilee

CC `@simlay,` `@thomcc`
`@rustbot` label O-macos O-ios O-tvos O-watchos O-visionos
2024-05-01 02:11:29 +00:00
joboet
8e4a6af39b
std: rewrite TLS on platforms without threads 2024-04-30 14:54:30 +02:00
Tobias Bucher
a0f8ada69e Document that create_dir_all calls mkdir/CreateDirW multiple times
Also mention that there might be leftover directories in the error case.
2024-04-29 21:22:34 +02:00
David Koloski
982a58e900 Fix Fuchsia build broken by #124210
Fuchsia doesn't support dirfd although we have a symbol stubbed for it.
2024-04-29 17:00:03 +00:00
ivmarkov
fa6db4c428 Fix ESP IDF build broken by #124210 2024-04-29 06:17:02 +00:00
Ryan Lowe
419924d878 Run tidy on tests 2024-04-28 18:04:25 -04:00
Mads Marquart
f9f3573b62 Fix posix_spawn not being used on iOS and visionOS
`man posix_spawn` documents it to be able to return `ENOENT`, and there
should be nothing preventing this. Tested in the iOS simulator and on
Mac Catalyst.
2024-04-28 22:34:51 +02:00
Ryan Lowe
ed9d6e0c03 Move various stdlib tests to library/std/tests 2024-04-28 16:10:12 -04:00
Mads Marquart
a6d9da6b2a Fix SIGEMT and SIGINFO parsing on watchOS and visionOS 2024-04-28 21:10:32 +02:00
Mads Marquart
79c6d91966 Fix available_parallelism on watchOS and visionOS
Both `sysconf` and `_SC_NPROCESSORS_ONLN` is available on all Apple platforms.
2024-04-28 21:10:32 +02:00
David Carlier
a25b0946a7
std::net: Socket::new_raw set to SO_NOSIGPIPE on freebsd/netbsd/dragonfly. 2024-04-28 17:44:42 +01:00
Mads Marquart
d9c0eb8084 Use target_vendor = "apple" instead of target_os = "..." 2024-04-28 18:22:37 +02:00
bors
cb49406457 Auto merge of #124210 - the8472:consign-ebadf-to-the-fire, r=Mark-Simulacrum
Abort a process when FD ownership is violated

When an owned FD has already been closed before it's dropped that means something else touched an FD in ways it is not allowed to. At that point things can already be arbitrarily bad, e.g. clobbered mmaps. Recovery is not possible.
All we can do is hasten the fire.

Unlike the previous attempt in #124130 this shouldn't suffer from the possibility that FUSE filesystems can return arbitrary errors.
2024-04-28 06:20:28 +00:00
The 8472
1ba00d9cb2 put FD validity behind late debug_asserts checking
uses the same machinery as assert_unsafe_precondition
2024-04-28 01:44:25 +02:00
Matthias Krüger
be8976022e
Rollup merge of #124447 - workingjubilee:set-argv-twice-on-gnu, r=ChrisDenton
Unconditionally call `really_init` on GNU/Linux

This makes miri not diverge in behavior, it fixes running Rust linux-gnu binaries on musl with gcompat, it fixes dlopen edge-cases that cranelift somehow hits, etc.

Fixes #124126

thou hast gazed into this abyss with me:
r? ``@ChrisDenton``
2024-04-28 01:25:02 +02:00
Jubilee Young
fa73ebb303 Unconditionally call really_init
This makes miri not diverge in behavior, it fixes running Rust linux-gnu
binaries on musl with gcompat, it fixes dlopen edge-cases that cranelift
somehow hits, etc.
2024-04-27 11:33:15 -07:00
Tobias Bucher
7d67ee5aba Lift the probe code of copy_file_range into a function 2024-04-27 18:44:30 +02:00
Tobias Bucher
adebad1dce Elaborate in comment about statx probe
As requested by @workingjubilee in
https://github.com/rust-lang/rust/pull/123928#discussion_r1564916743.
2024-04-27 18:36:29 +02:00
Ralf Jung
6b6bc9805d io safety: update Unix explanation 2024-04-27 09:40:55 +02:00
Matthias Krüger
7c5213cf0a
Rollup merge of #124387 - workingjubilee:use-raw-pointers-in-thread-locals, r=joboet
thread_local: be excruciatingly explicit in dtor code

Use raw pointers to accomplish internal mutability, and clearly split references where applicable. This reduces the likelihood that any of these parts are misunderstood, either by humans or the compiler's optimizations.

Fixes #124317

r? ``@joboet``
2024-04-27 07:55:38 +02:00
Jubilee
c63b0ceb94
thread_local: refine LazyKeyInner::take safety doc
Co-authored-by: joboet <jonasboettiger@icloud.com>
2024-04-26 18:28:46 -07:00
Jacob Pratt
7cbba53396
Rollup merge of #124410 - RalfJung:path-buf-transmute, r=Nilstrieb
PathBuf: replace transmuting by accessor functions

The existing `repr(transparent)` was anyway insufficient as `OsString` was not `repr(transparent)`. And furthermore, on Windows it was blatantly wrong as `OsString` wraps `Wtf8Buf` which is a `repr(Rust)` type with 2 fields:

51a7396ad3/library/std/src/sys_common/wtf8.rs (L131-L146)

So let's just be honest about what happens and add accessor methods that make this abstraction-breaking act of PathBuf visible on the APIs that it pierces through.

Fixes https://github.com/rust-lang/rust/issues/124409
2024-04-26 19:25:57 -04:00
bors
4d570eea02 Auto merge of #123909 - dtolnay:utf8chunks, r=joboet
Stabilize `Utf8Chunks`

Pending FCP in https://github.com/rust-lang/rust/issues/99543.

This PR includes the proposed modification in https://github.com/rust-lang/libs-team/issues/190 as agreed in https://github.com/rust-lang/rust/issues/99543#issuecomment-2050406568.
2024-04-26 17:41:24 +00:00
Ralf Jung
c47978a241 PathBuf: replace transmuting by accessor functions 2024-04-26 18:09:09 +02:00
Michael Goulet
6f5c69e65f
Rollup merge of #124076 - NobodyXu:patch-1, r=dtolnay
Stablise io_error_downcast

Tracking issue #99262
Closes #99262

FCP completed in https://github.com/rust-lang/rust/issues/99262#issuecomment-2077374397
2024-04-25 20:07:40 -04:00
Jubilee Young
43f21a6871 thread_local: split refs to fields of Key 2024-04-25 12:45:21 -07:00
Jubilee Young
538ddb0ac2 thread_local: use less &mut T in LazyKeyInner::take
Instead, use raw pointers to accomplish internal mutability throughout.
2024-04-25 12:33:09 -07:00
David Tolnay
61cf00464e
Stabilize Utf8Chunks 2024-04-24 15:27:47 -07:00
Matthias Krüger
ecf794bc69
Rollup merge of #124335 - ChrisDenton:stabilize-absolute, r=dtolnay
Stabilize `std::path::absolute`

FCP complete in https://github.com/rust-lang/rust/issues/92750#issuecomment-2075046985
2024-04-25 00:19:56 +02:00
Chris Denton
f56afa0477
Stabilize std::path::absolute 2024-04-24 14:35:02 +00:00
León Orell Valerian Liehr
388dc0d0b7
Rollup merge of #124282 - RalfJung:fill_utf16_buf, r=ChrisDenton
windows fill_utf16_buf: explain the expected return value

The comment just says "return what the syscall returns", but that doesn't work for all syscalls as the Windows API is not consistent in how buffer size is negotiated. For instance, GetUserProfileDirectoryW works a bit differently, and so home_dir_crt has to translate this to the usual protocol itself. So it's worth describing that protocol.

r? ``@ChrisDenton``
2024-04-24 14:00:57 +02:00
León Orell Valerian Liehr
4eda87603d
Rollup merge of #124281 - RalfJung:win-tls, r=joboet
fix weak memory bug in TLS on Windows

We need to store the `key` *after* we register the dtor.

Now I hope there isn't also some other reason why we have to actually register the dtor last... `@joboet` is there a reason you picked this particular order in https://github.com/rust-lang/rust/pull/102655?

Fixes https://github.com/rust-lang/rust/issues/123583
2024-04-24 14:00:57 +02:00
Stefan Lankes
5aa779fb64 increase the readability by using the unique name for the hermit-abi
Take up suggestion from the discussions within rust-lang/rust#115984
to increase readability.
2024-04-23 20:47:02 +02:00
Stefan Lankes
e0ac250909 revise the interpretation of ReadDir
HermitOS supports getdents64. As under Linux, the dirent64 entry
`d_off` is not longer used, because its definition is not clear.
Instead of `d_off` the entry `d_reclen` is used to determine the
end of the dirent64 entry.
2024-04-23 19:52:47 +02:00
Ralf Jung
d5d714bb34 fix weak memory bug in TLS on Windows 2024-04-23 10:42:45 +02:00
Ralf Jung
a21c2d8704 windows fill_utf16_buf: explain the expected return value 2024-04-23 09:32:35 +02:00
Matthias Krüger
819b4d5e5b
Rollup merge of #124266 - RalfJung:no-answer, r=joboet
remove an unused type from the reentrant lock tests

At least it seems unused. This was added back in 45aa6c8d1b together with a test related to poisoning; when the test got removed, it seems like it was forgotten to also remove this type.
2024-04-23 06:24:58 +02:00
Ralf Jung
df437a2af4 remove an unused type from the reentrant lock tests 2024-04-22 19:36:21 +02:00
The 8472
25babe9a79 export assert_unsafe_precondition macro for std-internal use 2024-04-22 19:02:37 +02:00
Markus Reiter
33e68aadc9
Stabilize generic NonZero. 2024-04-22 18:48:47 +02:00
Guillaume Gomez
9efd1477ac
Rollup merge of #124089 - simlay:fix-preadv64-and-pwritev64-link-for-watchos-and-visionos, r=workingjubilee
Fix watchOS and visionOS for pread64 and pwrite64 calls

In #122880, links to `preadv64` and `pwritev64` were added for `watchOS` however the underlying [`weak!` macro did not include `target_os = "watchos"`](c45dee5efd/library/std/src/sys/pal/unix/weak.rs (L30-L74)).

This resulted in an `xcodebuild` error when targeting `watchOS`:
```
Undefined symbols for architecture arm64:
  "_preadv64", referenced from:
      __rust_extern_with_linkage_preadv64 in libliveview_native_core.a[274](std-324fdd8d31e8eaa2.std.e18cf7e8d0336778-cgu.08.rcgu.o)
  "_pwritev64", referenced from:
      __rust_extern_with_linkage_pwritev64 in libliveview_native_core.a[274](std-324fdd8d31e8eaa2.std.e18cf7e8d0336778-cgu.08.rcgu.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```

So I added them. I also went ahead and added the same for visionOS because it's bound to create the same issue.
2024-04-21 13:30:25 +02:00
Sebastian Imlay
fa53b9f39c Fix watchOS and visionOS for pread64 and pwrite64 calls
* Refactor apple OSs  to use pwritev and preadv rather pwritev64 and preadv64
* Updated the comments for preadv and pwritev
2024-04-21 00:36:07 -04:00
The 8472
38ded12923 Abort a process when FD ownership is violated
When an EBADF happens then something else already touched an FD in ways it is not allowed to.
At that point things can already be arbitrarily bad, e.g. clobbered mmaps.
Recovery is not possible.
All we can do is hasten the fire.
2024-04-20 23:20:13 +02:00
许杰友 Jieyou Xu (Joe)
418a07861a
Rollup merge of #124103 - dtolnay:metadatadebug, r=Mark-Simulacrum
Improve std::fs::Metadata Debug representation

- Remove duplication of `mode` between `file_type` and `permissions`, which both involve operating on the same mode_t integer
- Add `is_symlink`
- Add `len` in bytes
- Remove Ok wrapping around `modified`, `accessed`, `created`, which eliminates 6 useless lines

<table>
<tr><th>Before</th><th>After</th></tr>
<tr><td>

```console
Metadata {
    file_type: FileType(
        FileType {
            mode: 0o100600 (-rw-------),
        },
    ),
    is_dir: false,
    is_file: true,
    permissions: Permissions(
        FilePermissions {
            mode: 0o100600 (-rw-------),
        },
    ),
    modified: Ok(
        SystemTime {
            tv_sec: 1713402981,
            tv_nsec: 682983531,
        },
    ),
    accessed: Ok(
        SystemTime {
            tv_sec: 1713402983,
            tv_nsec: 206999623,
        },
    ),
    created: Ok(
        SystemTime {
            tv_sec: 1713402981,
            tv_nsec: 682983531,
        },
    ),
    ..
}
```
</td><td>

```console
Metadata {
    file_type: FileType {
        is_file: true,
        is_dir: false,
        is_symlink: false,
        ..
    },
    permissions: Permissions(
        FilePermissions {
            mode: 0o100600 (-rw-------),
        },
    ),
    len: 2096,
    modified: SystemTime {
        tv_sec: 1713402981,
        tv_nsec: 682983531,
    },
    accessed: SystemTime {
        tv_sec: 1713402983,
        tv_nsec: 206999623,
    },
    created: SystemTime {
        tv_sec: 1713402981,
        tv_nsec: 682983531,
    },
    ..
}

```
</td></tr></table>

Generated by:

```rust
fn main() {
    println!("{:#?}", std::fs::metadata("Cargo.toml").unwrap());
}
```
2024-04-20 21:45:37 +01:00
许杰友 Jieyou Xu (Joe)
ccd9880769
Rollup merge of #123967 - RalfJung:static_mut_refs, r=Nilstrieb
static_mut_refs: use raw pointers to remove the remaining FIXME

Using `SyncUnsafeCell` would not make a lot of sense IMO.
2024-04-20 21:45:35 +01:00
Jubilee
c8d58faba2
Rollup merge of #124116 - RalfJung:miri-rust-backtrace, r=Nilstrieb
when suggesting RUST_BACKTRACE=1, add a special note for Miri's env var isolation

Fixes https://github.com/rust-lang/miri/issues/2855
2024-04-18 21:38:57 -07:00
Jubilee
55c35dd22e
Rollup merge of #124019 - ChrisDenton:futex-raw-dylib, r=joboet
Use raw-dylib for Windows synchronization functions

Fixes #123999 by using the raw-dylib feature to specify the DLL to load the Windows futex functions from (e.g. [`WaitOnAddress`](https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-waitonaddress)). This avoids reliance on the import library causing that issue.

With apologies to ``@bjorn3,`` as it's currently necessary to revert this for cranelift.
2024-04-18 21:38:56 -07:00
bors
c5de414865 Auto merge of #123144 - dpaoliello:arm64eclib, r=GuillaumeGomez,ChrisDenton,wesleywiser
Add support for Arm64EC to the Standard Library

Adds the final pieces so that the standard library can be built for arm64ec-pc-windows-msvc (initially added in #119199)

* Bumps `windows-sys` to 0.56.0, which adds support for Arm64EC.
* Correctly set the `isEC` parameter for LLVM's `writeArchive` function.
* Add `#![feature(asm_experimental_arch)]` to library crates where Arm64EC inline assembly is used, as it is currently unstable.
2024-04-18 12:22:52 +00:00
Ralf Jung
3e633981ef when suggesting RUST_BACKTRACE=1, add a special note for Miri's env var isolation 2024-04-18 12:05:08 +02:00
David Tolnay
fdf93bbde0
Improve std::fs::Metadata Debug representation
Before:

    Metadata {
        file_type: FileType(
            FileType {
                mode: 0o100600 (-rw-------),
            },
        ),
        is_dir: false,
        is_file: true,
        permissions: Permissions(
            FilePermissions {
                mode: 0o100600 (-rw-------),
            },
        ),
        modified: Ok(
            SystemTime {
                tv_sec: 1713402981,
                tv_nsec: 682983531,
            },
        ),
        accessed: Ok(
            SystemTime {
                tv_sec: 1713402983,
                tv_nsec: 206999623,
            },
        ),
        created: Ok(
            SystemTime {
                tv_sec: 1713402981,
                tv_nsec: 682983531,
            },
        ),
        ..
    }

After:

    Metadata {
        file_type: FileType {
            is_dir: false,
            is_file: true,
            is_symlink: false,
            ..
        },
        permissions: Permissions(
            FilePermissions {
                mode: 0o100600 (-rw-------),
            },
        ),
        len: 2096,
        modified: SystemTime {
            tv_sec: 1713402981,
            tv_nsec: 682983531,
        },
        accessed: SystemTime {
            tv_sec: 1713402983,
            tv_nsec: 206999623,
        },
        created: SystemTime {
            tv_sec: 1713402981,
            tv_nsec: 682983531,
        },
        ..
    }
2024-04-17 18:43:29 -07:00
Matthias Krüger
8f3fd9394f
Rollup merge of #124049 - slanterns:const_io_structs_stabilize, r=jhpratt
Stabilize `const_io_structs`

This PR stabilizes `const_io_structs`.

Tracking issue: https://github.com/rust-lang/rust/issues/78812.
Implementation PR: https://github.com/rust-lang/rust/pull/78811.

FCPs already completed in the tracking issue.

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

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

r? libs-api
2024-04-17 18:01:39 +02:00
Matthias Krüger
21deaed4a1
Rollup merge of #122201 - coolreader18:doc-clone_from, r=dtolnay
Document overrides of `clone_from()` in core/std

As mentioned in https://github.com/rust-lang/rust/pull/96979#discussion_r1379502413

Specifically, when an override doesn't just forward to an inner type, document the behavior and that it's preferred over simply assigning a clone of source. Also, change instances where the second parameter is "other" to "source".

I reused some of the wording over and over for similar impls, but I'm not sure that the wording is actually *good*. Would appreciate feedback about that.

Also, now some of these seem to provide pretty specific guarantees about behavior (e.g. will reuse the exact same allocation iff the len is the same), but I was basing it off of the docs for [`Box::clone_from`](https://doc.rust-lang.org/1.75.0/std/boxed/struct.Box.html#method.clone_from-1) - I'm not sure if providing those strong guarantees is actually good or not.
2024-04-17 18:01:37 +02:00
Jiahao XU
7b53f69674
Stablise io_error_downcast
Tracking issue #99262
2024-04-18 00:07:46 +10:00
Slanterns
b7f4332737
Stabilize const_io_structs 2024-04-17 08:09:13 +08: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
Chris Denton
f68529f2cf
Use raw-dylib for Windows futex APIs
This is a workaround for older mingw `synchronization` import library not working on at least some system.
2024-04-16 15:49:46 +00:00
joboet
10b6ca139e
std: fix lint on SGX 2024-04-16 16:50:56 +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
Daniel Paoliello
32f5ca4be7 Add support for Arm64EC to the Standard Library 2024-04-15 16:05:16 -07: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
Ralf Jung
b4a4645758 static_mut_refs: use raw pointers to remove the remaining FIXME 2024-04-15 18:45:56 +02: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
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
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
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
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
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
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
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
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
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
Benoît du Garreau
2e3ee23022 Avoid panicking branch in append_to_string 2024-04-12 09:46:01 +02:00
Benoît du Garreau
23211b638a VecDeque::read_to_string: avoid making the slices contiguous 2024-04-12 09:44:05 +02:00
Benoît du Garreau
b07c1f7f4d Improve several Read implementations 2024-04-12 09:43:39 +02: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
Kornel
1170d73007 Move rare overflow error to a cold function 2024-04-11 22:23:49 +01:00
Matthias Krüger
d8ae975c02
Rollup merge of #123806 - joboet:advanced_overflow, r=Amanieu
Panic on overflow in `BorrowedCursor::advance`

Passing `usize::MAX` to `advance` clearly isn't correct, but the current assertion fails to detect this when overflow checks are disabled. This isn't unsound, but should probably be fixed regardless.
2024-04-11 22:38:56 +02:00
Matthias Krüger
1e99af514b
Rollup merge of #122882 - Zoxc:panic-output-panic, r=Amanieu
Avoid a panic in `set_output_capture` in the default panic handler

This avoid a panic in the default panic handler by not using `set_output_capture` as `OUTPUT_CAPTURE.with` may panic once `OUTPUT_CAPTURE` is dropped.

A new non-panicking `try_set_output_capture` variant of `set_output_capture` is added for use in the default panic handler.
2024-04-11 22:38:53 +02:00
Slanterns
cf836bcc3c
Stabilize Seek::seek_relative 2024-04-12 02:27:58 +08:00
bors
aa6a697a1c Auto merge of #123732 - a1phyr:io_error_factor, r=cuviper
Factor some common `io::Error` constants
2024-04-11 17:49:04 +00:00
joboet
dbda4f91aa
std: use queue-based RwLock on Windows 7 2024-04-11 19:37:12 +02:00
joboet
8afee14202
std: use queue-based RwLock on Xous 2024-04-11 19:36:50 +02:00
joboet
a30a79c5b4
std: use queue-based RwLock on SGX 2024-04-11 19:36:30 +02:00
joboet
843cef3035
std: remove sys_common::thread 2024-04-11 18:49:45 +02:00
joboet
91fe6f9343
core: panic on overflow in BorrowedCursor 2024-04-11 18:33:46 +02:00
Sebastien Marie
7aaad6b7e2 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-11 08:43:38 +00:00
Benoît du Garreau
9c64068ddb Factor some common io::Error constants 2024-04-11 09:55:15 +02:00
León Orell Valerian Liehr
b24d2ad300
Rollup merge of #123756 - lukas-code:file-sync, r=jhpratt
clean up docs for `File::sync_*`

* Clarify that `sync_all` also writes data and not just metadata.
* Clarify that dropping a file is not equivalent to calling `sync_all` and ignoring the result. `sync_all` the still the recommended way to detect errors before closing, because we don't have a dedicated method for that.
* Add a link from `sync_all` to `sync_data`, because that's what the user might want to use instead.
* Add doc aliases for `fsync` -> `sync_all` and `fdatasync` -> `sync_data`. Those are the POSIX standard names for these functions. I was trying to find out what we call `fsync` in Rust and had to search through the source code to find it, so this alias should help with that in the future.
2024-04-11 01:56:26 +02:00
León Orell Valerian Liehr
084d27b120
Rollup merge of #123360 - adamgemmell:dev/adagem01/restricted-std, r=ehuss
Document restricted_std

This PR aims to pin down exactly what restricted_std is meant to achieve and what it isn't.

This commit fixes https://github.com/rust-lang/wg-cargo-std-aware/issues/87 by explaining why the error appears and what the choices the user has. The error describes how std cannot function without knowing about some form of OS/platform support. Any features of std that work without an OS should be moved to core/alloc (see https://github.com/rust-lang/rust/issues/27242 https://github.com/rust-lang/rust/issues/103765).

Note that the message says "platform" and "environment" because, since https://github.com/rust-lang/rust/pull/120232, libstd can be built for some JSON targets. This is still unsupported (all JSON targets probably should be unstable https://github.com/rust-lang/wg-cargo-std-aware/issues/90), but a JSON target with the right configuration should hopefully have some partial libstd support.

I propose closing https://github.com/rust-lang/wg-cargo-std-aware/issues/69 as "Won't fix" since any support of std without properly configured os, vendor or env fields is very fragile considering future upgrades of Rust or dependencies. In addition there's no likely path to it being fixed long term (making std buildable for all targets being the only solution). This is distinct from tier 3 platforms with limited std support implemented (and as such aren't restricted_std) because these platforms can conceptually work in the future and std support should mainly improve over time.

The alternative to closing https://github.com/rust-lang/wg-cargo-std-aware/issues/69 is a new crate feature for std which escapes the restricted_std mechanism in build.rs. It could be used with the -Zbuild-std-features flag if we keep it permanently unstable, which I hope we can do anyway. A minor side-effect in this scenario is that std wouldn't be marked as unstable if documentation for it were generated with build-std.

cc ```@ehuss```
2024-04-11 01:56:25 +02:00
León Orell Valerian Liehr
aac3f24054
Rollup merge of #122470 - tgross35:f16-f128-step4-libs-min, r=Amanieu
`f16` and `f128` step 4: basic library support

This is the next step after https://github.com/rust-lang/rust/pull/121926, another portion of https://github.com/rust-lang/rust/pull/114607

Tracking issue: https://github.com/rust-lang/rust/issues/116909

This PR adds the most basic operations to `f16` and `f128` that get lowered as LLVM intrinsics. This is a very small step but it seemed reasonable enough to add unopinionated basic operations before the larger modules that are built on top of them.

r? ```@Amanieu``` since you were pretty involved in the RFC
cc ```@compiler-errors```
```@rustbot``` label +T-libs-api +S-blocked +F-f16_and_f128
2024-04-11 01:56:23 +02:00
Lukas Markeffsky
f0fd5ad5d7 clean up docs for File::sync_* 2024-04-10 23:02:12 +02:00
Trevor Gross
143ecc3202 Add basic f16 and f128 modules
Create empty modules so `rustdoc` has someplace to link to for these
types.
2024-04-10 13:50:27 -04:00
bors
5974fe87c4 Auto merge of #123725 - GuillaumeGomez:rollup-gk2bbrg, r=GuillaumeGomez
Rollup of 7 pull requests

Successful merges:

 - #118391 (Add `REDUNDANT_LIFETIMES` lint to detect lifetimes which are semantically redundant)
 - #123534 (Windows: set main thread name without re-encoding)
 - #123659 (Add support to intrinsics fallback body)
 - #123689 (Add const generics support for pattern types)
 - #123701 (Only assert for child/parent projection compatibility AFTER checking that theyre coming from the same place)
 - #123702 (Further cleanup cfgs in the UI test suite)
 - #123706 (rustdoc: reduce per-page HTML overhead)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-04-10 14:28:52 +00:00
Guillaume Gomez
38af5f9ee8
Rollup merge of #123534 - ChrisDenton:name, r=workingjubilee
Windows: set main thread name without re-encoding

As a minor optimization, we can skip the runtime UTF-8 to UTF-16 conversion.
2024-04-10 16:15:23 +02:00
Mads Marquart
69a3b0e213 visionOS: Fix unused import warning
The import is used once in this file, inside `posix_spawn`, so let's move the import into that function instead, to reduce the number of `cfg`s that need to be kept in sync.
2024-04-10 15:05:06 +02:00
Kriskras99
6b0d3663c1
Rework Path::ancestors documentation to remove unwraps
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.
2024-04-10 13:43:36 +02:00
bors
e908cfd125 Auto merge of #122393 - a1phyr:specialize_read_buf_exact, r=joboet
Specialize many implementations of `Read::read_buf_exact`

This makes all implementations of `Read` that have a specialized `read_exact` implementation also have one for `read_buf_exact`.
2024-04-10 11:38:15 +00:00
Kriskras99
bc8ad6a41e
Bring documentation of Path::to_path_buf in line with the rest of Path/PathBuf
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.
2024-04-10 13:21:26 +02:00
bors
b14d8b2ef2 Auto merge of #122812 - dtolnay:mode, r=workingjubilee
Show mode_t as octal in std::fs Debug impls

Example:

```rust
fn main() {
    println!("{:?}", std::fs::metadata("Cargo.toml").unwrap().permissions());
}
```

- Before: `Permissions(FilePermissions { mode: 33204 })`

- ~~After: `Permissions(FilePermissions { mode: 0o100664 })`~~

- After: `Permissions(FilePermissions { mode: 0o100664 (-rw-rw-r--) })`

~~I thought about using the format from `ls -l` (`-rw-rw-r--`, `drwxrwxr-x`) but I am not sure how transferable the meaning of the higher bits between different unix systems, and anyway starting the value with a leading negative-sign seems objectionable.~~
2024-04-10 04:47:56 +00:00
Trevor Gross
a7238b9952 Update documentation related to the recent cmd.exe fix
Fix some grammar nits, change `bat` (extension) -> `batch` (file), and
make line wrapping more consistent.
2024-04-09 23:20:32 -04:00
Matthias Krüger
a3f10a47d9
Rollup merge of #123633 - bjorn3:unsupported_command_data, r=jhpratt
Store all args in the unsupported Command implementation

This allows printing them in the Debug impl as well as getting them again using the get_args() method. This allows programs that would normally spawn another process to more easily show which program they would have spawned if not for the fact that the target doesn't support spawning child processes without requiring intrusive changes to keep the args. For example rustc compiled to wasi will show the full linker invocation that would have been done.
2024-04-10 04:27:40 +02:00
David Tolnay
caf3766eaf
Show mode_t as octal in std::fs Debug impls 2024-04-09 18:12:41 -07:00
Chris Denton
19f04a7d68
Add comment on UTF-16 surrogates 2024-04-09 20:20:32 +00:00
Chris Denton
952d432666
Windows: set main thread name without reencoding 2024-04-09 20:20:31 +00:00
Chris Denton
b48e7e5496
Add const UTF-8 to UTF-16 conversion macros
`wide_str!` creates a null terminated UTF-16 string whereas `utf16!` just creates a UTF-16 string without adding a null.
2024-04-09 20:20:19 +00:00
bors
8b2459c1f2 Auto merge of #123683 - pietroalbini:pa-cve-2024-24576-nightly, r=pietroalbini
Backport fix of CVE-2024-24576

See https://blog.rust-lang.org/2024/04/09/cve-2024-24576.html

r? `@ghost`
2024-04-09 19:56:18 +00:00
bors
033becf83c Auto merge of #123485 - madsmtm:use-libc-copyfile, r=joboet
macOS: Use `libc` definitions for copyfile

`COPYFILE_ALL` is not yet exposed in `libc`, but the rest of what we need is, so use those definitions instead of manually defining them.

The definitions were added in https://github.com/rust-lang/libc/pull/2667 and https://github.com/rust-lang/libc/pull/3346.
2024-04-09 14:15:09 +00:00
bjorn3
b4a395bcce Fix dead code warning 2024-04-09 13:44:53 +00:00
Chris Denton
ceedae178e
Document Windows argument splitting 2024-04-09 01:19:33 +02:00
Chris Denton
f66a096607
Disallow or quote all specials in bat args 2024-04-09 01:19:08 +02:00
Trevor Gross
313085f725 Change method calls to using the method directly
This is in accordance with Clippy's redundant_closure_for_method_calls.
2024-04-08 17:48:07 -04:00
Trevor Gross
6e68a2f475 Add SAFETY comments to the thread local implementation
Reduce `unsafe` block scope and add `SAFETY` comments.
2024-04-08 17:47:09 -04:00
Trevor Gross
2aec2fe3b8 Update thread local docs with idiomatic cell type use
The `thread_local!` examples use `RefCell` for `Copy` types. Update
examples to have one `Copy` and one non-`Copy` type using `Cell` and
`RefCell`, respectively.
2024-04-08 17:43:24 -04:00
bors
537aab7a2e Auto merge of #120131 - oli-obk:pattern_types_syntax, r=compiler-errors
Implement minimal, internal-only pattern types in the type system

rebase of https://github.com/rust-lang/rust/pull/107606

You can create pattern types with `std::pat::pattern_type!(ty is pat)`. The feature is incomplete and will panic on you if you use any pattern other than integral range patterns. The only way to create or deconstruct a pattern type is via `transmute`.

This PR's implementation differs from the MCP's text. Specifically

> This means you could implement different traits for different pattern types with the same base type. Thus, we just forbid implementing any traits for pattern types.

is violated in this PR. The reason is that we do need impls after all in order to make them usable as fields. constants of type `std::time::Nanoseconds` struct are used in patterns, so the type must be structural-eq, which it only can be if you derive several traits on it. It doesn't need to be structural-eq recursively, so we can just manually implement the relevant traits on the pattern type and use the pattern type as a private field.

Waiting on:

* [x] move all unrelated commits into their own PRs.
* [x] fix niche computation (see 2db07f94f44f078daffe5823680d07d4fded883f)
* [x] add lots more tests
* [x] T-types MCP https://github.com/rust-lang/types-team/issues/126 to finish
* [x] some commit cleanup
* [x] full self-review
* [x] remove 61bd325da19a918cc3e02bbbdce97281a389c648, it's not necessary anymore I think.
* [ ] ~~make sure we never accidentally leak pattern types to user code (add stability checks or feature gate checks and appopriate tests)~~ we don't even do this for the new float primitives
* [x] get approval that [the scope expansion to trait impls](https://rust-lang.zulipchat.com/#narrow/stream/326866-t-types.2Fnominated/topic/Pattern.20types.20types-team.23126/near/427670099) is ok

r? `@BoxyUwU`
2024-04-08 16:25:23 +00:00
bjorn3
bbd82ff44e Store all args in the unsupported Command implementation
This allows printing them in the Debug impl as well as getting them
again using the get_args() method. This allows programs that would
normally spawn another process to more easily show which program they
would have spawned if not for the fact that the target doesn't support
spawning child processes without requiring intrusive changes to keep the
args. For example rustc compiled to wasi will show the full linker
invocation that would have been done.
2024-04-08 16:21:07 +00:00
Matthias Krüger
beaca9ce08
Rollup merge of #115984 - hermit-os:fuse, r=m-ou-se
extending filesystem support for Hermit

Extending `std` to create, change and read a directory for Hermit.

Hermit is a tier 3 platform and this PR changes only files, wich are related to the tier 3 platform.
2024-04-08 14:31:09 +02:00
Oli Scherer
c340e67dec Add pattern types to parser 2024-04-08 11:57:17 +00:00
joboet
37c1758214
std: update abort message in thread::set_current 2024-04-08 12:17:19 +02:00
bors
a2c72ce594 Auto merge of #123506 - RalfJung:miri-test-libstd, r=Mark-Simulacrum
check-aux: test core, alloc, std in Miri

Let's see if this works, and how long it takes.
2024-04-08 00:08:44 +00:00
Ralf Jung
b1d1ad9f8c sys_common::thread_local_key: make a note that this is not used on Windows 2024-04-07 12:23:47 +02:00
Ralf Jung
1242093da2 also test parts of std
requires disabling some tests that do not work
2024-04-07 10:05:57 +02:00
Guillaume Gomez
b4a761db78
Rollup merge of #123541 - RalfJung:remove-old-hacks, r=Mark-Simulacrum
remove miri-test-libstd hacks that are no longer needed

In https://github.com/rust-lang/rust/pull/123317 we developed a different approach to testing the standard library in Miri, and with https://github.com/rust-lang/miri-test-libstd/pull/56 the out-of-tree miri-test-libstd has been switched to that approach. That makes these hacks here no longer necessary.
2024-04-06 17:37:39 +02:00
Matthias Krüger
3bcf402322
Rollup merge of #114788 - tisonkun:get_mut_or_init, r=dtolnay
impl get_mut_or_init and get_mut_or_try_init for OnceCell and OnceLock

See also https://github.com/rust-lang/rust/issues/74465#issuecomment-1676522051

I'm trying to understand the process for such proposal. And I'll appreciate it if anyone can guide me the next step for consensus or adding tests.
2024-04-06 13:00:04 +02:00
Ralf Jung
a2799ef869 remove miri-test-libstd hacks that are no longer needed 2024-04-06 09:03:19 +02:00
bors
30840c53f4 Auto merge of #123433 - GnomedDev:remove-threadname-alloc, r=joboet
Remove rt::init allocation for thread name

This removes one of the allocations in a `fn main() {}` program.
2024-04-06 00:17:23 +00:00
Guillaume Gomez
1bffe75df6
Rollup merge of #123505 - ChrisDenton:revert-121666, r=workingjubilee
Revert "Use OS thread name by default"

This reverts #121666 (Use the OS thread name by default if `THREAD_INFO` has not been initialized) due to #123495 (Thread names are not always valid UTF-8).

It's not a direct revert because there have been other changes since that PR.
2024-04-05 22:33:28 +02:00
Guillaume Gomez
74a5bc6c9e
Rollup merge of #121419 - agg23:xrOS-pr, r=davidtwco
Add aarch64-apple-visionos and aarch64-apple-visionos-sim tier 3 targets

Introduces `aarch64-apple-visionos` and `aarch64-apple-visionos-sim` as tier 3 targets. This allows native development for the Apple Vision Pro's visionOS platform.

This work has been tracked in https://github.com/rust-lang/compiler-team/issues/642. There is a corresponding `libc` change https://github.com/rust-lang/libc/pull/3568 that is not required for merge.

Ideally we would be able to incorporate [this change](https://github.com/gimli-rs/object/pull/626) to the `object` crate, but the author has stated that a release will not be cut for quite a while. Therefore, the two locations that would reference the xrOS constant from `object` are hardcoded to their MachO values of 11 and 12, accompanied by TODOs to mark the code as needing change. I am open to suggestions on what to do here to get this checked in.

# Tier 3 Target Policy

At this tier, the Rust project provides no official support for a target, so we place minimal requirements on the introduction of targets.

> 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.)

See [src/doc/rustc/src/platform-support/apple-visionos.md](e88379034a/src/doc/rustc/src/platform-support/apple-visionos.md)

> 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.

This naming scheme matches `$ARCH-$VENDOR-$OS-$ABI` which is matches the iOS Apple Silicon simulator (`aarch64-apple-ios-sim`) and other Apple targets.

> 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 besubject 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.

This contribution is fully available under the standard Rust license with no additional legal restrictions whatsoever. This PR does not introduce any new dependency less permissive than the Rust license policy.

The new targets do not depend on proprietary libraries.

> 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.

This new target mirrors the standard library for watchOS and iOS, with minor divergences.

> 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.

Documentation is provided in [src/doc/rustc/src/platform-support/apple-visionos.md](e88379034a/src/doc/rustc/src/platform-support/apple-visionos.md)

> 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.
> * This requirement does not prevent part or all of this policy from being cited in an explicit contract or work agreement (e.g. to implement or maintain support for a target). This requirement exists to ensure that a developer or team responsible for reviewing and approving a target does not face any legal threats or obligations that would prevent them from freely exercising their judgment in such approval, even if such judgment involves subjective matters or goes beyond the letter of these requirements.

> 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.
> * 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.

> 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 acknowledge these requirements and intend to ensure that they are met.

This target does not touch any existing tier 2 or tier 1 targets and should not break any other targets.
2024-04-05 22:33:25 +02:00
bors
5958f5e08f Auto merge of #123317 - RalfJung:test-in-miri, r=m-ou-se,saethlin,onur-ozkan
Support running library tests in Miri

This adds a new bootstrap subcommand `./x.py miri` which can test libraries in Miri. This is in preparation for eventually doing that as part of bors CI, but this PR only adds the infrastructure, and doesn't enable it yet.

`@rust-lang/bootstrap` should this be `x.py test --miri library/core` or `x.py miri library/core`? The flag has the advantage that we don't have to copy all the arguments from `Subcommand::Test`. It has the disadvantage that most test steps just ignore `--miri` and still run tests the regular way. For clippy you went the route of making it a separate subcommand. ~~I went with a flag now as that seemed easier, but I can change this.~~ I made it a new subcommand. Note however that the regular cargo invocation would be `cargo miri test ...`, so `x.py` is still going to be different in that the `test` is omitted. That said, we could also make it `./x.py miri-test` to make that difference smaller -- that's in fact more consistent with the internal name of the command when bootstrap invokes cargo.

`@rust-lang/libs` ~~unfortunately this PR does some unholy things to the `lib.rs` files of our library crates.~~
`@m-ou-se` found a way that entirely avoids library-level hacks, except for some new small `lib.miri.rs` files that hopefully you will never have to touch. There's a new hack in cargo-miri but there it is in good company...
2024-04-05 13:17:09 +00:00
Chris Denton
7d008267dd
Revert #121666
This reverts #121666 due to #123495
2024-04-05 12:50:31 +00:00
Mads Marquart
3fe58393bc macOS: Use libc definitions for copyfile
`COPYFILE_ALL` is not yet exposed in `libc`, but the rest of what we need is, so use those definitions instead of manually defining them.
2024-04-05 04:25:39 +02:00
David Thomas
0989416d21 Remove rt::init allocation for thread name 2024-04-04 23:17:15 +01:00
Matthias Krüger
ee5009e745
Rollup merge of #123389 - ChrisDenton:dont-panic-on-startup, r=joboet
Avoid panicking unnecessarily on startup

On Windows, in `lang_start` we add an exception handler to catch stack overflows and we also reserve some stack space for the handler. Both of these are useful but they're not strictly necessary. The standard library has to work without them (e.g. if Rust is used from a foreign entry point) and the negative effect of not doing them is limited (i.e. you don't get the friendly stack overflow message).

As we really don't want to panic pre-main unless absolutely necessary, it now won't panic on failure. I've added some debug assertions so as to avoid programmer error.
2024-04-04 14:51:17 +02:00
Chris Denton
7b8f93ef4c
Add comments about using debug_assert 2024-04-04 10:48:11 +00:00
Jacob Pratt
875d254750
Rollup merge of #122356 - devnexen:dfbsd_build_fix, r=jhpratt
std::rand: fix dragonflybsd after #121942.
2024-04-03 20:17:04 -04:00
Ralf Jung
a6803b9de4 add 'x.py miri', and make it work for 'library/{core,alloc,std}' 2024-04-03 20:27:20 +02:00
joboet
989660c3e6
rename expose_addr to expose_provenance 2024-04-03 16:00:38 +02:00
joboet
061d8731fb
std: add comment about abort motivation 2024-04-03 14:33:43 +02:00
Jubilee
0c0d88864a
Rollup merge of #123388 - tshepang:consistency, r=jhpratt
use a consistent style for links
2024-04-02 23:44:29 -07:00
Jubilee
abb0393595
Rollup merge of #122411 - alexcrichton:wasm32-wasip2-cabi-realloc, r=m-ou-se
Provide cabi_realloc on wasm32-wasip2 by default

This commit provides a component model intrinsic in the standard library
by default on the `wasm32-wasip2` target. This intrinsic is not
required by the component model itself but is quite common to use, for
example it's needed if a wasm module receives a string or a list.

The intention of this commit is to provide an overridable definition in
the standard library through a weak definition of this function. That
means that downstream crates can provide their own customized and more
specific versions if they'd like, but the standard library's version
should suffice for general-purpose use.
2024-04-02 23:44:28 -07:00
Jacob Pratt
e9ef8e1efa
Rollup merge of #122935 - RalfJung:with-exposed-provenance, r=Amanieu
rename ptr::from_exposed_addr -> ptr::with_exposed_provenance

As discussed on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/To.20expose.20or.20not.20to.20expose/near/427757066).

The old name, `from_exposed_addr`, makes little sense as it's not the address that is exposed, it's the provenance. (`ptr.expose_addr()` stays unchanged as we haven't found a better option yet. The intended interpretation is "expose the provenance and return the address".)

The new name nicely matches `ptr::without_provenance`.
2024-04-02 20:37:39 -04:00
Chris Denton
e457b77e2a
Avoid panicking unnecessarily on startup 2024-04-02 19:41:58 +00:00
Tshepang Mbambo
a6b2d12c92 use a consistent style for links 2024-04-02 21:41:16 +02:00
Adam Gemmell
8923b589bd Document restricted_std
This PR aims to pin down exactly what restricted_std is meant to achieve
and what it isn't.

This commit fixes https://github.com/rust-lang/wg-cargo-std-aware/issues/87
by explaining why the error appears and what the choices the user has.
The error describes how std cannot function without knowing about some
form of OS/platform support. Any features of std that work without an
OS should be moved to core/alloc (see https://github.com/rust-lang/rust/issues/27242
https://github.com/rust-lang/rust/issues/103765).

Note that the message says "platform" and "environment" because, since
https://github.com/rust-lang/rust/pull/120232, libstd can be built for
some JSON targets. This is still unsupported (all JSON targets probably
should be unstable https://github.com/rust-lang/wg-cargo-std-aware/issues/90),
but a JSON target with the right configuration should hopefully have
some partial libstd support.

I propose closing https://github.com/rust-lang/wg-cargo-std-aware/issues/69
as "Won't fix" since any support of std without properly configured os,
vendor or env fields is very fragile considering future upgrades of Rust
or dependencies. In addition there's no likely path to it being fixed
long term (making std buildable for all targets being the only
solution). This is distinct from tier 3 platforms with limited std
support implemented (and as such aren't restricted_std) because these
platforms can conceptually work in the future and std support should
mainly improve over time.

The alternative to closing https://github.com/rust-lang/wg-cargo-std-aware/issues/69
is a new crate feature for std which escapes the restricted_std
mechanism in build.rs. It could be used with the -Zbuild-std-features
flag if we keep it permanently unstable, which I hope we can do anyway.
A minor side-effect in this scenario is that std wouldn't be marked as
unstable if documentation for it were generated with build-std.
2024-04-02 12:05:12 +01:00
joboet
e7b5730d36
std: reduce code size of set_current 2024-04-02 11:41:31 +02:00
Steve Lau
bb439900dd style: fmt 2024-04-02 14:29:38 +08:00
Steve Lau
6ad96825fc fix: build on haiku by adding missing import 2024-04-02 14:18:31 +08:00
Jubilee
48b2a517fc
Rollup merge of #123323 - devnexen:thread_set_name_solaris_fix, r=workingjubilee
std:🧵 set_name change for solaris/illumos.

truncate down to 32 (31 + 1) for solaris/illumos.
2024-04-01 17:22:10 -07:00
David Carlier
ca36fe310e
std:🧵 set_name change for solaris/illumos.
truncate down to 32 (31 + 1) for solaris/illumos.
2024-04-01 22:16:13 +01:00
bors
a7e3b1c8c5 Auto merge of #123315 - devnexen:thread_get_name_solaris, r=ChrisDenton
std:🧵 adding get_name implementation for solaris/illumos.

THREAD_NAME_MAX is 32 (31 max + 1 for the null terminator).
2024-04-01 16:38:55 +00:00
bors
c518e5aeec Auto merge of #123265 - joboet:guardians_of_the_unix, r=ChrisDenton
Refactor stack overflow handling

Currently, every platform must implement a `Guard` that protects a thread from stack overflow. However, UNIX is the only platform that actually does so. Windows has a different mechanism for detecting stack overflow, while the other platforms don't detect it at all. Also, the UNIX stack overflow handling is split between `sys::pal::unix::stack_overflow`, which implements the signal handler, and `sys::pal::unix::thread`, which detects/installs guard pages.

This PR cleans this by getting rid of `Guard` and unifying UNIX stack overflow handling inside `stack_overflow` (commit 1). Therefore we can get rid of `sys_common::thread_info`, which stores `Guard` and the current `Thread` handle and move the `thread::current` TLS variable into `thread` (commit 2).

The second commit is not strictly speaking necessary. To keep the implementation clean, I've included it here, but if it causes too much noise, I can split it out without any trouble.
2024-04-01 14:35:38 +00:00
joboet
d7b55e4c90
update comment 2024-04-01 15:28:27 +02:00
David Carlier
747d19326b
std:🧵 adding get_name implementation for solaris/illumos.
THREAD_NAME_MAX is 32 (31 max + 1 for the null terminator).
2024-04-01 10:01:21 +01:00
bors
8058136502 Auto merge of #123299 - workingjubilee:rollup-2z8amaj, r=workingjubilee
Rollup of 5 pull requests

Successful merges:

 - #123180 (Rewrite `core-no-fp-fmt-parse` test in Rust)
 - #123267 (std:🧵 adding get_name haiku implementation.)
 - #123268 (warn against implementing Freeze)
 - #123271 (doc: describe panic conditions for SliceIndex implementations)
 - #123295 (add myself to compiler review rotation)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-03-31 20:35:15 +00:00
David Carlier
e5c5ed00a5 std:🧵 adding get_name haiku implementation.
follow-up #123233
2024-03-31 17:47:44 +01:00
Ralf Jung
42972f52de catch_panic: warn about panicking payload drop 2024-03-31 11:54:16 +02:00
joboet
7668418101
std: move thread::current TLS variable out of thread_info 2024-03-31 11:28:24 +02:00
joboet
5b9d7ab558
std: move UNIX stack overflow guard page handling into stack_overflow.rs 2024-03-31 11:24:33 +02:00
David Carlier
c749483e26 std:🧵 adding freebsd/netbsd to the linux's get_name implementation. 2024-03-30 16:01:47 +00:00
Aria Beingessner
ea92faec49 stabilize ptr.is_aligned, move ptr.is_aligned_to to a new feature gate
This is an alternative to #121920
2024-03-29 19:59:46 -04:00
bors
760e567af5 Auto merge of #122975 - DianQK:simplify_ub_check, r=saethlin
Eliminate `UbChecks` for non-standard libraries

 The purpose of this PR is to allow other passes to treat `UbChecks` as constants in MIR for optimization after #122629.

r? RalfJung
2024-03-29 02:25:43 +00:00
Vagelis Prokopiou
cc4a1f42e6 Some wording improvement 2024-03-27 17:26:18 +02:00
DianQK
47ed73a7b5
Eliminate UbCheck for non-standard libraries 2024-03-27 21:02:40 +08:00
bors
10a7aa14fe Auto merge of #123128 - GuillaumeGomez:rollup-3l3zu6s, r=GuillaumeGomez
Rollup of 6 pull requests

Successful merges:

 - #121843 (Implement `-L KIND=`@RUSTC_BUILTIN/...`)`
 - #122860 (coverage: Re-enable `UnreachablePropagation` for coverage builds)
 - #123021 (Make `TyCtxt::coroutine_layout` take coroutine's kind parameter)
 - #123024 (CFI: Enable KCFI testing of run-pass tests)
 - #123083 (lib: fix some unnecessary_cast clippy lint)
 - #123116 (rustdoc: Swap fields and variant documentations)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-03-27 09:32:38 +00:00
Guillaume Gomez
64a9360d3f
Rollup merge of #123083 - klensy:clippy-me, r=workingjubilee
lib: fix some unnecessary_cast clippy lint

Fixes few instances of `unnecessary_cast` clippy lint
2024-03-27 10:13:44 +01:00
tison
95e195f41e
impl get_mut_or_init and get_mut_or_try_init for OnceCell and OnceLock
See also https://github.com/rust-lang/rust/issues/74465#issuecomment-1676522051

Signed-off-by: tison <wander4096@gmail.com>
2024-03-27 16:16:08 +08:00