about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2023-04-10Fix typos in libraryDaniPopes-3/+3
2023-04-10Stabilize IsTerminalJosh Triplett-6/+6
closes: https://github.com/rust-lang/rust/issues/98070
2023-04-09Apply suggestions from code review Richard Schneeman-1/+1
Fixes documentation. I wrote `env_clear` when I meant `env_remove`. Good catch. Co-authored-by: Josh Stone <cuviper@gmail.com>
2023-04-09Auto merge of #109500 - petrochenkov:modchainld, r=oli-obkbors-0/+2
resolve: Preserve reexport chains in `ModChild`ren This may be potentially useful for - avoiding uses of `hir::ItemKind::Use` (which usually lead to correctness issues) - preserving documentation comments on all reexports, including those from other crates - preserving and checking stability/deprecation info on reexports - all kinds of diagnostics The second commit then migrates some hacky logic from rustdoc to `module_reexports` to make it simpler and more correct. Ideally rustdoc should use `module_reexports` immediately at the top level, so `hir::ItemKind::Use`s are never used. The second commit also fixes issues with https://github.com/rust-lang/rust/pull/109330 and therefore Fixes https://github.com/rust-lang/rust/issues/109631 Fixes https://github.com/rust-lang/rust/issues/109614 Fixes https://github.com/rust-lang/rust/issues/109424
2023-04-09Rollup merge of #110060 - WaffleLapkin:sync_refs, r=jyn514Yuki Okushi-0/+1
Document that `&T` and `&mut T` are `Sync` if `T` is Proof: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=fec8dc9ec36e873bf2962a2367d67045
2023-04-08Add 64-bit `time_t` support on 32-bit glibc Linux to `set_times`beetrees-2/+39
2023-04-08sync::mpsc: synchronize receiver disconnect with initializationPetros Angelatos-0/+12
Receiver disconnection relies on the incorrect assumption that `head.index != tail.index` implies that the channel is initialized (i.e `head.block` and `tail.block` point to allocated blocks). However, it can happen that `head.index != tail.index` and `head.block == null` at the same time which leads to a segfault when a channel is dropped in that state. This can happen because initialization is performed in two steps. First, the tail block is allocated and the `tail.block` is set. If that is successful `head.block` is set to the same pointer. Importantly, initialization is skipped if `tail.block` is not null. Therefore we can have the following situation: 1. Thread A starts to send the first value of the channel, observes that `tail.block` is null and begins initialization. It sets `tail.block` to point to a newly allocated block and then gets preempted. `head.block` is still null at this point. 2. Thread B starts to send the second value of the channel, observes that `tail.block` *is not* null and proceeds with writing its value in the allocated tail block and sets `tail.index` to 1. 3. Thread B drops the receiver of the channel which observes that `head.index != tail.index` (0 and 1 respectively), therefore there must be messages to drop. It starts traversing the linked list from `head.block` which is still a null pointer, leading to a segfault. This PR fixes this problem by waiting for initialization to complete when `head.index != tail.index` and the `head.block` is still null. A similar check exists in `start_recv` for similar reasons. Fixes #110001 Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
2023-04-08std: Mark two reexports that should be inlined as `doc(inline)`Vadim Petrochenkov-0/+2
2023-04-08Auto merge of #109995 - ↵bors-1/+1
enkron:u/enkron/substitute-hardcoded-port-num-in-listen-on-fn, r=the8472 chore(tcp): change a hardcoded port number in a doctest to `port` var The `listen_on` function in the example has a `port` option but doesn't use it
2023-04-08fix(tcp): remove redundant `format!` macro callSergei Belokon-1/+1
2023-04-07Document that `&T` and `&mut T` are `Sync` if `T` isMaybe Waffle-0/+1
2023-04-08Define UNWIND_DATA_REG for loongarch64zhaixiaojuan-0/+3
2023-04-07Don't claim LocalKey::with prevents a reference to be sent across threadsGiacomo Stevanato-2/+2
2023-04-07Auto merge of #110019 - jplatte:jplatte/stabilize-is-some-and, r=Amanieubors-1/+0
Stabilize is_some_and This stabilizes the following public API: ```rust impl<T> Option<T> { pub fn is_some_and(self, f: impl FnOnce(T) -> bool) -> bool; } impl<T, E> Result<T, E> { pub fn is_ok_and(self, f: impl FnOnce(T) -> bool) -> bool; pub fn is_err_and(self, f: impl FnOnce(E) -> bool) -> bool; } ``` Closes #93050 (tracking issue). `@rustbot` label +T-libs-api -T-libs
2023-04-07Auto merge of #109990 - gwy15:remove-bufwriter-useless-mut-pointer, r=jyn514bors-1/+1
Remove an unnecessary `mut` in `BufWriter::into_parts`. `ptr::read` takes `*const T` so `&mut` is not necessary.
2023-04-07Rollup merge of #109960 - thomcc:symlink-junction-buffer-overrun, r=ChrisDentonMatthias Krüger-9/+25
Fix buffer overrun in bootstrap and (test-only) symlink_junction I don't think these can be hit in practice, due to their inputs being valid paths. It's also not security-sensitive code, but just... bad vibes. I think this is still not really the right way to do this (in terms of path correctness), but is no worse than it was. r? `@ChrisDenton`
2023-04-07Rollup merge of #109806 - Zoxc:gnu-tls, r=pnkfelixMatthias Krüger-1/+3
Workaround #109797 on windows-gnu The addition of `#[inline]` here in https://github.com/rust-lang/rust/pull/108089 caused an unrelated linking issue (https://github.com/rust-lang/rust/issues/109797). This PR removes this attribute again on Windows to avoid regressions.
2023-04-06Stabilize is_some_andJonas Platte-1/+0
2023-04-06chore(tcp): change the hardcoded port number to `port` varSergei Belokon-1/+1
The `listen_on` function in the example has a `port` option but doesn't use it
2023-04-06Remove an unnecessary `mut` in `BufWriter::into_parts`.管唯宇-1/+1
`ptr::read` takes `*const T` so `&mut` is not necessary.
2023-04-05Fix buffer overrun in (test-only) symlink_junctionThom Chiovoloni-9/+25
2023-04-04library/std: Add support for loongarch64zhaixiaojuan-0/+3
2023-04-03avoid zero-copy ops for File->Pipe and File->Socket in io::copyThe 8472-16/+46
2023-04-03test that modifications to the source don't become visible after io::copyThe 8472-0/+42
2023-04-03Preserve potential mood for equal or NUL signfleetingbytes-5/+3
Original `var_os` description said that it _may_ return an error if the value contains `=` or NUL. Let's make no promises on the `None` return value in these situation either, keep it in the [potential mood](https://en.wikipedia.org/wiki/Grammatical_mood#Potential).
2023-04-03Remove redundant empty linefleetingbytes-1/+0
one is enough
2023-04-03remove self-reference in var_os docfleetingbytes-1/+0
Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
2023-04-03add situation where var_os returns Nonefleetingbytes-1/+7
Re-introduced some of the former errors as situations where `None` is returned.
2023-04-03Update env.rsfleetingbytes-10/+0
Remove `Errors` section from `var_os` documentation
2023-04-03Rollup merge of #109722 - hermitcore:read, r=Mark-SimulacrumMatthias Krüger-7/+24
Implement read_buf for RustHermit In principle, this PR extends rust-lang/rust#108326 for RustyHermit.
2023-04-02Fix typo in std/src/os/fd/owned.rsTaiki Endo-1/+1
2023-03-31Rollup merge of #109443 - GuillaumeGomez:doc-primitive-hard-error, r=notriddleGuillaume Gomez-25/+50
Move `doc(primitive)` future incompat warning to `invalid_doc_attributes` Fixes #88070. It's been a while since this was turned into a "future incompatible lint" so I think we can now turn it into a hard error without problem. r? `@jyn514`
2023-03-31Workaround #109797 on windows-gnuJohn Kåre Alsaker-1/+3
2023-03-30Replace doc(primitive) with rustc_doc_primitiveGuillaume Gomez-25/+50
2023-03-30Refactor glibc time64 support, riscv32 always has 64-bit `time_t`beetrees-14/+36
2023-03-30Auto merge of #105587 - tgross35:once-cell-min, r=m-ou-sebors-53/+41
Partial stabilization of `once_cell` This PR aims to stabilize a portion of the `once_cell` feature: - `core::cell::OnceCell` - `std::cell::OnceCell` (re-export of the above) - `std::sync::OnceLock` This will leave `LazyCell` and `LazyLock` unstabilized, which have been moved to the `lazy_cell` feature flag. Tracking issue: https://github.com/rust-lang/rust/issues/74465 (does not fully close, but it may make sense to move to a new issue) Future steps for separate PRs: - ~~Add `#[inline]` to many methods~~ #105651 - Update cranelift usage of the `once_cell` crate - Update rust-analyzer usage of the `once_cell` crate - Update error messages discussing once_cell ## To be stabilized API summary ```rust // core::cell (in core/cell/once.rs) pub struct OnceCell<T> { .. } impl<T> OnceCell<T> { pub const fn new() -> OnceCell<T>; pub fn get(&self) -> Option<&T>; pub fn get_mut(&mut self) -> Option<&mut T>; pub fn set(&self, value: T) -> Result<(), T>; pub fn get_or_init<F>(&self, f: F) -> &T where F: FnOnce() -> T; pub fn into_inner(self) -> Option<T>; pub fn take(&mut self) -> Option<T>; } impl<T: Clone> Clone for OnceCell<T>; impl<T: Debug> Debug for OnceCell<T> impl<T> Default for OnceCell<T>; impl<T> From<T> for OnceCell<T>; impl<T: PartialEq> PartialEq for OnceCell<T>; impl<T: Eq> Eq for OnceCell<T>; ``` ```rust // std::sync (in std/sync/once_lock.rs) impl<T> OnceLock<T> { pub const fn new() -> OnceLock<T>; pub fn get(&self) -> Option<&T>; pub fn get_mut(&mut self) -> Option<&mut T>; pub fn set(&self, value: T) -> Result<(), T>; pub fn get_or_init<F>(&self, f: F) -> &T where F: FnOnce() -> T; pub fn into_inner(self) -> Option<T>; pub fn take(&mut self) -> Option<T>; } impl<T: Clone> Clone for OnceLock<T>; impl<T: Debug> Debug for OnceLock<T>; impl<T> Default for OnceLock<T>; impl<#[may_dangle] T> Drop for OnceLock<T>; impl<T> From<T> for OnceLock<T>; impl<T: PartialEq> PartialEq for OnceLock<T> impl<T: Eq> Eq for OnceLock<T>; impl<T: RefUnwindSafe + UnwindSafe> RefUnwindSafe for OnceLock<T>; unsafe impl<T: Send> Send for OnceLock<T>; unsafe impl<T: Sync + Send> Sync for OnceLock<T>; impl<T: UnwindSafe> UnwindSafe for OnceLock<T>; ``` No longer planned as part of this PR, and moved to the `rust_cell_try` feature gate: ```rust impl<T> OnceCell<T> { pub fn get_or_try_init<F, E>(&self, f: F) -> Result<&T, E> where F: FnOnce() -> Result<T, E>; } impl<T> OnceLock<T> { pub fn get_or_try_init<F, E>(&self, f: F) -> Result<&T, E> where F: FnOnce() -> Result<T, E>; } ``` I am new to this process so would appreciate mentorship wherever needed.
2023-03-30Auto merge of #107221 - kleisauke:getentropy-emscripten, r=ChrisDentonbors-2/+3
Use `getentropy()` instead of `/dev/urandom` on Emscripten `/dev/urandom` is usually available on Emscripten, except when using the special `NODERAWFS` filesystem backend, which replaces all normal filesystem access with direct Node.js operations. Since this filesystem backend directly access the filesystem on the OS, it is not recommended to depend on `/dev/urandom`, especially when trying to run the Wasm binary on OSes that are not Unix-based. This can be considered a non-functional change, since Emscripten implements `/dev/urandom` in the same way as `getentropy()` when not linking with `-sNODERAWFS`.
2023-03-29Documentation updates to better share the purpose of OnceCell/OnceLockTrevor Gross-1/+4
2023-03-29Stabilize a portion of 'once_cell'Trevor Gross-52/+37
Move items not part of this stabilization to 'lazy_cell' or 'once_cell_try'
2023-03-29Rollup merge of #107387 - joboet:hermit_random, r=ChrisDentonMatthias Krüger-2/+11
Use random `HashMap` keys on Hermit Initializing the keys with random data provided by the libOS avoids HashDOS attacks and similar issues. CC `@stlankes`
2023-03-29Auto merge of #108089 - Zoxc:windows-tls, r=bjorn3bors-48/+4
Support TLS access into dylibs on Windows This allows access to `#[thread_local]` in upstream dylibs on Windows by introducing a MIR shim to return the address of the thread local. Accesses that go into an upstream dylib will call the MIR shim to get the address of it. `convert_tls_rvalues` is introduced in `rustc_codegen_ssa` which rewrites MIR TLS accesses to dummy calls which are replaced with calls to the MIR shims when the dummy calls are lowered to backend calls. A new `dll_tls_export` target option enables this behavior with a `false` value which is set for Windows platforms. This fixes https://github.com/rust-lang/rust/issues/84933.
2023-03-29Implement read_buf for RustHermitStefan Lankes-7/+24
In principle, this PR extends rust-lang/rust#108326 for RustyHermit. Signed-off-by: Stefan Lankes <slankes@eonerc.rwth-aachen.de>
2023-03-29Use with_capacity_and_hasher instead of using basetosti007-1/+1
2023-03-29std: use `cvt` to handle errors from `read_entropy` on Hermitjoboet-9/+3
2023-03-29Auto merge of #108792 - Amanieu:ohos, r=petrochenkovbors-1/+4
Add OpenHarmony targets - `aarch64-unknown-linux-ohos` - `armv7-unknown-linux-ohos` Compiler team MCP: https://github.com/rust-lang/compiler-team/issues/568
2023-03-29Use #[inline] on Windows for thread local accessJohn Kåre Alsaker-48/+4
2023-03-28Add OpenHarmony targetsAmanieu d'Antras-1/+4
- `aarch64-unknown-linux-ohos` - `armv7-unknown-linux-ohos`
2023-03-28Rollup merge of #91793 - devnexen:anc_data_fbsd, r=ChrisDentonnils-21/+205
socket ancillary data implementation for FreeBSD (from 13 and above). introducing new build config as well.
2023-03-27Allow access to `OsStr` bytesEd Page-9/+91
`OsStr` has historically kept its implementation details private out of concern for locking us into a specific encoding on Windows. This is an alternative to #95290 which proposed specifying the encoding on Windows. Instead, this only specifies that for cross-platform code, `OsStr`'s encoding is a superset of UTF-8 and defines rules for safely interacting with it At minimum, this can greatly simplify the `os_str_bytes` crate and every arg parser that interacts with `OsStr` directly (which is most of those that support invalid UTF-8).
2023-03-28Add "Platform-specific behavior" heading and link to changes disclaimerJosh Triplett-0/+5