about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2022-10-16Eliminate 280-byte memset from ReadDir iteratorDavid Tolnay-20/+65
2022-10-16Support DirEntry metadata calls in miriAlex Saveau-2/+8
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-10-15Stabilize `main_separator_str`Alex Saveau-1/+1
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-10-15Auto merge of #100579 - joboet:sync_mutex_everywhere, r=thomccbors-123/+47
std: use `sync::Mutex` for internal statics Since `sync::Mutex` is now `const`-constructible, it can be used for internal statics, removing the need for `sys_common::StaticMutex`. This adds some extra allocations on platforms which need to box their mutexes (currently SGX and some UNIX), but these will become unnecessary with the lock improvements tracked in #93740. I changed the program argument implementation on Hermit, it does not need `Mutex` but can use atomics like some UNIX systems (ping `@mkroening` `@stlankes).`
2022-10-15Stabilize `duration_checked_float`Ryan Lopopolo-3/+2
Tracking issue: - https://github.com/rust-lang/rust/issues/83400
2022-10-15Rollup merge of #102773 - joboet:apple_parker, r=thomccDylan DPC-1/+165
Use semaphores for thread parking on Apple platforms Currently we use a mutex-condvar pair for thread parking on Apple systems. Unfortunately, `pthread_cond_timedwait` uses the real-time clock for measuring time, which causes problems when the system time changes. The parking implementation in this PR uses a semaphore instead, which measures monotonic time by default, avoiding these issues. As a further benefit, this has the potential to improve performance a bit, since `unpark` does not need to wait for a lock to be released. Since the Mach semaphores are poorly documented (I could not find availability or stability guarantees for instance), this uses a [dispatch semaphore](https://developer.apple.com/documentation/dispatch/dispatch_semaphore?language=objc) instead. While it adds a layer of indirection (it uses Mach semaphores internally), the overhead is probably negligible. Tested on macOS 12.5. r? ``````@thomcc``````
2022-10-15Auto merge of #98033 - joshtriplett:is-terminal-fd-handle, r=thomccbors-1/+158
Add `IsTerminal` trait to determine if a descriptor or handle is a terminal The UNIX implementation uses `isatty`. The Windows implementation uses the same logic the `atty` crate uses, including the hack needed to detect msys terminals. Implement this trait for `Stdin`/`Stdout`/`Stderr`/`File` on all platforms. On Unix, implement it for `BorrowedFd`/`OwnedFd`. On Windows, implement it for `BorrowedHandle`/`OwnedHandle`. Based on https://github.com/rust-lang/rust/pull/91121 Co-authored-by: Matt Wilkinson <mattwilki17@gmail.com>
2022-10-15Use Align8 to avoid misalignment if the allocator or Vec doesn't align ↵Josh Triplett-7/+7
allocations
2022-10-15Rewrite FILE_NAME_INFO handling to avoid enlarging slice referenceJosh Triplett-4/+4
Rather than referencing a slice's pointer and then creating a new slice with a longer length, offset from the base structure pointer instead. This makes some choices of Rust semantics happier.
2022-10-15Make is_terminal fail fast if a process has no console at allJosh Triplett-1/+9
If a process has no console, it'll have NULL in place of a console handle, so return early with `false` in that case without making any OS calls.
2022-10-15Add `IsTerminal` trait to determine if a descriptor or handle is a terminalJosh Triplett-0/+149
The UNIX and WASI implementations use `isatty`. The Windows implementation uses the same logic the `atty` crate uses, including the hack needed to detect msys terminals. Implement this trait for `File` and for `Stdin`/`Stdout`/`Stderr` and their locked counterparts on all platforms. On UNIX and WASI, implement it for `BorrowedFd`/`OwnedFd`. On Windows, implement it for `BorrowedHandle`/`OwnedHandle`. Based on https://github.com/rust-lang/rust/pull/91121 Co-authored-by: Matt Wilkinson <mattwilki17@gmail.com>
2022-10-14Rollup merge of #103067 - Nilstrieb:tidy-likes-the-alphabet, r=jackh726Matthias Krüger-1/+2
More alphabetical sorting Sort and enforce a few more things. The biggest change here is sorting all target features.
2022-10-14Rollup merge of #103017 - fortanix:raoul/sgx_tls_fix, r=ChrisDentonMatthias Krüger-0/+1
Avoid dropping TLS Key on sgx #102655 reenabled dropping thread local `Key` on every platform ([library/std/src/sys_common/thread_local_key.rs](https://github.com/rust-lang-ci/rust/commit/fa0ca783f89a83046e6ce0383385ba5b28296435#diff-5cb9acf9e243f35c975fa9fbac4885519dc104626bc03610dfa7a20bc79641ceL237-R215)). That's causing problems at least for sgx. cc: `@jethrogb` `@ChrisDenton`
2022-10-14Rollup merge of #102781 - StackOverflowExcept1on:master, r=joshtriplettMatthias Krüger-1/+2
Improved documentation for `std::io::Error`
2022-10-14Add some tidy-alphabeticalnils-1/+2
2022-10-14Auto merge of #102783 - RalfJung:tls, r=thomccbors-12/+27
sync thread_local key conditions exactly with what the macro uses This makes the `cfg` in `mod.rs` syntactically the same as those in `local.rs`. I don't think this should actually change anything, but seems better to be consistent? I looked into this due to https://github.com/rust-lang/rust/issues/102549, but this PR would make it *less* likely that `__OsLocalKeyInner` is going to get provided, so this cannot help with that issue. r? `@thomcc`
2022-10-14Bugfix: keep TLS data in syncRaoul Strackx-0/+1
2022-10-14Fix `checked_{add,sub}_duration` incorrectly returning `None` when `other` ↵beetrees-24/+35
has more than `i64::MAX` seconds
2022-10-14Tweak grammarJosh Triplett-1/+1
2022-10-14Rollup merge of #103018 - Rageking8:more-dupe-word-typos, r=TaKO8KiDylan DPC-2/+2
More dupe word typos I only picked those changes (from the regex search) that I am pretty certain doesn't change meaning and is just a typo fix. Do correct me if any fix is undesirable and I can revert those. Thanks.
2022-10-14Rollup merge of #102847 - joshtriplett:bugfix-impl-fd-traits-for-io-types, ↵Dylan DPC-98/+54
r=m-ou-se impl AsFd and AsRawFd for io::{Stdin, Stdout, Stderr}, not the sys versions https://github.com/rust-lang/rust/pull/100892 implemented AsFd for the sys versions, rather than for the public types. Change the implementations to apply to the public types.
2022-10-14more dupe word typosRageking8-2/+2
2022-10-13Rollup merge of #102854 - semarie:openbsd-immutablestack, r=m-ou-seDylan DPC-0/+10
openbsd: don't reallocate a guard page on the stack. the kernel currently enforce that a stack is immutable. calling mmap(2) or mprotect(2) to change it will result in EPERM, which generate a panic!(). so just do like for Linux, and trust the kernel to do the right thing.
2022-10-13smarter way to avoid 'unused' warning when building for testsRalf Jung-9/+2
2022-10-13sync thread_local key conditions exactly with what the macro usesRalf Jung-10/+32
2022-10-13std: use `sync::Mutex` for internal staticsjoboet-123/+47
2022-10-13Auto merge of #102655 - joboet:windows_tls_opt, r=ChrisDentonbors-117/+202
Optimize TLS on Windows This implements the suggestion in the current TLS code to embed the linked list of destructors in the `StaticKey` structure to save allocations. Additionally, locking is avoided when no destructor needs to be run. By using one Windows-provided `Once` per key instead of a global lock, locking is more finely-grained (this unblocks #100579).
2022-10-13kmc-solid: Handle errors returned by `SOLID_FS_ReadDir`Tomoaki Kawada-8/+12
2022-10-13Auto merge of #102995 - JohnTitor:rollup-yomkwge, r=JohnTitorbors-2/+2
Rollup of 7 pull requests Successful merges: - #102641 (Support casting boxes to dyn*) - #102836 (rustc_target: Fix json target specs using LLD linker flavors in link args) - #102949 (should-skip-this: add missing backslash) - #102967 (Add test for issue 102964) - #102971 (tidy: error if a lang feature is already present) - #102974 (Fix small word dupe typos) - #102980 (rustdoc: merge separate `.item-info` CSS) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-10-13Auto merge of #102372 - abrown:issue-102157, r=thomccbors-9/+28
Allow compiling the `wasm32-wasi` std library with atomics The issue #102157 demonstrates how currently the `-Z build-std` option will fail when re-compiling the standard library with `RUSTFLAGS` like `RUSTFLAGS="-C target-feature=+atomics,+bulk-memory -C link-args=--shared-memory"`. This change attempts to resolve those build issues by depending on the the WebAssembly `futex` module and providing an implementation for `env_lock`. Fixes #102157.
2022-10-13fix small word dupe typosRageking8-2/+2
2022-10-12Auto merge of #102460 - flba-eb:fix_85261_prevent_alloc_after_fork, r=thomccbors-4/+23
Prevent UB in child process after calling libc::fork After calling libc::fork, the child process tried to access a TLS variable when processing a panic. This caused a memory allocation which is UB in the child. To prevent this from happening, the panic handler will not access the TLS variable in case `panic::always_abort` was called before. Fixes #85261 (not only on Android systems, but also on Linux/QNX with TLS disabled, see issue for more details) Main drawbacks of this fix: * Panic messages can incorrectly omit `core::panic::PanicInfo` struct in case several panics (of multiple threads) occur at the same time. The handler cannot distinguish between multiple panics in different threads or recursive ones in the same thread, but the message will contain a hint about the uncertainty. * `panic_count::increase()` will be a bit slower as it has an additional `if`, but this should be irrelevant as it is only called in case of a panic.
2022-10-12Rollup merge of #102811 - the8472:bufread-memset, r=m-ou-seDylan DPC-3/+6
Use memset to initialize readbuf The write loop was found to be slow in #102727 The proper fix is in #102760 but this might still help debug builds and code running under miri by using the write_bytes intrinsic instead of writing one byte at a time.
2022-10-11fix: return type of single-threaded dummy lock must be droppableAndrew Brown-2/+2
2022-10-11Rollup merge of #102869 - azdavis:master, r=joshtriplettMatthias Krüger-0/+2
Add basename and dirname aliases Users might be used to the POSIX names of these functions. In fact, here's a [blog post][1] about this very thing. [1]: https://boinkor.net/2019/07/basename-and-dirname-in-rust/
2022-10-11Rollup merge of #102685 - nbdd0121:unwind, r=m-ou-seMatthias Krüger-3/+2
Interpret EH actions properly The EH actions stored in the LSDA follows the format of GCC except table (even for LLVM-generated code). An missing action in the table is the encoding for `Terminate`, see https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/libsupc%2B%2B/eh_personality.cc#L522-L526. The currently code interprets it as `None`, as a workaround for #35011, an issue that seems to occur in LLVM 3.7 and not after 3.9. These are very old versions of LLVM and we don't support them anymore, so remove this workaround and interpret them properly. Note that LLVM currently does not emit any `Terminate` actions, but GCC does. Although GCC backend currently doesn't do unwinding, removing it preemptively would prevent future developers from wasting time to figure out what's wrong. ``@rustbot`` label: +T-compiler
2022-10-11Rollup merge of #102227 - devnexen:solarish_get_path, r=m-ou-seMatthias Krüger-2/+9
fs::get_path solarish version. similar to linux, albeit there is no /proc/self notion on solaris based system thus flattening the difference for simplification sake.
2022-10-11Rollup merge of #102625 - Rageking8:fix-backtrace-small-typo, r=m-ou-seYuki Okushi-3/+3
fix backtrace small typo
2022-10-11Rollup merge of #102589 - RalfJung:scoped-threads-dangling, r=m-ou-seYuki Okushi-0/+33
scoped threads: pass closure through MaybeUninit to avoid invalid dangling references The `main` function defined here looks roughly like this, if it were written as a more explicit stand-alone function: ```rust // Not showing all the `'lifetime` tracking, the point is that // this closure might live shorter than `thread`. fn thread(control: ..., closure: impl FnOnce() + 'lifetime) { closure(); control.signal_done(); // A lot of time can pass here. } ``` Note that `thread` continues to run even after `signal_done`! Now consider what happens if the `closure` captures a reference of lifetime `'lifetime`: - The type of `closure` is a struct (the implicit unnameable closure type) with a `&'lifetime mut T` field. References passed to a function are marked with `dereferenceable`, which is LLVM speak for *this reference will remain live for the entire duration of this function*. - The closure runs, `signal_done` runs. Then -- potentially -- this thread gets scheduled away and the main thread runs, seeing the signal and returning to the user. Now `'lifetime` ends and the memory the reference points to might be deallocated. - Now we have UB! The reference that as passed to `thread` with the promise of remaining live for the entire duration of the function, actually got deallocated while the function still runs. Oops. Long-term I think we should be able to use `ManuallyDrop` to fix this without `unsafe`, or maybe a new `MaybeDangling` type. I am working on an RFC for that. But in the mean time it'd be nice to fix this so that Miri with `-Zmiri-retag-fields` (which is needed for "full enforcement" of all the LLVM flags we generate) stops erroring on scoped threads. Fixes https://github.com/rust-lang/rust/issues/101983 r? `@m-ou-se`
2022-10-11Rollup merge of #102412 - joboet:dont_panic, r=m-ou-seYuki Okushi-2/+20
Never panic in `thread::park` and `thread::park_timeout` fixes #102398 `@rustbot` label +T-libs +T-libs-api
2022-10-11Rollup merge of #102277 - mgeisler:rwlock, r=m-ou-seYuki Okushi-31/+32
Consistently write `RwLock` Before the documentation sometimes referred to an "rwlock" and sometimes to "`RwLock`".
2022-10-10Do not alias for fsAriel Davis-1/+0
2022-10-10Implement `env_lock` with `RwLock`Andrew Brown-12/+23
Copying the approach of the Unix target, this change uses the standard `RwLock` to protect against concurrent access of libc's environment. This locking is only enabled when WebAssembly's `atomics` feature is also enabled.
2022-10-10Allow compiling the `wasm32-wasi` std library with atomicsAndrew Brown-3/+11
The issue #102157 demonstrates how currently the `-Z build-std` option will fail when re-compiling the standard library with `RUSTFLAGS` like `RUSTFLAGS="-C target-feature=+atomics,+bulk-memory -C link-args=--shared-memory"`. This change attempts to resolve those build issues by depending on the the WebAssembly `futex` module and providing an implementation for `env_lock`. Fixes #102157.
2022-10-10Consolidate AsFd instances for stdio types into `library/std/src/os/fd/owned.rs`Josh Triplett-98/+54
2022-10-10Rollup merge of #102794 - dtolnay:termination, r=thomccDylan DPC-9/+24
Make tests capture the error printed by a Result return An error returned by tests previously would get written directly to stderr, instead of to the capture buffer set up by the test harness. This PR makes it write to the capture buffer so that it can be integrated as part of the test output by build tools such as `buck test`, since being able to read the error message returned by a test is pretty critical to debugging why the test failed. <br> **Before:** ```rust // tests/test.rs #[test] fn test() -> Result<(), &'static str> { println!("STDOUT"); eprintln!("STDERR"); Err("RESULT") } ``` ```console $ cargo build --test test $ target/debug/deps/test-???????????????? -Z unstable-options --format=json { "type": "suite", "event": "started", "test_count": 1 } { "type": "test", "event": "started", "name": "test" } Error: "RESULT" { "type": "test", "name": "test", "event": "failed", "stdout": "STDOUT\nSTDERR\n" } { "type": "suite", "event": "failed", "passed": 0, "failed": 1, "ignored": 0, "measured": 0, "filtered_out": 0, "exec_time": 0.00040313 } ``` **After:** ```console $ target/debug/deps/test-???????????????? -Z unstable-options --format=json { "type": "suite", "event": "started", "test_count": 1 } { "type": "test", "event": "started", "name": "test" } { "type": "test", "name": "test", "event": "failed", "stdout": "STDOUT\nSTDERR\nError: \"RESULT\"" } { "type": "suite", "event": "failed", "passed": 0, "failed": 1, "ignored": 0, "measured": 0, "filtered_out": 0, "exec_time": 0.000261894 } ```
2022-10-09Add basename and dirname aliasesAriel Davis-0/+3
2022-10-09Auto merge of #102850 - JohnTitor:rollup-lze1w03, r=JohnTitorbors-2/+16
Rollup of 8 pull requests Successful merges: - #101118 (fs::get_mode enable getting the data via fcntl/F_GETFL on major BSD) - #102072 (Add `ptr::Alignment` type) - #102799 (rustdoc: remove hover gap in file picker) - #102820 (Show let-else suggestion on stable.) - #102829 (rename `ImplItemKind::TyAlias` to `ImplItemKind::Type`) - #102831 (Don't use unnormalized type in `Ty::fn_sig` call in rustdoc `clean_middle_ty`) - #102834 (Remove unnecessary `lift`/`lift_to_tcx` calls from rustdoc) - #102838 (remove cfg(bootstrap) from Miri) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-10-09impl AsFd for io::{Stdin, Stdout, Stderr}, not the sys versionsJosh Triplett-3/+3
https://github.com/rust-lang/rust/pull/100892 implemented AsFd for the sys versions, rather than for the public types. Change the implementations to apply to the public types.
2022-10-09openbsd: don't reallocate a guard page on the stack.Sébastien Marie-0/+10
the kernel currently enforce that a stack is immutable. calling mmap(2) or mprotect(2) to change it will result in EPERM, which generate a panic!(). so just do like for Linux, and trust the kernel to do the right thing.