about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2022-09-10Better documentation for env::home_dir()'s broken behaviourTim Hutt-1/+8
This improves the documentation to say *why* it was deprecated. The reason was because it reads `HOME` on Windows which is meaningless there. Note that the PR that deprecated it stated that returning an empty string if `HOME` is set to an empty string was a problem, however I can find no evidence that this is the case. `cd` handles it fine whereas if `HOME` is unset it gives an explicit `HOME not set` error. * Original deprecation reason: https://internals.rust-lang.org/t/deprecate-or-break-fix-std-env-home-dir/7315 * Original deprecation PR: https://github.com/rust-lang/rust/pull/51656 See #71684
2022-09-10Explicitly link kernel32.lib from allocChris Denton-0/+1
2022-09-09Auto merge of #101617 - Dylan-DPC:rollup-iiy4ipc, r=Dylan-DPCbors-18/+20
Rollup of 5 pull requests Successful merges: - #101366 (Restore old behaviour on broken UNC paths) - #101492 (Suggest adding array lengths to references to arrays if possible) - #101529 (Fix the example code and doctest for Formatter::sign_plus) - #101573 (update `ParamKindOrd`) - #101612 (Fix code generation of `Rvalue::Repeat` with 128 bit values) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-09-09Rollup merge of #101366 - ChrisDenton:unc-forward-slash, r=m-ou-seDylan DPC-18/+20
Restore old behaviour on broken UNC paths This fixes #101358 by restoring the behaviour from previous stable Rust versions. I'm not convinced this is ultimately right but I think it's less wrong and maybe this should be backported to beta? r? libs
2022-09-09std: use futex-based locks and thread parker on Hermitjoboet-452/+48
2022-09-09doc: fix minor typoAkhilesh Singhania-1/+1
2022-09-08Rollup merge of #101423 - mkroening:hermit-warnings, r=sanxiynMichael Goulet-4/+0
Fix hermit warnings This fixes two `unused_imprt` and one `dead_code` warning for hermit.
2022-09-08Rollup merge of #101422 - mkroening:hermit-file-time, r=joshtriplettDylan DPC-0/+12
Hermit: Add File::set_time stub This is not supported on hermit yet. This change is required for compiling std.
2022-09-07Stabilize `#![feature(mixed_integer_ops)]`Jacob Pratt-1/+0
2022-09-07Auto merge of #101544 - matthiaskrgr:rollup-4urx917, r=matthiaskrgrbors-0/+15
Rollup of 14 pull requests Successful merges: - #101343 (Add -api-level to pm command) - #101416 (stdio: Document no support for writing to non-blocking stdio/stderr) - #101435 (Remove unnecessary `EMIT_MIR_FOR_EACH_BITWIDTH`) - #101493 (Pass ImplTraitContext as &mut to avoid the need of ImplTraitContext::reborrow) - #101502 (Do not suggest a semicolon for a macro without `!`) - #101503 (Add debug calls) - #101506 (rustdoc: remove unused CSS `#main-content > .since`) - #101507 (rustdoc: remove unused CSS `#main-content > table td`) - #101521 (Rustdoc-Json: More accurate struct type.) - #101525 (Fix typo in pass_manager.rs) - #101534 (rustdoc: remove unused mobile CSS `.rustdoc { flex-direction }`) - #101535 (Fix error printing mistake in tidy) - #101536 (Add documentation for Attr::is_doc_comment) - #101538 (rustdoc: remove unused CSS `.content .methods > div`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-09-07Auto merge of #101476 - ChrisDenton:BCryptRandom-fix, r=thomccbors-20/+88
Open a BCrypt algorithm handle Fixes #101474, supplants #101456. Replaces use of a pseduo handle with manually opening a algorithm handle. Most interesting thing here is the atomics. r? `@thomcc`
2022-09-07stdio: Document no support for writing to non-blocking stdio/stderrUsama Arif-0/+15
Printing to stdio/stderr that have been opened with non-blocking (O_NONBLOCK in linux) can result in an error, which is not handled by std::io module causing a panic. Signed-off-by: Usama Arif <usama.arif@bytedance.com>
2022-09-07Don't break windows/rand for miriChris Denton-0/+12
2022-09-06Open a BCrypt algorithm handleChris Denton-20/+76
2022-09-06Fix compile errors for uwp-windows-msvc targetsChris Denton-1/+1
2022-09-06Rollup merge of #101426 - beetrees:dup-no-stdio, r=thomccYuki Okushi-1/+2
Don't duplicate file descriptors into stdio fds Ensures that file descriptors are never duplicated into the stdio fds even if a stdio fd has been closed.
2022-09-06Rollup merge of #101404 - joboet:always_cleanup_stdout, r=joshtriplettYuki Okushi-8/+17
Fix cleanup for uninitialized stdout Fixes #101375 by disabling buffering even if the buffer was not initialized yet.
2022-09-05Rollup merge of #101391 - matthiaskrgr:perf0309, r=oli-obkDylan DPC-1/+1
more clippy::perf fixes
2022-09-05std: clarify semantics of SGX parkerjoboet-15/+29
2022-09-05std: fix cleanup for uninitialized stdout (#101375)joboet-8/+17
2022-09-04Auto merge of #100576 - joboet:movable_const_remutex, r=Mark-Simulacrumbors-165/+39
Make `ReentrantMutex` movable and `const` As `MovableMutex` is now `const`, it can be used to simplify the implementation and interface of the internal reentrant mutex type. Consequently, the standard error stream does not need to be wrapped in `OnceLock` and `OnceLock::get_or_init_pin()` can be removed.
2022-09-05Hermit: Remove unused socklen_t (dead_code)Martin Kröning-2/+0
2022-09-05Hermit: Fix unused_importsMartin Kröning-2/+0
2022-09-05Hermit: Add File::set_time stubMartin Kröning-0/+12
This is not supported on hermit yet. This change is required for compiling std.
2022-09-04Rollup merge of #101394 - CAD97:patch-3, r=Mark-SimulacrumMatthias Krüger-1/+4
Forbid mixing `System` with direct sytem allocator calls e.g. [on windows](https://github.com/rust-lang/rust/blob/dec689432fac6720b2f18101ac28a21add98b1b8/library/std/src/sys/windows/alloc.rs#L129-L178), trying to mix `System::alloc` and `HeapFree` will not work because of the extra work done to serve higher alignments.
2022-09-04Make code worling w/ pointers in ↵Maybe Waffle-14/+14
`library/std/src/sys/sgx/abi/usercalls/alloc.rs` nicer - Use `.addr()` instead of `as`-cast - Use `add` instead of `offset` and remove some `as isize` casts by doing that - Remove some casts
2022-09-04Don't duplicate file descriptors into stdio fdsbeetrees-1/+2
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``