Commit Graph

1294 Commits

Author SHA1 Message Date
Andrea Nall 5ef202520f add diagnostic items
Add diagnostic items to the following types:
  OsString (os_string_type)
  PathBuf (path_buf_type)
  Owned (to_owned_trait)

As well as the to_vec method on slice/[T]
2021-02-15 02:27:28 +00:00
Ryan Lopopolo 3ed6184434
Implement Extend and FromIterator for OsString
Add the following trait impls:

- `impl Extend<OsString> for OsString`
- `impl<'a> Extend<&'a OsStr> for OsString`
- `impl FromIterator<OsString> for OsString`
- `impl<'a> FromIterator<&'a OsStr> for OsString`

Because `OsString` is a platform string with no particular semantics,
concatenating them together seems acceptable.
2021-02-14 15:01:46 -08:00
Steven Fackler 4613b3764c Stabilize Arguments::as_str
Closes #74442
2021-02-14 17:48:51 -05:00
Mara Bos 1aa965101c Fix typo in link to CreateSymbolicLinkW documentation. 2021-02-14 23:16:45 +01:00
Victor Roest ee9709fae6
Fixed minor typo in catch_unwind docs
Changed 'a an exception' to 'an exception'
2021-02-13 16:59:06 +01:00
Dylan DPC 354f19cf24
Rollup merge of #81850 - the8472:env-rwlock, r=m-ou-se
use RWlock when accessing os::env

Multiple threads modifying the current process environment is fairly uncommon. Optimize for the more common read case.

r? ````@m-ou-se````
2021-02-12 22:53:33 +01:00
Dan Gohman 0060c91cfc Make WASI's `hard_link` behavior match other platforms.
Following #78026, `std::fs::hard_link` on most platforms does not follow
symlinks. Change the WASI implementation to also not follow symlinks.
2021-02-10 17:52:36 -08:00
Amanieu d'Antras bfd1ccfb27 Seal the CommandExt, OsStrExt and OsStringExt traits 2021-02-10 21:30:30 +00:00
Jacob Pratt c28f2a8bee
Stabilize str_split_once 2021-02-09 23:17:11 -05:00
Yuki Okushi bb06b13131
Rollup merge of #79849 - Digital-Chaos:sleep-zero, r=m-ou-se
Clarify docs regarding sleep of zero duration

Clarify that the behaviour of sleep() when given a duration of zero is actually platform specific.
2021-02-10 12:24:18 +09:00
The8472 4fc181dd62 split guard into read and write types 2021-02-09 19:13:21 +01:00
The8472 44abad5b12 introduce StaticRWLock wrapper to make methods safe 2021-02-08 23:35:02 +01:00
The8472 2200cf10d8 avoid &mut on the read path since it now allows concurrent readers 2021-02-08 23:31:49 +01:00
Mara Bos 15de287cd5 Remove outdated comment. 2021-02-08 22:27:34 +01:00
Vadim Petrochenkov dbdbd30bf2 expand/resolve: Turn `#[derive]` into a regular macro attribute 2021-02-07 20:08:45 +03:00
The8472 406fd3a277 silence dead code warnings on windows 2021-02-07 09:45:49 +01:00
The8472 55ca27faa7 use rwlock for accessing ENV 2021-02-07 09:12:21 +01:00
bors 0961ae83b8 Auto merge of #81821 - nikic:update-wasm32, r=sanxiyn
Upgrade wasm32 image to Ubuntu 20.04

This switches the wasm32 image, which is used to test
wasm32-unknown-emscripten, to Ubuntu 20.04. While at it, enable
most of the excluded tests, as they seem to work fine with some
minor fixes.
2021-02-07 02:36:08 +00:00
Martin Habovstiak 66f7f7d8a9 Added `try_exists()` method to `std::path::Path`
This method is similar to the existing `exists()` method, except it
doesn't silently ignore the errors, leading to less error-prone code.

This change intentionally does NOT touch the documentation of `exists()`
nor recommend people to use this method while it's unstable.
Such changes are reserved for stabilization to prevent confusing people.

Apart from that it avoids conflicts with #80979.
2021-02-06 22:16:54 +01:00
Nikita Popov 55e237284f Upgrade wasm32 image to Ubuntu 20.04
This switches the wasm32 image, which is used to test
wasm32-unknown-emscripten to Ubuntu 20.04. While at it, enable
most of the excluded tests, as they seem to work fine with some
minor fixes.
2021-02-06 13:05:56 +01:00
Mara Bos ce1020fc55
Rollup merge of #81542 - RReverser:wasi-symlink, r=alexcrichton
Expose correct symlink API on WASI

As described in https://github.com/rust-lang/rust/issues/68574, the currently exposed API for symlinks is, in fact, a thin wrapper around the corresponding syscall, and not suitable for public usage.

The reason is that the 2nd param in the call is expected to be a handle of a "preopened directory" (a WASI concept for exposing dirs), and the only way to retrieve such handle right now is by tinkering with a private `__wasilibc_find_relpath` API, which is an implementation detail and definitely not something we want users to call directly.

Making matters worse, the semantics of this param aren't obvious from its name (`fd`), and easy to misinterpret, resulting in people trying to pass a handle of the target file itself (as in https://github.com/vitiral/path_abs/pull/50), which doesn't work as expected.

I did a [codesearch among open-source repos](https://sourcegraph.com/search?q=std%3A%3Aos%3A%3Awasi%3A%3Afs%3A%3Asymlink&patternType=literal), and the usage above is so far the only usage of this API at all, but we should fix it before more people start using it incorrectly.

While this is technically a breaking API change, I believe it's a justified one, as 1) it's OS-specific and 2) there was strictly no way to correctly use the previous form of the API, and if someone does use it, they're likely doing it wrong like in the example above.

The new API does not lead to the same confusion, as it mirrors `std::os::unix::fs::symlink` and `std::os::windows::fs::symlink_{file,dir}` variants by accepting source/target paths.

Fixes #68574.

r? ``@alexcrichton``
2021-02-05 12:26:00 +01:00
Mara Bos 6f014cd4db
Rollup merge of #81745 - Kixunil:stabilize_once_poison, r=m-ou-se
Stabilize poison API of Once, rename poisoned()

This stabilizes:

* `OnceState`
* `OnceState::is_poisoned()` (previously named `poisoned()`)
* `Once::call_once_force()`

`poisoned()` was renamed because the new name is more clear as a few
people agreed and nobody objected.

Closes #33577

Notes:

* I'm not entirely sure it's supposed to be 1.51, LMK if I did it wrong
* I failed to run tests locally, so we will have to leave it to bors or someone else can try
2021-02-04 21:10:44 +01:00
Mara Bos e0ddc053f9
Rollup merge of #81711 - saethlin:ipaddr-inline, r=m-ou-se
add #[inline] to all the public IpAddr functions
2021-02-04 21:10:39 +01:00
Mara Bos 21e5827800
Rollup merge of #81710 - TyPR124:patch-2, r=m-ou-se
OsStr eq_ignore_ascii_case takes arg by value

Per a comment on #70516 this changes `eq_ignore_ascii_case` to take the generic parameter `S: AsRef<OsStr>` by value instead of by reference.

This is technically a breaking change to an unstable method. I think the only way it would break is if you called this method with an explicit type parameter, ie `my_os_str.eq_ignore_ascii_case::<str>("foo")` becomes `my_os_str.eq_ignore_ascii_case::<&str>("foo")`.

Besides that, I believe it is overall more flexible since it can now take an owned `OsString` for example.

