about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
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.
2022-10-10Rollup merge of #101118 - devnexen:fs_getmode_bsd, r=Mark-SimulacrumYuki Okushi-2/+16
fs::get_mode enable getting the data via fcntl/F_GETFL on major BSD supporting this flag.
2022-10-09Auto merge of #93668 - SUPERCILEX:path_alloc, r=joshtriplettbors-286/+394
Reduce CString allocations in std as much as possible Currently, every operation involving paths in `fs` allocates memory to hold the path before sending it through the syscall. This PR instead uses a stack allocation (chosen size is somewhat arbitrary) when the path is short before falling back to heap allocations for long paths. Benchmarks show that the stack allocation is ~2x faster for short paths: ``` test sys::unix::fd::tests::bench_heap_path_alloc ... bench: 34 ns/iter (+/- 2) test sys::unix::fd::tests::bench_stack_path_alloc ... bench: 15 ns/iter (+/- 1) ``` For long paths, I couldn't find any measurable difference. --- I'd be surprised if I was the first to think of this, so I didn't fully flush out the PR. If this change is desirable, I'll make use of `run_with_cstr` across all platforms in every fs method (currently just unix open for testing). I also added an `impl From<FromBytesWithNulError>` which is presumably a no-no (or at least needs to be done in another PR). --- Also see https://github.com/nix-rust/nix/pull/1655 with a bunch of discussion where I'm doing something similar.
2022-10-08Rollup merge of #102812 - est31:remove_lazy, r=dtolnayMichael Howell-4/+0
Remove empty core::lazy and std::lazy PR #98165 with commits 7c360dc117d554a11f7193505da0835c4b890c6f and c1a2db3372a4d6896744919284f3287650a38ab7 has moved all of the components of these modules into different places, namely {std,core}::sync and {std,core}::cell. The empty modules remained. As they are unstable, we can simply remove them.
2022-10-08std: optimize TLS on Windowsjoboet-117/+202
2022-10-08Remove empty core::lazy and std::lazyest31-4/+0
PR #98165 with commits 7c360dc117d554a11f7193505da0835c4b890c6f and c1a2db3372a4d6896744919284f3287650a38ab7 has moved all of the components of these modules into different places, namely {std,core}::sync and {std,core}::cell. The empty modules remained. As they are unstable, we can simply remove them.
2022-10-08use memset to initialize a readbufThe 8472-3/+6
2022-10-08std: do not use dispatch semaphore under miri (yet)joboet-5/+8
2022-10-08std: remove unused linker attributejoboet-1/+1
2022-10-08Auto merge of #99505 - joboet:futex_once, r=thomccbors-289/+483
std: use futex in `Once` Now that we have efficient locks, let's optimize the rest of `sync` as well. This PR adds a futex-based implementation for `Once`, which drastically simplifies the implementation compared to the generic version, which is provided as fallback for platforms without futex (Windows only supports them on newer versions, so it uses the fallback for now). Instead of storing a linked list of waiters, the new implementation adds another state (`QUEUED`), which is set when there are waiting threads. These now use `futex_wait` on that state and are woken by the running thread when it finishes and notices the `QUEUED` state, thereby avoiding unnecessary calls to `futex_wake_all`.
2022-10-07Make tests capture the error printed by a Result returnDavid Tolnay-9/+24
2022-10-07Rollup merge of #102760 - saethlin:dont-reinit-buffer, r=Mark-SimulacrumDylan DPC-3/+48
Avoid repeated re-initialization of the BufReader buffer Fixes https://github.com/rust-lang/rust/issues/102727 We accidentally removed this in https://github.com/rust-lang/rust/pull/98748. It looks so redundant. But it isn't. The default `Read::read_buf` will defensively initialize the whole buffer, if any of it is indicated to be uninitialized. In uses where reads from the wrapped `Read` impl completely fill the `BufReader`, `initialized` and `filled` are the same, and this extra member isn't required. But in the reported issue, the `BufReader` wraps a `Read` impl which will _never_ fill the whole buffer. So the default `Read::read_buf` implementation repeatedly re-initializes the extra space in the buffer. This adds back the extra `initialized` member, which ensures that the default `Read::read_buf` only zero-initialized the buffer once, and I've tried to add a comment which explains this whole situation.
2022-10-07Rollup merge of #102475 - RalfJung:unsafe, r=dtolnayDylan DPC-31/+120
unsafe keyword: trait examples and unsafe_op_in_unsafe_fn update Having a safe `fn` in an `unsafe trait` vs an `unsafe fn` in a safe `trait` are pretty different situations, but the distinction is subtle and can confuse even seasoned Rust developers. So let's have explicit examples of both. I also removed the existing `unsafe trait` example since it was rather strange. Also the `unsafe_op_in_unsafe_fn` lint can help disentangle the two sides of `unsafe`, so update the docs to account for that.
2022-10-07review feedbackRalf Jung-42/+43
2022-10-07Improved documentation for `std::io::Error`StackOverflowExcept1on-1/+2
2022-10-07std: use futex in `Once`joboet-289/+483
2022-10-06Don't needless link to `libresolv` on Darwin in libstdThom Chiovoloni-4/+0
2022-10-06Avoid defensive re-initialization of the BufReader bufferBen Kimock-3/+48
2022-10-06std: add thread parking testsjoboet-0/+22
2022-10-06std: use semaphore for thread parking on Apple platformsjoboet-1/+140
2022-10-06Auto merge of #99497 - vladimir-ea:stdlib_os_api_watchos, r=thomccbors-0/+235
Standard library OS support for Apple WatchOS This PR was split from https://github.com/rust-lang/rust/pull/98101
2022-10-06Fix whitespaceFlorian Bartels-2/+2
2022-10-06Prevent UB in child process after calling libc::forkFlorian Bartels-4/+23
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.
2022-10-06Rollup merge of #102693 - BlackHoleFox:revert-apple-entropy-changes, r=thomccMatthias Krüger-56/+38
Revert "Use getentropy when possible on all Apple platforms" Per https://github.com/rust-lang/rust/issues/102643, This reverts commit 3fc35b5b935e390c61ea2bbf744838b2632b2df1 to avoid breaking any Rust on iOS users. Closes https://github.com/rust-lang/rust/issues/102643
2022-10-05tidyIbraheem Ahmed-2/+2
Co-authored-by: yvt <i@yvt.jp>
2022-10-05Revert "Use getentropy when possible on all Apple platforms"BlackHoleFox-56/+38
This reverts commit 3fc35b5b935e390c61ea2bbf744838b2632b2df1.
2022-10-04Rollup merge of #102574 - aDotInTheVoid:const_collections_with_hasher, ↵Michael Howell-2/+17
r=oli-obk,fee1-dead Make Hash{Set,Map}::with_hasher unstably const Makes [`HashMap::with_hasher`](https://doc.rust-lang.org/stable/std/collections/hash_map/struct.HashMap.html#method.with_hasher) and [`HashSet::with_hasher`](https://doc.rust-lang.org/stable/std/collections/hash_set/struct.HashSet.html#method.with_hasher) `const`. This allows ```rust static GlobalState: Mutex<HashMap<i32, i32, SomeHasher>> = Mutex::new(HashMap::with_hasher(SomeHasher::new())) ``` Tracking issue: #102575
2022-10-05Interpret EH actions properlyGary Guo-3/+2
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 [1]. 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. [1]: https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/libsupc%2B%2B/eh_personality.cc#L522-L526