about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2023-11-01Auto merge of #115356 - devnexen:haiku_set_name_use_return, r=thomccbors-1/+3
`std::thread::set_name` exploit the return on haiku
2023-11-01Auto merge of #117422 - joshtriplett:stabilize-file-times, r=workingjubileebors-21/+19
Stabilize `file_set_times` Approved via FCP in https://github.com/rust-lang/rust/issues/98245 .
2023-10-31Add support for pre-unix-epoch file dates on Apple platforms (#108277)Sebastian Thiel-0/+66
Time in UNIX system calls counts from the epoch, 1970-01-01. The timespec struct used in various system calls represents this as a number of seconds and a number of nanoseconds. Nanoseconds are required to be between 0 and 999_999_999, because the portion outside that range should be represented in the seconds field; if nanoseconds were larger than 999_999_999, the seconds field should go up instead. Suppose you ask for the time 1969-12-31, what time is that? On UNIX systems that support times before the epoch, that's seconds=-86400, one day before the epoch. But now, suppose you ask for the time 1969-12-31 23:59:00.1. In other words, a tenth of a second after one minute before the epoch. On most UNIX systems, that's represented as seconds=-60, nanoseconds=100_000_000. The macOS bug is that it returns seconds=-59, nanoseconds=-900_000_000. While that's in some sense an accurate description of the time (59.9 seconds before the epoch), that violates the invariant of the timespec data structure: nanoseconds must be between 0 and 999999999. This causes this assertion in the Rust standard library. So, on macOS, if we get a Timespec value with seconds less than or equal to zero, and nanoseconds between -999_999_999 and -1 (inclusive), we can add 1_000_000_000 to the nanoseconds and subtract 1 from the seconds, and then convert. The resulting timespec value is still accepted by macOS, and when fed back into the OS, produces the same results. (If you set a file's mtime with that timestamp, then read it back, you get back the one with negative nanoseconds again.) Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2023-10-31Stabilize `file_set_times`Josh Triplett-21/+19
Approved via FCP in https://github.com/rust-lang/rust/issues/98245 .
2023-10-30Rollup merge of #117177 - Ayush1325:uefi-alloc-type, r=workingjubileeLeón Orell Valerian Liehr-3/+19
Use ImageDataType for allocation type Suggested at #100499 cc `@dvdhrm` cc `@nicholasbishop`
2023-10-30Use ImageDataType for allocation typeAyush Singh-3/+19
Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
2023-10-30Auto merge of #117332 - saethlin:panic-immediate-abort, r=workingjubileebors-1/+59
Increase the reach of panic_immediate_abort I wanted to use/abuse this recently as part of another project, and I was surprised how many panic-related things were left in my binaries if I built a large crate with the feature enabled along with LTO. These changes get all the panic-related symbols that I could find out of my set of locally installed Rust utilities.
2023-10-29Increase the reach of panic_immediate_abortBen Kimock-1/+59
2023-10-29Don't use LFS64 symbols on muslgit-bruh-14/+42
Simplify #[cfg] blocks fmt don't try to use the more appropriate direntry on musl
2023-10-28Rollup merge of #116816 - ChrisDenton:api.rs, r=workingjubileeJubilee-53/+212
Create `windows/api.rs` for safer FFI FFI is inherently unsafe. For memory safety we need to assert that some contract is being upheld on both sides of the FFI, though of course we can only ever check our side. In Rust, `unsafe` blocks are used to assert safety and `// SAFETY` comments describing why it is safe. Currently in sys/windows we have a lot of this unsafety spread all over the place, with variations on the same unsafe patterns repeated. And because of the repitition and frequency, we're a bit lax with the safety comments. This PR aims to fix this and to make FFI safety more auditable by creating an `api` module with the goal of centralising and consolidating this unsafety. It contains thin wrappers around the Windows API that make most functions safe to call or, if that's not possible, then at least safer. Note that its goal is *only* to address safety. It does not stray far from the Windows API and intentionally does not attempt to make higher lever wrappers around, for example, file handles. This is better left to the existing modules. The windows/api.rs file has a top level comment to help future contributors understand the intent of the module and the design decisions made. I chose two functions as a first tentative step towards the above goal: - [`GetLastError`](https://learn.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-getlasterror) is trivially safe. There's no reason to wrap it in an `unsafe` block every time. So I simply created a safe `get_last_error` wrapper. - [`SetFileInformationByHandle`](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-setfileinformationbyhandle) is more complex. It essentially takes a generic type but over a C API which necessitates some amount of ceremony. Rather than implementing similar unsafe patterns in multiple places, I provide a safe `set_file_information_by_handle` that takes a Rusty generic type and handles converting that to the form required by the C FFI. r? libs
2023-10-27Rollup merge of #117281 - RalfJung:thread-safety, r=thomccMatthias Krüger-0/+2
std::thread : add SAFETY comment I forgot to add this in https://github.com/rust-lang/rust/pull/117266.
2023-10-27Rollup merge of #117270 - jhpratt:hide-print-internals, r=ChrisDentonMatthias Krüger-0/+1
Hide internal methods from documentation The two methods here are perma-unstable and only made public for technical reasons. There is no reason to show them in documentation. `@rustbot` label +A-docs
2023-10-27std::thread: add SAFETY commentRalf Jung-0/+2
2023-10-27Auto merge of #117272 - matthiaskrgr:rollup-upg122z, r=matthiaskrgrbors-8/+8
Rollup of 6 pull requests Successful merges: - #114998 (feat(docs): add cargo-pgo to PGO documentation 📝) - #116868 (Tweak suggestion span for outer attr and point at item following invalid inner attr) - #117240 (Fix documentation typo in std::iter::Iterator::collect_into) - #117241 (Stash and cancel cycle errors for auto trait leakage in opaques) - #117262 (Create a new ConstantKind variant (ZeroSized) for StableMIR) - #117266 (replace transmute by raw pointer cast) r? `@ghost` `@rustbot` modify labels: rollup
2023-10-27Hide internal methods from documentationJacob Pratt-0/+1
2023-10-27replace transmute by raw pointer castRalf Jung-8/+8
2023-10-25Stabilize `[const_]pointer_byte_offsets`Maybe Waffle-1/+0
2023-10-25Auto merge of #117102 - devnexen:dfbsd_stack_overflow_upd, r=thomccbors-2/+12
stack_overflow: get_stackp using MAP_STACK flag on dragonflybsd too.
2023-10-24Auto merge of #116773 - dtolnay:validatestable, r=compiler-errorsbors-4/+4
Validate `feature` and `since` values inside `#[stable(…)]` Previously the string passed to `#[unstable(feature = "...")]` would be validated as an identifier, but not `#[stable(feature = "...")]`. In the standard library there were `stable` attributes containing the empty string, and kebab-case string, neither of which should be allowed. Pre-existing validation of `unstable`: ```rust // src/lib.rs #![allow(internal_features)] #![feature(staged_api)] #![unstable(feature = "kebab-case", issue = "none")] #[unstable(feature = "kebab-case", issue = "none")] pub struct Struct; ``` ```console error[E0546]: 'feature' is not an identifier --> src/lib.rs:5:1 | 5 | #![unstable(feature = "kebab-case", issue = "none")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ``` For an `unstable` attribute, the need for an identifier is obvious because the downstream code needs to write a `#![feature(...)]` attribute containing that identifier. `#![feature(kebab-case)]` is not valid syntax and `#![feature(kebab_case)]` would not work if that is not the name of the feature. Having a valid identifier even in `stable` is less essential but still useful because it allows for informative diagnostic about the stabilization of a feature. Compare: ```rust // src/lib.rs #![allow(internal_features)] #![feature(staged_api)] #![stable(feature = "kebab-case", since = "1.0.0")] #[stable(feature = "kebab-case", since = "1.0.0")] pub struct Struct; ``` ```rust // src/main.rs #![feature(kebab_case)] use repro::Struct; fn main() {} ``` ```console error[E0635]: unknown feature `kebab_case` --> src/main.rs:3:12 | 3 | #![feature(kebab_case)] | ^^^^^^^^^^ ``` vs the situation if we correctly use `feature = "snake_case"` and `#![feature(snake_case)]`, as enforced by this PR: ```console warning: the feature `snake_case` has been stable since 1.0.0 and no longer requires an attribute to enable --> src/main.rs:3:12 | 3 | #![feature(snake_case)] | ^^^^^^^^^^ | = note: `#[warn(stable_features)]` on by default ```
2023-10-24Auto merge of #116461 - ChrisDenton:sleep, r=thomccbors-1/+88
Windows: Support sub-millisecond sleep Use `CreateWaitableTimerExW` with `CREATE_WAITABLE_TIMER_HIGH_RESOLUTION`. Does not work before Windows 10, version 1803 so in that case we fallback to using `Sleep`. I've created a `WaitableTimer` type so it can one day be adapted to also support waiting to an absolute time (which has been talked about). Note though that it currently returns `Err(())` because we can't do anything with the errors other than fallback to the old `Sleep`. Feel free to tell me to do errors properly. It just didn't seem worth constructing an `io::Error` if we're never going to surface it to the user. And it *should* all be infallible anyway unless the OS is too old to support it. Closes #43376
2023-10-24Auto merge of #116319 - BlackHoleFox:apple-rand-take-2, r=thomccbors-58/+52
Remove Apple RNG fallbacks and simplify implementation Now that we have [higher Apple platform requirements](https://github.com/rust-lang/rust/pull/104385), the RNG code can be simplified a lot. Since `getentropy` still doesn't look to be usable outside macOS this implementation: - Removes any macOS fallback paths and unconditionally links to `getentropy` - Minimizes the implementation for everything else (iOS, watchOS, etc). `CCRandomGenerateBytes` was added in iOS 8 which means that we can use it now. It and `SecRandomCopyBytes` have the exact same functionality, but the former has a simpler API and no longer requires libstd to link to `Security.framework` for one function. Its also available in all the other target's SDKs. Why care about `getentropy` then though on macOS? Well, its still much more performant. Benchmarking shows it runs at ~2x the speed of `CCRandomGenerateBytes`, which makes sense since it directly pulls from the kernel vs going through its own generator etc. Semi-related to a previous, but reverted, attempt at improving this logic in https://github.com/rust-lang/rust/pull/101011
2023-10-24Auto merge of #116238 - tamird:gettimeofday, r=thomccbors-200/+80
time: use clock_gettime on macos Replace `gettimeofday` with `clock_gettime(CLOCK_REALTIME)` on: ``` all(target_os = "macos", not(target_arch = "aarch64")), target_os = "ios", target_os = "watchos", target_os = "tvos" ))] ``` `gettimeofday` was first used in https://github.com/time-rs/time/commit/cc367edd953e72756ed6f0980918795c11e469b1 which predated the introduction of `clock_gettime` support in macOS 10.12 Sierra which became the minimum supported version in 58bbca958d917a89124da248735926f86c59a149. Replace `mach_{absolute_time,timebase_info}` with `clock_gettime(CLOCK_REALTIME)` on: ``` all(target_os = "macos", not(target_arch = "aarch64")), target_os = "ios", target_os = "watchos", target_os = "tvos" ))] ``` `mach_{absolute_time,timebase_info}` were first used in https://github.com/time-rs/time/commit/cc367edd953e72756ed6f0980918795c11e469b1 which predated the introduction of `clock_gettime` support in macOS 10.12 Sierra which became the minimum supported version in 58bbca958d917a89124da248735926f86c59a149. Note that this change was made for aarch64 in 5008a317ce8e508c390ed12bff281f307313376e which predated 10.12 becoming the minimum supported version. The discussion took place in https://github.com/rust-lang/rust/issues/91417 and in particular https://github.com/rust-lang/rust/issues/91417#issuecomment-992151582 and https://github.com/rust-lang/rust/issues/91417#issuecomment-1033048064 are relevant.
2023-10-23Remove Apple RNG fallbacks and simplify implementationBlackHoleFox-58/+52
2023-10-23Auto merge of #117103 - matthiaskrgr:rollup-96zuuom, r=matthiaskrgrbors-9/+7
Rollup of 6 pull requests Successful merges: - #107159 (rand use getrandom for freebsd (available since 12.x)) - #116859 (Make `ty::print::Printer` take `&mut self` instead of `self`) - #117046 (return unfixed len if pat has reported error) - #117070 (rustdoc: wrap Type with Box instead of Generics) - #117074 (Remove smir from triage and add me to stablemir) - #117086 (Update .mailmap to promote my livename) r? `@ghost` `@rustbot` modify labels: rollup
2023-10-23stack_overflow: get_stackp using MAP_STACK flag on dragonflybsd too.David Carlier-2/+12
2023-10-23Rollup merge of #107159 - devnexen:random_fbsd_update, r=workingjubileeMatthias Krüger-9/+7
rand use getrandom for freebsd (available since 12.x)
2023-10-23Auto merge of #116033 - bvanjoi:fix-116032, r=petrochenkovbors-1/+3
report `unused_import` for empty reexports even it is pub Fixes #116032 An easy fix. r? `@petrochenkov` (Discovered this issue while reviewing #115993.)
2023-10-23Fix invalid stability attribute features in standard libraryDavid Tolnay-4/+4
2023-10-23Auto merge of #116606 - ChrisDenton:empty, r=dtolnaybors-0/+8
On Windows make `read_dir` error on the empty path This makes Windows consistent with other platforms. Note that this should not be taken to imply any decision on #114149 has been taken. However it was felt that while there is a lack of libs-api consensus, we should be consistent across platforms in the meantime. This is a change in behaviour for Windows so will also need an fcp before merging. r? libs-api
2023-10-22use visibility to check unused imports and delete some stmtsbohan-1/+3
2023-10-22Rollup merge of #116989 - ChrisDenton:skip-unsupported, r=Mark-SimulacrumMatthias Krüger-2/+11
Skip test if Unix sockets are unsupported Fixes https://github.com/rust-lang/rust/pull/116683#issuecomment-1772314187 The test will be skipped if `AF_UNIX` is not supported. In that case [`WSASocketW` returns `WSAEAFNOSUPPORT`](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasocketw#return-value). It will never skip the test when run in CI but maybe this is me being too defensive since the error code is narrowly scoped to just the af family parameter being unsupported? Also fixed a minor typo. r? `@Mark-Simulacrum`
2023-10-21Rollup merge of #114521 - devnexen:std_fbsd_13_upd, r=cuviperMatthias Krüger-10/+0
std: freebsd build update. since freebsd 11 had been removed, minimum is now 12.
2023-10-20changes from feedbackDavid Carlier-10/+0
2023-10-20s/generator/coroutine/Oli Scherer-1/+1
2023-10-20Skip test if Unix sockets are unsupportedChris Denton-2/+11
2023-10-20Auto merge of #116785 - nnethercote:spec-Bytes-read, r=the8472bors-15/+60
Specialize `Bytes<R>::next` when `R` is a `BufReader`. This reduces the runtime for a simple program using `Bytes::next` to iterate through a file from 220ms to 70ms on my Linux box. r? `@the8472`
2023-10-20Specialize `Bytes<R>::next` when `R` is a `BufReader`.Nicholas Nethercote-15/+60
This reduces the runtime for a simple program using `Bytes::next` to iterate through a file from 220ms to 70ms on my Linux box.
2023-10-19Auto merge of #116132 - darthunix:connect_poll, r=cuviperbors-12/+38
Make TCP connect handle EINTR correctly According to the [POSIX](https://pubs.opengroup.org/onlinepubs/009695399/functions/connect.html) standard, if connect() is interrupted by a signal that is caught while blocked waiting to establish a connection, connect() shall fail and set errno to EINTR, but the connection request shall not be aborted, and the connection shall be established asynchronously. When the connection has been established asynchronously, select() and poll() shall indicate that the file descriptor for the socket is ready for writing. The previous implementation differs from the recomendation: in a case of the EINTR we tried to reconnect in a loop and sometimes get EISCONN error (this problem was originally detected on MacOS). 1. More details about the problem in an [article](http://www.madore.org/~david/computers/connect-intr.html). 2. The original [issue](https://git.picodata.io/picodata/picodata/tarantool-module/-/issues/157).
2023-10-19Auto merge of #114534 - niluxv:strict_prov_unwind, r=cuviper,workingjubileebors-46/+94
Strict provenance unwind 1. Turned many `usize`s in the personality/unwind code that are actually pointers into `*const u8`. 2. Rewrote `read_encoded_pointer` to conform to strict-provenance, along the lines as described by `@eddyb` [in zulip some time ago](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/strict.20provenance.20in.20dwarf.3A.3Aeh/near/276197290). This should make supporting CHERI in the future easier (but they use a [slightly modified format in the callsite table](https://cheri-compiler-explorer.cl.cam.ac.uk/z/n6GhhW), which requires a CHERI specific modification to `find_eh_action`).
2023-10-19Auto merge of #116402 - joboet:global_alloc_tls_unsoundness, ↵bors-29/+51
r=thomcc,workingjubilee Panic when the global allocator tries to register a TLS destructor Using a `RefCell` avoids the undefined behaviour encountered in #116390 and reduces the amount of `unsafe` code in the codebase.
2023-10-17Automatically enable cross-crate inlining for small functionsBen Kimock-0/+1
2023-10-17Auto merge of #116518 - vita-rust:vita, r=workingjubileebors-5/+5
Updated libc and doc for Vita target Doc changes: - Updated Vita target readme. The recommended approach to build artifacts for the platform now is [cargo-vita](https://crates.io/crates/cargo-vita) which wraps all the convoluted steps previously described in a yaml for `cargo-make` - Updated maintainer list for Vita target. (`@ZetaNumbers` `@pheki` please agree to be added to the list, `@amg98` please let us know if you're still planning on actively maintaining target support) Code changes: - ~Updated libc for rust-lang/libc#3284 and rust-lang/libc#3366~ (Already merged in #116527) - In dupfd changed the flag same as for esp target, there is no CLOEXEC on Vita - Enabled `new_pair` since we've implemented `socketpair` in Vita newlib
2023-10-17Updated libc and doc for Vita targetNikolay Arhipov-5/+5
2023-10-16Create `windows/api.rs` for safer FFIChris Denton-53/+212
2023-10-16Auto merge of #116775 - nnethercote:inline-Bytes-next, r=the8472bors-0/+2
Inline `Bytes::next` and `Bytes::size_hint`. This greatly increases its speed. On one small test program using `Bytes::next` to iterate over a large file, execution time dropped from ~330ms to ~220ms. r? `@the8472`
2023-10-16Auto merge of #114589 - ijackson:exit-code-default, r=dtolnaybors-1/+9
impl Default for ExitCode As suggested here https://github.com/rust-lang/rust/pull/106425#issuecomment-1382952598 Needs FCP since this is an insta-stable impl. Ideally we would have `impl From<ExitCode> for ExitStatus` and implement the default `ExitStatus` using that. That is sadly not so easy because of the various strange confusions about `ExitCode` (unix: exit status) vs `ExitStatus` (unix: wait status) in the not-really-unix platforms in `library//src/sys/unix/process`. I'll try to follow that up.
2023-10-15Auto merge of #116772 - matthiaskrgr:rollup-mpff3lh, r=matthiaskrgrbors-4/+168
Rollup of 7 pull requests Successful merges: - #116172 (Broaden the consequences of recursive TLS initialization) - #116341 (Implement sys::args for UEFI) - #116522 (use `PatKind::Error` when an ADT const value has violation) - #116732 (Make x capable of resolving symlinks) - #116755 (Remove me from libcore review rotation) - #116760 (Remove trivial cast in `guaranteed_eq`) - #116771 (Ignore let-chains formatting) r? `@ghost` `@rustbot` modify labels: rollup
2023-10-16Inline `Bytes::next` and `Bytes::size_hint`.Nicholas Nethercote-0/+2
This greatly increases its speed.
2023-10-15Rollup merge of #116341 - Ayush1325:uefi-args, r=Mark-SimulacrumMatthias Krüger-1/+165
Implement sys::args for UEFI - Uses `EFI_LOADED_IMAGE_PROTOCOL`, which is implemented for all loaded images. Tested on qemu with OVMF cc ``@nicholasbishop`` cc ``@dvdhrm``
2023-10-15Rollup merge of #116172 - joboet:recursive_tls_initialization, r=dtolnayMatthias Krüger-3/+3
Broaden the consequences of recursive TLS initialization This PR updates the documentation of `LocalKey` to clearly disallow the behaviour described in [this comment](https://github.com/rust-lang/rust/issues/110897#issuecomment-1525738849). This allows using `OnceCell` for the lazy initialization of TLS variables, which panics on reentrant initialization instead of updating the value like TLS variables currently do. ``@rustbot`` label +T-libs-api r? ``@m-ou-se``