about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2023-07-02Rollup merge of #113202 - guilliamxavier:patch-1, r=workingjubileeMatthias Krüger-6/+8
std docs: factorize literal in Barrier example Motivated by https://www.reddit.com/r/rust/comments/rnh5hu/barrier_question_barrier_does_not_sync_many/ (but maybe not worth it?)
2023-07-01Return `Ok` on kill if process has already exitedChris Denton-14/+17
2023-06-30std docs: factorize literal in Barrier exampleGuilliam Xavier-6/+8
2023-06-29make HashMap::or_insert_with example more simpleTshepang Mbambo-4/+4
2023-06-27std: remove an allocation in `Path::with_extension`João M. Bezerra-3/+21
`Path::with_extension` used to reallocate (and copy) paths twice per call, now it does it once, by checking the size of the previous and new extensions it's possible to call `PathBuf::with_capacity` and pass the exact capacity it takes. Also reduce the memory consumption of the path returned from `Path::with_extension` by using exact capacity instead of using amortized exponential growth.
2023-06-25Stabilize chown functions (`unix_chown`)Yuki Okushi-6/+3
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
2023-06-25Auto merge of #113001 - ChrisDenton:win-arm32-shim, r=thomccbors-49/+44
Move windows-sys arm32 shim to c.rs This moves the arm32 shim in to c.rs instead of appending to the generated file itself. This makes it simpler to change these workarounds if/when needed. The downside is we need to exclude a couple of functions from being generated (see the comment). A metadata solution could help here but they'll be easy enough to add back if that happens.
2023-06-25Rollup merge of #113009 - ChrisDenton:remove-path, r=workingjubileeMatthias Krüger-1/+0
Remove unnecessary `path` attribute Follow up to #111401. I missed this at the time but it should now be totally unnecessary since the other include was removed. r? `@workingjubilee`
2023-06-25Rollup merge of #112950 - tshepang:patch-4, r=Mark-SimulacrumMatthias Krüger-2/+8
DirEntry::file_name: improve explanation
2023-06-24Remove unnecessary `path` attributeChris Denton-1/+0
2023-06-24Move arm32 shim to c.rsChris Denton-49/+44
2023-06-23Rollup merge of #111087 - ibraheemdev:patch-15, r=dtolnayMichael Goulet-2/+2
Implement `Sync` for `mpsc::Sender` `mpsc::Sender` is currently `!Sync` because the previous implementation contained an optimization where the channel started out as single-producer and was dynamically upgraded on the first clone, which relied on a unique reference to the sender. This optimization is one of the main reasons the old implementation was so complex and was removed in #93563. `mpsc::Sender` can now soundly implement `Sync`. Note for any potential confusion, this chance does *not* add MPMC behavior. This only affects the already `Send + Clone` *sender*, not *receiver*. It's technically possible to rely on the `!Sync` behavior in the same way as a `PhantomData<*mut T>`, but that seems very unlikely in practice. Either way, this change is insta-stable and needs an FCP. `@rustbot` label +T-libs-api -T-libs
2023-06-23Add `Read`, `Write` and `Seek` impls for `Arc<File>` where appropriateTobias Bucher-0/+46
If `&T` implements these traits, `Arc<T>` has no reason not to do so either. This is useful for operating system handles like `File` or `TcpStream` which don't need a mutable reference to implement these traits. CC #53835. CC #94744.
2023-06-23Forward `io::{Read,Seek,Write}` impls of `File` to `&File`Tobias Bucher-33/+20
This reduces code duplication.
2023-06-23DirEntry::file_name: improve explanationTshepang Mbambo-2/+8
2023-06-21Actually save all the filesThom Chiovoloni-7/+6
2023-06-21Update tvOS support elsewhere in the stdlibThom Chiovoloni-7/+36
2023-06-21Avoid fork/exec spawning on tvOS/watchOS, as those functions are marked as ↵Thom Chiovoloni-4/+48
prohibited
2023-06-21Finish up preliminary tvos support in libstdThom Chiovoloni-1/+15
2023-06-21wip: Support Apple tvOS in libstdThom Chiovoloni-20/+82
2023-06-21Rollup merge of #112863 - clubby789:stderr-typo, r=albertlarsan68Guillaume Gomez-2/+2
Fix copy-paste typo in `eprint(ln)` docs Fixes #112862
2023-06-21Rollup merge of #99587 - ibraheemdev:park-orderings, r=m-ou-seGuillaume Gomez-11/+21
Document memory orderings of `thread::{park, unpark}` Document `thread::park/unpark` as having acquire/release synchronization. Without that guarantee, even the example in the documentation can deadlock: ```rust let flag = Arc::new(AtomicBool::new(false)); let t2 = thread::spawn(move || { while !flag.load(Ordering::Acquire) { thread::park(); } }); flag.store(true, Ordering::Release); t2.thread().unpark(); // t1: flag.store(true) // t1: thread.unpark() // t2: flag.load() == false // t2 now parks, is immediately unblocked but never // acquires the flag, and thus spins forever ``` Multiple calls to `unpark` should also maintain a release sequence to make sure operations released by previous `unpark`s are not lost: ```rust let a = Arc::new(AtomicBool::new(false)); let b = Arc::new(AtomicBool::new(false)); let t2 = thread::spawn(move || { while !a.load(Ordering::Acquire) || !b.load(Ordering::Acquire) { thread::park(); } }); thread::spawn(move || { a.store(true, Ordering::Release); t2.thread().unpark(); }); b.store(true, Ordering::Release); t2.thread().unpark(); // t1: a.store(true) // t1: t2.unpark() // t3: b.store(true) // t3: t2.unpark() // t2 now parks, is immediately unblocked but never // acquires the store of `a`, only the store of `b` which // was released by the most recent unpark, and thus spins forever ``` This is of course a contrived example, but is reasonable to rely upon in real code. Note that all implementations of park/unpark already comply with the rules, it's just undocumented.
2023-06-21"Memory Orderings" -> "Memory Ordering"Mara Bos-1/+1
Co-authored-by: yvt <i@yvt.jp>
2023-06-21Fix typo in `eprintln` docsclubby789-2/+2
2023-06-20relaxed orderings in `thread::park` exampleIbraheem Ahmed-3/+4
2023-06-20Rollup merge of #112464 - eval-exec:exec/fix-connect_timeout-overflow, ↵Guillaume Gomez-1/+12
r=ChrisDenton Fix windows `Socket::connect_timeout` overflow This PR want to close #112405 - [x] add unit test
2023-06-20Remove useless unit testsEval EXEC-21/+0
2023-06-20Ignore `connect_timeout` unit test on SGX platformEval EXEC-0/+1
Co-authored-by: Chris Denton <christophersdenton@gmail.com>
2023-06-19Rollup merge of #112606 - clarfonthey:ip-display, r=thomccMichael Goulet-1/+1
Alter `Display` for `Ipv6Addr` for IPv4-compatible addresses ACP: rust-lang/libs-team#239
2023-06-19Document thread names for SGX compilation targetVas-1/+9
2023-06-18Add unit test to connect to an unreachable addressEval EXEC-0/+11
Signed-off-by: Eval EXEC <execvy@gmail.com>
2023-06-18Rollup merge of #107200 - mina86:c, r=AmanieuMatthias Krüger-5/+6
io: soften ‘at most one write attempt’ requirement in io::Write::write At the moment, documentation of std::io::Write::write indicates that call to it ‘represents at most one attempt to write to any wrapped object’. It seems that such wording was put there to contrast it with pre-1.0 interface which attempted to write all the data (it has since been changed in [RFC 517]). However, the requirement puts unnecessary constraints and may complicate adaptors which perform non-trivial transformations on the data. For example, they may maintain an internal buffer which needs to be written out before the write method accepts more data. It might be natural to code the method such that it flushes the buffer and then grabs another chunk of user data. With the current wording in the documentation, the adaptor would be forced to return Ok(0). This commit softens the wording such that implementations can choose code structure which makes most sense for their particular use case. While at it, elaborate on the meaning of `Ok(0)` return pointing out that the write_all methods interprets it as an error. [RFC 517]: https://rust-lang.github.io/rfcs/0517-io-os-reform.html
2023-06-17Auto merge of #112595 - hargoniX:l4re_fix, r=Mark-Simulacrumbors-3/+23
fix: get the l4re target working again This is based on work from https://github.com/rust-lang/rust/pull/103966, addressing the review comment by `@m-ou-se` at the time and "fixing" the (probably newly) missing read_buf.
2023-06-18Add unit test for `TcpStream::connect_timeout`Eval EXEC-0/+20
Signed-off-by: Eval EXEC <execvy@gmail.com>
2023-06-18Fix windows `Socket::connect_timeout` overflowEval EXEC-1/+1
Signed-off-by: Eval EXEC <execvy@gmail.com>
2023-06-17Auto merge of #112739 - matthiaskrgr:rollup-8cfggml, r=matthiaskrgrbors-1/+7
Rollup of 6 pull requests Successful merges: - #112352 (Fix documentation build on FreeBSD) - #112644 (Correct types in method descriptions of `NonZero*` types) - #112683 (fix ICE on specific malformed asm clobber_abi) - #112707 ([rustdoc] Fix invalid handling of "going back in history" when "go to only search result" setting is enabled) - #112719 (Replace fvdl with ffx, allow test without install) - #112728 (Add `<meta charset="utf-8">` to `-Zdump-mir-spanview` output) r? `@ghost` `@rustbot` modify labels: rollup
2023-06-17Rollup merge of #112352 - dankm:fbsd_doc_fix, r=thomccMatthias Krüger-1/+7
Fix documentation build on FreeBSD After the socket ancillary data implementation was introduced, the documentation build was broken on FreeBSD hosts, add the same workaround as for the existing implementations. Fixes the doc build after #91793
2023-06-17Extend io::copy buffer reuse to BufReader tooThe 8472-74/+207
previously it was only able to use BufWriter. This was due to a limitation in the BufReader generics that prevented specialization. This change works around the issue by using `where Self: Read` instead of `where I: Read`. This limits our options, e.g. we can't access BufRead methods, but it happens to work out if we rely on some implementation details.
2023-06-16Rollup merge of #112226 - devnexen:netbsd_affinity, r=cuviperMichael Goulet-0/+23
std: available_parallelism using native netbsd api first before falling back to existing code paths like FreeBSD does.
2023-06-16Rollup merge of #111074 - WaffleLapkin:🌟unsizes_your_buf_reader🌟, ↵Michael Goulet-111/+118
r=Amanieu Relax implicit `T: Sized` bounds on `BufReader<T>`, `BufWriter<T>` and `LineWriter<T>` TL;DR: ```diff,rust -pub struct BufReader<R> { /* ... */ } +pub struct BufReader<R: ?Sized> { /* ... */ } -pub struct BufWriter<W: Write> { /* ... */ } +pub struct BufWriter<W: ?Sized + Write> { /* ... */ } -pub struct LineWriter<W: Write> { /* ... */ } +pub struct LineWriter<W: ?Sized + Write> { /* ... */ } ``` This allows using `&mut BufReader<dyn Read>`, for example. **This is an insta-stable change**.
2023-06-16Remove `#[cfg(all())]` workarounds from `c_char`Alex Macleod-5/+0
2023-06-16Rollup merge of #112579 - MikaelUrankar:freebsd_docs, r=cuviperDylan DPC-0/+1
Fix building libstd documentation on FreeBSD. It fixes the following error: ``` error[E0412]: cannot find type `sockcred2` in module `libc` --> library/std/src/os/unix/net/ancillary.rs:211:29 | 211 | pub struct SocketCred(libc::sockcred2); | ^^^^^^^^^ not found in `libc` ```
2023-06-16Rollup merge of #112535 - RalfJung:miri-test-libstd, r=cuviperDylan DPC-6/+7
reorder attributes to make miri-test-libstd work again Fixes fallout from https://github.com/rust-lang/rust/pull/110141
2023-06-15Extend `unused_must_use` to cover block exprs许杰友 Jieyou Xu (Joe)-1/+1
2023-06-15Auto merge of #104455 - the8472:dont-drain-on-drop, r=Amanieubors-73/+76
Don't drain-on-drop in DrainFilter impls of various collections. This removes drain-on-drop behavior from various unstable DrainFilter impls (not yet for HashSet/Map) because that behavior [is problematic](https://github.com/rust-lang/rust/issues/43244#issuecomment-641638196) (because it can lead to panic-in-drop when user closures panic) and may become forbidden if [this draft RFC passes](https://github.com/rust-lang/rfcs/pull/3288). closes #101122 [ACP](https://github.com/rust-lang/libs-team/issues/136) affected tracking issues * #43244 * #70530 * #59618 Related hashbrown update: https://github.com/rust-lang/hashbrown/pull/374
2023-06-14Fix `SocketAddrV6: Display` testsltdk-1/+1
2023-06-14Rollup merge of #107619 - stepancheg:hash-set-insert, r=AmanieuMatthias Krüger-1/+23
Specify behavior of HashSet::insert `HashSet::insert` does not replace the value with equal value. Fixes #107581.
2023-06-14Rollup merge of #98202 - aticu:impl_tryfrom_osstr_for_str, r=AmanieuMatthias Krüger-14/+27
Implement `TryFrom<&OsStr>` for `&str` Recently when trying to work with `&OsStr` I was surprised to find this `impl` missing. Since the `to_str` method already existed the actual implementation is fairly non-controversial, except for maybe the choice of the error type. I chose an opaque error here instead of something like `std::str::Utf8Error`, since that would already make a number of assumption about the underlying implementation of `OsStr`. As this is a trait implementation, it is insta-stable, if I'm not mistaken? Either way this will need an FCP. I chose "1.64.0" as the version, since this is unlikely to land before the beta cut-off. `@rustbot` modify labels: +T-libs-api API Change Proposal: rust-lang/rust#99031 (accepted)
2023-06-14update hashbrown and replace Hash{Set,Map}::DrainFilter with ExtractIfThe 8472-73/+76
2023-06-13fix: get the l4re target working againHenrik Böving-3/+23