about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2022-03-31Rollup merge of #95130 - workingjubilee:stably-finished, r=m-ou-seDylan DPC-2/+1
Stabilize thread::is_finished Closes #90470. r? `@m-ou-se`
2022-03-30Auto merge of #94963 - lcnr:inherent-impls-std, r=oli-obk,m-ou-sebors-2/+81
allow arbitrary inherent impls for builtin types in core Part of https://github.com/rust-lang/compiler-team/issues/487. Slightly adjusted after some talks with `@m-ou-se` about the requirements of `t-libs-api`. This adds a crate attribute `#![rustc_coherence_is_core]` which allows arbitrary impls for builtin types in core. For other library crates impls for builtin types should be avoided if possible. We do have to allow the existing stable impls however. To prevent us from accidentally adding more of these in the future, there is a second attribute `#[rustc_allow_incoherent_impl]` which has to be added to **all impl items**. This only supports impls for builtin types but can easily be extended to additional types in a future PR. This implementation does not check for overlaps in these impls. Perfectly checking that requires us to check the coherence of these incoherent impls in every crate, as two distinct dependencies may add overlapping methods. It should be easy enough to detect if it goes wrong and the attribute is only intended for use inside of std. The first two commits are mostly unrelated cleanups.
2022-03-30Don't stabilize ScopedJoinHandle::is_finished yet.Mara Bos-1/+0
2022-03-30Auto merge of #95241 - Gankra:cleaned-provenance, r=workingjubileebors-82/+101
Strict Provenance MVP This patch series examines the question: how bad would it be if we adopted an extremely strict pointer provenance model that completely banished all int<->ptr casts. The key insight to making this approach even *vaguely* pallatable is the ptr.with_addr(addr) -> ptr function, which takes a pointer and an address and creates a new pointer with that address and the provenance of the input pointer. In this way the "chain of custody" is completely and dynamically restored, making the model suitable even for dynamic checkers like CHERI and Miri. This is not a formal model, but lots of the docs discussing the model have been updated to try to the *concept* of this design in the hopes that it can be iterated on. See #95228
2022-03-30remove now unnecessary lang itemslcnr-2/+2
2022-03-30rework implementation for inherent impls for builtin typeslcnr-0/+79
2022-03-30Rollup merge of #95452 - yaahc:termination-version-correction, r=ehussDylan DPC-13/+13
fix since field version for termination stabilization fixes incorrect version fields in stabilization of https://github.com/rust-lang/rust/pull/93840 r? `@ehuss`
2022-03-30Rollup merge of #95294 - sourcefrog:doc-copy, r=dtolnayDylan DPC-3/+19
Document Linux kernel handoff in std::io::copy and std::fs::copy
2022-03-29Warn that platform-specific behavior may changeMartin Pool-1/+5
2022-03-29fix unix typedefAria Beingessner-1/+1
2022-03-29mark FIXMES for all the places found that are probably offset_fromAria Beingessner-0/+2
2022-03-29cleanup some of the less terrifying library codeAria Beingessner-1/+1
2022-03-29revert changes that cast functions to raw pointers, portability hazardAria Beingessner-11/+10
2022-03-29Make some linux/unix APIs better conform to strict provenance.Alexis Beingessner-36/+39
This largely makes the stdlib conform to strict provenance on Ubuntu. Some hairier things have been left alone for now.
2022-03-29Make the stdlib largely conform to strict provenance.Aria Beingessner-57/+72
Some things like the unwinders and system APIs are not fully conformant, this only covers a lot of low-hanging fruit.
2022-03-29fix since field version for termination stabilizationJane Lusby-13/+13
2022-03-29Rollup merge of #95256 - thomcc:fix-unwind-safe, r=m-ou-seDylan DPC-5/+15
Ensure io::Error's bitpacked repr doesn't accidentally impl UnwindSafe Sadly, I'm not sure how to easily test that we don't impl a trait, though (or can libstd use `where io::Error: !UnwindSafe` or something). Fixes #95203
2022-03-29Rollup merge of #93840 - ↵Dylan DPC-24/+68
yaahc:termination-stabilization-celebration-station, r=joshtriplett Stabilize Termination and ExitCode From https://github.com/rust-lang/rust/issues/43301 This PR stabilizes the Termination trait and associated ExitCode type. It also adjusts the ExitCode feature flag to replace the placeholder flag with a more permanent name, as well as splitting off the `to_i32` method behind its own permanently unstable feature flag. This PR stabilizes the termination trait with the following signature: ```rust pub trait Termination { fn report(self) -> ExitCode; } ``` The existing impls of `Termination` are effectively already stable due to the prior stabilization of `?` in main. This PR also stabilizes the following APIs on exit code ```rust #[derive(Clone, Copy, Debug)] pub struct ExitCode(_); impl ExitCode { pub const SUCCESS: ExitCode; pub const FAILURE: ExitCode; } impl From<u8> for ExitCode { /* ... */ } ``` --- All of the previous blockers have been resolved. The main ones that were resolved recently are: * The trait's name: We decided against changing this since none of the alternatives seemed particularly compelling. Instead we decided to end the bikeshedding and stick with the current name. ([link to the discussion](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization/near/269793887)) * Issues around platform specific representations: We resolved this issue by changing the return type of `report` from `i32` to the opaque type `ExitCode`. That way we can change the underlying representation without affecting the API, letting us offer full support for platform specific exit code APIs in the future. * Custom exit codes: We resolved this by adding `From<u8> for ExitCode`. We choose to only support u8 initially because it is the least common denominator between the sets of exit codes supported by our current platforms. In the future we anticipate adding platform specific extension traits to ExitCode for constructors from larger or negative numbers, as needed.
2022-03-29Indicate the correct error code in the `compile_fail` block.Thom Chiovoloni-1/+1
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2022-03-29Auto merge of #95375 - MarcusCalhoun-Lopez:i686_apple_darwin, r=m-ou-sebors-5/+8
Fix build on i686-apple-darwin systems Replace `target_arch = "x86_64"` with `not(target_arch = "aarch64")` so that i686-apple-darwin systems dynamically choose implementation.
2022-03-28Fix build on i686-apple-darwin systemsMarcus Calhoun-Lopez-0/+3
On 32-bit systems, fdopendir is called `_fdopendir$INODE64$UNIX2003`. On 64-bit systems, fdopendir is called `_fdopendir$INODE64`.
2022-03-28Fix build on i686-apple-darwin systemsMarcus Calhoun-Lopez-5/+5
Replace `target_arch = "x86_64"` with `not(target_arch = "aarch64")` so that i686-apple-darwin systems dynamically choose implementation.
2022-03-28Touch up ExitCode docsNoa-7/+26
2022-03-27Link to std::io's platform-specific behavior disclaimerDavid Tolnay-4/+13
2022-03-25std::process docs: linkify references to output, spawn and statusest31-7/+20
2022-03-24Document Linux kernel handoff in std::io::copy and std::fs::copyMartin Pool-2/+14
2022-03-23Add a `compile_fail` doctest to check that `io::Error: !UnwindSafe`Thom Chiovoloni-0/+9
2022-03-23Ensure io::Error's bitpacked repr doesn't accidentally impl UnwindSafeThom Chiovoloni-5/+6
2022-03-23Auto merge of #95173 - m-ou-se:sys-locks-module, r=dtolnaybors-100/+133
Move std::sys::{mutex, condvar, rwlock} to std::sys::locks. This cleans up the the std::sys modules a bit by putting the locks in a single module called `locks` rather than spread over the three modules `mutex`, `condvar`, and `rwlock`. This makes it easier to organise lock implementations, which helps with https://github.com/rust-lang/rust/issues/93740.
2022-03-22Move std::sys::{mutex, condvar, rwlock} to std::sys::locks.Mara Bos-40/+64
2022-03-22add some fixZHANGWENTAI-3/+4
Signed-off-by: ZHANGWENTAI <2092913428@qq.com>
2022-03-22fix the lint problemZHANGWENTAI-1/+1
Signed-off-by: ZHANGWENTAI <2092913428@qq.com>
2022-03-22update Termination trait docsZHANGWENTAI-0/+4
2022-03-22Auto merge of #95158 - sunfishcode:sunfishcode/windows-8, r=joshtriplettbors-2/+24
Preserve the Windows `GetLastError` error in `HandleOrInvalid`. In the `TryFrom<HandleOrInvalid> for OwnedHandle` and `TryFrom<HandleOrNull> for OwnedHandle` implemenations, `forget` the owned handle on the error path, to avoid calling `CloseHandle` on an invalid handle. It's harmless, except that it may overwrite the thread's `GetLastError` error. r? `@joshtriplett`
2022-03-21Move pthread locks to own module.Mara Bos-60/+69
2022-03-20Add a testcase.Dan Gohman-0/+6
2022-03-20Preserve the Windows `GetLastError` error in `HandleOrInvalid`.Dan Gohman-2/+18
In the `TryFrom<HandleOrInvalid> for OwnedHandle` and `TryFrom<HandleOrNull> for OwnedHandle` implemenations, `forget` the owned handle on the error path, to avoid calling `CloseHandle` on an invalid handle. It's harmless, except that it may overwrite the thread's `GetLastError` error.
2022-03-20Rollup merge of #95114 - ChrisDenton:symlink-test, r=the8472Matthias Krüger-2/+9
Skip a test if symlink creation is not possible If someone running tests on Windows does not have Developer Mode enabled then creating symlinks will fail which in turn would cause this test to fail. This can be a stumbling block for contributors.
2022-03-20Rollup merge of #94749 - RalfJung:remove-dir-all-miri, r=cuviperMatthias Krüger-6/+7
remove_dir_all: use fallback implementation on Miri Fixes https://github.com/rust-lang/miri/issues/1966 The new implementation requires `openat`, `unlinkat`, and `fdopendir`. These cannot easily be shimmed in Miri since libstd does not expose APIs corresponding to them. So for now it is probably easiest to just use the fallback code in Miri. Nobody should run Miri as root anyway...
2022-03-19Stabilize thread::is_finishedJubilee Young-2/+2
2022-03-19Skip a test if symlink creation is not possibleChris Denton-2/+9
2022-03-19Rollup merge of #94650 - ChrisDenton:windows-absolute-fix, r=dtolnayDylan DPC-7/+7
Relax tests for Windows dos device names Windows 11 no longer turn paths ending with dos device names into device paths. E.g. `C:\path\to\COM1.txt` used to get turned into `\\.\COM1`. Whereas now this path is left as is. Note though that if the given path is an exact (case-insensitive) match for the string `COM1` then it'll still be converted to `\\.\COM1`.
2022-03-19Rollup merge of #93858 - krallin:process-process_group, r=dtolnayDylan DPC-2/+90
Add a `process_group` method to UNIX `CommandExt` - Tracking issue: #93857 - RFC: https://github.com/rust-lang/rfcs/pull/3228 Add a `process_group` method to `std::os::unix::process::CommandExt` that allows setting the process group id (i.e. calling `setpgid`) in the child, thus enabling users to set process groups while leveraging the `posix_spawn` fast path.
2022-03-19Rollup merge of #94984 - ericseppanen:cstr_from_bytes, r=Mark-SimulacrumDylan DPC-0/+106
add `CStr` method that accepts any slice containing a nul-terminated string I haven't created an issue (tracking or otherwise) for this yet; apologies if my approach isn't correct. This is my first code contribution. This change adds a member fn that converts a slice into a `CStr`; it is intended to be safer than `from_ptr` (which is unsafe and may read out of bounds), and more useful than `from_bytes_with_nul` (which requires that the caller already know where the nul byte is). The reason I find this useful is for situations like this: ```rust let mut buffer = [0u8; 32]; unsafe { some_c_function(buffer.as_mut_ptr(), buffer.len()); } let result = CStr::from_bytes_with_nul(&buffer).unwrap(); ``` This code above returns an error with `kind = InteriorNul`, because `from_bytes_with_nul` expects that the caller has passed in a slice with the NUL byte at the end of the slice. But if I just got back a nul-terminated string from some FFI function, I probably don't know where the NUL byte is. I would wish for a `CStr` constructor with the following properties: - Accept `&[u8]` as input - Scan for the first NUL byte and return the `CStr` that spans the correct sub-slice (see [future note below](https://github.com/rust-lang/rust/pull/94984#issuecomment-1070754281)). - Return an error if no NUL byte is found within the input slice I asked on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/CStr.20from.20.26.5Bu8.5D.20without.20knowing.20the.20NUL.20location.3F) whether this sounded like a good idea, and got a couple of positive-sounding responses from ``@joshtriplett`` and ``@AzureMarker.`` This is my first draft, so feedback is welcome. A few issues that definitely need feedback: 1. Naming. ``@joshtriplett`` called this `from_bytes_with_internal_nul` on Zulip, but after staring at all of the available methods, I believe that this function is probably what end users want (rather than the existing fn `from_bytes_with_nul`). Giving it a simpler name (**`from_bytes`**) implies that this should be their first choice. 2. Should I add a similar method on `CString` that accepts `Vec<u8>`? I'd assume the answer is probably yes, but I figured I'd try to get early feedback before making this change bigger. 3. What should the error type look like? I made a unit struct since `CStr::from_bytes` can only fail in one obvious way, but if I need to do this for `CString` as well then that one may want to return `FromVecWithNulError`. And maybe that should dictate the shape of the `CStr` error type also? Also, cc ``@poliorcetics`` who wrote #73139 containing similar fns.
2022-03-19Rollup merge of #93692 - mfrw:mfrw/document-keyword-in, r=dtolnayDylan DPC-0/+14
keyword_docs: document use of `in` with `pub` keyword Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com> Fixes: #93609
2022-03-19Rollup merge of #93263 - sunfishcode:sunfishcode/detatched-console-handle, ↵Dylan DPC-16/+100
r=dtolnay Consistently present absent stdio handles on Windows as NULL handles. 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-19Rollup merge of #92663 - cuviper:generic-write-cursor, r=dtolnayDylan DPC-51/+86
Implement `Write for Cursor<[u8; N]>`, plus `A: Allocator` cursor support This implements `Write for Cursor<[u8; N]>`, and also adds support for generic `A: Allocator` in `Box` and `Vec` cursors. This was inspired by a user questioning why they couldn't write a `Cursor<[u8; N]>`: https://users.rust-lang.org/t/why-vec-and-not-u8-makes-cursor-have-write/68210 Related history: - #27197 switched `AsRef<[u8]>` for reading and seeking - #67415 tried to use `AsMut<[u8]>` for writing, but did not specialize `Vec`.
2022-03-19Rollup merge of #92612 - atopia:update-lib-l4re, r=dtolnayDylan DPC-17/+809
Update stdlib for the l4re target This PR contains the work by ``@humenda`` and myself to update standard library support for the x86_64-unknown-l4re-uclibc tier 3 target, split out from humenda/rust as requested in #85967. The changes have been rebased on current master and updated in follow up commits by myself. The publishing of the changes is authorized and preferred by the original author. To preserve attribution, when standard library changes were introduced as part of other changes to the compiler, I have kept the changes concerning the standard library and altered the commit messages as indicated. Any incompatibilities have been remedied in follow up commits, so that the PR as a whole should result in a clean update of the target.
2022-03-19Rollup merge of #92519 - ChrisDenton:command-maybe-verbatim, r=dtolnayDylan DPC-30/+44
Use verbatim paths for `process::Command` if necessary In #89174, the standard library started using verbatim paths so longer paths are usable by default. However, `Command` was originally left out because of the way `CreateProcessW` was being called. This was changed as a side effect of #87704 so now `Command` paths can be converted to verbatim too (if necessary).
2022-03-18add CStr::from_bytes_until_nulEric Seppanen-0/+106
This adds a member fn that converts a slice into a CStr; it is intended to be safer than from_ptr (which is unsafe and may read out of bounds), and more useful than from_bytes_with_nul (which requires that the caller already know where the nul byte is). feature gate: cstr_from_bytes_until_nul Also add an error type FromBytesUntilNulError for this fn.