about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2022-09-03Forbid mixing `System` with sytem allocator callsChristopher Durham-1/+4
2022-09-03more clippy::perf fixesMatthias Krüger-1/+1
2022-09-03updated description of File struct in std::fsBart Massey-1/+1
2022-09-03std: make `ReentrantMutex` movable and `const`; simplify `Stdout` initializationjoboet-165/+39
2022-09-03Restore old behaviour on broken UNC pathsChris Denton-18/+20
2022-09-03Rollup merge of #101330 - wkordalski:hashset-drain-doc, r=jyn514Dylan DPC-1/+1
Fix `std::collections::HashSet::drain` documentation Hi! `std::collections::HashSet::drain` contains small typo in the docstring. I didn't read too much about the model of contributing to Rust, so merge this PR or close and fix the typo the right way :) Thanks for Rust!
2022-09-03Rollup merge of #101325 - ChrisDenton:BCRYPT_RNG_ALG_HANDLE, r=thomccDylan DPC-5/+38
Windows RNG: Use `BCRYPT_RNG_ALG_HANDLE` by default This only changes a small amount of actual code, the rest is documentation outlining the history of this module as I feel it will be relevant to any future issues that might crop up. The code change is to use the `BCRYPT_RNG_ALG_HANDLE` [pseudo-handle](https://docs.microsoft.com/en-us/windows/win32/seccng/cng-algorithm-pseudo-handles) by default, which simply uses the default RNG. Previously we used `BCRYPT_USE_SYSTEM_PREFERRED_RNG` which has to load the system configuration and then find and load that RNG. I suspect this was the cause of failures on some systems (e.g. due to corrupted config). However, this is admittedly speculation as I can't reproduce the issue myself (and it does seem quite rare even in the wild). Still, removing a possible point of failure is likely worthwhile in any case. r? libs
2022-09-02Fix compilation of the doc tests on Windows.Dan Gohman-0/+4
2022-09-02Auto merge of #97802 - Enselic:add-no_ignore_sigkill-feature, r=joshtriplettbors-14/+63
Support `#[unix_sigpipe = "inherit|sig_dfl"]` on `fn main()` to prevent ignoring `SIGPIPE` When enabled, programs don't have to explicitly handle `ErrorKind::BrokenPipe` any longer. Currently, the program ```rust fn main() { loop { println!("hello world"); } } ``` will print an error if used with a short-lived pipe, e.g. % ./main | head -n 1 hello world thread 'main' panicked at 'failed printing to stdout: Broken pipe (os error 32)', library/std/src/io/stdio.rs:1016:9 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace by enabling `#[unix_sigpipe = "sig_dfl"]` like this ```rust #![feature(unix_sigpipe)] #[unix_sigpipe = "sig_dfl"] fn main() { loop { println!("hello world"); } } ``` there is no error, because `SIGPIPE` will not be ignored and thus the program will be killed appropriately: % ./main | head -n 1 hello world The current libstd behaviour of ignoring `SIGPIPE` before `fn main()` can be explicitly requested by using `#[unix_sigpipe = "sig_ign"]`. With `#[unix_sigpipe = "inherit"]`, no change at all is made to `SIGPIPE`, which typically means the behaviour will be the same as `#[unix_sigpipe = "sig_dfl"]`. See https://github.com/rust-lang/rust/issues/62569 and referenced issues for discussions regarding the `SIGPIPE` problem itself See the [this](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Proposal.3A.20First.20step.20towards.20solving.20the.20SIGPIPE.20problem) Zulip topic for more discussions, including about this PR. Tracking issue: https://github.com/rust-lang/rust/issues/97889
2022-09-02Rollup merge of #101260 - ChrisDenton:attribute-tag, r=thomccMatthias Krüger-8/+24
Use `FILE_ATTRIBUTE_TAG_INFO` to get reparse tag I've been looking at this code recently and it just occurred to me we don't actually use the full reparse data at this point, only the tag. [`GetFileInformationByHandleEx`](https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getfileinformationbyhandleex) can do exactly that by filling a [`FILE_ATTRIBUTE_TAG_INFO`](https://docs.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-file_attribute_tag_info) struct. r? ```````@thomcc``````` since you've made changes here recently (which is why I have this code on my mind atm)
2022-09-02Fix `std::collections::HashSet::drain` documentationWojciech Kordalski-1/+1
2022-09-02Use `BCRYPT_RNG_ALG_HANDLE` by defaultChris Denton-5/+38
Also briefly document the history of `sys/windows/rand.rs` as they may be relevant to any future changes.
2022-09-02Rollup merge of #97739 - a2aaron:let_underscore, r=estebankGuillaume Gomez-0/+3
Uplift the `let_underscore` lints from clippy into rustc. This PR resolves #97241. This PR adds three lints from clippy--`let_underscore_drop`, `let_underscore_lock`, and `let_underscore_must_use`, which are meant to capture likely-incorrect uses of `let _ = ...` bindings (in particular, doing this on a type with a non-trivial `Drop` causes the `Drop` to occur immediately, instead of at the end of the scope. For a type like `MutexGuard`, this effectively releases the lock immediately, which is almost certainly the wrong behavior) In porting the lints from clippy I had to copy over a bunch of utility functions from `clippy_util` that these lints also relied upon. Is that the right approach? Note that I've set the `must_use` and `drop` lints to Allow by default and set `lock` to Deny by default (this matches the same settings that clippy has). In talking with `@estebank` he informed me to do a Crater run (I am not sure what type of Crater run to request here--I think it's just "check only"?) On the linked issue, there's some discussion about using `must_use` and `Drop` together as a heuristic for when to warn--I did not implement this yet. r? `@estebank`
2022-09-01Update outdated comment about output capturing in print_to.Mara Bos-4/+4
2022-09-01Auto merge of #100707 - dzvon:fix-typo, r=davidtwcobors-8/+8
Fix a bunch of typo This PR will fix some typos detected by [typos]. I only picked the ones I was sure were spelling errors to fix, mostly in the comments. [typos]: https://github.com/crate-ci/typos
2022-09-01unix_sigpipe: Make `sigpipe` param docs long-formMartin Nordholts-4/+20
2022-09-01Use `FILE_ATTRIBUTE_TAG_INFO` to get reparse tagChris Denton-8/+24
This avoid unnecessarily getting the full reparse data when all we need is the tag.
2022-08-31unix_sigpipe: Add docs for `init()` `sigpipe` paramMartin Nordholts-0/+4
2022-08-31unix_sigpipe: Inline compiler sigpipe constants in stdMartin Nordholts-3/+9
2022-08-31Avoid needless buffer zeroing in `std::sys::windows::fs`Thom Chiovoloni-14/+24
2022-08-31Correct typoDezhi Wu-1/+1
2022-08-31Fix a bunch of typoDezhi Wu-8/+8
This PR will fix some typos detected by [typos]. I only picked the ones I was sure were spelling errors to fix, mostly in the comments. [typos]: https://github.com/crate-ci/typos
2022-08-31Rollup merge of #101171 - thomcc:fix-winfs-ub, r=ChrisDentonMatthias Krüger-28/+55
Fix UB from misalignment and provenance widening in `std::sys::windows` This fixes two types of UB: 1. Reading past the end of a reference in types like `&c::REPARSE_DATA_BUFFER` (see https://github.com/rust-lang/unsafe-code-guidelines/issues/256). This is fixed by using `addr_of!`. I think there are probably a couple more cases where we do this for other structures, and will look into it in a bit. 2. Failing to ensure that a `[u8; N]` on the stack is sufficiently aligned to convert to a `REPARSE_DATA_BUFFER`. ~~This was done by introducing a new `AlignedAs` struct that allows aligning one type to the alignment of another type. I expect there are other places where we have this issue too, or I wouldn't introduce this type, but will get to them after this lands.~~ ~~Worth noting, it *is* implemented in a way that can cause problems depending on how we fix #81996, but this would be caught by the test I added (and presumably if we decide to fix that in a way that would break this code, we'd also introduce a `#[repr(simple)]` or `#[repr(linear)]` as a replacement for this usage of `#[repr(C)]`).~~ Edit: None of that is still in the code, I just went with a `Align8` since that's all we'll need for almost everything we want to call. These are more or less "potential UB" since it's likely at the moment everything works fine, although the alignment not causing issues might just be down to luck (and x86 being forgiving). ~~NB: I've only ensured this check builds, but will run tests soon.~~ All tests pass, including stage2 compiler tests. r? ``@ChrisDenton``
2022-08-31Rollup merge of #101011 - BlackHoleFox:apple-random-improvements, r=thomccMatthias Krüger-38/+56
Use getentropy when possible on all Apple platforms As the current code comments say, `SecRandomCopyBytes` is very heavyweight (regardless of purpose) compared to just asking the kernel directly for bytes from its own CSPRNG. We were not previously making an attempt to use the more efficient `getentropy` call on other Apple targets, instead solely using it on macOS. As the function is available on newer versions of Apple's different OSes, this changes the random filling to always attempt it first everywhere, only falling back to the less ideal alternatives after. This also cleans up the multiple Apple `imp` blocks into one. It also should give a perf improvement, even if its likely unnoticeably small. Refed XCode header for `getentropy` in the SDK: ```h int getentropy(void* buffer, size_t size) __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0) __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0); ``` r? ``@thomcc``
2022-08-31Rollup merge of #100984 - ChrisDenton:reinstate-init, r=Mark-SimulacrumMatthias Krüger-33/+52
Reinstate preloading of some dll imports I've now come around to the conclusion that there is a justification for pre-loading the synchronization functions `WaitOnAddress` and `WakeByAddressSingle`. I've found this to have a particularly impact in testing frameworks that may have short lived processes which immediately spawn lots of threads. Also, because pre-main initializers imply a single-threaded environment, we can switch back to using relaxed atomics which might be a minor perf improvement on some platforms (though I doubt it's particularly notable). r? ``@Mark-Simulacrum`` and sorry for the churn here. For convenience I'll summarise previous issues with preloading and the solutions that are included in this PR (if any): **Issue:** User pre-main initializers may be run before std's **Solution:** The std now uses initializers that are guaranteed to run earlier than the old initializers. A note is also added that users should not copy std's behaviour if they want to ensure they run their initializers after std. **Issue:** Miri does not understand pre-main initializers. **Solution:** For miri only, run the function loading lazily instead. **Issue:** We should ideally use `LoadLibrary` to get "api-ms-win-core-synch-l1-2-0". Only "ntdll" and "kernel32" are guaranteed to always be loaded. **Solution:** None. We can't use `LoadLibrary` pre-main. However, in the past `GetModuleHandle` has always worked in practice so this should hopefully not be a problem. If/when Windows 7 support is dropped, we can finally remove all this for good and just use normal imports.
2022-08-31Rollup merge of #101193 - thomcc:win-stdio-nozero, r=ChrisDentonYuki Okushi-14/+27
Avoid zeroing large stack buffers in stdio on Windows Does what it says on the tin, using `[MaybeUninit<u16>; N]` instead of `[0u16; N]`. These buffers seem to be around 8kb, which is big enough that this is likely to be a very nice perf boost to stdio-heavy windows code. r? ``@ChrisDenton`` *(Note: this PR also has a commit that adds windows to CI, but as it mentions I'll revert that after it comes out green -- I can only do a check build on the machine I'm typing this on)*
2022-08-31Rollup merge of #100892 - sunfishcode:wasi-stdio-asfd, r=joshtriplettYuki Okushi-1/+22
Add `AsFd` implementations for stdio types on WASI. This mirrors the implementations on Unix platforms, and also mirrors the existing `AsRawFd` impls.
2022-08-30Avoid `MaybeUninit::uninit_array()`Thom Chiovoloni-4/+4
2022-08-30Fix UB in Windows `DirBuffIter` (provenance and alignment)Thom Chiovoloni-7/+10
2022-08-30Avoid zeroing large stack buffers in stdio on WindowsThom Chiovoloni-14/+27
2022-08-30Replace `AlignedAs` with a more specific `Align8` typeThom Chiovoloni-52/+20
2022-08-30Fix UWP and use `AlignedReparseBuf` in `symlink_junction_inner`Thom Chiovoloni-5/+6
2022-08-30Auto merge of #100812 - Nilstrieb:revert-let-chains-nightly, r=Mark-Simulacrumbors-0/+1
Revert let_chains stabilization This is the revert against master, the beta revert was already done in #100538. Bumps the stage0 compiler which already has it reverted.
2022-08-29Fix some possible UB in std::sys::windowsThom Chiovoloni-16/+71
2022-08-29Auto merge of #101167 - matthiaskrgr:rollup-yt3jdmp, r=matthiaskrgrbors-1/+1
Rollup of 7 pull requests Successful merges: - #100898 (Do not report too many expr field candidates) - #101056 (Add the syntax of references to their documentation summary.) - #101106 (Rustdoc-Json: Retain Stripped Modules when they are imported, not when they have items) - #101131 (CTFE: exposing pointers and calling extern fn is just impossible) - #101141 (Simplify `get_trait_ref` fn used for `virtual_function_elimination`) - #101146 (Various changes to logging of borrowck-related code) - #101156 (Remove `Sync` requirement from lint pass objects) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-08-29Rollup merge of #101056 - kpreid:prim-doc, r=JohnTitorMatthias Krüger-1/+1
Add the syntax of references to their documentation summary. Without this change, in <https://doc.rust-lang.org/1.63.0/std/#primitives>, `reference` is the only entry in that list which does not contain the syntax by which the type is named in source code. With this change, it contains them, in roughly the same way as the `pointer` entry does.
2022-08-29Revert let_chains stabilizationNilstrieb-0/+1
This reverts commit 326646074940222d602f3683d0559088690830f4. This is the revert against master, the beta revert was already done in #100538.
2022-08-29Re-introduce `unstable` attributes.Dan Gohman-2/+2
Add `#[unstable(feature = "os_fd", issue = "98699")]` to the new `pub use` declarations.
2022-08-29Clarify that the `fd` module is supported on Unix and WASI.Dan Gohman-3/+2
2022-08-29Make `std::os::fd` public.Dan Gohman-46/+23
`std::os::fd` defines types like `OwnedFd` and `RawFd` and is common between Unix and non-Unix platforms that share a basic file-descriptor concept. Rust currently uses this internally to simplify its own code, but it would be useful for external users in the same way, so make it public. This means that `OwnedFd` etc. will all appear in three places, for example on unix platforms: - `std::os::fd::OwnedFd` - `std::os::unix::io::OwnedFd` - `std::os::unix::prelude::OwnedFd`
2022-08-29Rollup merge of #100819 - WaffleLapkin:use_ptr_byte_methods, r=scottmcmDylan DPC-2/+3
Make use of `[wrapping_]byte_{add,sub}` These new methods trivially replace old `.cast().wrapping_offset().cast()` & similar code. Note that [`arith_offset`](https://doc.rust-lang.org/std/intrinsics/fn.arith_offset.html) and `wrapping_offset` are the same thing. r? ``@scottmcm`` _split off from #100746_
2022-08-29Rollup merge of #100337 - camelid:stabilize-io_read_to_string, r=JohnTitorDylan DPC-3/+1
Stabilize `std::io::read_to_string` Closes #80218. :tada: This PR stabilizes the `std::io::read_to_string` function, with the following public API: ```rust pub fn read_to_string<R: Read>(reader: R) -> Result<String>; ``` It's analogous to `std::fs::read_to_string` for files, but it works on anything that implements `io::Read`, including `io::stdin()`. See the tracking issue (#80218) or documentation for details.
2022-08-29Rollup merge of #98801 - joshtriplett:file-create-new, r=thomccDylan DPC-0/+29
Add a `File::create_new` constructor We have `File::create` for creating a file or opening an existing file, but the secure way to guarantee creating a new file requires a longhand invocation via `OpenOptions`. Add `File::create_new` to handle this case, to make it easier for people to do secure file creation.
2022-08-29Auto merge of #100786 - sunshowers:macos-posix-chdir, r=sunshowersbors-1/+60
Use posix_spawn for absolute paths on macOS Currently, on macOS, Rust never uses the fast posix_spawn path if a directory change is requested, due to a bug in Apple's libc. However, the bug is only triggered if the program is a relative path. This PR makes it so that the fast path continues to work if the program is an absolute path or a lone filename. This was an alternative proposed in https://github.com/rust-lang/rust/pull/80537#issue-776674009, and it makes a measurable performance difference in some of my code that spawns thousands of processes.
2022-08-29Rollup merge of #96334 - devnexen:socket_mark, r=dtolnayMatthias Krüger-0/+61
socket `set_mark` addition. to be able to set a marker/id on the socket for network filtering (iptables/ipfw here) purpose.
2022-08-29Rollup merge of #94890 - marmeladema:ip-addr-try-from-bytes, r=joshtriplettMatthias Krüger-13/+125
Support parsing IP addresses from a byte string Fixes #94821 The goal is to be able to parse addresses from a byte string without requiring to do any utf8 validation. Since internally the parser already works on byte strings, this should be possible and I personally already needed this in the past too. ~~I used the proposed approach from the issue by implementing `TryFrom<&'a [u8]>` for all 6 address types (3 ip address types and 3 socket address types). I believe implementing stable traits for stable types is insta-stable so this will probably need an FCP?~~ Switched to an unstable inherent method approach called `parse_ascii` as requested. cc ``````@jyn514``````
2022-08-28Use posix_spawn for absolute paths on macOSRain-1/+60
Currently, on macOS, Rust never uses the fast posix_spawn path if a directory change is requested due to a bug in Apple's libc. However, the bug is only triggered if the program is a relative path. This PR makes it so that the fast path continues to work if the program is an absolute path or a lone filename. This was an alternative proposed in https://github.com/rust-lang/rust/pull/80537#issue-776674009, and it makes a measurable performance difference in some of my code that spawns thousands of processes.
2022-08-28Auto merge of #100578 - Urgau:float-next-up-down, r=scottmcmbors-0/+155
Add next_up and next_down for f32/f64 - take 2 This is a revival of https://github.com/rust-lang/rust/pull/88728 which staled due to inactivity of the original author. I've address the last review comment. --- This is a pull request implementing the features described at https://github.com/rust-lang/rfcs/pull/3173. `@rustbot` label +T-libs-api -T-libs r? `@scottmcm` cc `@orlp`
2022-08-28Stabilize `std::io::read_to_string`Noah Lev-3/+1
2022-08-28Support `#[unix_sigpipe = "inherit|sig_dfl|sig_ign"]` on `fn main()`Martin Nordholts-14/+37
This makes it possible to instruct libstd to never touch the signal handler for `SIGPIPE`, which makes programs pipeable by default (e.g. with `./your-program | head -n 1`) without `ErrorKind::BrokenPipe` errors.