about summary refs log tree commit diff
path: root/library/std/src
AgeCommit message (Collapse)AuthorLines
2021-07-03Rollup merge of #86807 - tversteeg:patch-1, r=bjorn3Yuki Okushi-1/+0
Fix double import in wasm thread The `unsupported` type is imported two times, as `super::unsupported` and as `crate::sys::unsupported`, throwing an error. Remove `super::unsupported` in favor of the other. As reported in #86802. Fix #86802
2021-07-03Rollup merge of #86803 - ↵Yuki Okushi-2/+2
xfix:remove-unnecessary-ampersand-from-command-args-calls, r=joshtriplett Remove & from Command::args calls in documentation Now that arrays implement `IntoIterator`, using `&` is no longer necessary. This makes examples easier to understand.
2021-07-03Rollup merge of #85001 - CDirkx:bytestring, r=JohnTitorYuki Okushi-50/+28
Merge `sys_common::bytestring` back into `os_str_bytes` `bytestring` contains code for correctly debug formatting a byte slice (`[u8]`). This functionality is and has historically only been used to provide the debug formatting of byte-based os-strings (on unix etc.). Having this functionality in the separate `bytestring` module was useful in the past to reduce duplication, as [when it was added](https://github.com/rust-lang/rust/pull/46798) `os_str_bytes` was still split into `sys::{unix, redox, wasi, etc.}::os_str`. However, now that is no longer the case, there is not much reason for the `bytestring` functionality to be separate from `os_str_bytes`; I don't think it is very likely that another part of std will need to handle formatting byte strings that are not os-strings in the future (everything should be `utf8`). This is why this PR merges the functionality of `bytestring` directly into the debug implementation in `os_str_bytes`.
2021-07-02Fix double import in wasm threadThomas Versteeg-1/+0
The `unsupported` type is imported two times, as `super::unsupported` and as `crate::sys::unsupported`, throwing an error. Remove `super::unsupported` in favor of the other.
2021-07-02Remove & from Command::args calls in documentationKonrad Borowski-2/+2
Now that arrays implement `IntoIterator`, using `&` is no longer necessary. This makes examples easier to understand.
2021-07-02Auto merge of #85746 - m-ou-se:io-error-other, r=joshtriplettbors-73/+96
Redefine `ErrorKind::Other` and stop using it in std. This implements the idea I shared yesterday in the libs meeting when we were discussing how to handle adding new `ErrorKind`s to the standard library: This redefines `Other` to be for *user defined errors only*, and changes all uses of `Other` in the standard library to a `#[doc(hidden)]` and permanently `#[unstable]` `ErrorKind` that users can not match on. This ensures that adding `ErrorKind`s at a later point in time is not a breaking change, since the user couldn't match on these errors anyway. This way, we use the `#[non_exhaustive]` property of the enum in a more effective way. Open questions: - How do we check this change doesn't cause too much breakage? Will a crate run help and be enough? - How do we ensure we don't accidentally start using `Other` again in the standard library? We don't have a `pub(not crate)` or `#[deprecated(in this crate only)]`. cc https://github.com/rust-lang/rust/pull/79965 cc `@rust-lang/libs` `@ijackson` r? `@dtolnay`
2021-07-02Rollup merge of #86783 - mark-i-m:mutex-drop-unsized, r=XanewokYuki Okushi-20/+20
Move Mutex::unlock to T: ?Sized r? ``@mbrubeck`` cc https://github.com/rust-lang/rust/issues/81872
2021-07-01Move Mutex::unlock to T: ?SizedMark Mansi-20/+20
2021-06-28Update to new bootstrap compilerMark Rousskov-3/+2
2021-06-28Auto merge of #82624 - ojeda:rwlock-example-deadlock, r=JohnTitorbors-1/+13
RWLock: Add deadlock example Suggested in https://github.com/rust-lang/rust/pull/82596 but it was a bit too late. `@matklad` `@azdavis` `@sfackler`
2021-06-26Auto merge of #86586 - Smittyvb:https-everywhere, r=petrochenkovbors-14/+14
Use HTTPS links where possible While looking at #86583, I wondered how many other (insecure) HTTP links were in `rustc`. This changes most other `http` links to `https`. While most of the links are in comments or documentation, there are a few other HTTP links that are used by CI that are changed to HTTPS. Notes: - I didn't change any to or in licences - Some links don't support HTTPS :( - Some `http` links were dead, in those cases I upgraded them to their new places (all of which used HTTPS)
2021-06-26Auto merge of #86637 - ehuss:spellings, r=dtolnaybors-4/+4
Fix a few misspellings.
2021-06-25Fix a few misspellings.Eric Huss-4/+4
2021-06-25Restore original ordering of `ErrorKind::Other`.Mara Bos-8/+9
2021-06-26Rollup merge of #86592 - jhpratt:non_exhaustive, r=JohnTitorYuki Okushi-12/+9
Use `#[non_exhaustive]` where appropriate Due to the std/alloc split, it is not possible to make `alloc::collections::TryReserveError::AllocError` non-exhaustive without having an unstable, doc-hidden method to construct (which negates the benefits from `#[non_exhaustive]`). `@rustbot` label +C-cleanup +T-libs +S-waiting-on-review
2021-06-24Auto merge of #86467 - ChrisDenton:win-env-clear, r=JohnTitorbors-0/+15
Windows: Fix `Command::env_clear` so it works if no variables are set Previously, it would error unless at least one new environment variable was added. The missing null presumably meant that Windows was reading random memory in that case. See: [CreateProcessW](https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw) (scroll down to `lpEnvironment`). Essentially the environment block is a null terminated list of null terminated strings and an empty list is `\0\0` and not `\0`. EDIT: Oh, [CreateEnvironmentBlock](https://docs.microsoft.com/en-gb/windows/win32/api/userenv/nf-userenv-createenvironmentblock) states this much more explicitly. Fixes #31259
2021-06-24Test that `env_clear` works on WindowsChris Denton-0/+9
2021-06-24Use `#[non_exhaustive]` where appropriateJacob Pratt-12/+9
Due to the std/alloc split, it is not possible to make `alloc::collections::TryReserveError::AllocError` non-exhaustive without having an unstable, doc-hidden method to construct (which negates the benefits from `#[non_exhaustive]`.
2021-06-23Use HTTPS links where possibleSmitty-14/+14
2021-06-22Auto merge of #84910 - eopb:stabilize_int_error_matching, r=yaahcbors-7/+1
stabilize `int_error_matching` closes #22639 > It has been over half a year since https://github.com/rust-lang/rust/pull/77640#pullrequestreview-511263516, and the indexing question is rejected in https://github.com/rust-lang/rust/pull/79728#pullrequestreview-633030341, so I guess we can submit another stabilization attempt? 😉 _Originally posted by `@kennytm` in https://github.com/rust-lang/rust/issues/22639#issuecomment-831738266_
2021-06-22postpone stabilizaton by one releaseEthan Brierley-1/+1
2021-06-22Auto merge of #86527 - JohnTitor:rollup-cbu78g4, r=JohnTitorbors-177/+277
Rollup of 11 pull requests Successful merges: - #85054 (Revert SGX inline asm syntax) - #85182 (Move `available_concurrency` implementation to `sys`) - #86037 (Add `io::Cursor::{remaining, remaining_slice, is_empty}`) - #86114 (Reopen #79692 (Format symbols under shared frames)) - #86297 (Allow to pass arguments to rustdoc-gui tool) - #86334 (Resolve type aliases to the type they point to in intra-doc links) - #86367 (Fix comment about rustc_inherit_overflow_checks in abs().) - #86381 (Add regression test for issue #39161) - #86387 (Remove `#[allow(unused_lifetimes)]` which is now unnecessary) - #86398 (Add regression test for issue #54685) - #86493 (Say "this enum variant takes"/"this struct takes" instead of "this function takes") Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-06-22Rollup merge of #86114 - JDuchniewicz:feat/panic-frame-fmt, r=yaahcYuki Okushi-3/+2
Reopen #79692 (Format symbols under shared frames) Reopening #79692.
2021-06-22Rollup merge of #86037 - soerenmeier:cursor_remaining, r=yaahcYuki Okushi-4/+85
Add `io::Cursor::{remaining, remaining_slice, is_empty}` Tracking issue: #86369 I came across an inconvenience when answering the following [Stack Overflow](https://stackoverflow.com/questions/67831170) question. To get the remaining slice you have to call `buff.fill_buf().unwrap()`. Which in my opinion doesn't really tell you what is returned (in the context of Cursor). To improve readability and convenience when using Cursor i propose adding the method `remaining`. The next thing i found inconvenient (unnecessary long) was detecting if the cursor reached the end. There are a few ways this can be achieved right now: - `buff.fill_buf().unwrap().is_empty()` - `buff.position() >= buff.get_ref().len()` - `buff.bytes().next().is_none()` Which all seem a bit unintuitive, hidden in trait documentations or just a bit long for such a simple task. Therefor i propose another method called `is_empty`, maybe with another name, since this one may leave room for interpretation on what really is empty (the underlying slice, the remaining slice or maybe the position). Since it seemed easier to create this PR instead of an RFC i did that, if an RFC is wanted, i can close this PR and write an RFC first.
2021-06-22Rollup merge of #85182 - CDirkx:available_concurrency, r=JohnTitorYuki Okushi-162/+182
Move `available_concurrency` implementation to `sys` This splits out the platform-specific implementation of `available_concurrency` to the corresponding platforms under `sys`. No changes are made to the implementation. Tidy didn't lint against this code being originally added outside of `sys` because of a bug (see #84677), this PR also reverts the exclusion that was introduced in that bugfix. Tracking issue of `available_concurrency`: #74479
2021-06-22Rollup merge of #85054 - jethrogb:jb/sgx-inline-asm, r=AmanieuYuki Okushi-8/+8
Revert SGX inline asm syntax This was erroneously changed in #83387
2021-06-21Auto merge of #86383 - shamatar:slice_len_lowering, r=bjorn3bors-1/+1
Add MIR pass to lower call to `core::slice::len` into `Len` operand During some larger experiment with range analysis I've found that code like `let l = slice.len()` produces different MIR then one found in bound checks. This optimization pass replaces terminators that are calls to `core::slice::len` with just a MIR operand and Goto terminator. It uses some heuristics to remove the outer borrow that is made to call `core::slice::len`, but I assume it can be eliminated, just didn't find how. Would like to express my gratitude to `@oli-obk` who helped me a lot on Zullip
2021-06-21Merge `sys_common::bytestring` into `os_str_bytes`Christiaan Dirkx-50/+28
2021-06-21Use `Unsupported` on platforms where `available_concurrency` is not implemented.Christiaan Dirkx-21/+9
2021-06-21Move `available_concurrency` implementation to `sys`Christiaan Dirkx-162/+194
2021-06-20Auto merge of #84967 - CDirkx:os_str_ext, r=m-ou-sebors-78/+92
Move `OsStringExt` and `OsStrExt` to `std::os` Moves the `OsStringExt` and `OsStrExt` traits and implementations from `sys_common` to `os`. `sys_common` is for abstractions over `sys` and shouldn't really contain publicly exported items. This does introduce some duplication: the traits and implementations are now duplicated in `unix`, `wasi`, `hermit`, and `sgx`. However, I would argue that this duplication is no different to how something like `MetadataExt` is duplicated in `linux`, `vxworkx`, `redox`, `solaris` etc. The duplication also matches the fact that the traits on different platforms are technically distinct types: any platform is free to add it's own extra methods to the extension trait.
2021-06-20Squashed implementation of the passAlex Vlasov-1/+1
2021-06-20Add comment to `std::os::unix::ffi::os_str` explaining that the module is ↵Christiaan Dirkx-0/+3
reused on other platforms.
2021-06-20Make `os_str_bytes::{Buf, Slice}` `pub` and `repr(transparent)`Christiaan Dirkx-8/+4
2021-06-20Move `OsStringExt` and `OsStrExt` to `std::os`Christiaan Dirkx-70/+85
2021-06-20Auto merge of #86463 - fee1-dead:fixed-encode_wide, r=m-ou-sebors-1/+14
Account for self.extra in size_hint for EncodeWide Fixes #86414.
2021-06-19Auto merge of #86034 - nagisa:nagisa/rt-soundness, r=m-ou-sebors-15/+31
Change entry point to 🛡️ against 💥 💥-payloads Guard against panic payloads panicking within entrypoints, where it is UB to do so. Note that there are a number of tradeoffs to consider. For instance, I considered guarding against accidental panics inside the `rt::init` and `rt::cleanup` code as well, as it is not all that obvious these may not panic, but doing so would mean that we initialize certain thread-local slots unconditionally, which has its own problems. Fixes #86030 r? `@m-ou-se`
2021-06-19Change entry point to 🛡️ against 💥 💥-payloadsSimonas Kazlauskas-15/+31
Guard against panic payloads panicking within entrypoints, where it is UB to do so. Note that there are a number of implementation approaches to consider. Some simpler, some more complicated. This particular solution is nice in that it also guards against accidental implementation issues in various pieces of runtime code, something we cannot prevent statically right now. Fixes #86030
2021-06-19Windows: Fix `Command::env_clear` so it worksChris Denton-0/+6
Previously, it would error unless at least one new environment variable was added.
2021-06-19Auto merge of #86426 - hi-rustin:rustin-patch-lint-warn, r=Aaron1011bors-3/+3
Lint for unused borrows as part of UNUSED_MUST_USE close https://github.com/rust-lang/rust/issues/76264 base on https://github.com/rust-lang/rust/pull/76894 r? `@RalfJung`
2021-06-19Account for self.extra in size_hint for EncodeWideDeadbeef-1/+14
2021-06-18Auto merge of #85815 - YuhanLiin:buf-read-data-left, r=m-ou-sebors-0/+41
Add has_data_left() to BufRead This is a continuation of #40747 and also addresses #40745. The problem with the previous PR was that it had "eof" in its method name. This PR uses a more descriptive method name, but I'm open to changing it.
2021-06-18Auto merge of #85747 - maxwase:path-symlinks-methods, r=m-ou-sebors-0/+52
Path methods — symlinks improvement This PR adds symlink method for the `Path`. Tracking issue: #85748 For the discussion you can see [internals topic](https://internals.rust-lang.org/t/path-methods-symlinks-improvement/14776) P.S. I'm not fully sure about `stable` attribute, correct me if I'm wrong.
2021-06-18`no_run` and `ignore` doc attributesMax Wase-2/+4
2021-06-18Lint for unused borrows as part of UNUSED_MUST_USEhi-rustin-3/+3
2021-06-17Update tracking issueYuhanLiin-1/+1
2021-06-17Rollup merge of #86357 - de-vri-es:simplify-repeated-cfg-ifs, r=m-ou-seMara Bos-100/+10
Rely on libc for correct integer types in os/unix/net/ancillary.rs. This PR is a small maintainability improvement. It simplifies `unix/net/ancillary.rs` in `std` by removing the `cfg_ifs` for casting to the correct integer type, and just rely on libc to define the struct correctly.
2021-06-17Rollup merge of #86202 - a1phyr:spec_io_bytes_size_hint, r=m-ou-seMara Bos-3/+96
Specialize `io::Bytes::size_hint` for more types Improve the result of `<io::Bytes as Iterator>::size_hint` for some readers. I did not manage to specialize `SizeHint` for `io::Cursor` Side question: would it be interesting for `io::Read` to have an optional `size_hint` method ?
2021-06-17Rollup merge of #85925 - clarfonthey:lerp, r=m-ou-seMara Bos-0/+191
Linear interpolation #71016 is a previous attempt at implementation that was closed by the author. I decided to reuse the feature request issue (#71015) as a tracking issue. A member of the rust-lang org will have to edit the original post to be formatted correctly as I am not the issue's original author. The common name `lerp` is used because it is the term used by most code in a wide variety of contexts; it also happens to be the recently chosen name of the function that was added to C++20. To ensure symmetry as a method, this breaks the usual ordering of the method from `lerp(a, b, t)` to `t.lerp(a, b)`. This makes the most sense to me personally, and there will definitely be discussion before stabilisation anyway. Implementing lerp "correctly" is very dififcult even though it's a very common building-block used in all sorts of applications. A good prior reading is [this proposal](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0811r2.html#linear-interpolation) for the C++20 lerp which talks about the various guarantees, which I've simplified down to: 1. Exactness: `(0.0).lerp(start, end) == start` and `(1.0).lerp(start, end) == end` 2. Consistency: `anything.lerp(x, x) == x` 3. Monotonicity: once you go up don't go down Fun story: the version provided in that proposal, from what I understand, isn't actually monotonic. I messed around with a *lot* of different lerp implementations because I kind of got a bit obsessed and I ultimately landed on one that uses the fused `mul_add` instruction. Floating-point lerp lore is hard to come by, so, just trust me when I say that this ticks all the boxes. I'm only 90% certain that it's monotonic, but I'm sure that people who care deeply about this will be there to discuss before stabilisation. The main reason for using `mul_add` is that, in general, it ticks more boxes with fewer branches to be "correct." Although it will be slower on architectures without the fused `mul_add`, that's becoming more and more rare and I have a feeling that most people who will find themselves needing `lerp` will also have an efficient `mul_add` instruction available.
2021-06-17Rely on libc for correct integer types in os/unix/net/ancillary.rs.Maarten de Vries-100/+10