If this change should be made in some other PR (like #80193) then please just close this.
2021-02-04 21:10:37 +01:00
Martin Habovstiak f42e96149d Stabilize poison API of Once, rename poisoned()
This stabilizes:

* `OnceState`
* `OnceState::is_poisoned()` (previously named `poisoned()`)
* `Once::call_once_force()`

`poisoned()` was renamed because the new name is more clear as a few
people agreed and nobody objected.

Closes #33577
2021-02-04 15:20:14 +01:00
Yoshua Wuyts 2c8bf1db54 Stabilize the Wake trait
Co-Authored-By: Ashley Mannix <kodraus@hey.com>
2021-02-03 16:54:29 +01:00
Ben Kimock d3d0fb7b45 add #[inline] to all the public IpAddr functions 2021-02-03 10:53:25 -05:00
Ingvar Stepanyan f4b1bef542
Restore comment as it was 2021-02-03 15:46:57 +00:00
Ingvar Stepanyan 1578f2e1e8
Keep old symlink; expose new symlink_path 2021-02-03 15:45:30 +00:00
Tyler Ruckinger 4d1efb751a
OsStr eq_ignore_ascii_case takes arg by value
Per a comment on #70516 this changes `eq_ignore_ascii_case` to take the generic parameter `S: AsRef<OsStr>` by value instead of by reference.

This is technically a breaking change to an unstable method. I think the only way it would break is if you called this method with an explicit type parameter, ie `my_os_str.eq_ignore_ascii_case::<str>("foo")` becomes `my_os_str.eq_ignore_ascii_case::<&str>("foo")`.

Besides that, I believe it is overall more flexible since it can now take an owned `OsString` for example.

If this change should be made in some other PR (like #80193) then please just close this.
2021-02-03 10:28:51 -05:00
Jack Huey d3304c8ac3
Rollup merge of #81588 - xfix:delete-doc-alias, r=Mark-Simulacrum
Add doc aliases for "delete"

This patch adds doc aliases for "delete". The added aliases are supposed to reference usages `delete` in other programming languages.

- `HashMap::remove`, `BTreeMap::remove` -> `Map#delete` and `delete` keyword in JavaScript.

- `HashSet::remove`, `BTreeSet::remove` -> `Set#delete` in JavaScript.

- `mem::drop` -> `delete` keyword in C++.

- `fs::remove_file`, `fs::remove_dir`, `fs::remove_dir_all`-> `File#delete` in Java, `File#delete` and `Dir#delete` in Ruby.

Before this change, searching for "delete" in documentation returned no results.
2021-02-02 16:01:41 -05:00
Jack Huey 76be6bb4de
Rollup merge of #81530 - ojeda:sys-use-abort-instead-of-wasm32-unreachable, r=Mark-Simulacrum
sys: use `process::abort()` instead of `arch::wasm32::unreachable()`

Rationale:

  - `abort()` lowers to `wasm32::unreachable()` anyway.
  - `abort()` isn't `unsafe`.
  - `abort()` matches the comment better.
  - `abort()` avoids confusion by future readers (e.g. https://github.com/rust-lang/rust/pull/81527): the naming of wasm's `unreachable` instruction is a bit unfortunate because it is not related to the `unreachable()` intrinsic (intended to trigger UB).

Codegen is likely to be different since `unreachable()` is `inline` while `abort()` is `cold`. Since it doesn't look like we are expecting here to trigger this case, the latter seems better anyway.
2021-02-02 16:01:38 -05:00
Jack Huey 399c0a8e52
Rollup merge of #81455 - Amanieu:aarch64_ilp32, r=sanxiyn
Add AArch64 big-endian and ILP32 targets

This PR adds 3 new AArch64 targets:
- `aarch64_be-unknown-linux-gnu`
- `aarch64-unknown-linux-gnu_ilp32`
- `aarch64_be-unknown-linux-gnu_ilp32`

It also fixes some ABI issues on big-endian ARM and AArch64.
2021-02-02 16:01:35 -05:00
Jonas Schievink f61ab58574
Rollup merge of #81022 - seanchen1991:feat/frames-iter, r=KodrAus
Add Frames Iterator for Backtrace

Second attempt at adding the ability to iterate over the frames of a Backtrace by exposing the frames method.
2021-02-02 12:14:49 +01:00
Amanieu d'Antras 3408c58bdf Fix AArch64 types in std::os::raw 2021-02-02 05:49:31 +00:00
Jonas Schievink 2622227208
Rollup merge of #81598 - sivadeilra:windows_dll_imports_fix_x86, r=m-ou-se
Fix calling convention for CRT startup

My PR #81478 used the wrong calling convention for a set of
functions that are called by the CRT. These functions need to use
`extern "C"`.

This would only affect x86, which is the only target (that I know of)
that has multiple calling conventions.

```@bors``` r? ```@m-ou-se```
2021-02-01 14:29:45 +01:00
Jonas Schievink a7a6f013a2
Rollup merge of #78641 - the8472:buffered-copy, r=sfackler
Let io::copy reuse BufWriter buffers

This optimization will allow users to implicitly set the buffer size for io::copy by wrapping the writer into a `BufWriter` if the default block size is insufficient, which should fix #49921

Due to min_specialization limitations this approach only works with `BufWriter` but not for `BufReader<R>` since `R` is unconstrained and thus the necessary specialization on `R: Read` is not always applicable. Once specialization becomes more powerful this optimization could be extended to look at the reader and writer side and use whichever buffer is larger.
2021-02-01 14:29:28 +01:00
bors e0d9f79399 Auto merge of #80851 - m-ou-se:panic-2021, r=petrochenkov
Implement Rust 2021 panic

This implements the Rust 2021 versions of `panic!()`. See https://github.com/rust-lang/rust/issues/80162 and https://github.com/rust-lang/rfcs/pull/3007.

It does so by replacing `{std, core}::panic!()` by a bulitin macro that expands to either `$crate::panic::panic_2015!(..)` or `$crate::panic::panic_2021!(..)` depending on the edition of the caller.

This does not yet make std's panic an alias for core's panic on Rust 2021 as the RFC proposes. That will be a separate change: c5273bdfb2 That change is blocked on figuring out what to do with https://github.com/rust-lang/rust/issues/80846 first.
2021-02-01 10:25:31 +00:00
Arlie Davis 3acd1a4f92 Fix calling convention for CRT startup
My PR #81478 used the wrong calling convention for a set of
functions that are called by the CRT. These functions need to use
`extern "C"`.

This would only affect x86, which is the only target (that I know of)
that has multiple calling conventions.
2021-01-31 08:49:23 -08:00
Jonas Schievink 47a5312c30
Rollup merge of #81549 - est31:wording_fix, r=jonas-schievink
Misc ip documentation fixes
2021-01-31 16:36:47 +01:00
The8472 4105506656 specialize io::copy to use the memory of the writer if it is a BufWriter 2021-01-31 14:58:03 +01:00
Xavientois 7674ae1a4e Fix line length format 2021-01-31 08:52:57 -05:00
Xavientois fc9cd4a14b Fix formatting on mod 2021-01-31 08:34:42 -05:00
Xavientois 81aba388f1 Add space for proper indentation 2021-01-31 08:34:42 -05:00
Xavientois b837f3a99b Remove trailing newline 2021-01-31 08:34:42 -05:00
Xavientois 389e638c05 Add tests for SizeHint implementations 2021-01-31 08:34:42 -05:00
Xavientois 96255f82c9 Implement SizeHint trait for BufReader, Emtpy, and Chain 2021-01-31 08:34:42 -05:00
Xavientois c8e0f8aaa3 Use fully qualified syntax to avoid dyn 2021-01-31 08:31:35 -05:00
Xavientois 7869371bf1 Remove unnecessary default keyword 2021-01-31 08:31:35 -05:00
Xavientois 93870c8d5f Remove stable annotation 2021-01-31 08:31:35 -05:00
Xavientois 265db94dc2 Fix formatting 2021-01-31 08:31:35 -05:00
Xavientois 421b40cd6a Add dyn for SizeHint cast 2021-01-31 08:31:35 -05:00
Xavientois 1190321b76 Remove exposing private trait 2021-01-31 08:31:35 -05:00
Xavientois 442de9ac45 Fix semicolon 2021-01-31 08:31:35 -05:00
Xavientois 7e56637c74 Add back lower_bound as memeber 2021-01-31 08:31:35 -05:00
Xavientois eea99f491b Add default keyword for specialization 2021-01-31 08:31:34 -05:00
Xavientois 5f60a3048e Fix incorrect token 2021-01-31 08:31:34 -05:00
Xavientois 260a270f7c Move default to trait definition 2021-01-31 08:31:34 -05:00
Xavientois 11c49f6a2a Add missing generic 2021-01-31 08:31:34 -05:00
Xavientois fa76db3104 Use helper trait to follow min_specialization rules 2021-01-31 08:31:34 -05:00
Xavientois c3e47d974a Fix implementation to specialize 2021-01-31 08:31:34 -05:00
Xavientois f45bdcce69 Implement size_hint for BufReader 2021-01-31 08:31:34 -05:00
Konrad Borowski 15701f7531 Add doc aliases for "delete"
This patch adds doc aliases for "delete". The added aliases are
supposed to reference usages `delete` in other programming
languages.

- `HashMap::remove`, `BTreeMap::remove` -> `Map#delete` and `delete`
  keyword in JavaScript.

- `HashSet::remove`, `BTreeSet::remove` -> `Set#delete` in JavaScript.

- `mem::drop` -> `delete` keyword in C++.

- `fs::remove_file`, `fs::remove_dir`, `fs::remove_dir_all`
  -> `File#delete` in Java, `File#delete` and `Dir#delete` in Ruby.

Before this change, searching for "delete" in documentation
returned no results.
2021-01-31 11:07:37 +01:00
bors 0e63af5da3 Auto merge of #81478 - sivadeilra:windows_dll_imports, r=m-ou-se
Resolve DLL imports at CRT startup, not on demand

On Windows, libstd uses GetProcAddress to locate some DLL imports, so
that libstd can run on older versions of Windows. If a given DLL import
is not present, then libstd uses other behavior (such as fallback
implementations).

This commit uses a feature of the Windows CRT to do these DLL imports
during module initialization, before main() (or DllMain()) is called.
This is the ideal time to resolve imports, because the module is
effectively single-threaded at that point; no other threads can
touch the data or code of the module that is being initialized.

This avoids several problems. First, it makes the cost of performing
the DLL import lookups deterministic. Right now, the DLL imports are
done on demand, which means that application threads _might_ have to
do the DLL import during some time-sensitive operation. This is a
small source of unpredictability. Since threads can race, it's even
possible to have more than one thread running the same redundant
DLL lookup.

This commit also removes using the heap to allocate strings, during
the DLL lookups.
2021-01-31 10:01:15 +00:00
Jonas Schievink 635dbd60bf
Rollup merge of #81550 - xfix:replace-mention-of-predecessor, r=jonas-schievink
Replace predecessor with range in collections documentation

Fixes #81548.
2021-01-31 01:47:43 +01:00
Jonas Schievink 1bf130519c
Rollup merge of #78044 - oberien:empty-seek, r=m-ou-se
Implement io::Seek for io::Empty

Fix #78029
2021-01-31 01:47:18 +01:00
oberien f1cd17961c impl Seek for Empty
Fix #78029
2021-01-30 23:00:10 +01:00
Konrad Borowski 56c27360b1 Replace predecessor with range in collections documentation
Fixes #81548.
2021-01-30 14:24:06 +01:00
est31 cddeb5e47b Misc ip documentation fixes 2021-01-30 12:06:06 +01:00
Yuki Okushi b94d84d38a
Rollup merge of #80886 - RalfJung:stable-raw-ref-macros, r=m-ou-se
Stabilize raw ref macros

This stabilizes `raw_ref_macros` (https://github.com/rust-lang/rust/issues/73394), which is possible now that https://github.com/rust-lang/rust/issues/74355 is fixed.

However, as I already said in https://github.com/rust-lang/rust/issues/73394#issuecomment-751342185, I am not particularly happy with the current names of the macros. So I propose we also change them, which means I am proposing to stabilize the following in `core::ptr`:
```rust
pub macro const_addr_of($e:expr) {
    &raw const $e
}

pub macro mut_addr_of($e:expr) {
    &raw mut $e
}
```

The macro name change means we need another round of FCP. Cc `````@rust-lang/libs`````
Fixes #73394
2021-01-30 13:36:43 +09:00
Yuki Okushi ecd7cb1c3a
Rollup merge of #79023 - yoshuawuyts:stream, r=KodrAus
Add `core::stream::Stream`

[[Tracking issue: #79024](https://github.com/rust-lang/rust/issues/79024)]

This patch adds the `core::stream` submodule and implements `core::stream::Stream` in accordance with [RFC2996](https://github.com/rust-lang/rfcs/pull/2996). The RFC hasn't been merged yet, but as requested by the libs team in https://github.com/rust-lang/rfcs/pull/2996#issuecomment-725696389 I'm filing this PR to get the ball rolling.

## Documentatation

The docs in this PR have been adapted from [`std::iter`](https://doc.rust-lang.org/std/iter/index.html), [`async_std::stream`](https://docs.rs/async-std/1.7.0/async_std/stream/index.html), and [`futures::stream::Stream`](https://docs.rs/futures/0.3.8/futures/stream/trait.Stream.html). Once this PR lands my plan is to follow this up with PRs to add helper methods such as `stream::repeat` which can be used to document more of the concepts that are currently missing. That will allow us to cover concepts such as "infinite streams" and "laziness" in more depth.

## Feature gate

The feature gate for `Stream` is `stream_trait`. This matches the `#[lang = "future_trait"]` attribute name. The intention is that only the APIs defined in RFC2996 will use this feature gate, with future additions such as `stream::repeat` using their own feature gates. This is so we can ensure a smooth path towards stabilizing the `Stream` trait without needing to stabilize all the APIs in `core::stream` at once. But also don't start expanding the API until _after_ stabilization, as was the case with `std::future`.

__edit:__ the feature gate has been changed to `async_stream` to match the feature gate proposed in the RFC.

## Conclusion

This PR introduces `core::stream::{Stream, Next}` and re-exports it from `std` as `std::stream::{Stream, Next}`. Landing `Stream` in the stdlib has been a mult-year process; and it's incredibly exciting for this to finally happen!

---

r? `````@KodrAus`````
cc/ `````@rust-lang/wg-async-foundations````` `````@rust-lang/libs`````
2021-01-30 13:36:39 +09:00
Ingvar Stepanyan 5882cce54e Expose correct symlink API on WASI
As described in https://github.com/rust-lang/rust/issues/68574, the currently exposed API for symlinks is, in fact, a thin wrapper around the corresponding syscall, and not suitable for public usage.

The reason is that the 2nd param in the call is expected to be a handle of a "preopened directory" (a WASI concept for exposing dirs), and the only way to retrieve such handle right now is by tinkering with a private `__wasilibc_find_relpath` API, which is an implementation detail and definitely not something we want users to call directly.

Making matters worse, the semantics of this param aren't obvious from its name (`fd`), and easy to misinterpret, resulting in people trying to pass a handle of the target file itself (as in https://github.com/vitiral/path_abs/pull/50), which doesn't work as expected.

I did a codesearch among open-source repos, and the usage above is so far the only usage of this API at all, but we should fix it before more people start using it incorrectly.

While this is technically a breaking API change, I believe it's a justified one, as 1) it's OS-specific and 2) there was strictly no way to correctly use the previous form of the API, and if someone does use it, they're likely doing it wrong like in the example above.

The new API does not lead to the same confusion, as it mirrors `std::os::unix::fs::symlink` and `std::os::windows::fs::symlink_{file,dir}` variants by accepting source/target paths.

Fixes #68574.
2021-01-30 02:30:52 +00:00
Miguel Ojeda c7f4154c6a sys: use `process::abort()` instead of `arch::wasm32::unreachable()`
Rationale:

  - `abort()` lowers to `wasm32::unreachable()` anyway.
  - `abort()` isn't `unsafe`.
  - `abort()` matches the comment better.
  - `abort()` avoids confusion by future readers (e.g.
    https://github.com/rust-lang/rust/pull/81527): the naming of wasm's
    `unreachable' instruction is a bit unfortunate because it is not
    related to the `unreachable()` intrinsic (intended to trigger UB).

Codegen is likely to be different since `unreachable()` is `inline`
while `abort()` is `cold`. Since it doesn't look like we are expecting
here to trigger this case, the latter seems better anyway.

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2021-01-29 20:25:23 +01:00
Arlie Davis f4debc8e94 Resolve DLL imports at CRT startup, not on demand
On Windows, libstd uses GetProcAddress to locate some DLL imports, so
that libstd can run on older versions of Windows. If a given DLL import
is not present, then libstd uses other behavior (such as fallback
implementations).

This commit uses a feature of the Windows CRT to do these DLL imports
during module initialization, before main() (or DllMain()) is called.
This is the ideal time to resolve imports, because the module is
effectively single-threaded at that point; no other threads can
touch the data or code of the module that is being initialized.

This avoids several problems. First, it makes the cost of performing
the DLL import lookups deterministic. Right now, the DLL imports are
done on demand, which means that application threads _might_ have to
do the DLL import during some time-sensitive operation. This is a
small source of unpredictability. Since threads can race, it's even
possible to have more than one thread running the same redundant
DLL lookup.

This commit also removes using the heap to allocate strings, during
the DLL lookups.
2021-01-29 10:41:49 -08:00
Ralf Jung 13ffa43bbb rename raw_const/mut -> const/mut_addr_of, and stabilize them 2021-01-29 15:18:45 +01:00
Yuki Okushi 025a850d21
Rollup merge of #70904 - LukasKalbertodt:stabilize-seek-convenience, r=m-ou-se
Stabilize `Seek::stream_position` (feature `seek_convenience`)

Tracking issue: #59359

Unresolved questions from tracking issue:
- "Override `stream_len` for `File`?" → we can do that in the future, this does not block stabilization.
- "Rename to `len` and `position`?" → as noted in the tracking issue, both of these shorter names have problems (`len` is usually a cheap getter, `position` clashes with `Cursor`). I do think the current names are perfectly fine.
- "Rename `stream_position` to `tell`?" → as mentioned in [the comment bringing this up](https://github.com/rust-lang/rust/issues/59359#issuecomment-559541545), `stream_position` is more descriptive. I don't think `tell` would be a good name.

What remains to decide, is whether or not adding these methods is worth it.
2021-01-28 15:09:00 +09:00
bors a2f8f62818 Auto merge of #81335 - thomwiggers:no-panic-shrink-to, r=Mark-Simulacrum
Trying to shrink_to greater than capacity should be no-op

Per the discussion in https://github.com/rust-lang/rust/issues/56431, `shrink_to` shouldn't panic if you try to make a vector shrink to a capacity greater than its current capacity.
2021-01-27 18:36:32 +00:00
Thom Wiggers d069c58e78
shrink_to shouldn't panic on len greater than capacity 2021-01-26 19:25:37 +01:00
Mara Bos fc7c5e486c Make std::panic_2021 an alias for core::panic_2021. 2021-01-25 13:49:00 +01:00
Mara Bos d5414f9a9f Implement new panic!() behaviour for Rust 2021. 2021-01-25 13:48:11 +01:00
Jonas Schievink 13b88c21d0
Rollup merge of #79174 - taiki-e:std-future, r=Mark-Simulacrum
Make std::future a re-export of core::future

After 1a764a7ef5, there are no `std::future`-specific items (except for `cfg(bootstrap)` items removed in 93eed402ad). So, instead of defining `std` own module, we can re-export the `core::future` directly.
2021-01-24 22:09:49 +01:00
Jonas Schievink 5a1f2ecdd7
Rollup merge of #75180 - KodrAus:feat/error-by-ref, r=m-ou-se
Implement Error for &(impl Error)

Opening this up just to see what it breaks. It's unfortunate that `&(impl Error)` doesn't actually implement `Error`. If this direct approach doesn't work out then I'll try something different, like an `Error::by_ref` method.

**EDIT:** This is a super low-priority experiment so feel free to cancel it for more important crater runs! 🙂

-----

# Stabilization Report

## Why?

We've been working for the last few years to try "fix" the `Error` trait, which is probably one of the most fundamental in the whole standard library. One of its issues is that we commonly expect you to work with abstract errors through `dyn Trait`, but references and smart pointers over `dyn Trait` don't actually implement the `Error` trait. If you have a `&dyn Error` or a `Box<dyn Error>` you simply can't pass it to a method that wants a `impl Error`.

## What does this do?

This stabilizes the following trait impl:

```rust
impl<'a, T: Error + ?Sized + 'static> Error for &'a T;
```

This means that `&dyn Error` will now satisfy a `impl Error` bound.

It doesn't do anything with `Box<dyn Error>` directly. We discussed how we could do `Box<dyn Error>` in the thread here (and elsewhere in the past), but it seems like we need something like lattice-based specialization or a sprinkling of snowflake compiler magic to make that work. Having said that, with this new impl you _can_ now get a `impl Error` from a `Box<dyn Error>`  by dereferencing it.

## What breaks?

A crater run revealed a few crates broke with something like the following:

```rust
// where e: &'short &'long dyn Error
err.source()
```

previously we'd auto-deref that `&'short &'long dyn Error` to return a `Option<&'long dyn Error>` from `source`, but now will call directly on `&'short impl Error`, so will return a `Option<&'short dyn Error>`. The fix is to manually deref:

```rust
// where e: &'short &'long dyn Error
(*err).source()
```

In the recent Libs meeting we considered this acceptable breakage.
2021-01-24 22:09:45 +01:00
bors 9a9477fada Auto merge of #81250 - sivadeilra:remove_xp_compat, r=joshtriplett,m-ou-se
Remove delay-binding for Win XP and Vista

The minimum supported Windows version is now Windows 7. Windows XP
and Windows Vista are no longer supported; both are already broken, and
require extra steps to use.

This commit removes the delayed-binding support for Windows API
functions that are present on all supported Windows targets. This has
several benefits: Removes needless complexity. Removes a load and
dynamic call on hot paths in mutex acquire / release. This may have
performance benefits.

* "Drop official support for Windows XP"
  https://github.com/rust-lang/compiler-team/issues/378

* "Firefox has ended support for Windows XP and Vista"
  https://support.mozilla.org/en-US/kb/end-support-windows-xp-and-vista
2021-01-24 12:34:08 +00:00
Lukas Kalbertodt 8a18fb0f73
Stabilize `Seek::stream_position` & change feature of `Seek::stream_len` 2021-01-24 10:14:24 +01:00
Jonas Schievink 44c668cfca
Rollup merge of #81281 - a1phyr:inline_path, r=dtolnay
Inline methods of Path and OsString

These methods are not generic, and therefore aren't candidates for cross-crate inlining without an `#[inline]` attribute.
2021-01-23 20:16:12 +01:00
Sean Chen 050643a960 Add Frames iterator for Backtrace 2021-01-23 11:56:33 -06:00
bors 22ddcd1a13 Auto merge of #72160 - slo1:libstd-setgroups, r=KodrAus
Add setgroups to std::os::unix::process::CommandExt

Should fix #38527. I'm not sure groups is the greatest name though.
2021-01-22 19:00:11 +00:00
Benoît du Garreau 9880560a1c Inline methods of Path and OsString 2021-01-22 18:46:00 +01:00
Yoshua Wuyts 0c8db16a67 Add `core::stream::Stream`
This patch adds the `core::stream` submodule and implements `core::stream::Stream` in accordance with RFC2996.

Add feedback from @camelid
2021-01-22 17:41:56 +01:00
Mara Bos 81a60b7aa8
Rollup merge of #81233 - lzutao:dbg, r=KodrAus
Document why not use concat! in dbg! macro

Original title: Reduce code generated by `dbg!` macro
The expanded code before/after: <https://rust.godbolt.org/z/hE3j95>.

---

We cannot use `concat!` since `file!` could contains `{` or the expression is a block (`{ .. }`).
Using it will generated malformed format strings.
So let's document this reason why we don't use `concat!` macro at all.
2021-01-22 14:30:17 +00:00
Mara Bos 950ed27e8b
Rollup merge of #81202 - lzutao:dbg_ipv6, r=Amanieu
Don't prefix 0x for each segments in `dbg!(Ipv6)`

Fixes #81182
2021-01-22 14:30:12 +00:00
Mara Bos b59f6e05ef
Rollup merge of #81194 - m-ou-se:stabilize-panic-any, r=m-ou-se
Stabilize std::panic::panic_any.

This stabilizes `std::panic::panic_any`.
2021-01-22 14:30:11 +00:00
Arlie Davis 59855e0bbf Remove delay-binding for Win XP and Vista
The minimum supported Windows version is now Windows 7. Windows XP
and Windows Vista are no longer supported; both are already broken, and
require extra steps to use.

This commit removes the delayed-binding support for Windows API
functions that are present on all supported Windows targets. This has
several benefits: Removes needless complexity. Removes a load and
dynamic call on hot paths in mutex acquire / release. This may have
performance benefits.

* "Drop official support for Windows XP"
  https://github.com/rust-lang/compiler-team/issues/378

* "Firefox has ended support for Windows XP and Vista"
  https://support.mozilla.org/en-US/kb/end-support-windows-xp-and-vista
2021-01-22 02:02:39 -08:00
slo1 41e6b23000 Add setgroups to std::os::unix::process::CommandExt 2021-01-21 22:42:38 -08:00
bors a243ad280a Auto merge of #81240 - JohnTitor:rollup-ieaz82a, r=JohnTitor
Rollup of 11 pull requests

Successful merges:

 - #79655 (Add Vec visualization to understand capacity)
 - #80172 (Use consistent punctuation for 'Prelude contents' docs)
 - #80429 (Add regression test for mutual recursion in obligation forest)
 - #80601 (Improve grammar in documentation of format strings)
 - #81046 (Improve unknown external crate error)
 - #81178 (Visit only terminators when removing landing pads)
 - #81179 (Fix broken links with `--document-private-items` in the standard library)
 - #81184 (Remove unnecessary `after_run` function)
 - #81185 (Fix ICE in mir when evaluating SizeOf on unsized type)
 - #81187 (Fix typo in counters.rs)
 - #81219 (Document security implications of std::env::temp_dir)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-01-21 12:18:32 +00:00
Yuki Okushi d6c7a797fc
Rollup merge of #81219 - joshtriplett:temp_dir-docs, r=sfackler
Document security implications of std::env::temp_dir

Update the sample code to not create an insecure temporary file.
2021-01-21 20:04:56 +09:00
Yuki Okushi 9abd746a32
Rollup merge of #80172 - camelid:prelude-docs-consistent-punct, r=steveklabnik
Use consistent punctuation for 'Prelude contents' docs
2021-01-21 20:04:39 +09:00
Lzu Tao d0c1405564 Document why cannot use concat! in dbg!
Co-authored-by: Miguel Ojeda <ojeda@users.noreply.github.com>
2021-01-21 10:50:21 +00:00
bstrie 6f3df00610 Deprecate-in-future the constants superceded by RFC 2700 2021-01-20 20:08:11 -05:00
Josh Triplett 27f3764519 Document security implications of std::env::temp_dir
Update the sample code to not create an insecure temporary file.
2021-01-20 11:24:47 -08:00
Lzu Tao 116b66ad49 Dont prefix 0x when `dbg!(ipv6)` 2021-01-20 04:31:34 +00:00
Lzu Tao 6b66749e17 Use slice::split_first instead of manuall slicing 2021-01-20 04:31:34 +00:00
bors 14265f9c55 Auto merge of #79578 - alexcrichton:update-waasi, r=KodrAus
std: Update wasi-libc commit of the wasm32-wasi target

This brings in an implementation of `current_dir` and `set_current_dir`
(emulation in `wasi-libc`) as well as an updated version of finding
relative paths. This also additionally updates clang to the latest
release to build wasi-libc with.
2021-01-19 22:20:58 +00:00
Mara Bos 8cac04e8b8 Make 'static bound on panic_any explicit.
This was already implied because Any: 'static, but this makes it
explicit.
2021-01-19 21:41:41 +01:00
Mara Bos 230d5b1e5f Stabilize std::panic::panic_any. 2021-01-19 21:30:49 +01:00
bors cf04ae54e6 Auto merge of #79705 - ijackson:bufwriter-disassemble, r=m-ou-se
BufWriter: Provide into_raw_parts

If something goes wrong, one might want to unpeel the layers of nested
Writers to perform recovery actions on the underlying writer, or reuse
its resources.

`into_inner` can be used for this when the inner writer is still
working.  But when the inner writer is broken, and returning errors,
`into_inner` simply gives you the error from flush, and the same
`Bufwriter` back again.

Here I provide the necessary function, which I have chosen to call
`into_raw_parts`.

I had to do something with `panicked`.  Returning it to the caller as
a boolean seemed rather bare.  Throwing the buffered data away in this
situation also seems unfriendly: maybe the programmer knows something
about the underlying writer and can recover somehow.

So I went for a custom Error.  This may be overkill, but it does have
the nice property that a caller who actually wants to look at the
buffered data, rather than simply extracting the inner writer, will be
told by the type system if they forget to handle the panicked case.

If a caller doesn't need the buffer, it can just be discarded.  That
WriterPanicked is a newtype around Vec<u8> means that hopefully the
layouts of the Ok and Err variants can be very similar, with just a
boolean discriminant.  So this custom error type should compile down
to nearly no code.

*If this general idea is felt appropriate, I will open a tracking issue, etc.*
2021-01-19 16:42:19 +00:00
bors c4df63f47f Auto merge of #80537 - ehuss:macos-posix-spawn-chdir, r=dtolnay
Don't use posix_spawn_file_actions_addchdir_np on macOS.

There is a bug on macOS where using `posix_spawn_file_actions_addchdir_np` with a relative executable path will cause `posix_spawnp` to return ENOENT, even though it successfully spawned the process in the given directory.

`posix_spawn_file_actions_addchdir_np` was introduced in macOS 10.15 first released in Oct 2019.  I have tested macOS 10.15.7 and 11.0.1.

Example offending program:

```rust
use std::fs;
use std::os::unix::fs::PermissionsExt;
use std::process::*;

fn main() {
    fs::create_dir_all("bar").unwrap();
    fs::create_dir_all("foo").unwrap();
    fs::write("foo/foo.sh", "#!/bin/sh\necho hello ${PWD}\n").unwrap();
    let perms = fs::Permissions::from_mode(0o755);
    fs::set_permissions("foo/foo.sh", perms).unwrap();
    let c = Command::new("../foo/foo.sh").current_dir("bar").spawn();
    eprintln!("{:?}", c);
}
```

This prints:

```
Err(Os { code: 2, kind: NotFound, message: "No such file or directory" })
hello /Users/eric/Temp/bar
```

I wanted to open this PR to get some feedback on possible solutions.  Alternatives:
* Do nothing.
* Document the bug.
* Try to detect if the executable is a relative path on macOS, and avoid using `posix_spawn_file_actions_addchdir_np` only in that case.

I looked at the [XNU source code](https://opensource.apple.com/source/xnu/xnu-6153.141.1/bsd/kern/kern_exec.c.auto.html), but I didn't see anything obvious that would explain the behavior.  The actual chdir succeeds, it is something else further down that fails, but I couldn't see where.

EDIT: I forgot to mention, relative exe paths with `current_dir` in general are discouraged (see #37868).  I don't know if #37868 is fixable, since normalizing it would change the semantics for some platforms. Another option is to convert the executable to an absolute path with something like joining the cwd with the new cwd and the executable, but I'm uncertain about that.
2021-01-17 23:44:46 +00:00
Eric Huss a938725ef7 Don't use posix_spawn_file_actions_addchdir_np on macOS. 2021-01-17 09:51:02 -08:00
Ben Kimock 4e27ed3af1 Add benchmark and fast path for BufReader::read_exact 2021-01-17 12:10:39 +10:00
Mara Bos 40d2506cab
Rollup merge of #80681 - ChrisJefferson:logic-error-doc, r=m-ou-se
Clarify what the effects of a 'logic error' are

This clarifies what a 'logic error' is (which is a term used to describe what happens if you put things in a hash table or btree and then use something like a refcell to break the internal ordering). This tries to be as vague as possible, as we don't really want to promise what happens, except "bad things, but not UB". This was discussed in #80657
2021-01-16 17:29:53 +00:00
Chris Jefferson 78d919280d Clarify what the effects of a 'logic error' are 2021-01-16 09:36:28 +00:00
James Wright bb2a27ba4f
Update library/std/src/thread/mod.rs
Fix link reference

Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2021-01-15 21:41:26 +00:00
James Wright 8a85a85cea Clarify difference between unix/windows behaviour
Updated to specify the underlying syscalls
2021-01-15 21:18:44 +00:00
Alex Crichton 5756bd7f2d std: Update wasi-libc commit of the wasm32-wasi target
This brings in an implementation of `current_dir` and `set_current_dir`
(emulation in `wasi-libc`) as well as an updated version of finding
relative paths. This also additionally updates clang to the latest
release to build wasi-libc with.
2021-01-14 10:40:10 -08:00
Mara Bos 7855a730b9
Rollup merge of #80966 - KodrAus:deprecate/spin_loop_hint, r=m-ou-se
Deprecate atomic::spin_loop_hint in favour of hint::spin_loop

For https://github.com/rust-lang/rust/issues/55002

We wanted to leave `atomic::spin_loop_hint` alone when stabilizing `hint::spin_loop` so folks had some time to migrate. This now deprecates `atomic_spin_loop_hint`.
2021-01-14 18:00:14 +00:00
Mara Bos ce48709405
Rollup merge of #80895 - sfackler:read-to-end-ub, r=m-ou-se
Fix handling of malicious Readers in read_to_end

A malicious `Read` impl could return overly large values from `read`, which would result in the guard's drop impl setting the buffer's length to greater than its capacity! ~~To fix this, the drop impl now uses the safe `truncate` function instead of `set_len` which ensures that this will not happen. The result of calling the function will be nonsensical, but that's fine given the contract violation of the `Read` impl.~~

~~The `Guard` type is also used by `append_to_string` which does not pass untrusted values into the length field, so I've copied the guard type into each function and only modified the one used by `read_to_end`. We could just keep a single one and modify it, but it seems a bit cleaner to keep the guard code close to the functions and related specifically to them.~~

To fix this, we now assert that the returned length is not larger than the buffer passed to the method.

For reference, this bug has been present for ~2.5 years since 1.20: ecbb896b9e.

Closes #80894.
2021-01-14 18:00:11 +00:00
Mara Bos 9fc298ca89
Rollup merge of #80217 - camelid:io-read_to_string, r=m-ou-se
Add a `std::io::read_to_string` function

I recognize that you're usually supposed to open an issue first, but the
implementation is very small so it's okay if this is closed and it was 'wasted
work' :)

-----

The equivalent of `std::fs::read_to_string`, but generalized to all
`Read` impls.

As the documentation on `std::io::read_to_string` says, the advantage of
this function is that it means you don't have to create a variable first
and it provides more type safety since you can only get the buffer out
if there were no errors. If you use `Read::read_to_string`, you have to
remember to check whether the read succeeded because otherwise your
buffer will be empty.

It's friendlier to newcomers and better in most cases to use an explicit
return value instead of an out parameter.
2021-01-14 18:00:00 +00:00
Mara Bos 930371b3ae
Rollup merge of #80169 - frewsxcv:frewsxcv-docs-fix, r=jyn514
Recommend panic::resume_unwind instead of panicking.

Fixes https://github.com/rust-lang/rust/issues/79950.
2021-01-14 17:59:57 +00:00
Mara Bos 8ac21fb201
Rollup merge of #79982 - ijackson:exit-status, r=dtolnay
Add missing methods to unix ExitStatusExt

These are the methods corresponding to the remaining exit status examination macros from `wait.h`.  `WCOREDUMP` isn't in SuS but is it is very standard.  I have not done portability testing to see if this builds everywhere, so I may need to Do Something if it doesn't.

There is also a bugfix and doc improvement to `.signal()`, and an `.into_raw()` accessor.

This would fix #73128 and fix #73129.  Please let me know if you like this direction, and if so I will open the tracking issue and so on.

If this MR goes well, I may tackle #73125 next - I have an idea for how to do it.
2021-01-14 17:59:53 +00:00
David Tolnay a8d0161960
Fix typos in Fuchsia unix_process_wait_more 2021-01-13 22:13:45 -08:00
Ian Jackson 05a88aabc1 ExitStatusExt: Fix build on Fuchsia
This is not particularly pretty but the current situation is a mess
and I don't think I'm making it significantly worse.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 13:27:30 +00:00
David Tolnay efddf5949f Fix typo saeled -> sealed 2021-01-13 12:50:29 +00:00
Ian Jackson f3e7199a79 ExitStatusExt windows: Retrospectively seal this trait
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 12:50:29 +00:00
Ian Jackson 70121941ff ExitStatusExt unix: Retrospectively seal this trait
As discussed in #79982.

I think the "new interfaces", ie the new trait and impl, must be
insta-stable.  This seems OK because we are, in fact, adding a new
restriction to the stable API.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 12:50:29 +00:00
Ian Jackson fa68567a1f unix ExitStatus: Add tracking issue to new methods
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 12:50:29 +00:00
Ian Jackson 06a405c49c Replace `Ie` with `In other words`
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2021-01-13 12:50:29 +00:00
Ian Jackson 29c851aef6 Replace `Ie` with `In other words`
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2021-01-13 12:50:29 +00:00
Ian Jackson 42ea8f6434 unix ExitStatus: Provide .continued()
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 12:50:29 +00:00
Ian Jackson f060b9e0d9 unix ExitStatus: Provide .stopped_signal()
Necessary to handle WIFSTOPPED.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 12:50:29 +00:00
Ian Jackson 3f05051d6b unix ExitStatus: Provide .core_dumped
This is essential for proper reporting of child process status on Unix.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 12:50:29 +00:00
Ian Jackson 530270f94a unix ExitStatus: Provide .into_raw()
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 12:50:29 +00:00
Ian Jackson 12d62aa436 unix ExitStatus: Clarify docs for .signal()
We need to be clear that this never returns WSTOPSIG.  That is, if
WIFSTOPPED, the return value is None.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 12:50:29 +00:00
Ian Jackson 5b1316f781 unix ExitStatus: Do not treat WIFSTOPPED as WIFSIGNALED
A unix wait status can contain, at least, exit statuses, termination
signals, and stop signals.

WTERMSIG is only valid if WIFSIGNALED.

https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html

It will not be easy to experience this bug with `Command`, because
that doesn't pass WUNTRACED.  But you could make an ExitStatus
containing, say, a WIFSTOPPED, from a call to one of the libc wait
functions.

(In the WIFSTOPPED case, there is WSTOPSIG.  But a stop signal is
encoded differently to a termination signal, so WTERMSIG and WSTOPSIG
are by no means the same.)

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-13 12:50:29 +00:00
Mark Rousskov 4614671cae Update code to account for extern ABI requirement 2021-01-13 07:49:45 -05:00
Mark Rousskov 8a3edb1d66 Update tests for extern block linting 2021-01-13 07:49:16 -05:00
Ashley Mannix d65cb6ebce deprecate atomic::spin_loop_hint in favour of hint::spin_loop 2021-01-13 16:30:29 +10:00
Dylan DPC e73ee1dde2
Rollup merge of #80736 - KodrAus:feat/lazy-resolve, r=dtolnay
use Once instead of Mutex to manage capture resolution

For #78299

This allows us to return borrows of the captured backtrace frames that are tied to a borrow of the Backtrace itself, instead of to some short-lived Mutex guard.

We could alternatively share `&Mutex<Capture>`s and lock on-demand, but then we could potentially forget to call `resolve()` before working with the capture. It also makes it semantically clearer what synchronization is needed on the capture.

cc `@seanchen1991` `@rust-lang/project-error-handling`
2021-01-13 03:20:17 +01:00
Camelid 7463292015 Add docs on performance 2021-01-11 19:18:39 -08:00
Steven Fackler e6c07b0628 clarify docs a bit 2021-01-11 17:16:44 -05:00
Steven Fackler 5cb830397e make check a bit more clear 2021-01-11 17:13:50 -05:00
Steven Fackler a9ef7983a6 clean up control flow 2021-01-11 07:48:24 -05:00
Steven Fackler ebe402dc9e Fix handling of malicious Readers in read_to_end 2021-01-11 07:27:03 -05:00
bors 34628e5b53 Auto merge of #80867 - JohnTitor:rollup-tvqw555, r=JohnTitor
Rollup of 9 pull requests

Successful merges:

 - #79502 (Implement From<char> for u64 and u128.)
 - #79968 (Improve core::ptr::drop_in_place debuginfo)
 - #80774 (Fix safety comment)
 - #80801 (Use correct span for structured suggestion)
 - #80803 (Remove useless `fill_in` function)
 - #80820 (Support `download-ci-llvm` on NixOS)
 - #80825 (Remove under-used ImplPolarity enum)
 - #80850 (Allow #[rustc_builtin_macro = "name"])
 - #80857 (Add comment to `Vec::truncate` explaining `>` vs `>=`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-01-10 08:01:12 +00:00
Yuki Okushi d64356f06c
Rollup merge of #80774 - LingMan:patch-1, r=nagisa
Fix safety comment

The size assertion in the comment was inverted compared to the code. After fixing that the implication that `(new_size >= old_size) => new_size != 0` still doesn't hold so explain why `old_size != 0` at this point.
2021-01-10 16:55:57 +09:00
bors 7a193921a0 Auto merge of #77862 - danielhenrymantilla:rustdoc/fix-macros_2_0-paths, r=jyn514,petrochenkov
Rustdoc: Fix macros 2.0 and built-in derives being shown at the wrong path

Fixes #74355

  - ~~waiting on author + draft PR since my code ought to be cleaned up _w.r.t._ the way I avoid the `.unwrap()`s:~~

      - ~~dummy items may avoid the first `?`,~~

      - ~~but within the module traversal some tests did fail (hence the second `?`), meaning the crate did not possess the exact path of the containing module (`extern` / `impl` blocks maybe? I'll look into that).~~

r? `@jyn514`
2021-01-10 05:15:01 +00:00
bors 1f9dc9a182 Auto merge of #80755 - sunfishcode:path-cleanup/copy, r=nagisa
Optimize away some path lookups in the generic `fs::copy` implementation

This also eliminates a use of a `Path` convenience function, in support
of #80741, refactoring `std::path` to focus on pure data structures and
algorithms.
2021-01-09 07:48:53 +00:00
bors 8f0b945cfc Auto merge of #77853 - ijackson:slice-strip-stab, r=Amanieu
Stabilize slice::strip_prefix and slice::strip_suffix

These two methods are useful.  The corresponding methods on `str` are already stable.

I believe that stablising these now would not get in the way of, in the future, extending these to take a richer pattern API a la `str`'s patterns.

Tracking PR: #73413.  I also have an outstanding PR to improve the docs for these two functions and the corresponding ones on `str`: #75078

I have tried to follow the [instructions in the dev guide](https://rustc-dev-guide.rust-lang.org/stabilization_guide.html#stabilization-pr).  The part to do with `compiler/rustc_feature` did not seem applicable.  I assume that's because these are just library features, so there is no corresponding machinery in rustc.
2021-01-07 15:21:30 +00:00
LingMan 769fb8a8b7
Fix safety comment
The size assertion in the comment was inverted compared to the code. After fixing that the implication that `(new_size >= old_size) => new_size != 0` still doesn't hold so explain why `old_size != 0` at this point.
2021-01-07 09:13:21 +01:00
Yuki Okushi 6275a29dbe Update `compiler_builtins` to 0.1.39 2021-01-07 16:16:36 +09:00
Dan Gohman 97baac4184 Optimize away some path lookups in the generic `fs::copy` implementation.
This also eliminates a use of a `Path` convenience function, in support
of #80741, refactoring `std::path` to focus on pure data structures and
algorithms.
2021-01-06 08:36:31 -08:00
Daniel Henry-Mantilla aa863caebe Style nit: replace `for_each` & `return` with `for` & `continue`
Co-Authored-By: Joshua Nelson <jyn514@gmail.com>
2021-01-06 15:13:38 +01:00
Camelid 25a4964191 Use heading for `std::prelude` and not `io::prelude`
The heading style for `std::prelude` is to be consistent with the
headings for `std` and `core`: `# The Rust Standard Library` and
`# The Rust Core Library`, respectively.
2021-01-05 17:52:24 -08:00
Camelid 4274ba40bd Use lowercase for prelude items 2021-01-05 17:51:27 -08:00
Ashley Mannix db4585aa3b use Once instead of Mutex to manage capture resolution
This allows us to return borrows of the captured backtrace frames
that are tied to a borrow of the Backtrace itself, instead of to
some short-lived Mutex guard.

It also makes it semantically clearer what synchronization is needed
on the capture.
2021-01-06 10:44:06 +10:00
Ian Jackson dea6d6c909 BufWriter::into_raw_parts: Add tracking issue number
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-04 15:35:28 +00:00
bors bcd6975079 Auto merge of #80590 - camelid:bool-never-docs, r=nagisa
Update `bool` and `!` docs
2021-01-03 12:21:12 +00:00
Camelid 4e767596e2
always demands -> requires 2021-01-01 18:55:01 -08:00
Camelid 4af11126a8
Update `bool` and `!` docs 2021-01-01 10:09:56 -08:00
Camelid 0506789014 Remove many unnecessary manual link resolves from library
Now that #76934 has merged, we can remove a lot of these! E.g, this is
no longer necessary:

    [`Vec<T>`]: Vec
2020-12-31 11:54:32 -08:00
Camelid 588786a788 Add error docs 2020-12-30 11:44:03 -08:00
Camelid 4ee6d1bf54 Add description independent of `Read::read_to_string` 2020-12-30 11:35:17 -08:00
bors e226704685 Auto merge of #80511 - Mark-Simulacrum:bump-stage0, r=pietroalbini
Bump bootstrap compiler to 1.50 beta

r? `@pietroalbini`
2020-12-30 18:32:31 +00:00
Mark Rousskov fe031180d0 Bump bootstrap compiler to 1.50 beta 2020-12-30 09:27:19 -05:00
Yuki Okushi 00741b8810
Rollup merge of #80260 - RalfJung:less-untyped-panics, r=m-ou-se
slightly more typed interface to panic implementation

The panic payload is currently being passed around as a `usize`. However, it actually is a pointer, and the involved types are available on all ends of this API, so I propose we use the proper pointer type to avoid some casts. Avoiding int-to-ptr casts also makes this code work with `miri -Zmiri-track-raw-pointers`.
2020-12-30 22:49:17 +09:00
BlackHoleFox 5449a42a1c Fix small typo in time comment 2020-12-29 02:10:29 -06:00
Konrad Borowski 9e779986aa Add "length" as doc alias to len methods 2020-12-28 09:13:46 +01:00
bors 257becbfe4 Auto merge of #80181 - jyn514:intra-doc-primitives, r=Manishearth
Fix intra-doc links for non-path primitives

This does *not* currently work for associated items that are
auto-implemented by the compiler (e.g. `never::eq`), because they aren't
present in the source code. I plan to fix this in a follow-up PR.

Fixes https://github.com/rust-lang/rust/issues/63351 using the approach mentioned in https://github.com/rust-lang/rust/issues/63351#issuecomment-683352130.

r? `@Manishearth`

cc `@petrochenkov` - this makes `rustc_resolve::Res` public, is that ok? I'd just add an identical type alias in rustdoc if not, which seems a waste.
2020-12-27 18:55:33 +00:00
Ian Jackson 274e2993cb Stablize slice::strip_prefix and strip_suffix, with SlicePattern
We hope later to extend `core::str::Pattern` to slices too, perhaps as
part of stabilising that.  We want to minimise the amount of type
inference breakage when we do that, so we don't want to stabilise
strip_prefix and strip_suffix taking a simple `&[T]`.

@KodrAus suggested the approach of introducing a new perma-unstable
trait, which reduces this future inference break risk.

I found it necessary to make two impls of this trait, as the unsize
coercion don't apply when hunting for trait implementations.

Since SlicePattern's only method returns a reference, and the whole
trait is just a wrapper for slices, I made the trait type be the
non-reference type [T] or [T;N] rather than the reference.  Otherwise
the trait would have a lifetime parameter.

I marked both the no-op conversion functions `#[inline]`.  I'm not
sure if that is necessary but it seemed at the very least harmless.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2020-12-27 00:50:46 +00:00
David Adler 7adeb710fb Use the hashbrown::{HashMap,HashSet} `clone_from` impls. 2020-12-26 19:39:38 -05:00
Ralf Jung 1600f7d693 fix another comment, and make __rust_start_panic code a bit more semantically clear 2020-12-25 23:37:27 +01:00
Dylan DPC 21d36e0daf
Rollup merge of #79213 - yoshuawuyts:stabilize-slice-fill, r=m-ou-se
Stabilize `core::slice::fill`

Tracking issue https://github.com/rust-lang/rust/issues/70758

Stabilizes the `core::slice::fill` API in Rust 1.50, adding a `memset` doc alias so people coming from C/C++ looking for this operation can find it in the docs. This API hasn't seen any changes since we changed the signature in https://github.com/rust-lang/rust/pull/71165/, and it seems like the right time to propose stabilization. Thanks!

r? `@m-ou-se`
2020-12-25 03:39:31 +01:00
Joshua Nelson 8842c1ccf3 Fix new ambiguity in the standard library
This caught several bugs where people expected `slice` to link to the
primitive, but it linked to the module instead.

This also uses `cfg_attr(bootstrap)` since the ambiguity only occurs
when compiling with stage 1.
2020-12-22 11:45:23 -05:00
Ralf Jung 7524eb2704 update a seemingly outdated comment 2020-12-22 12:49:59 +01:00
Linus Färnstrand 454f3ed902
Update library/std/src/sys/windows/thread_parker.rs
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2020-12-22 12:33:11 +01:00
Linus Färnstrand 865e4797df Fix compare_and_swap in Windows thread_parker 2020-12-22 12:24:17 +01:00
Linus Färnstrand 427996a286 Fix documentation typo 2020-12-22 12:19:46 +01:00
Linus Färnstrand 828d4ace4d Migrate standard library away from compare_and_swap 2020-12-22 12:19:46 +01:00
Yoshua Wuyts c2281cc189 Stabilize `core::slice::fill` 2020-12-22 00:16:04 +01:00
Ralf Jung 29bed26036 slightly more typed interface to panic implementation 2020-12-21 13:37:59 +01:00
Ashley Mannix bbf5001b94
bump stabilization to 1.51.0 2020-12-21 18:40:34 +10:00
bors 15d1f81196 Auto merge of #80253 - Dylan-DPC:rollup-bkmn74z, r=Dylan-DPC
Rollup of 11 pull requests

Successful merges:

 - #80159 (Add array search aliases)
 - #80166 (Edit rustc_middle docs)
 - #80170 (Fix ICE when lookup method in trait for type that have bound vars)
 - #80171 (Edit rustc_middle::ty::TyKind docs)
 - #80199 (also const-check FakeRead)
 - #80211 (Handle desugaring in impl trait bound suggestion)
 - #80236 (Use pointer type in AtomicPtr::swap implementation)
 - #80239 (Update Clippy)
 - #80240 (make sure installer only creates directories in DESTDIR)
 - #80244 (Cleanup markdown span handling)
 - #80250 (Minor cleanups in LateResolver)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2020-12-21 04:08:35 +00:00
Dylan DPC 635ea920f1
Rollup merge of #80159 - jyn514:array, r=m-ou-se
Add array search aliases

Missed this in https://github.com/rust-lang/rust/pull/80068. This one will really fix https://github.com/rust-lang/rust/issues/46075.

The last alias especially I'm a little unsure about - maybe fuzzy search should be fixed in rustdoc instead? Happy to make that change although I'd have to figure out how.

r? ``@m-ou-se`` although cc ``@GuillaumeGomez`` for the search issue.
2020-12-21 02:47:33 +01:00
bors c8135455c4 Auto merge of #80088 - operutka:fix-cmsg-len-uclibc, r=dtolnay
Fix failing build of std on armv5te-unknown-linux-uclibceabi due to missing cmsg_len_zero

I'm getting the following error when trying to build `std` on `armv5te-unknown-linux-uclibceabi`:

```
error[E0425]: cannot find value `cmsg_len_zero` in this scope
   --> /home/operutka/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/unix/ext/net/ancillary.rs:376:47
    |
376 |             let data_len = (*cmsg).cmsg_len - cmsg_len_zero;
    |                                               ^^^^^^^^^^^^^ not found in this scope
```

Obviously, this branch:
```rust
cfg_if::cfg_if! {
    if #[cfg(any(target_os = "android", all(target_os = "linux", target_env = "gnu")))] {
        let cmsg_len_zero = libc::CMSG_LEN(0) as libc::size_t;
    } else if #[cfg(any(
                  target_os = "dragonfly",
                  target_os = "emscripten",
                  target_os = "freebsd",
                  all(target_os = "linux", target_env = "musl",),
                  target_os = "netbsd",
                  target_os = "openbsd",
              ))] {
        let cmsg_len_zero = libc::CMSG_LEN(0) as libc::socklen_t;
    }
}
```

does not cover the case `all(target_os = "linux", target_env = "uclibc")`.
2020-12-21 01:16:20 +00:00
bors b0e5c7d1fe Auto merge of #74699 - notriddle:fd-non-negative, r=m-ou-se
Mark `-1` as an available niche for file descriptors

Based on discussion from <https://internals.rust-lang.org/t/can-the-standard-library-shrink-option-file/12768>, the file descriptor `-1` is chosen based on the POSIX API designs that use it as a sentinel to report errors. A bigger niche could've been chosen, particularly on Linux, but would not necessarily be portable.

This PR also adds a test case to ensure that the -1 niche (which is kind of hacky and has no obvious test case) works correctly. It requires the "upper" bound, which is actually -1, to be expressed in two's complement.
2020-12-20 16:36:23 +00:00
Mara Bos 094b1da3a1
Check that c_int is i32 in FileDesc::new. 2020-12-20 11:56:51 +00:00
Camelid 1f9a8a1620 Add a `std::io::read_to_string` function
The equivalent of `std::fs::read_to_string`, but generalized to all
`Read` impls.

As the documentation on `std::io::read_to_string` says, the advantage of
this function is that it means you don't have to create a variable first
and it provides more type safety since you can only get the buffer out
if there were no errors. If you use `Read::read_to_string`, you have to
remember to check whether the read succeeded because otherwise your
buffer will be empty.

It's friendlier to newcomers and better in most cases to use an explicit
return value instead of an out parameter.
2020-12-19 21:46:40 -08:00
bors c1d5843661 Auto merge of #79473 - m-ou-se:clamp-in-core, r=m-ou-se
Move {f32,f64}::clamp to core.

`clamp` was recently stabilized (tracking issue: https://github.com/rust-lang/rust/issues/44095). But although `Ord::clamp` was added in `core` (because `Ord` is in `core`), the versions for the `f32` and `f64` primitives were added in `std` (together with `floor`, `sin`, etc.), not in `core` (together with `min`, `max`, `from_bits`, etc.).

This change moves them to `core`, such that `clamp` on floats is available in `no_std` programs as well.
2020-12-19 21:57:38 +00:00
bors bd2f1cb278 Auto merge of #79342 - CDirkx:ipaddr-const, r=oli-obk
Stabilize all stable methods of `Ipv4Addr`, `Ipv6Addr` and `IpAddr` as const

This PR stabilizes all currently stable methods of `Ipv4Addr`, `Ipv6Addr` and `IpAddr` as const.
Tracking issue: #76205

`Ipv4Addr` (`const_ipv4`):
 - `octets`
 - `is_loopback`
 - `is_private`
 - `is_link_local`
 - `is_multicast`
 - `is_broadcast`
 - `is_docmentation`
 - `to_ipv6_compatible`
 - `to_ipv6_mapped`

`Ipv6Addr` (`const_ipv6`):
 - `segments`
 - `is_unspecified`
 - `is_loopback`
 - `is_multicast`
 - `to_ipv4`

`IpAddr` (`const_ip`):
 - `is_unspecified`
 - `is_loopback`
 - `is_multicast`

## Motivation
The ip methods seem like prime candidates to be made const: their behavior is defined by an external spec, and based solely on the byte contents of an address. These methods have been made unstable const in the beginning of September, after the necessary const integer arithmetic was stabilized.

There is currently a PR open (#78802) to change the internal representation of `IpAddr{4,6}` from `libc` types to a byte array. This does not have any impact on the constness of the methods.

## Implementation
Most of the stabilizations are straightforward, with the exception of `Ipv6Addr::segments`, which uses the unstable feature `const_fn_transmute`. The code could be rewritten to equivalent stable code, but this leads to worse code generation (#75085).
This is why `segments` gets marked with `#[rustc_allow_const_fn_unstable(const_fn_transmute)]`, like the already const-stable `Ipv6Addr::new`, the justification being that a const-stable alternative implementation exists https://github.com/rust-lang/rust/pull/76206#issuecomment-685044184.

## Future posibilities
This PR const-stabilizes all currently stable ip methods, however there are also a number of unstable methods under the `ip` feature (#27709). These methods are already unstable const. There is a PR open (#76098) to stabilize those methods, which could include const-stabilization. However, stabilizing those methods as const is dependent on `Ipv4Addr::octets` and `Ipv6Addr::segments` (covered by this PR).
2020-12-19 13:13:41 +00:00
Yuki Okushi dbcf659dce
Rollup merge of #80068 - jyn514:mut-reference, r=m-ou-se
Add `&mut` as an alias for 'reference' primitive

Closes https://github.com/rust-lang/rust/issues/46075.
2020-12-19 15:16:05 +09:00
Yuki Okushi 60aad47c13
Rollup merge of #79211 - yoshuawuyts:future-doc-alias, r=Mark-Simulacrum
Add the "async" and "promise" doc aliases to `core::future::Future`

Adds the "async" and "promise" doc aliases to `core::future::Future`. This enables people who search for "async" or "promise" to find `Future`, which is Rust's core primitive for async programming. Thanks!
2020-12-19 15:16:01 +09:00
Yuki Okushi 0765536c0b
Rollup merge of #78083 - ChaiTRex:master, r=m-ou-se
Stabilize or_insert_with_key

Stabilizes the `or_insert_with_key` feature from https://github.com/rust-lang/rust/issues/71024. This allows inserting key-derived values when a `HashMap`/`BTreeMap` entry is vacant.

The difference between this and  `.or_insert_with(|| ... )` is that this provides a reference to the key to the closure after it is moved with `.entry(key_being_moved)`, avoiding the need to copy or clone the key.
2020-12-19 15:15:57 +09:00
Camelid 4a6014bc28 Use heading style for 'The I/O Prelude' in `std::io::prelude` 2020-12-18 15:05:15 -08:00
Camelid c78bfbae28 Use consistent punctuation for 'Prelude contents' docs 2020-12-18 15:05:14 -08:00
Corey Farwell 3ea744e2ac Recommend panic::resume_unwind instead of panicking.
Fixes https://github.com/rust-lang/rust/issues/79950.
2020-12-18 17:03:45 -05:00
Joshua Nelson f2743a5db7 Add array search aliases 2020-12-18 11:56:07 -05:00
Yoshua Wuyts 48d5874914 Add the "promise" aliases to the `async` lang feature 2020-12-18 16:27:09 +01:00
Ralf Jung 441a33e81b
Rollup merge of #80147 - pierwill:patch-9, r=lcnr
Add missing punctuation to std::alloc docs

Add a period to first line of module docs to match other modules in std.
2020-12-18 16:22:14 +01:00
Ralf Jung 5bcbd0f5c1
Rollup merge of #80146 - pierwill:pierwill-prelude-mod-docs, r=lcnr
Edit formatting in Rust Prelude docs

Use consistent punctuation and capitalization in the list of things re-exported in the prelude.

Also adds a (possibly missing) word.
2020-12-18 16:22:13 +01:00
bors 6340607aca Auto merge of #79485 - EllenNyan:stabilize_unsafe_cell_get_mut, r=m-ou-se
Stabilize `unsafe_cell_get_mut`

Tracking issue: #76943

r? `@m-ou-se`
2020-12-18 11:39:26 +00:00
pierwill 9cb43bd994
Add missing punctuation to std::alloc docs
Add a period to first line of module docs to match other modules in std.
2020-12-17 21:49:32 -08:00