about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2022-05-16Improve error message for fallback RNG failureChris Martin-1/+1
2022-05-16Allow `unused_macro_rules` in path testsRaoul Strackx-0/+1
2022-05-15Rollup merge of #97060 - bdbai:fix/uwphandle, r=ChrisDentonDylan DPC-1/+15
Fix use of SetHandleInformation on UWP The use of `SetHandleInformation` (introduced in #96441 to make `HANDLE` inheritable) breaks UWP builds because it is not available for UWP targets. Proposed workaround: duplicate the `HANDLE` with `inherit = true` and immediately close the old one. Traditional Windows Desktop programs are not affected. cc `@ChrisDenton`
2022-05-15Rollup merge of #96947 - ↵Dylan DPC-0/+47
sunfishcode:sunfishcode/rustc-nonnull-optimization-guaranteed, r=joshtriplett Add rustc_nonnull_optimization_guaranteed to Owned/Borrowed Fd/Socket PR #94586 added support for using `rustc_nonnull_optimization_guaranteed` on values where the "null" value is the all-ones bitpattern. Now that #94586 has made it to the stage0 compiler, add `rustc_nonnull_optimization_guaranteed` to `OwnedFd`, `BorrowedFd`, `OwnedSocket`, and `BorrowedSocket`, since these types all exclude all-ones bitpatterns. This allows `Option<OwnedFd>`, `Option<BorrowedFd>`, `Option<OwnedSocket>`, and `Option<BorrowedSocket>` to be used in FFI declarations, as described in the [I/O safety RFC]. [I/O safety RFC]: https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md#ownedfd-and-borrowedfdfd-1
2022-05-15fix use of SetHandleInformation on UWPbdbai-1/+15
2022-05-14Use Rust ABI for `__rust_start_panic` and `_{rdl,rg}_oom`Gary Guo-1/+1
2022-05-13Address review feedbackChris Martin-31/+22
2022-05-13Auto merge of #95356 - coolreader18:exitstatus-exit-method, r=<try>bors-28/+56
ExitCode::exit_process() method cc `@yaahc` / #93840 (eeek, hit ctrl-enter before I meant to and right after realizing the branch name was wrong. oh, well) I feel like it makes sense to have the `exit(ExitCode)` function as a method or at least associated function on ExitCode, but maybe that would hurt discoverability? Probably not as much if it's at the top of the `process::exit()` documentation or something, but idk. Also very unsure about the name, I'd like something that communicates that you are exiting with *this* ExitCode, but with a method name being postfix it doesn't seem to flow. `code.exit_process_with()` ? `.exit_process_with_self()` ? Blech. Maybe it doesn't matter, since ideally just `code.exit()` or something would be clear simply by the name and single parameter but :shrug: Also I'd like to touch up the `ExitCode` docs (which I did a bit here), but that would probably be good in a separate PR, right? Since I think the beta deadline is coming up.
2022-05-13Guarantee less in docsNoa-2/+2
2022-05-13Add ExitCode::exit_process exampleNoa-0/+23
2022-05-13Rollup merge of #96932 - sunfishcode:sunfishcode/document-borrowed-handle, ↵Matthias Krüger-12/+26
r=joshtriplett Clarify what values `BorrowedHandle`, `OwnedHandle` etc. can hold. Reword the documentation to clarify that when `BorrowedHandle`, `OwnedHandle`, or `HandleOrNull` hold the value `-1`, it always means the current process handle, and not `INVALID_HANDLE_VALUE`. `-1` should only mean `INVALID_HANDLE_VALUE` after a call to a function documented to return that to report errors, which should lead I/O functions to produce errors rather than succeeding and producing `OwnedHandle` or `BorrowedHandle` values. So if a consumer of an `OwnedHandle` or `BorrowedHandle` ever sees them holding a `-1`, it should always mean the current process handle.
2022-05-11Fix comment syntax.Dan Gohman-0/+1
2022-05-11Relax the wording about the meaning of -1.Dan Gohman-6/+11
2022-05-11Fix attribute name.Dan Gohman-2/+2
2022-05-11RawSocket is unsigned on Windows.Dan Gohman-10/+9
2022-05-11Fix duplicate import on Windows.Dan Gohman-1/+1
2022-05-11Add rustc_nonnull_optimization_guaranteed to Owned/Borrowed Fd/SocketDan Gohman-0/+48
PR #94586 added support for using `rustc_nonnull_optimization_guaranteed` on values where the "null" value is the all-ones bitpattern. Now that #94586 has made it to the stage0 compiler, add `rustc_nonnull_optimization_guaranteed` to `OwnedFd`, `BorrowedFd`, `OwnedSocket`, and `BorrowedSocket`, since these types all exclude all-ones bitpatterns. This allows `Option<OwnedFd>`, `Option<BorrowedFd>`, `Option<OwnedSocket>`, and `Option<BorrowedSocket>` to be used in FFI declarations, as described in the [I/O safety RFC]. [I/O safety RFC]: https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md#ownedfd-and-borrowedfdfd-1
2022-05-11HandleOrNull can hold null, and HandleOrInvalid can hold INVALID_HANDLE_VALUE.Dan Gohman-9/+5
2022-05-11Use `fcntl(fd, F_GETFD)` to detect if standard streams are openTomasz Miąsko-31/+6
In the previous implementation, if the standard streams were open, but the RLIMIT_NOFILE value was below three, the poll would fail with EINVAL: > ERRORS: EINVAL The nfds value exceeds the RLIMIT_NOFILE value. Switch to the existing fcntl based implementation to avoid the issue.
2022-05-10Fix incorrect mentions of `OwnedFd` and `BorrowedFd` in Windows docs.Dan Gohman-4/+4
2022-05-11to_timespec could be unused by some targetsSébastien Marie-0/+1
2022-05-11avoid using both Some() and ? on linux/android/freebsd codeSébastien Marie-1/+1
2022-05-11openbsd: convert futex timeout managment to Timespec usageSébastien Marie-9/+7
2022-05-10Also document that `as_raw_handle` may return NULL.Dan Gohman-0/+7
2022-05-10Clarify what values `BorrowedHandle`, `OwnedHandle` etc. can hold.Dan Gohman-12/+17
Clarify that when `BorrowedHandle`, `OwnedHandle`, or `HandleOrNull` hold the value `-1`, it always means the current process handle, and not `INVALID_HANDLE_VALUE`.
2022-05-10Auto merge of #96232 - sunfishcode:sunfishcode/io-safety-const-fns, ↵bors-5/+5
r=joshtriplett Make `BorrowedFd::borrow_raw` a const fn. Making `BorrowedFd::borrow_raw` a const fn allows it to be used to create a constant `BorrowedFd<'static>` holding constants such as `AT_FDCWD`. This will allow [`rustix::fs::cwd`] to become a const fn. For consistency, make similar changes to `BorrowedHandle::borrow_raw` and `BorrowedSocket::borrow_raw`. [`rustix::fs::cwd`]: https://docs.rs/rustix/latest/rustix/fs/fn.cwd.html r? `@joshtriplett`
2022-05-10Recommend `Ipv6Addr::to_ipv4_mapped` over `Ipv6Addr::to_ipv4`Tobias Bucher-2/+4
Fixes #96718.
2022-05-10Stabilize `Ipv6Addr::to_ipv4_mapped`Tobias Bucher-3/+1
CC #27709 (tracking issue for the `ip` feature which contains more functions) The function `Ipv6Addr::to_ipv4` is bad because it also returns an IPv4 address for the IPv6 loopback address `::1`. Stabilize `Ipv6Addr::to_ipv4_mapped` so we can recommend that function instead.
2022-05-10Make HashMap fall back to RtlGenRandom if BCryptGenRandom failsChris Martin-4/+83
Issue #84096 changed the hashmap RNG to use BCryptGenRandom instead of RtlGenRandom on Windows. Mozilla Firefox started experiencing random failures in env_logger::Builder::new() (Issue #94098) during initialization of their unsandboxed main process with an "Access Denied" error message from BCryptGenRandom(), which is used by the HashMap contained in env_logger::Builder The root cause appears to be a virus scanner or other software interfering with BCrypt DLLs loading. This change adds a fallback option if BCryptGenRandom is unusable for whatever reason. It will fallback to RtlGenRandom in this case. Fixes #94098
2022-05-11Rollup merge of #96861 - m-ou-se:std-use-prelude-2021, r=joshtriplettYuki Okushi-43/+7
Use Rust 2021 prelude in std itself.
2022-05-10Expose process main_thread_handle on Windowsunknown-7/+52
2022-05-09Implement [OsStr]::joinest31-0/+33
Second attempt at implementing [OsStr]::join.
2022-05-09Rollup merge of #96841 - thomcc:revert-osstr-join, r=m-ou-seMatthias Krüger-33/+0
Revert "Implement [OsStr]::join", which was merged without FCP. This reverts commit 4fcbc53820ab423bbeb41f07822369aa05da1d68, see https://github.com/rust-lang/rust/pull/96744. (I'm terribly sorry, and truly don't remember r+ing it, or even having seen it before yesterday, which is... genuinely very worrisome for me). r? `@m-ou-se`
2022-05-09Rollup merge of #95483 - golddranks:improve_float_docs, r=joshtriplettMatthias Krüger-26/+46
Improve floating point documentation This is my attempt to improve/solve https://github.com/rust-lang/rust/issues/95468 and https://github.com/rust-lang/rust/issues/73328 . Added/refined explanations: - Refine the "NaN as a special value" top level explanation of f32 - Refine `const NAN` docstring: add an explanation about there being multitude of NaN bitpatterns and disclaimer about the portability/stability guarantees. - Refine `fn is_sign_positive` and `fn is_sign_negative` docstrings: add disclaimer about the sign bit of NaNs. - Refine `fn min` and `fn max` docstrings: explain the semantics and their relationship to the standard and libm better. - Refine `fn trunc` docstrings: explain the semantics slightly more. - Refine `fn powi` docstrings: add disclaimer that the rounding behaviour might be different from `powf`. - Refine `fn copysign` docstrings: add disclaimer about payloads of NaNs. - Refine `minimum` and `maximum`: add disclaimer that "propagating NaN" doesn't mean that propagating the NaN bit patterns is guaranteed. - Refine `max` and `min` docstrings: add "ignoring NaN" to bring the one-row explanation to parity with `minimum` and `maximum`. Cosmetic changes: - Reword `NaN` and `NAN` as plain "NaN", unless they refer to the specific `const NAN`. - Reword "a number" to `self` in function docstrings to clarify. - Remove "Returns NAN if the number is NAN" from `abs`, as this is told to be the default behavior in the top explanation.
2022-05-09Use Rust 2021 prelude in std itself.Mara Bos-43/+7
2022-05-09Auto merge of #95960 - jhpratt:remove-rustc_deprecated, r=compiler-errorsbors-163/+157
Remove `#[rustc_deprecated]` This removes `#[rustc_deprecated]` and introduces diagnostics to help users to the right direction (that being `#[deprecated]`). All uses of `#[rustc_deprecated]` have been converted. CI is expected to fail initially; this requires #95958, which includes converting `stdarch`. I plan on following up in a short while (maybe a bootstrap cycle?) removing the diagnostics, as they're only intended to be short-term.
2022-05-09Auto merge of #96802 - gimbles:windows_slice, r=thomccbors-0/+1
[feat] Make sys::windows::os_str::Slice repr(transparent) Fixes #96577
2022-05-08Auto merge of #96302 - Serial-ATA:more-diagnostic-items, r=manishearthbors-0/+1
Add more diagnostic items This just adds a handful diagnostic items I noticed were missing. Would it be worth doing this for all of the remaining types? I'm willing to do it if it'd be helpful.
2022-05-08Revert "Implement [OsStr]::join", which was merged without FCPThom Chiovoloni-33/+0
This reverts commit 4fcbc53820ab423bbeb41f07822369aa05da1d68.
2022-05-08fix panic in Path::strip_prefixname1e5s-1/+13
2022-05-08Auto merge of #94206 - PrestonFrom:significant_drop, r=flip1995bors-0/+3
Create clippy lint against unexpectedly late drop for temporaries in match scrutinee expressions A new clippy lint for issue 93883 (https://github.com/rust-lang/rust/issues/93883). Relies on a new trait in `marker` (called `SignificantDrop` to enable linting), which is why this PR is for the rust-lang repo and not the clippy repo. changelog: new lint [`significant_drop_in_scrutinee`]
2022-05-07Rollup merge of #96671 - mgeisler:current-exe-docstring, r=Mark-SimulacrumMatthias Krüger-30/+17
Remove hard links from `env::current_exe` security example The security example shows that `env::current_exe` will return the path used when the program was started. This is not really surprising considering how hard links work: after `ln foo bar`, the two files are _equivalent_. It is _not_ the case that `bar` is a “link” to `foo`, nor is `foo` a link to `bar`. They are simply two names for the same underlying data. The security vulnerability linked to seems to be different: there an attacker would start a SUID binary from a directory under the control of the attacker. The binary would respawn itself by executing the program found at `/proc/self/exe` (which the attacker can control). This is a real problem. In my opinion, the example given here doesn’t really show the same problem, it just shows a misunderstanding of what hard links are. I looked through the history a bit and found that the example was introduced in https://github.com/rust-lang/rust/pull/33526. That PR actually has two commits, and the first (https://github.com/rust-lang/rust/commit/8478d48dad949b3b1374569a5391089a49094eeb) explains the race condition at the root of the linked security vulnerability. The second commit proceeds to replace the explanation with the example we have today. This commit reverts most of the second commit from https://github.com/rust-lang/rust/pull/33526.
2022-05-07Rollup merge of #96586 - ear7h:master, r=joshtriplettMatthias Krüger-0/+2
Add aliases for std::fs::canonicalize The aliases are `realpath` and `GetFinalPathNameByHandle` which are explicitly mentioned in `canonicalize`'s documentation.
2022-05-07Auto merge of #96657 - cuviper:time64, r=joshtriplettbors-168/+205
Use 64-bit time on 32-bit linux-gnu The standard library suffered the [Year 2038 problem][Y2038] in two main places on targets with 32-bit `time_t`: - In `std::time::SystemTime`, we stored a `timespec` that has `time_t` seconds. This is now changed to directly store 64-bit seconds and nanoseconds, and on 32-bit linux-gnu we try to use `__clock_gettime64` (glibc 2.34+) to get the larger timestamp. - In `std::fs::Metadata`, we store a `stat64`, which has 64-bit `off_t` but still 32-bit `time_t`, and unfortunately that is baked in the API by the (deprecated) `MetadataExt::as_raw_stat()`. However, we can use `statx` for 64-bit `statx_timestamp` to store in addition to the `stat64`, as we already do to support creation time, and the rest of the `MetadataExt` methods can return those full values. Note that some filesystems may still be limited in their actual timestamp support, but that's not something Rust can change. There remain a few places that need `timespec` for system call timeouts -- I leave that to future work. [Y2038]: https://en.wikipedia.org/wiki/Year_2038_problem
2022-05-07[fix] remove pub(crate) visibilitygimbles-1/+1
2022-05-06Rollup merge of #96701 - kraktus:alloc_example_2018_edition, r=Mark-SimulacrumMichael Goulet-2/+0
update `jemallocator` example to use 2018 edition import syntax
2022-05-06Mark locks in std lib with clippy::has_significant_dropPreston From-0/+3
2022-05-06This is a pretty good start if you ask meJane Lusby-1/+132
2022-05-06Share more unix SystemTime codeJosh Stone-101/+57
2022-05-06[feat] Make sys::windows::os_str::Slice repr(transparent)gimbles-1/+2