about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2022-06-04Rollup merge of #97647 - m-ou-se:lazy-box-locks, r=AmanieuDylan DPC-123/+184
Lazily allocate and initialize pthread locks. Lazily allocate and initialize pthread locks. This allows {Mutex, Condvar, RwLock}::new() to be const, while still using the platform's native locks for features like priority inheritance and debug tooling. E.g. on macOS, we cannot directly use the (private) APIs that pthread's locks are implemented with, making it impossible for us to use anything other than pthread while still preserving priority inheritance, etc. This PR doesn't yet make the public APIs const. That's for a separate PR with an FCP. Tracking issue: https://github.com/rust-lang/rust/issues/93740
2022-06-03Update set.rsnzrq-6/+4
2022-06-03Fully stabilize NLLJack Huey-2/+2
2022-06-03Auto merge of #95833 - notriddle:notriddle/human-readable-signals, r=yaahcbors-6/+82
std: `<ExitStatus as Display>::fmt` name the signal it died from Related to #95601
2022-06-03Add note to documentation of HashSet::intersectionnzrq-0/+7
2022-06-03Lazily allocate+initialize locks.Mara Bos-36/+145
2022-06-03Use Drop instead of destroy() for locks.Mara Bos-87/+39
2022-06-02Fix MIPS-specific signal bugMichael Howell-1/+10
2022-06-02Rollup merge of #97635 - rgwood:patch-1, r=ChrisDentonDylan DPC-2/+2
Fix file metadata documentation for Windows I noticed that the documentation for `fs::symlink_metadata()` and `fs::metadata()` is incorrect; [the underlying code](https://github.com/rust-lang/rust/blob/481db40311cdd241ae4d33f34f2f75732e44d8e8/library/std/src/sys/windows/fs.rs#L334) calls [`GetFileInformationByHandle()`](https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfileinformationbyhandle) on Windows, not [`GetFileAttributesEx()`](https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfileattributesexw). There are currently [no uses of `GetFileAttributesEx()` in this repo](https://github.com/rust-lang/rust/search?q=GetFileAttributesEx).
2022-06-02Auto merge of #97414 - LYF1999:yf/cachealign, r=Mark-Simulacrumbors-1/+2
use 128 cache align for aarch64 the cache line size of m1 mac is 128. so use `align(128)` for m1 mac here is `sysctl -a hw machdep.cpu` output on m1 mac ``` hw.ncpu: 10 hw.byteorder: 1234 hw.memsize: 68719476736 hw.activecpu: 10 hw.perflevel0.physicalcpu: 8 hw.perflevel0.physicalcpu_max: 8 hw.perflevel0.logicalcpu: 8 hw.perflevel0.logicalcpu_max: 8 hw.perflevel0.l1icachesize: 196608 hw.perflevel0.l1dcachesize: 131072 hw.perflevel0.l2cachesize: 12582912 hw.perflevel0.cpusperl2: 4 hw.perflevel1.physicalcpu: 2 hw.perflevel1.physicalcpu_max: 2 hw.perflevel1.logicalcpu: 2 hw.perflevel1.logicalcpu_max: 2 hw.perflevel1.l1icachesize: 131072 hw.perflevel1.l1dcachesize: 65536 hw.perflevel1.l2cachesize: 4194304 hw.perflevel1.cpusperl2: 2 hw.optional.arm.FEAT_FlagM: 1 hw.optional.arm.FEAT_FlagM2: 1 hw.optional.arm.FEAT_FHM: 1 hw.optional.arm.FEAT_DotProd: 1 hw.optional.arm.FEAT_SHA3: 1 hw.optional.arm.FEAT_RDM: 1 hw.optional.arm.FEAT_LSE: 1 hw.optional.arm.FEAT_SHA256: 1 hw.optional.arm.FEAT_SHA512: 1 hw.optional.arm.FEAT_SHA1: 1 hw.optional.arm.FEAT_AES: 1 hw.optional.arm.FEAT_PMULL: 1 hw.optional.arm.FEAT_SPECRES: 0 hw.optional.arm.FEAT_SB: 1 hw.optional.arm.FEAT_FRINTTS: 1 hw.optional.arm.FEAT_LRCPC: 1 hw.optional.arm.FEAT_LRCPC2: 1 hw.optional.arm.FEAT_FCMA: 1 hw.optional.arm.FEAT_JSCVT: 1 hw.optional.arm.FEAT_PAuth: 1 hw.optional.arm.FEAT_PAuth2: 0 hw.optional.arm.FEAT_FPAC: 0 hw.optional.arm.FEAT_DPB: 1 hw.optional.arm.FEAT_DPB2: 1 hw.optional.arm.FEAT_BF16: 0 hw.optional.arm.FEAT_I8MM: 0 hw.optional.arm.FEAT_ECV: 1 hw.optional.arm.FEAT_LSE2: 1 hw.optional.arm.FEAT_CSV2: 1 hw.optional.arm.FEAT_CSV3: 1 hw.optional.arm.FEAT_FP16: 1 hw.optional.arm.FEAT_SSBS: 1 hw.optional.arm.FEAT_BTI: 0 hw.optional.floatingpoint: 1 hw.optional.neon: 1 hw.optional.neon_hpfp: 1 hw.optional.neon_fp16: 1 hw.optional.armv8_1_atomics: 1 hw.optional.armv8_2_fhm: 1 hw.optional.armv8_2_sha512: 1 hw.optional.armv8_2_sha3: 1 hw.optional.armv8_3_compnum: 1 hw.optional.watchpoint: 4 hw.optional.breakpoint: 6 hw.optional.armv8_crc32: 1 hw.optional.armv8_gpi: 1 hw.optional.AdvSIMD: 1 hw.optional.AdvSIMD_HPFPCvt: 1 hw.optional.ucnormal_mem: 1 hw.optional.arm64: 1 hw.features.allows_security_research: 0 hw.physicalcpu: 10 hw.physicalcpu_max: 10 hw.logicalcpu: 10 hw.logicalcpu_max: 10 hw.cputype: 16777228 hw.cpusubtype: 2 hw.cpu64bit_capable: 1 hw.cpufamily: 458787763 hw.cpusubfamily: 5 hw.cacheconfig: 10 1 2 0 0 0 0 0 0 0 hw.cachesize: 3373957120 65536 4194304 0 0 0 0 0 0 0 hw.pagesize: 16384 hw.pagesize32: 16384 hw.cachelinesize: 128 hw.l1icachesize: 131072 hw.l1dcachesize: 65536 hw.l2cachesize: 4194304 hw.tbfrequency: 24000000 hw.packages: 1 hw.osenvironment: hw.ephemeral_storage: 0 hw.use_recovery_securityd: 0 hw.use_kernelmanagerd: 1 hw.serialdebugmode: 0 hw.nperflevels: 2 hw.targettype: J316c machdep.cpu.cores_per_package: 10 machdep.cpu.core_count: 10 machdep.cpu.logical_per_package: 10 machdep.cpu.thread_count: 10 machdep.cpu.brand_string: Apple M1 Max ```
2022-06-01Fix Windows file metadata docsReilly Wood-2/+2
Retrieving file metadata on Windows now uses GetFileInformationByHandle not GetFileAttributesEx
2022-06-01std: show signal number along with nameMichael Howell-46/+50
2022-06-01Rollup merge of #97611 - azdavis:master, r=Dylan-DPCYuki Okushi-2/+3
Tweak insert docs For `{Hash, BTree}Map::insert`, I always have to take a few extra seconds to think about the slight weirdness about the fact that if we "did not" insert (which "sounds" false), we return true, and if we "did" insert, (which "sounds" true), we return false. This tweaks the doc comments for the `insert` methods of those types (as well as what looks like a rustc internal data structure that I found just by searching the codebase for "If the set did") to first use the "Returns whether _something_" pattern used in e.g. `remove`, where we say that `remove` "returns whether the value was present".
2022-06-01Rollup merge of #94647 - Urgau:hash-map-many-mut, r=AmanieuYuki Okushi-0/+113
Expose `get_many_mut` and `get_many_unchecked_mut` to HashMap This pull-request expose the function [`get_many_mut`](https://docs.rs/hashbrown/0.12.0/hashbrown/struct.HashMap.html#method.get_many_mut) and [`get_many_unchecked_mut`](https://docs.rs/hashbrown/0.12.0/hashbrown/struct.HashMap.html#method.get_many_unchecked_mut) from `hashbrown` to the standard library `HashMap` type. They obviously keep the same API and are added under the (new) `map_many_mut` feature. - `get_many_mut`: Attempts to get mutable references to `N` values in the map at once. - `get_many_unchecked_mut`: Attempts to get mutable references to `N` values in the map at once, without validating that the values are unique.
2022-05-31Tweak insert docsAriel Davis-2/+3
2022-06-01use 128 cache align for m1 macyifei-1/+2
2022-06-01Expose get_many_mut and get_many_unchecked_mut to HashMapLoïc BRANSTETT-0/+113
2022-05-31Rollup merge of #97316 - CAD97:bound-misbehavior, r=dtolnayMatthias Krüger-8/+10
Put a bound on collection misbehavior As currently written, when a logic error occurs in a collection's trait parameters, this allows *completely arbitrary* misbehavior, so long as it does not cause undefined behavior in std. However, because the extent of misbehavior is not specified, it is allowed for *any* code in std to start misbehaving in arbitrary ways which are not formally UB; consider the theoretical example of a global which gets set on an observed logic error. Because the misbehavior is only bound by not resulting in UB from safe APIs and the crate-level encapsulation boundary of all of std, this makes writing user unsafe code that utilizes std theoretically impossible, as it now relies on undocumented QOI (quality of implementation) that unrelated parts of std cannot be caused to misbehave by a misuse of std::collections APIs. In practice, this is a nonconcern, because std has reasonable QOI and an implementation that takes advantage of this freedom is essentially a malicious implementation and only compliant by the most langauage-lawyer reading of the documentation. To close this hole, we just add a small clause to the existing logic error paragraph that ensures that any misbehavior is limited to the collection which observed the logic error, making it more plausible to prove the soundness of user unsafe code. This is not meant to be formal; a formal refinement would likely need to mention that values derived from the collection can also misbehave after a logic error is observed, as well as define what it means to "observe" a logic error in the first place. This fix errs on the side of informality in order to close the hole without complicating a normal reading which can assume a reasonable nonmalicious QOI. See also [discussion on IRLO][1]. [1]: https://internals.rust-lang.org/t/using-std-collections-and-unsafe-anything-can-happen/16640 r? rust-lang/libs-api ```@rustbot``` label +T-libs-api -T-libs This technically adds a new guarantee to the documentation, though I argue as written it's one already implicitly provided.
2022-05-31Auto merge of #97574 - Dylan-DPC:rollup-jq850l6, r=Dylan-DPCbors-1/+0
Rollup of 6 pull requests Successful merges: - #97089 (Improve settings theme display) - #97229 (Document the current aliasing rules for `Box<T>`.) - #97371 (Suggest adding a semicolon to a closure without block) - #97455 (Stabilize `toowned_clone_into`) - #97565 (Add doc alias `memset` to `write_bytes`) - #97569 (Remove `memset` alias from `fill_with`.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-05-31Rollup merge of #97455 - JohnTitor:stabilize-toowned-clone-into, r=dtolnayDylan DPC-1/+0
Stabilize `toowned_clone_into` Closes #41263 FCP has been done: https://github.com/rust-lang/rust/issues/41263#issuecomment-1100760750
2022-05-31Auto merge of #96881 - est31:join_osstr, r=dtolnaybors-0/+33
Implement [OsStr]::join Implements join for `OsStr` and `OsString` slices: ```Rust let strings = [OsStr::new("hello"), OsStr::new("dear"), OsStr::new("world")]; assert_eq!("hello dear world", strings.join(OsStr::new(" "))); ```` This saves one from converting to strings and back, or from implementing it manually. This PR has been re-filed after #96744 was first accidentally merged and then reverted. The change is instantly stable and thus: r? rust-lang/libs-api `@rustbot` label +T-libs-api -T-libs cc `@thomcc` `@m-ou-se` `@faptc`
2022-05-30Rollup merge of #97499 - est31:master, r=Dylan-DPCDylan DPC-3/+2
Remove "sys isn't exported yet" phrase The oldest occurence is from 9e224c2bf18ebf8f871efb2e1aba43ed7970ebb7, which is from the pre-1.0 days. In the years since then, std::sys still hasn't been exported, and the last attempt was met with strong criticism: https://github.com/rust-lang/rust/pull/97151 Thus, removing the "yet" part makes a lot of sense.
2022-05-30Rollup merge of #97494 - est31:remove_box_alloc_tests, r=Dylan-DPCDylan DPC-22/+22
Use Box::new() instead of box syntax in library tests The tests inside `library/*` have no reason to use `box` syntax as they have 0 performance relevance. Therefore, we can safely remove them (instead of having to use alternatives like the one in #97293).
2022-05-30Remove "sys isn't exported yet" phraseest31-3/+2
The oldest occurence is from 9e224c2bf18ebf8f871efb2e1aba43ed7970ebb7, which is from the pre-1.0 days. In the years since then, std::sys still hasn't been exported, and the last attempt was met with strong criticism: https://github.com/rust-lang/rust/pull/97151 Thus, removing the "yet" part makes a lot of sense.
2022-05-29Auto merge of #97514 - WaffleLapkin:panick, r=Dylan-DPCbors-1/+1
Fix typo (panick -> panic) Fix typo (panick -> panic) in `std::error` module docs.
2022-05-29Auto merge of #97214 - Mark-Simulacrum:stage0-bump, r=pietroalbinibors-4/+0
Finish bumping stage0 It looks like the last time had left some remaining cfg's -- which made me think that the stage0 bump was actually successful. This brings us to a released 1.62 beta though. This now brings us to cfg-clean, with the exception of check-cfg-features in bootstrap; I'd prefer to leave that for a separate PR at this time since it's likely to be more tricky. cc https://github.com/rust-lang/rust/pull/97147#issuecomment-1132845061 r? `@pietroalbini`
2022-05-29Fix typo (panick -> panic)Maybe Waffle-1/+1
2022-05-29protect `std::io::Take::limit` from overflow in `read`Frank King-0/+20
fixs #94981
2022-05-29Use Box::new() instead of box syntax in std testsest31-22/+22
2022-05-28Stabilize `toowned_clone_into`Yuki Okushi-1/+0
2022-05-27Call the OS function to set the main thread's name on program initWesley Wiser-1/+15
Normally, `Thread::spawn` takes care of setting the thread's name, if one was provided, but since the main thread wasn't created by calling `Thread::spawn`, we need to call that function in `std::rt::init`. This is mainly useful for system tools like debuggers and profilers which might show the thread name to a user. Prior to these changes, gdb and WinDbg would show all thread names except the main thread's name to a user. I've validated that this patch resolves the issue for both debuggers.
2022-05-27Finish bumping stage0Mark Rousskov-4/+0
It looks like the last time had left some remaining cfg's -- which made me think that the stage0 bump was actually successful. This brings us to a released 1.62 beta though.
2022-05-27docs: Don't imply that OsStr on Unix is always UTF-8Xiretza-1/+1
The methods in `OsStrExt` consume and return `&[u8]` and don't perform any UTF-8 checks.
2022-05-26Rollup merge of #96033 - yaahc:expect-elaboration, r=scottmcmMatthias Krüger-1/+137
Add section on common message styles for Result::expect Based on a question from https://github.com/rust-lang/project-error-handling/issues/50#issuecomment-1092339937 ~~One thing I haven't decided on yet, should I duplicate this section on `Option::expect`, link to this section, or move it somewhere else and link to that location from both docs?~~: I ended up moving the section to `std::error` and referencing it from both `Result::expect` and `Option::expect`'s docs. I think this section, when combined with the similar update I made on [`std::panic!`](https://doc.rust-lang.org/nightly/std/macro.panic.html#when-to-use-panic-vs-result) implies that we should possibly more aggressively encourage and support the "expect as precondition" style described in this section. The consensus among the libs team seems to be that panic should be used for bugs, not expected potential failure modes. The "expect as error message" style seems to align better with the panic for unrecoverable errors style where they're seen as normal errors where the only difference is a desire to kill the current execution unit (aka erlang style error handling). I'm wondering if we should be providing a panic hook similar to `human-panic` or more strongly recommending the "expect as precondition" style of expect message.
2022-05-26Auto merge of #96742 - m-ou-se:bsd-no-ancillary, r=joshtriplettbors-173/+33
Disable unix::net::ancillary on BSD. See https://github.com/rust-lang/rust/issues/76915#issuecomment-1118954474
2022-05-25Disable unix::net::ancillary on BSD.Mara Bos-173/+33
2022-05-25fix linksJane Lusby-11/+13
2022-05-24add aliases for current_dirjulio-0/+3
2022-05-24explained unwrap vs expectJane Losare-Lusby-12/+15
2022-05-25Rollup merge of #97364 - notriddle:continue-keyword, r=JohnTitorYuki Okushi-6/+6
Fix weird indentation in continue_keyword docs This format was causing every line in the code examples to have a space at the start.
2022-05-24Fix weird indentation in continue_keyword docsMichael Howell-6/+6
This format was causing every line in the code examples to have a space at the start.
2022-05-24Rollup merge of #97321 - RalfJung:int-to-fnptr, r=Dylan-DPCDylan DPC-0/+26
explain how to turn integers into fn ptrs (with an intermediate raw ptr, not a direct transmute) Direct int2ptr transmute, under the semantics I am imagining, will produce a ptr with "invalid" provenance that is invalid to deref or call. We cannot give it the same semantics as int2ptr casts since those do [something complicated](https://www.ralfj.de/blog/2022/04/11/provenance-exposed.html). To my great surprise, that is already what the example in the `transmute` docs does. :) I still added a comment to say that that part is important, and I added a section explicitly talking about this to the `fn()` type docs. With https://github.com/rust-lang/miri/pull/2151, Miri will start complaining about direct int-to-fnptr transmutes (in the sense that it is UB to call the resulting pointer).
2022-05-24Fix stabilization version of `Ipv6Addr::to_ipv4_mapped`Tobias Bucher-1/+1
2022-05-23sync primitive_docsRalf Jung-0/+26
2022-05-23Auto merge of #97315 - Dylan-DPC:rollup-2wee2oz, r=Dylan-DPCbors-0/+13
Rollup of 4 pull requests Successful merges: - #96129 (Document rounding for floating-point primitive operations and string parsing) - #97286 (Add new eslint rule to prevent whitespace before function call paren) - #97292 (Lifetime variance fixes for rustc) - #97309 (Add some regression tests for #90400) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-05-23Put a bound on collection misbehaviorChristopher Durham-8/+10
As currently written, when a logic error occurs in a collection's trait parameters, this allows *completely arbitrary* misbehavior, so long as it does not cause undefined behavior in std. However, because the extent of misbehavior is not specified, it is allowed for *any* code in std to start misbehaving in arbitrary ways which are not formally UB; consider the theoretical example of a global which gets set on an observed logic error. Because the misbehavior is only bound by not resulting in UB from safe APIs and the crate-level encapsulation boundary of all of std, this makes writing user unsafe code that utilizes std theoretically impossible, as it now relies on undocumented QOI that unrelated parts of std cannot be caused to misbehave by a misuse of std::collections APIs. In practice, this is a nonconcern, because std has reasonable QOI and an implementation that takes advantage of this freedom is essentially a malicious implementation and only compliant by the most langauage-lawyer reading of the documentation. To close this hole, we just add a small clause to the existing logic error paragraph that ensures that any misbehavior is limited to the collection which observed the logic error, making it more plausible to prove the soundness of user unsafe code. This is not meant to be formal; a formal refinement would likely need to mention that values derived from the collection can also misbehave after a logic error is observed, as well as define what it means to "observe" a logic error in the first place. This fix errs on the side of informality in order to close the hole without complicating a normal reading which can assume a reasonable nonmalicious QOI. See also [discussion on IRLO][1]. [1]: https://internals.rust-lang.org/t/using-std-collections-and-unsafe-anything-can-happen/16640
2022-05-23Rollup merge of #96129 - mattheww:2022-04_float_rounding, r=Dylan-DPCDylan DPC-0/+13
Document rounding for floating-point primitive operations and string parsing The docs for floating point don't have much to say at present about either the precision of their results or rounding behaviour. As I understand it[^1][^2], Rust doesn't support operating with non-default rounding directions, so we need only describe roundTiesToEven. [^1]: https://github.com/rust-lang/rust/issues/41753#issuecomment-299322887 [^2]: https://github.com/llvm/llvm-project/issues/8472#issuecomment-980888781 This PR makes a start by documenting that for primitive operations and `from_str()`.
2022-05-23Auto merge of #92461 - rust-lang:const_tls_local_panic_count, r=Mark-Simulacrumbors-1/+1
Use const initializer for LOCAL_PANIC_COUNT This reduces the size of the __getit function for LOCAL_PANIC_COUNT and should speed up accesses of LOCAL_PANIC_COUNT a bit.
2022-05-23Rollup merge of #97294 - jersou:patch-1, r=Dylan-DPCDylan DPC-2/+2
std::time : fix variable name in the doc
2022-05-23Auto merge of #96455 - dtolnay:writetmp, r=m-ou-sebors-6/+6
Make write/print macros eagerly drop temporaries This PR fixes the 2 regressions in #96434 (`println` and `eprintln`) and changes all the other similar macros (`write`, `writeln`, `print`, `eprint`) to match the old pre-#94868 behavior of `println` and `eprintln`. argument position | before #94868 | after #94868 | after this PR --- |:---:|:---:|:---: `write!($tmp, "…", …)` | :rage: | :rage: | :smiley_cat: `write!(…, "…", $tmp)` | :rage: | :rage: | :smiley_cat: `writeln!($tmp, "…", …)` | :rage: | :rage: | :smiley_cat: `writeln!(…, "…", $tmp)` | :rage: | :rage: | :smiley_cat: `print!("…", $tmp)` | :rage: | :rage: | :smiley_cat: `println!("…", $tmp)` | :smiley_cat: | :rage: | :smiley_cat: `eprint!("…", $tmp)` | :rage: | :rage: | :smiley_cat: `eprintln!("…", $tmp)` | :smiley_cat: | :rage: | :smiley_cat: `panic!("…", $tmp)` | :smiley_cat: | :smiley_cat: | :smiley_cat: Example of code that is affected by this change: ```rust use std::sync::Mutex; fn main() { let mutex = Mutex::new(0); print!("{}", mutex.lock().unwrap()) /* no semicolon */ } ``` You can see several real-world examples like this in the Crater links at the top of #96434. This code failed to compile prior to this PR as follows, but works after this PR. ```console error[E0597]: `mutex` does not live long enough --> src/main.rs:5:18 | 5 | print!("{}", mutex.lock().unwrap()) /* no semicolon */ | ^^^^^^^^^^^^--------- | | | borrowed value does not live long enough | a temporary with access to the borrow is created here ... 6 | } | - | | | `mutex` dropped here while still borrowed | ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `MutexGuard` ```