about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2021-04-05Auto merge of #83864 - Dylan-DPC:rollup-78an86n, r=Dylan-DPCbors-1/+0
Rollup of 7 pull requests Successful merges: - #80525 (wasm64 support) - #83019 (core: disable `ptr::swap_nonoverlapping_one`'s block optimization on SPIR-V.) - #83717 (rustdoc: Separate filter-empty-string out into its own function) - #83807 (Tests: Remove redundant `ignore-tidy-linelength` annotations) - #83815 (ptr::addr_of documentation improvements) - #83820 (Remove attribute `#[link_args]`) - #83841 (Allow clobbering unsupported registers in asm!) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-04-05Rollup merge of #83820 - petrochenkov:nolinkargs, r=nagisaDylan DPC-1/+0
Remove attribute `#[link_args]` Closes https://github.com/rust-lang/rust/issues/29596 The attribute could always be replaced with `-C link-arg`, but cargo didn't provide a reasonable way to pass such flags to rustc. Now cargo supports `cargo:rustc-link-arg*` directives in build scripts (https://doc.rust-lang.org/cargo/reference/unstable.html#extra-link-arg), so this attribute can be removed.
2021-04-04Bump cfgsMark Rousskov-4/+1
2021-04-04Add `#[inline]` to IpAddr methodsAngelicosPhosphoros-0/+3
Add some inlines to trivial methods of IpAddr Closes https://github.com/rust-lang/rust/issues/77583
2021-04-03Remove attribute `#[link_args]`Vadim Petrochenkov-1/+0
2021-04-04Rollup merge of #83780 - matklad:doc-error-message, r=JohnTitorYuki Okushi-8/+15
Document "standard" conventions for error messages These are currently documented in the API guidelines: https://rust-lang.github.io/api-guidelines/interoperability.html#error-types-are-meaningful-and-well-behaved-c-good-err I think it makes sense to uplift this guideline (in a milder form) into std docs. Printing and producing errors is something that even non-expert users do frequently, so it is useful to give at least some indication of what a typical error message looks like.
2021-04-04Rollup merge of #82487 - CDirkx:const-socketaddr, r=m-ou-seYuki Okushi-10/+21
Constify methods of `std::net::SocketAddr`, `SocketAddrV4` and `SocketAddrV6` The following methods are made unstable const under the `const_socketaddr` feature (https://github.com/rust-lang/rust/issues/82485): ```rust // std::net impl SocketAddr { pub const fn ip(&self) -> IpAddr; pub const fn port(&self) -> u16; pub const fn is_ipv4(&self) -> bool; pub const fn is_ipv6(&self) -> bool; } impl SocketAddrV4 { pub const fn ip(&self) -> IpAddr; pub const fn port(&self) -> u16; } impl SocketAddrV6 { pub const fn ip(&self) -> IpAddr; pub const fn port(&self) -> u16; pub const fn flowinfo(&self) -> u32; pub const fn scope_id(&self) -> u32; } ``` Note: `SocketAddrV4::ip` and `SocketAddrV6::ip` use pointer casting and depend on the unstable feature `const_raw_ptr_deref`
2021-04-02Rollup merge of #83771 - asomers:stack_overflow_freebsd, r=dtolnayDylan DPC-7/+16
Fix stack overflow detection on FreeBSD 11.1+ Beginning with FreeBSD 10.4 and 11.1, there is one guard page by default. And the stack autoresizes, so if Rust allocates its own guard page, then FreeBSD's will simply move up one page. The best solution is to just use the OS's guard page.
2021-04-02Rollup merge of #83065 - CDirkx:win-alloc, r=dtolnayDylan DPC-33/+220
Rework `std::sys::windows::alloc` I came across https://github.com/rust-lang/rust/pull/76676#discussion_r488729990, which points out that there was unsound code in the Windows alloc code, creating a &mut to possibly uninitialized memory. I reworked the code so that that particular issue does not occur anymore, and started adding more documentation and safety comments. Full list of changes: - moved and documented the relevant Windows Heap API functions - refactor `allocate_with_flags` to `allocate` (and remove the other helper functions), which now takes just a `bool` if the memory should be zeroed - add checks for if `GetProcessHeap` returned null - add a test that checks if the size and alignment of a `Header` are indeed <= `MIN_ALIGN` - add `#![deny(unsafe_op_in_unsafe_fn)]` and the necessary unsafe blocks with safety comments I feel like I may have overdone the documenting, the unsoundness fix is the most important part; I could spit this PR up in separate parts.
2021-04-02Remove `debug_assert`Christiaan Dirkx-4/+1
2021-04-02Introduce `get_process_heap` and fix atomic ordering.Christiaan Dirkx-13/+22
2021-04-02Rollup merge of #83740 - obi1kenobi:patch-1, r=joshtriplettYuki Okushi-1/+1
Fix comment typo in once.rs I believe I came across a minor typo in a comment. I am not particularly familiar with this part of the codebase, but I have read the surrounding code as well as the referenced `park` and `unpark` functions, and I believe my proposed change is true to the intended meaning of the comment. I intentionally tried to keep the change as minimal as possible. If I have the maintainers' permission, I'd also love to add a comma to improve readability as follows: `Luckily ``park`` comes with the guarantee that if it got an ``unpark`` just before on an unparked thread, it does not park.`
2021-04-02Document "standard" conventions for error messagesAleksey Kladov-8/+15
These are currently documented in the API guidelines: https://rust-lang.github.io/api-guidelines/interoperability.html#error-types-are-meaningful-and-well-behaved-c-good-err I think it makes sense to uplift this guideline (in a milder form) into std docs. Printing and producing errors is something that even non-expert users do frequently, so it is useful to give at least some indication of what a typical error message looks like.
2021-04-02Auto merge of #80965 - camelid:rename-doc-spotlight, r=jyn514bors-3/+6
Rename `#[doc(spotlight)]` to `#[doc(notable_trait)]` Fixes #80936. "spotlight" is not a very specific or self-explaining name. Additionally, the dialog that it triggers is called "Notable traits". So, "notable trait" is a better name. * Rename `#[doc(spotlight)]` to `#[doc(notable_trait)]` * Rename `#![feature(doc_spotlight)]` to `#![feature(doc_notable_trait)]` * Update documentation * Improve documentation r? `@Manishearth`
2021-04-01Fix stack overflow detection on FreeBSD 11.1+Alan Somers-7/+16
Beginning with FreeBSD 10.4 and 11.1, there is one guard page by default. And the stack autoresizes, so if Rust allocates its own guard page, then FreeBSD's will simply move up one page. The best solution is to just use the OS's guard page.
2021-04-01Fix minor typo in once.rsPredrag Gruevski-1/+1
2021-03-31Apply suggestions from code reviewFrank Steffahn-2/+2
More links, one more occurrence of “a OsString” Co-authored-by: Yuki Okushi <huyuumi.dev@gmail.com>
2021-03-31Add a few missing links, fix a typoFrank Steffahn-8/+8
2021-03-31Fix documentation of conversion from String to OsStringFrank Steffahn-1/+1
2021-03-31Rollup merge of #83680 - ibraheemdev:patch-2, r=Dylan-DPCDylan DPC-9/+12
Update for loop desugaring docs It looks like the documentation for `for` loops was not updated to match the new de-sugaring process.
2021-03-31Rollup merge of #83678 - GuillaumeGomez:hack-Self-keyword-conflict, r=jyn514Dylan DPC-1/+5
Fix Self keyword doc URL conflict on case insensitive file systems (until definitely fixed on rustdoc) This is just a hack to allow rustup to work on macOS and windows again to distribute std documentation (hopefully once https://github.com/rust-lang/rfcs/pull/3097 or an equivalent is merged). Fixes https://github.com/rust-lang/rust/issues/80504. Prevents https://github.com/rust-lang/rust/issues/83154 and https://github.com/rust-lang/rustup/issues/2694 in future releases. cc ``@kinnison`` r? ``@jyn514``
2021-03-31Rollup merge of #80720 - steffahn:prettify_prelude_imports, r=camelid,jyn514Dylan DPC-32/+32
Make documentation of which items the prelude exports more readable. I recently figured out that rustdoc allows link inside of inline code blocks as long as they’re delimited with `<code> </code>` instead of `` ` ` ``. I think this applies nicely in the listing of prelude exports [in the docs](https://doc.rust-lang.org/std/prelude/index.html). There, currently unformatted `::` and `{ , }` is used in order to mimick import syntax while attatching links to individual identifiers. ## Rendered Comparison ### Currently (light) ![Screenshot_20210105_155801](https://user-images.githubusercontent.com/3986214/103661510-1a87be80-4f6f-11eb-8360-1dfb23f732e8.png) ### After this PR (light) ![Screenshot_20210105_155811](https://user-images.githubusercontent.com/3986214/103661533-1f4c7280-4f6f-11eb-89d4-874793937824.png) ### Currently (dark) ![Screenshot_20210105_155824](https://user-images.githubusercontent.com/3986214/103661571-2a9f9e00-4f6f-11eb-95f9-e291b5570b41.png) ### After this PR (dark) ![Screenshot_20210105_155836](https://user-images.githubusercontent.com/3986214/103661592-2ffce880-4f6f-11eb-977a-82afcb07d331.png) ### Currently (ayu) ![Screenshot_20210105_155917](https://user-images.githubusercontent.com/3986214/103661619-39865080-4f6f-11eb-9ca1-9045a107cddd.png) ### After this PR (ayu) ![Screenshot_20210105_155923](https://user-images.githubusercontent.com/3986214/103661652-3db26e00-4f6f-11eb-82b7-378e38f0c41f.png) _Edit:_ I just noticed, the “current” screenshots are from stable, so there are a few more differences in the pictures than the ones from just this PR.
2021-03-30Auto merge of #83652 - xu-cheng:ipv4-octal, r=sfacklerbors-1/+23
Disallow octal format in Ipv4 string In its original specification, leading zero in Ipv4 string is interpreted as octal literals. So a IP address 0127.0.0.1 actually means 87.0.0.1. This confusion can lead to many security vulnerabilities. Therefore, in [IETF RFC 6943], it suggests to disallow octal/hexadecimal format in Ipv4 string all together. Existing implementation already disallows hexadecimal numbers. This commit makes Parser reject octal numbers. Fixes #83648. [IETF RFC 6943]: https://tools.ietf.org/html/rfc6943#section-3.1.1
2021-03-30update for loop desugaring docsIbraheem Ahmed-9/+12
2021-03-30Fix Self keyword doc URL conflict on case insensitive file systemsGuillaume Gomez-1/+5
2021-03-30Auto merge of #83170 - joshtriplett:spawn-cleanup, r=kennytmbors-33/+27
Simplify Command::spawn (no semantic change) This minimizes the size of an unsafe block, and allows outdenting some complex code.
2021-03-30Disallow octal format in Ipv4 stringCheng XU-1/+23
In its original specification, leading zero in Ipv4 string is interpreted as octal literals. So a IP address 0127.0.0.1 actually means 87.0.0.1. This confusion can lead to many security vulnerabilities. Therefore, in [IETF RFC 6943], it suggests to disallow octal/hexadecimal format in Ipv4 string all together. Existing implementation already disallows hexadecimal numbers. This commit makes Parser reject octal numbers. Fixes #83648. [IETF RFC 6943]: https://tools.ietf.org/html/rfc6943#section-3.1.1
2021-03-30Rollup merge of #83374 - reyk:fix/bsd-ancillary, r=joshtriplettDylan DPC-23/+34
unix: Fix feature(unix_socket_ancillary_data) on macos and other BSDs This adds support for CMSG handling on macOS and fixes it on OpenBSD and possibly other BSDs. When traversing the CMSG list, the previous code had an exception for Android where the next element after the last pointer could point to the first pointer instead of NULL. This is actually not specific to Android: the `libc::CMSG_NXTHDR` implementation for Linux and emscripten have a special case to return NULL when the length of the previous element is zero; most other implementations simply return the previous element plus a zero offset in this case. This MR makes the check non-optional which fixes CMSG handling and a possible endless loop on such systems; tested with file descriptor passing on OpenBSD, Linux, and macOS. This MR additionally adds `SocketAncillary::is_empty` because clippy is right that it should be added. This belongs to the `feature(unix_socket_ancillary_data)` tracking issue: https://github.com/rust-lang/rust/issues/76915 r? `@joshtriplett`
2021-03-29Simplify Command::spawn (no semantic change)Josh Triplett-33/+27
This minimizes the size of an unsafe block, and allows outdenting some complex code.
2021-03-29Change back prelude headlineFrank Steffahn-1/+1
2021-03-29ffi::c_str smaller as_bytesklensy-2/+4
2021-03-28ffi::c_str added tests for empty stringsklensy-0/+16
2021-03-27Rollup merge of #83555 - m-ou-se:inline-io-error-new-const, r=jackh726Dylan DPC-0/+8
Add #[inline] to io::Error methods Fixes #82812
2021-03-27Rollup merge of #83522 - pickfire:patch-6, r=JohnTitorDylan DPC-9/+9
Improve fs error open_from unix Consistency for #79399 Suggested by JohnTitor r? `@JohnTitor` Not user if the error is too long now, do we handle long errors well?
2021-03-27Rollup merge of #82917 - cuviper:iter-zip, r=m-ou-seDylan DPC-2/+3
Add function core::iter::zip This makes it a little easier to `zip` iterators: ```rust for (x, y) in zip(xs, ys) {} // vs. for (x, y) in xs.into_iter().zip(ys) {} ``` You can `zip(&mut xs, &ys)` for the conventional `iter_mut()` and `iter()`, respectively. This can also support arbitrary nesting, where it's easier to see the item layout than with arbitrary `zip` chains: ```rust for ((x, y), z) in zip(zip(xs, ys), zs) {} for (x, (y, z)) in zip(xs, zip(ys, zs)) {} // vs. for ((x, y), z) in xs.into_iter().zip(ys).zip(xz) {} for (x, (y, z)) in xs.into_iter().zip((ys.into_iter().zip(xz)) {} ``` It may also format more nicely, especially when the first iterator is a longer chain of methods -- for example: ```rust iter::zip( trait_ref.substs.types().skip(1), impl_trait_ref.substs.types().skip(1), ) // vs. trait_ref .substs .types() .skip(1) .zip(impl_trait_ref.substs.types().skip(1)) ``` This replaces the tuple-pair `IntoIterator` in #78204. There is prior art for the utility of this in [`itertools::zip`]. [`itertools::zip`]: https://docs.rs/itertools/0.10.0/itertools/fn.zip.html
2021-03-28Rollup merge of #83561 - m-ou-se:lock-debug, r=jackh726Yuki Okushi-8/+16
Improve Debug implementations of Mutex and RwLock. This improves the Debug implementations of Mutex and RwLock. They now show the poison flag and use debug_non_exhaustive. (See #67364.)
2021-03-28Rollup merge of #83560 - m-ou-se:io-chain-debug, r=sfacklerYuki Okushi-7/+1
Derive Debug for io::Chain instead of manually implementing it. This derives Debug for io::Chain instead of manually implementing it. The manual implementation has the same bounds, so I don't think there's any reason for a manual implementation. The names used in the derive implementation are even nicer (`first`/`second`) than the manual implementation (`t`/`u`), and include the `done_first` field too.
2021-03-28Rollup merge of #83559 - m-ou-se:rwlock-guard-debug-fix, r=jackh726Yuki Okushi-2/+2
Fix Debug implementation for RwLock{Read,Write}Guard. This would attempt to print the Debug representation of the lock that the guard has locked, which will try to lock again, fail, and just print `"<locked>"` unhelpfully. After this change, this just prints the contents of the mutex, like the other smart pointers (and MutexGuard) do. MutexGuard had this problem too: https://github.com/rust-lang/rust/issues/57702
2021-03-28Rollup merge of #83558 - m-ou-se:use-finish-non-exhaustive, r=jackh726Yuki Okushi-15/+21
Use DebugStruct::finish_non_exhaustive() in std. See https://github.com/rust-lang/rust/issues/67364
2021-03-28Rollup merge of #83462 - ijackson:exitstatus-message-wording, r=joshtriplettYuki Okushi-3/+3
ExitStatus: print "exit status: {}" rather than "exit code: {}" on unix Proper Unix terminology is "exit status" (vs "wait status"). "exit code" is imprecise on Unix and therefore unclear. (As far as I can tell, "exit code" is correct terminology on Windows.) This new wording is unfortunately inconsistent with the identifier names in the Rust stdlib. It is the identifier names that are wrong, as discussed at length in eg https://doc.rust-lang.org/nightly/std/process/struct.ExitStatus.html https://doc.rust-lang.org/nightly/std/os/unix/process/trait.ExitStatusExt.html Unfortunately for API stability reasons it would be a lot of work, and a lot of disruption, to change the names in the stdlib (eg to rename `std::process::ExitStatus` to `std::process::ChildStatus` or something), but we should fix the message output. Many (probably most) readers of these messages about exit statuses will be users and system administrators, not programmers, who won't even know that Rust has this wrong terminology. So I think the right thing is to fix the documentation (as I have already done) and, now, the terminology in the implementation. This is a user-visible change to the behaviour of all Rust programs which run Unix subprocesses. Hopefully no-one is matching against the exit status string, except perhaps in tests.
2021-03-28Rollup merge of #79399 - pickfire:patch-3, r=JohnTitorYuki Okushi-3/+3
Use detailed and shorter fs error explaination Includes suggestion from `@the8472` https://github.com/rust-lang/rust/issues/79390#issuecomment-733263336
2021-03-27Improve fs error open_from unixIvan Tham-9/+9
Consistency for #79399 Suggested by JohnTitor Improve fs error invaild input for sys_common The text was duplicated from unix.
2021-03-27Use detailed and shorter fs error explainationIvan Tham-3/+3
Includes suggestion from the8472 https://github.com/rust-lang/rust/issues/79390#issuecomment-733263336 More detail error explanation in fs doc
2021-03-27Improve Debug implementations of Mutex and RwLock.Mara Bos-8/+16
They now show the poison flag and use debug_non_exhaustive.
2021-03-27Derive Debug for io::Chain instead of manually implementing it.Mara Bos-7/+1
The manual implementation has the same bounds, so I don't think there's any reason for a manual implementation. The names used in the derive implementation are even nicer (`first`/`second`) than the manual implementation (`t`/`u`), and include the `done_first` field too.
2021-03-27Fix Debug implementation for RwLock{Read,Write}Guard.Mara Bos-2/+2
This would attempt to print the Debug representation of the lock that the guard has locked, which will try to lock again, fail, and just print "<locked>" unhelpfully. After this change, this just prints the contents of the mutex, like the other smart pointers (and MutexGuard) do.
2021-03-27Use DebugStruct::finish_non_exhaustive() in std.Mara Bos-15/+21
2021-03-27Add #[inline] to io::Error methods.Mara Bos-0/+8
2021-03-27Auto merge of #78618 - workingjubilee:ieee754-fmt, r=m-ou-sebors-3/+5
Add IEEE 754 compliant fmt/parse of -0, infinity, NaN This pull request improves the Rust float formatting/parsing libraries to comply with IEEE 754's formatting expectations around certain special values, namely signed zero, the infinities, and NaN. It also adds IEEE 754 compliance tests that, while less stringent in certain places than many of the existing flt2dec/dec2flt capability tests, are intended to serve as the beginning of a roadmap to future compliance with the standard. Some relevant documentation is also adjusted with clarifying remarks. This PR follows from discussion in https://github.com/rust-lang/rfcs/issues/1074, and closes #24623. The most controversial change here is likely to be that -0 is now printed as -0. Allow me to explain: While there appears to be community support for an opt-in toggle of printing floats as if they exist in the naively expected domain of numbers, i.e. not the extended reals (where floats live), IEEE 754-2019 is clear that a float converted to a string should be capable of being transformed into the original floating point bit-pattern when it satisfies certain conditions (namely, when it is an actual numeric value i.e. not a NaN and the original and destination float width are the same). -0 is given special attention here as a value that should have its sign preserved. In addition, the vast majority of other programming languages not only output `-0` but output `-0.0` here. While IEEE 754 offers a broad leeway in how to handle producing what it calls a "decimal character sequence", it is clear that the operations a language provides should be capable of round tripping, and it is confusing to advertise the f32 and f64 types as binary32 and binary64 yet have the most basic way of producing a string and then reading it back into a floating point number be non-conformant with the standard. Further, existing documentation suggested that e.g. -0 would be printed with -0 regardless of the presence of the `+` fmt character, but it prints "+0" instead if given such (which was what led to the opening of #24623). There are other parsing and formatting issues for floating point numbers which prevent Rust from complying with the standard, as well as other well-documented challenges on the arithmetic level, but I hope that this can be the beginning of motion towards solving those challenges.
2021-03-27Rollup merge of #83524 - faern:document-socketaddr-mem-layout, r=sfacklerYuki Okushi-2/+8
Document that the SocketAddr memory representation is not stable Intended to help out with #78802. Work has been put into finding and fixing code that assumes the memory layout of `SocketAddrV4` and `SocketAddrV6`. But it turns out there are cases where new code continues to make the same assumption ([example](https://github.com/spacejam/seaslug/commit/96927dc2b7b918860a79c4eb6336051e52c6137a#diff-917db3d8ca6f862ebf42726b23c72a12b35e584e497ebdb24e474348d7c6ffb6R610-R621)). The memory layout of a type in `std` is never part of the public API. Unless explicitly stated I guess. But since that is invalidly relied upon by a considerable amount of code for these particular types, it might make sense to explicitly document this. This can be temporary. Once #78802 lands it does not make sense to rely on the layout any longer, and this documentation can also be removed.