about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2022-03-05Add tracking issue number for local_key_cell_methods.Mara Bos-9/+9
2022-03-05Rename LocalKey's with_{ref,mut} to with_borrow{,_mut}.Mara Bos-9/+9
2022-03-05Implement RFC 3184 - thread local cell methods.Mara Bos-10/+348
2022-03-05Auto merge of #94546 - JmPotato:std-features-cleanup, r=m-ou-sebors-23/+0
Clean up the std library's #![feature]s Signed-off-by: JmPotato <ghzpotato@gmail.com> This is part of https://github.com/rust-lang/rust/issues/87766. r? `@m-ou-se`
2022-03-05Rollup merge of #94446 - rusticstuff:remove_dir_all-illumos-fix, r=cuviperDylan DPC-131/+74
UNIX `remove_dir_all()`: Try recursing first on the slow path This only affects the _slow_ code path - if there is no `dirent.d_type` or if it is `DT_UNKNOWN`. POSIX specifies that calling `unlink()` or `unlinkat(..., 0)` on a directory is allowed to succeed: > The _path_ argument shall not name a directory unless the process has appropriate privileges and the implementation supports using _unlink()_ on directories. This however can cause dangling inodes requiring an fsck e.g. on Illumos UFS, so we have to avoid that in the common case. We now just try to recurse into it first and unlink() if we can't open it as a directory. The other two commits integrate the Macos x86-64 implementation reducing redundancy. Split into two commits for better reviewing. Fixes #94335.
2022-03-05Clean up the std library's #![feature]sJmPotato-23/+0
Signed-off-by: JmPotato <ghzpotato@gmail.com>
2022-03-05Auto merge of #94628 - Dylan-DPC:rollup-v2slupe, r=Dylan-DPCbors-4/+1
Rollup of 5 pull requests Successful merges: - #94362 (Add well known values to `--check-cfg` implementation) - #94577 (only disable SIMD for doctests in Miri (not for the stdlib build itself)) - #94595 (Fix invalid `unresolved imports` errors for a single-segment import) - #94596 (Delay bug in expr adjustment when check_expr is called multiple times) - #94618 (Don't round stack size up for created threads in Windows) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-03-04Rollup merge of #94618 - lewisclark:remove-stack-size-rounding, r=yaahcDylan DPC-4/+1
Don't round stack size up for created threads in Windows Fixes #94454 Windows does the rounding itself, so there isn't a need to explicity do the rounding beforehand, as mentioned by ```@ChrisDenton``` in #94454 > The operating system rounds up the specified size to the nearest multiple of the system's allocation granularity (typically 64 KB). To retrieve the allocation granularity of the current system, use the [GetSystemInfo](https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getsysteminfo) function. https://docs.microsoft.com/en-us/windows/win32/procthread/thread-stack-size
2022-03-04Auto merge of #94298 - Urgau:rustbuild-check-cfg, r=Mark-Simulacrumbors-0/+3
Enable conditional compilation checking on the Rust codebase This pull-request enable conditional compilation checking on every rust project build by the `bootstrap` tool. To be more specific, this PR only enable well known names checking + extra names (bootstrap, parallel_compiler, ...). r? `@Mark-Simulacrum`
2022-03-04Don't round stack size up for created threadsLewis Clark-4/+1
2022-03-04Rollup merge of #94549 - m-ou-se:thread-is-finished, r=yaahcMatthias Krüger-14/+22
Rename JoinHandle::is_running to is_finished. This is renaming `is_running` to `is_finished` as discussed on the tracking issue here: https://github.com/rust-lang/rust/issues/90470#issuecomment-1050188499 Taking some of the docs suggestions from https://github.com/rust-lang/rust/pull/94033
2022-03-04Rollup merge of #94236 - reez12g:add_track_caller_87707, r=yaahcMatthias Krüger-0/+2
Add #[track_caller] to track callers when initializing poisoned Once This PR is for this Issue. https://github.com/rust-lang/rust/issues/87707 With this fix, we expect to be able to track the caller when poisoned Once is initialized.
2022-03-04Remove redundant code for handling NULL handles on Windows.Dan Gohman-13/+0
Before calling `CreateProcessW`, stdio handles are passed through `stdio::get_handle`, which already converts NULL to `INVALID_HANDLE_VALUE`, so we don't need extra checks for NULL after that point.
2022-03-04Fix a compilation error.Dan Gohman-1/+1
2022-03-04Consistently present absent stdio handles on Windows as NULL handles.Dan Gohman-16/+113
This addresses #90964 by making the std API consistent about presenting absent stdio handles on Windows as NULL handles. Stdio handles may be absent due to `#![windows_subsystem = "windows"]`, due to the console being detached, or due to a child process having been launched from a parent where stdio handles are absent. Specifically, this fixes the case of child processes of parents with absent stdio, which previously ended up with `stdin().as_raw_handle()` returning `INVALID_HANDLE_VALUE`, which was surprising, and which overlapped with an unrelated valid handle value. With this patch, `stdin().as_raw_handle()` now returns null in these situation, which is consistent with what it does in the parent process. And, document this in the "Windows Portability Considerations" sections of the relevant documentation.
2022-03-04Integrate macos x86-64 remove_dir_all() impl. Step 2: readdHans Kratz-6/+60
2022-03-04Integrate macos x86-64 remove_dir_all() impl. Step 1: removeHans Kratz-118/+0
2022-03-04remove_dir_all(): try recursing first instead of trying to unlink()Hans Kratz-15/+22
This only affects the `slow` code path, if there is no `dirent.d_type` or if the type is `DT_UNKNOWN`. POSIX specifies that calling `unlink()` or `unlinkat(..., 0)` on a directory can succeed: > "The _path_ argument shall not name a directory unless the process has > appropriate privileges and the implementation supports using _unlink()_ on > directories." This however can cause orphaned directories requiring an fsck e.g. on Illumos UFS, so we have to avoid that in the common case. We now just try to recurse into it first and unlink() if we can't open it as a directory.
2022-03-04Use '_ for irrelevant lifetimes in Debug impl.Mara Bos-1/+1
Co-authored-by: Daniel Henry-Mantilla <daniel.henry.mantilla@gmail.com>
2022-03-04Add #![allow(unexpected_cfgs)] in preparation of global --check-cfgLoïc BRANSTETT-0/+3
2022-03-03Add #[track_caller] to track callers when initializing poisoned Oncereez12g-0/+2
2022-03-04Rollup merge of #94572 - sunfishcode:sunfishcode/handle-or, r=joshtriplettDylan DPC-17/+22
Use `HandleOrNull` and `HandleOrInvalid` in the Windows FFI bindings. Use the new `HandleOrNull` and `HandleOrInvalid` types that were introduced as part of [I/O safety] in a few functions in the Windows FFI bindings. This factors out an `unsafe` block and two `unsafe` function calls in the Windows implementation code. And, it helps test `HandleOrNull` and `HandleOrInvalid`, and indeed, it turned up a bug: `OwnedHandle` also needs to be `#[repr(transparent)]`, as it's used inside of `HandleOrNull` and `HandleOrInvalid` which are also `#[repr(transparent)]`. r? ```@joshtriplett``` [I/O safety]: https://github.com/rust-lang/rust/issues/87074
2022-03-04Rollup merge of #93965 - Mark-Simulacrum:owned-stdio, r=dtolnayDylan DPC-228/+18
Make regular stdio lock() return 'static handles This also deletes the unstable API surface area previously added to expose this functionality on new methods rather than built into the current set. Closes #86845 (tracking issue for unstable API needed without this) r? ``````@dtolnay`````` to kick off T-libs-api FCP
2022-03-04Rollup merge of #88805 - krhancoc:master, r=dtolnayDylan DPC-0/+4
Clarification of default socket flags This PR outlines the decision to disable inheritance of socket objects when possible to child processes in the documentation.
2022-03-03Use `HandleOrNull` and `HandleOrInvalid` in the Windows FFI bindings.Dan Gohman-17/+22
Use the new `HandleOrNull` and `HandleOrInvalid` types that were introduced as part of [I/O safety] in a few functions in the Windows FFI bindings. This factors out an `unsafe` block and two `unsafe` function calls in the Windows implementation code. And, it helps test `HandleOrNull` and `HandleOrInvalid`, which indeed turned up a bug: `OwnedHandle` also needs to be `#[repr(transparent)]`, as it's used inside of `HandleOrNull` and `HandleOrInvalid` which are also `#[repr(transparent)]`. [I/O safety]: https://github.com/rust-lang/rust/issues/87074
2022-03-03Rollup merge of #92697 - the8472:cgroups, r=joshtriplettMatthias Krüger-4/+86
Use cgroup quotas for calculating `available_parallelism` Automated tests for this are possible but would require a bunch of assumptions. It requires root + a recent kernel, systemd and maybe docker. And even then it would need a helper binary since the test has to run in a separate process. Limitations * only supports cgroup v2 and assumes it's mounted under `/sys/fs/cgroup` * procfs must be available * the quota gets mixed into `sched_getaffinity`, so if the latter doesn't work then quota information gets ignored too Manually tested via ``` // spawn a new cgroup scope for the current user $ sudo systemd-run -p CPUQuota="300%" --uid=$(id -u) -tdS // quota.rs #![feature(available_parallelism)] fn main() { println!("{:?}", std::thread::available_parallelism()); // prints Ok(3) } ``` strace: ``` sched_getaffinity(3041643, 32, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47]) = 32 openat(AT_FDCWD, "/proc/self/cgroup", O_RDONLY|O_CLOEXEC) = 3 statx(0, NULL, AT_STATX_SYNC_AS_STAT, STATX_ALL, NULL) = -1 EFAULT (Bad address) statx(3, "", AT_STATX_SYNC_AS_STAT|AT_EMPTY_PATH, STATX_ALL, {stx_mask=STATX_BASIC_STATS|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0444, stx_size=0, ...}) = 0 lseek(3, 0, SEEK_CUR) = 0 read(3, "0::/system.slice/run-u31477.serv"..., 128) = 36 read(3, "", 92) = 0 close(3) = 0 statx(AT_FDCWD, "/sys/fs/cgroup/system.slice/run-u31477.service/cgroup.controllers", AT_STATX_SYNC_AS_STAT, STATX_ALL, {stx_mask=STATX_BASIC_STATS|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0444, stx_size=0, ...}) = 0 openat(AT_FDCWD, "/sys/fs/cgroup/system.slice/run-u31477.service/cpu.max", O_RDONLY|O_CLOEXEC) = 3 statx(3, "", AT_STATX_SYNC_AS_STAT|AT_EMPTY_PATH, STATX_ALL, {stx_mask=STATX_BASIC_STATS|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0644, stx_size=0, ...}) = 0 lseek(3, 0, SEEK_CUR) = 0 read(3, "300000 100000\n", 20) = 14 read(3, "", 6) = 0 close(3) = 0 openat(AT_FDCWD, "/sys/fs/cgroup/system.slice/cpu.max", O_RDONLY|O_CLOEXEC) = 3 statx(3, "", AT_STATX_SYNC_AS_STAT|AT_EMPTY_PATH, STATX_ALL, {stx_mask=STATX_BASIC_STATS|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0644, stx_size=0, ...}) = 0 lseek(3, 0, SEEK_CUR) = 0 read(3, "max 100000\n", 20) = 11 read(3, "", 9) = 0 close(3) = 0 openat(AT_FDCWD, "/sys/fs/cgroup/cpu.max", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) sched_getaffinity(0, 128, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47]) = 40 ``` r? ```````@joshtriplett``````` cc ```````@yoshuawuyts``````` Tracking issue and previous discussion: #74479
2022-03-03Add -Z oom={panic,abort} command-line optionAmanieu d'Antras-1/+15
2022-03-03Remove argument from closure in thread::Scope::spawn.Mara Bos-21/+23
2022-03-03Remove unnecessary #![feature]s from doctest.Mara Bos-2/+0
2022-03-03Update test.Mara Bos-4/+4
2022-03-03Rename JoinHandle::is_running to is_finished and update docs.Mara Bos-8/+18
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2022-03-03Rollup merge of #94534 - bstrie:cffistd, r=Mark-SimulacrumMatthias Krüger-0/+10
Re-export (unstable) core::ffi types from std::ffi
2022-03-03Rollup merge of #93562 - sunfishcode:sunfishcode/io-docs, r=joshtriplettMatthias Krüger-72/+111
Update the documentation for `{As,Into,From}Raw{Fd,Handle,Socket}`. This change weakens the descriptions of the `{as,into,from}_raw_{fd,handle,socket}` descriptions from saying that they *do* express ownership relations to say that they are *typically used* in ways that express ownership relations. This is needed since, for example, std's own [`RawFd`] implements `{As,From,Into}Fd` without any of the ownership relationships. This adds proper `# Safety` comments to `from_raw_{fd,handle,socket}`, adds the requirement that raw handles be not opened with the `FILE_FLAG_OVERLAPPED` flag, and merges the `OwnedHandle::from_raw_handle` comment into the main `FromRawHandle::from_raw_handle` comment. And, this changes `HandleOrNull` and `HandleOrInvalid` to not implement `FromRawHandle`, since they are intended for limited use in FFI situations, and not for generic use, and they have constraints that are stronger than the those of `FromRawHandle`. [`RawFd`]: https://doc.rust-lang.org/stable/std/os/unix/io/type.RawFd.html
2022-03-02Remove the comment about `FILE_FLAG_OVERLAPPED`.Dan Gohman-2/+0
There may eventually be something to say about `FILE_FLAG_OVERLAPPED` here, however this appears to be independent of the other changes in this PR, so remove them from this PR so that it can be discussed separately.
2022-03-03Rollup merge of #93663 - sunfishcode:sunfishcode/as-raw-name, r=joshtriplettDylan DPC-25/+62
Rename `BorrowedFd::borrow_raw_fd` to `BorrowedFd::borrow_raw`. Also, rename `BorrowedHandle::borrow_raw_handle` and `BorrowedSocket::borrow_raw_socket` to `BorrowedHandle::borrow_raw` and `BorrowedSocket::borrow_raw`. This is just a minor rename to reduce redundancy in the user code calling these functions, and to eliminate an inessential difference between `BorrowedFd` code and `BorrowedHandle`/`BorrowedSocket` code. While here, add a simple test exercising `BorrowedFd::borrow_raw_fd`. r? ``````@joshtriplett``````
2022-03-03Rollup merge of #93354 - ↵Dylan DPC-0/+12
sunfishcode:sunfishcode/document-borrowedfd-toowned, r=joshtriplett Add documentation about `BorrowedFd::to_owned`. Following up on #88564, this adds documentation explaining why `BorrowedFd::to_owned` returns another `BorrowedFd` rather than an `OwnedFd`. And similar for `BorrowedHandle` and `BorrowedSocket`. r? `````@joshtriplett`````
2022-03-03update available_parallelism docs since cgroups and sched_getaffinity are ↵The 8472-1/+4
now taken into account
2022-03-03hardcode /sys/fs/cgroup instead of doing a lookup via mountinfoThe 8472-53/+67
this avoids parsing mountinfo which can be huge on some systems and something might be emulating cgroup fs for sandboxing reasons which means it wouldn't show up as mountpoint additionally the new implementation operates on a single pathbuffer, reducing allocations
2022-03-03Use cgroup quotas for calculating `available_parallelism`The 8472-3/+68
Manually tested via ``` // spawn a new cgroup scope for the current user $ sudo systemd-run -p CPUQuota="300%" --uid=$(id -u) -tdS // quota.rs #![feature(available_parallelism)] fn main() { println!("{:?}", std::thread::available_parallelism()); // prints Ok(3) } ``` Caveats * cgroup v1 is ignored * funky mountpoints (containing spaces, newlines or control chars) for cgroupfs will not be handled correctly since that would require unescaping /proc/self/mountinfo The escaping behavior of procfs seems to be undocumented. systemd and docker default to `/sys/fs/cgroup` so it should be fine for most systems. * quota will be ignored when `sched_getaffinity` doesn't work * assumes procfs is mounted under `/proc` and cgroupfs mounted and readable somewhere in the directory tree
2022-03-02Fix a broken doc link on Windows.Dan Gohman-3/+1
2022-03-02Re-export core::ffi types from std::ffibstrie-0/+10
2022-03-01Provide C FFI types via core::ffi, not just in stdJosh Triplett-220/+27
The ability to interoperate with C code via FFI is not limited to crates using std; this allows using these types without std. The existing types in `std::os::raw` become type aliases for the ones in `core::ffi`. This uses type aliases rather than re-exports, to allow the std types to remain stable while the core types are unstable. This also moves the currently unstable `NonZero_` variants and `c_size_t`/`c_ssize_t`/`c_ptrdiff_t` types to `core::ffi`, while leaving them unstable.
2022-03-01Rollup merge of #94094 - chrisnc:tcp-nodelay-windows-bool, r=dtolnayDylan DPC-11/+26
use BOOL for TCP_NODELAY setsockopt value on Windows This issue was found by the Wine project and mitigated there [^1]. Windows' setsockopt expects a BOOL (a typedef for int) for TCP_NODELAY [^2]. Windows itself is forgiving and will accept any positive optlen and interpret the first byte of *optval as the value, so this bug does not affect Windows itself, but does affect systems implementing Windows' interface more strictly, such as Wine. Wine was previously passing this through to the host's setsockopt, where, e.g., Linux requires that optlen be correct for the chosen option, and TCP_NODELAY expects an int. [^1]: https://source.winehq.org/git/wine.git/commit/d6ea38f32dfd3edbe107a255c37e9f7f3da06ae7 [^2]: https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-setsockopt
2022-02-27Stabilize unix_socket_creationThomas de Zeeuw-3/+1
2022-02-27Auto merge of #94373 - erikdesjardins:getitinl, r=Mark-Simulacrumbors-2/+2
Make TLS __getit #[inline(always)] on non-Windows This may improve perf, and/or stop `externs` perf benchmarks from being flaky. r? `@ghost`
2022-02-25Make TLS __getit #[inline(always)] on non-WindowsErik Desjardins-2/+2
This may improve perf.
2022-02-25Auto merge of #94290 - Mark-Simulacrum:bump-bootstrap, r=pietroalbinibors-21/+20
Bump bootstrap to 1.60 This bumps the bootstrap compiler to 1.60 and cleans up cfgs and Span's rustc_pass_by_value (enabled by the bootstrap bump).
2022-02-25Switch bootstrap cfgsMark Rousskov-21/+20
2022-02-25Rename unix::net::SocketAddr::from_path to from_pathnameThomas de Zeeuw-3/+3
Matching SocketAddr::as_pathname.
2022-02-25Fix SGX docs buildJethro Beekman-1/+1