Commit Graph

1294 Commits

Author SHA1 Message Date
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
pierwill ea338f5443 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-17 21:22:58 -08:00
Ondrej Perutka ec078155f1 Fix failing build of std on armv5te-unknown-linux-uclibceabi due to missing cmsg_len_zero 2020-12-16 20:34:21 +01:00
Joshua Nelson 8fb553c7da Add `&mut` as an alias for 'reference' primitive 2020-12-15 20:22:12 -05:00
bors c00a4648a4 Auto merge of #78833 - CDirkx:parse_prefix, r=dtolnay
Refactor and fix `parse_prefix` on Windows

This PR is an extension of #78692 as well as a general refactor of `parse_prefix`:

**Fixes**:
There are two errors in the current implementation of `parse_prefix`:

Firstly, in the current implementation only `\` is recognized as a separator character in device namespace prefixes. This behavior is only correct for verbatim paths; `"\\.\C:/foo"` should be parsed as `"C:"` instead of `"C:/foo"`.

Secondly, the current implementation only handles single separator characters. In non-verbatim paths a series of separator characters should be recognized as a single boundary, e.g. the UNC path `"\\localhost\\\\\\C$\foo"` should be parsed as `"\\localhost\\\\\\C$"` and then `UNC(server: "localhost", share: "C$")`, but currently it is not parsed at all, because it starts being parsed as `\\localhost\` and then has an invalid empty share location.

Paths like `"\\.\C:/foo"` and `"\\localhost\\\\\\C$\foo"` are valid on Windows, they are equivalent to just `"C:\foo"`.

**Refactoring**:
All uses of `&[u8]` within `parse_prefix` are extracted to helper functions and`&OsStr` is used instead. This reduces the number of places unsafe is used:
- `get_first_two_components` is adapted to the more general `parse_next_component` and used in more places
- code for parsing drive prefixes is extracted to `parse_drive`
2020-12-16 00:47:50 +00:00
bors fa41639427 Auto merge of #77618 - fusion-engineering-forks:windows-parker, r=Amanieu
Add fast futex-based thread parker for Windows.

This adds a fast futex-based thread parker for Windows. It either uses WaitOnAddress+WakeByAddressSingle or NT Keyed Events (NtWaitForKeyedEvent+NtReleaseKeyedEvent), depending on which is available. Together, this makes this thread parker work for Windows XP and up. Before this change, park()/unpark() did not work on Windows XP: it needs condition variables, which only exist since Windows Vista.

---

Unfortunately, NT Keyed Events are an undocumented Windows API. However:
- This API is relatively simple with obvious behaviour, and there are several (unofficial) articles documenting the details. [1]
- parking_lot has been using this API for years (on Windows versions before Windows 8). [2] Many big projects extensively use parking_lot, such as servo and the Rust compiler itself.
- It is the underlying API used by Windows SRW locks and Windows critical sections. [3] [4]
- The source code of the implementations of Wine, ReactOs, and Windows XP are available and match the expected behaviour.
- The main risk with an undocumented API is that it might change in the future. But since we only use it for older versions of Windows, that's not a problem.
- Even if these functions do not block or wake as we expect (which is unlikely, see all previous points), this implementation would still be memory safe. The NT Keyed Events API is only used to sleep/block in the right place.

[1]\: http://www.locklessinc.com/articles/keyed_events/
[2]\: https://github.com/Amanieu/parking_lot/commit/43abbc964e
[3]\: https://docs.microsoft.com/en-us/archive/msdn-magazine/2012/november/windows-with-c-the-evolution-of-synchronization-in-windows-and-c
[4]\: Windows Internals, Part 1, ISBN 9780735671300

---

The choice of fallback API is inspired by parking_lot(_core), but the implementation of this thread parker is different. While parking_lot has no use for a fast path (park() directly returning if unpark() was already called), this implementation has a fast path that returns without even checking which waiting/waking API to use, as the same atomic variable with compatible states is used in all cases.
2020-12-14 16:41:14 +00:00
Guillaume Gomez 5d8b2a5bf1
Rollup merge of #79918 - woodruffw-forks:ww/doc-initializer-side-effects, r=dtolnay
doc(array,vec): add notes about side effects when empty-initializing

Copying some context from a conversation in the Rust discord:

* Both `vec![T; 0]` and `[T; 0]` are syntactically valid, and produce empty containers of their respective types

* Both *also* have side effects:

```rust
fn side_effect() -> String {
    println!("side effect!");

    "foo".into()
}

fn main() {
    println!("before!");

    let x = vec![side_effect(); 0];

    let y = [side_effect(); 0];

    println!("{:?}, {:?}", x, y);
}
```

produces:

```
before!
side effect!
side effect!
[], []
```

This PR just adds two small notes to each's documentation, warning users that side effects can occur.

I've also submitted a clippy proposal: https://github.com/rust-lang/rust-clippy/issues/6439
2020-12-14 14:43:44 +01:00
Yuki Okushi d559bb6707
Rollup merge of #79398 - pickfire:keyword, r=Dylan-DPC
Link loop/for keyword

Even though the reference already have all of these, I am just adding related keywords in the see also to let others easily click on the related keyword.
2020-12-13 11:05:30 +09:00
Ian Jackson 79c72f57d5 fixup! WriterPanicked: Use debug_struct 2020-12-12 18:39:30 +00:00
Ian Jackson 5ac431fb08
WriterPanicked: Use debug_struct
Co-authored-by: Ivan Tham <pickfire@riseup.net>
2020-12-12 13:37:29 +00:00
Ian Jackson 7fab9cb8ac bufwriter::WriterPanicked: Provide panicking example
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2020-12-12 12:34:48 +00:00
William Woodruff d986924eb1
doc: apply suggestions 2020-12-11 10:09:40 -05:00
bors a2e29d67c2 Auto merge of #79893 - RalfJung:forget-windows, r=oli-obk
Windows TLS: ManuallyDrop instead of mem::forget

The Windows TLS implementation still used `mem::forget` instead of `ManuallyDrop`, leading to the usual problem of "using" the `Box` when it should not be used any more.
2020-12-11 07:54:35 +00:00
Tyler Mandry 17ec4b8258
Rollup merge of #79809 - Eric-Arellano:split-once, r=matklad
Dogfood `str_split_once()`

Part of https://github.com/rust-lang/rust/issues/74773.

Beyond increased clarity, this fixes some instances of a common confusion with how `splitn(2)` behaves: the first element will always be `Some()`, regardless of the delimiter, and even if the value is empty.

Given this code:

```rust
fn main() {
    let val = "...";
    let mut iter = val.splitn(2, '=');
    println!("Input: {:?}, first: {:?}, second: {:?}", val, iter.next(), iter.next());
}
```

We get:

```
Input: "no_delimiter", first: Some("no_delimiter"), second: None
Input: "k=v", first: Some("k"), second: Some("v")
Input: "=", first: Some(""), second: Some("")
```

Using `str_split_once()` makes more clear what happens when the delimiter is not found.
2020-12-10 21:33:08 -08:00
Tyler Mandry a8c19e1b48
Rollup merge of #79375 - vext01:kernel-copy-temps, r=bjorn3
Make the kernel_copy tests more robust/concurrent.

These tests write to the same filenames in /tmp and in some cases these files don't get cleaned up properly. This caused issues for us when different users run the tests on the same system, e.g.:

```
---- sys::unix::kernel_copy::tests::bench_file_to_file_copy stdout ----
thread 'sys::unix::kernel_copy::tests::bench_file_to_file_copy' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 13, kind: PermissionDenied, message: "Permission denied" }', library/std/src/sys/unix/kernel_copy/tests.rs:71:10
---- sys::unix::kernel_copy::tests::bench_file_to_socket_copy stdout ----
thread 'sys::unix::kernel_copy::tests::bench_file_to_socket_copy' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 13, kind: PermissionDenied, message: "Permission denied" }', library/std/src/sys/unix/kernel_copy/tests.rs💯10
```

Use `std::sys_common::io__test::tmpdir()` to solve this.

CC ``@the8472.``
2020-12-10 21:33:02 -08:00
Tyler Mandry 1b4ffe4705
Rollup merge of #77027 - termhn:mul_add_doc_change, r=m-ou-se
Improve documentation for `std::{f32,f64}::mul_add`

Makes it more clear that performance improvement is not guaranteed when using FMA, even when the target architecture supports it natively.
2020-12-10 21:32:59 -08:00
bors 8cef65fde3 Auto merge of #77801 - fusion-engineering-forks:pin-mutex, r=Mark-Simulacrum
Enforce no-move rule of ReentrantMutex using Pin and fix UB in stdio

A `sys_common::ReentrantMutex` may not be moved after initializing it with `.init()`. This was not enforced, but only stated as a requirement in the comments on the unsafe functions. This change enforces this no-moving rule using `Pin`, by changing `&self` to a `Pin` in the `init()` and `lock()` functions.

This uncovered a bug I introduced in #77154: stdio.rs (the only user of ReentrantMutex) called `init()` on its ReentrantMutexes while constructing them in the intializer of `SyncOnceCell::get_or_init`, which would move them afterwards. Interestingly, the ReentrantMutex unit tests already had the same bug, so this invalid usage has been tested on all (CI-tested) platforms for a long time. Apparently this doesn't break badly on any of the major platforms, but it does break the rules.\*

To be able to keep using SyncOnceCell, this adds a `SyncOnceCell::get_or_init_pin` function, which makes it possible to work with pinned values inside a (pinned) SyncOnceCell. Whether this function should be public or not and what its exact behaviour and interface should be if it would be public is something I'd like to leave for a separate issue or PR. In this PR, this function is internal-only and marked with `pub(crate)`.

\* Note: That bug is now included in 1.48, while this patch can only make it to ~~1.49~~ 1.50. We should consider the implications of 1.48 shipping with a wrong usage of `pthread_mutex_t` / `CRITICAL_SECTION` / .. which technically invokes UB according to their specification. The risk is very low, considering the objects are not 'used' (locked) before the move, and the ReentrantMutex unit tests have verified this works fine in practice.

Edit: This has been backported and included in 1.48. And soon 1.49 too.

---

In future changes, I want to push this usage of Pin further inside `sys` instead of only `sys_common`, and apply it to all 'unmovable' objects there (`Mutex`, `Condvar`, `RwLock`). Also, while `sys_common`'s mutexes and condvars are already taken care of by #77147 and #77648, its `RwLock` should still be made movable or get pinned.
2020-12-10 23:43:20 +00:00
William Woodruff 9cf2516251
doc(array,vec): add notes about side effects when empty-initializing 2020-12-10 17:47:28 -05:00
Michael Howell 08b70eda2c Fix fd test case 2020-12-10 15:05:22 -07:00
Michael Howell a50811a214 Add safety note to library/std/src/sys/unix/fd.rs
Co-authored-by: Elichai Turkel <elichai.turkel@gmail.com>
2020-12-10 13:31:52 -07:00
Michael Howell 59abdb6a7e 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-10 13:31:52 -07:00
Ralf Jung 594b451ccc Windows TLS: ManuallyDrop instead of mem::forget 2020-12-10 11:07:39 +01:00
bors e413d89aa7 Auto merge of #79274 - the8472:probe-eperm, r=nagisa
implement better availability probing for copy_file_range

Followup to https://github.com/rust-lang/rust/pull/75428#discussion_r469616547

Previously syscall detection was overly pessimistic. Any attempt to copy to an immutable file (EPERM) would disable copy_file_range support for the whole process.

The change tries to copy_file_range on invalid file descriptors which will never run into the immutable file case and thus we can clearly distinguish syscall availability.
2020-12-10 03:11:27 +00:00
The8472 7647d03c33 Improve comment grammar 2020-12-09 21:31:37 +01:00
The8472 028754a2f7 implement better availability probing for copy_file_range
previously any attempt to copy to an immutable file (EPERM) would disable
copy_file_range support for the whole process.
2020-12-09 21:31:37 +01:00
bors f0f68778f7 Auto merge of #77611 - oli-obk:atomic_miri_leakage, r=nagisa
Directly use raw pointers in `AtomicPtr` store/load

I was unable to find any reason for this limitation in the latest source of LLVM or in the documentation [here](http://llvm.org/docs/Atomics.html#libcalls-atomic).

fixes https://github.com/rust-lang/miri/issues/1574
2020-12-09 19:53:23 +00:00
bors c16d52db77 Auto merge of #79387 - woodruffw-forks:ww/peer-cred-pid-macos, r=Amanieu
ext/ucred: Support PID in peer creds on macOS

This is a follow-up to https://github.com/rust-lang/rust/pull/75148 (RFC: https://github.com/rust-lang/rust/issues/42839).

The original PR used `getpeereid` on macOS and the BSDs, since they don't (generally) support the `SO_PEERCRED` mechanism that Linux supplies.

This PR splits the macOS/iOS implementation of `peer_cred()` from that of the BSDs, since macOS supplies the `LOCAL_PEERPID` sockopt as a source of the missing PID. It also adds a `cfg`-gated tests that ensures that platforms with support for PIDs in `UCred` have the expected data.
2020-12-09 17:27:35 +00:00
bors 2c56ea38b0 Auto merge of #78768 - mzabaluev:optimize-buf-writer, r=cramertj
Use is_write_vectored to optimize the write_vectored implementation for BufWriter

In case when the underlying writer does not have an efficient implementation `write_vectored`, the present implementation of
`write_vectored` for `BufWriter` may still forward vectored writes directly to the writer depending on the total length of the data. This misses the advantage of buffering, as the actually written slice may be small.

Provide an alternative code path for the non-vectored case, where the slices passed to `BufWriter` are coalesced in the buffer before being flushed to the underlying writer with plain `write` calls. The buffer is only bypassed if an individual slice's length is at least as large as the buffer.

Remove a FIXME comment referring to #72919 as the issue has been closed with an explanation provided.
2020-12-09 01:54:08 +00:00
Mara Bos 67c18fdec5 Use Pin for the 'don't move' requirement of ReentrantMutex.
The code in io::stdio before this change misused the ReentrantMutexes,
by calling init() on them and moving them afterwards. Now that
ReentrantMutex requires Pin for init(), this mistake is no longer easy
to make.
2020-12-08 22:57:57 +01:00
Mara Bos 8fe90966e1 Add (internal-only) SyncOnceCell::get_or_init_pin. 2020-12-08 22:57:50 +01:00
Mara Bos 9dc7f13c39 Remove unnecessary import of `crate::marker` in std::sys_common::remutex.
It was used for marker::Send, but Send is already in scope.
2020-12-08 22:57:49 +01:00
Mara Bos 2bc5d44ca9 Fix outdated comment about not needing to flush stderr. 2020-12-08 22:57:49 +01:00
Chai T. Rex f1b930d57c Improved documentation for HashMap/BTreeMap Entry's .or_insert_with_key method 2020-12-07 21:36:01 -05:00
Eric Arellano a3174de9ff Fix net.rs - rsplitn() returns a reverse iterator 2020-12-07 18:47:10 -07:00
Eric Arellano d2de69da2e Dogfood 'str_split_once()` in the std lib 2020-12-07 14:24:05 -07:00
Jethro Beekman 9703bb8192 Fix SGX CI, take 3
Broken in #79038
2020-12-07 15:22:34 +01:00
bors ddafcc0b66 Auto merge of #79650 - the8472:fix-take, r=dtolnay
Fix incorrect io::Take's limit resulting from io::copy specialization

The specialization introduced in #75272 fails to update `io::Take` wrappers after performing the copy syscalls which bypass those wrappers. The buffer flushing before the copy does update them correctly, but the bytes copied after the initial flush weren't subtracted.

The fix is to subtract the bytes copied from each `Take` in the chain of wrappers, even when an error occurs during the syscall loop. To do so the `CopyResult` enum now has to carry the bytes copied so far in the error case.
2020-12-06 01:15:37 +00:00
bors a5fbaed6c3 Auto merge of #79673 - ijackson:intoinnerintoinnererror, r=m-ou-se
Provide IntoInnerError::into_parts

Hi.  This is an updated version of the IntoInnerError bits of my previous portmanteau MR #78689.  Thanks to `@jyn514` and `@m-ou-se` for helpful comments there.

I have made this insta-stable since it seems like it will probably be uncontroversial, but that is definitely something that someone from the libs API team should be aware of and explicitly consider.

I included a tangentially-related commit providing documentation of the buffer full behaviiour of `&mut [u8] as Write`; the behaviour I am documenting is relied on by the doctest for `into_parts`.
2020-12-04 22:30:19 +00:00
Ian Jackson b777552167 IntoInnerError: Provide into_error
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2020-12-04 18:43:02 +00:00
Ian Jackson 19c7619dcd IntoInnerError: Provide into_parts
In particular, IntoIneerError only currently provides .error() which
returns a reference, not an owned value.  This is not helpful and
means that a caller of BufWriter::into_inner cannot acquire an owned
io::Error which seems quite wrong.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2020-12-04 18:43:02 +00:00
Ian Jackson db5d697004 std: impl of `Write` for `&mut [u8]`: document the buffer full error
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2020-12-04 18:38:44 +00:00
Ian Jackson 381763185e 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.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2020-12-04 18:28:02 +00:00
Tim Diekmann 9274b37d99 Rename `AllocRef` to `Allocator` and `(de)alloc` to `(de)allocate` 2020-12-04 14:47:15 +01:00
Dylan DPC 88f0c72dc6
Rollup merge of #79611 - poliorcetics:use-std-in-docs, r=jyn514
Use more std:: instead of core:: in docs for consistency

``@rustbot`` label T-doc

Some cleanup work to use `std::` instead of `core::` in docs as much as possible. This helps with terminology and consistency, especially for newcomers from other languages that have often heard of `std` to describe the standard library but not of `core`.

Edit: I also added more intra doc links when I saw the opportunity.
2020-12-04 03:30:27 +01:00
Dylan DPC 6b42900e40
Rollup merge of #79602 - jethrogb:sgx-fix-79038, r=Mark-Simulacrum
Fix SGX CI

Broken in #79038
2020-12-04 03:30:25 +01:00
Guillaume Gomez 50eb3a89f8 Only deny doc_keyword in std and set it as "allow" by default 2020-12-03 16:48:17 +01:00
Edd Barrett 87c1fdbcfb Make the kernel_copy tests more robust/concurrent.
These tests write to the same filenames in /tmp and in some cases these
files don't get cleaned up properly. This caused issues for us when
different users run the tests on the same system, e.g.:

```
---- sys::unix::kernel_copy::tests::bench_file_to_file_copy stdout ----
thread 'sys::unix::kernel_copy::tests::bench_file_to_file_copy' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 13, kind: PermissionDenied, message: "Permission denied" }', library/std/src/sys/unix/kernel_copy/tests.rs:71:10
---- sys::unix::kernel_copy::tests::bench_file_to_socket_copy stdout ----
thread 'sys::unix::kernel_copy::tests::bench_file_to_socket_copy' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 13, kind: PermissionDenied, message: "Permission denied" }', library/std/src/sys/unix/kernel_copy/tests.rs💯10
```

Use `std::sys_common::io__test::tmpdir()` to solve this.
2020-12-03 13:49:24 +00:00
The8472 a9b1381b8d fix copy specialization not updating Take wrappers 2020-12-03 00:02:01 +01:00
The8472 9b390e73db update test to check Take limits after copying 2020-12-02 23:34:59 +01:00
bors af69066aa6 Auto merge of #69864 - LinkTed:master, r=Amanieu
unix: Extend UnixStream and UnixDatagram to send and receive file descriptors

Add the functions `recv_vectored_fds` and `send_vectored_fds` to `UnixDatagram` and `UnixStream`. With this functions `UnixDatagram` and `UnixStream` can send and receive file descriptors, by using `recvmsg` and `sendmsg` system call.
2020-12-02 17:36:29 +00:00
Alexis Bourget 4eb76fcc8e Use more std:: instead of core:: in docs for consistency, add more intra doc links 2020-12-02 00:41:53 +01:00
Guillaume Gomez 9e26fc60b1
Rollup merge of #79600 - nicokoch:kernel_copy_unixstream, r=m-ou-se
std::io: Use sendfile for UnixStream

`UnixStream` was forgotten in #75272 .

Benchmark yields the following results.
Before:
`running 1 test
test sys::unix::kernel_copy::tests::bench_file_to_uds_copy        ... bench:      54,399 ns/iter (+/- 6,817) = 2409 MB/s`

After:
`running 1 test
test sys::unix::kernel_copy::tests::bench_file_to_uds_copy        ... bench:      18,627 ns/iter (+/- 6,007) = 7036 MB/s`
2020-12-01 23:46:13 +01:00
Jethro Beekman b787d723fc Fix SGX CI
Broken in #79038
2020-12-01 18:15:00 +01:00
Nicolas Koch 59874516fa Leverage kernel copy for UnixStream
UDS can be a sendfile destination, just like TCP sockets.
2020-12-01 14:45:36 +01:00
Nicolas Koch eda4c63fdc Add benchmark for File to UnixStream copy 2020-12-01 14:44:40 +01:00
Mara Bos 2404409c6c
Rollup merge of #79444 - sasurau4:test/move-const-ip, r=matklad
Move const ip in ui test to unit test

Helps with #76268

r? ``@matklad``
2020-12-01 10:50:15 +00:00
Chai T. Rex 866ef87d3f Update rustc version that or_insert_with_key landed 2020-12-01 01:06:40 -05:00
Christiaan Dirkx be554c4101 Make ui test that are run-pass and do not test the compiler itself library tests 2020-11-30 02:47:32 +01:00
oli 79fb037cc5 Remove now-unnecessary `miri_static_root` invocation 2020-11-28 17:13:47 +00:00
Jonas Schievink 13375864ed
Rollup merge of #79383 - abdnh:patch-1, r=shepmaster
Fix bold code formatting in keyword docs
2020-11-28 15:58:21 +01:00
Jonas Schievink 772b1a6d79
Rollup merge of #78086 - poliorcetics:as-placeholder, r=Mark-Simulacrum
Improve doc for 'as _'

Fix #78042.

`@rustbot` modify labels: A-coercions T-doc
2020-11-28 15:58:13 +01:00
Ellen 9db1f42fa2 Stabilize unsafe_cell_get_mut 2020-11-28 00:30:26 +00:00
Christiaan Dirkx 4fcef4b157 Stabilize all stable methods of `Ipv4Addr`, `Ipv6Addr` and `IpAddr` as const
`Ipv4Addr`
 - `octets`
 - `is_loopback`
 - `is_private`
 - `is_link_local`
 - `is_multicast`
 - `is_broadcast`
 - `is_docmentation`
 - `to_ipv6_compatible`
 - `to_ipv6_mapped`

`Ipv6Addr`
 - `segments`
 - `is_unspecified`
 - `is_loopback`
 - `is_multicast`
 - `to_ipv4`

`IpAddr`
 - `is_unspecified`
 - `is_loopback`
 - `is_multicast`
2020-11-27 20:36:47 +01:00
Mara Bos 0523eeb8a3 Move {f32,f64}::clamp to core. 2020-11-27 19:15:51 +01:00
LinkTed 8983752c12 Add comment for the previous android bug fix 2020-11-26 18:54:13 +01:00
Daiki Ihara d4ee2f6dc5 Move const ip in ui test to unit test 2020-11-26 23:15:32 +09:00
Ivan Tham 2d4cfd0779 Add while loop keyword to see also
Suggested by withoutboats
2020-11-26 01:05:20 +08:00
bors ec039bd075 Auto merge of #79336 - camelid:rename-feature-oibit-to-auto, r=oli-obk
Rename `optin_builtin_traits` to `auto_traits`

They were originally called "opt-in, built-in traits" (OIBITs), but
people realized that the name was too confusing and a mouthful, and so
they were renamed to just "auto traits". The feature flag's name wasn't
updated, though, so that's what this PR does.

There are some other spots in the compiler that still refer to OIBITs,
but I don't think changing those now is worth it since they are internal
and not particularly relevant to this PR.

Also see <https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/opt-in.2C.20built-in.20traits.20(auto.20traits).20feature.20name>.

r? `@oli-obk` (feel free to re-assign if you're not the right reviewer for this)
2020-11-25 07:25:19 +00:00
Ivan Tham 6b272e0231
Fix typo in keyword link
Co-authored-by: Camelid <camelidcamel@gmail.com>
2020-11-25 11:11:25 +08:00
Ivan Tham 872b5cd80a Link loop/for keyword 2020-11-25 11:00:40 +08:00
abdo 38cc998da0 Fix bold code formatting in keyword docs 2020-11-25 01:05:46 +03:00
LinkTed 9b9dd4aeea Bug fix for android platform, because of the wrong behavior of CMSG_NXTHDR 2020-11-24 22:15:04 +01:00
William Woodruff 3d8329f6fc
ext/ucred: fmt check 2020-11-24 14:55:35 -05:00
William Woodruff fe0bea2cc1
ext/ucred: Support PID in peer creds on macOS 2020-11-24 13:46:51 -05:00
Jonas Schievink ed5d539c62
Rollup merge of #79351 - Takashiidobe:keyword-docs-typo, r=m-ou-se
Fix typo in `keyword` docs for traits

This PR fixes a small typo in the `keyword_docs.rs` file, describing the differences between the 2015 and 2018 editions of traits.
2020-11-24 13:17:43 +01:00
bors 4167d731dc Auto merge of #78953 - mzohreva:mz/from_raw_fd, r=Mark-Simulacrum
Add Metadata in std::os::fortanix_sgx::io::FromRawFd

Needed for https://github.com/fortanix/rust-sgx/pull/291

cc `@jethrogb`
2020-11-24 03:12:20 +00:00
Camelid 810324d1f3 Rename `optin_builtin_traits` to `auto_traits`
They were originally called "opt-in, built-in traits" (OIBITs), but
people realized that the name was too confusing and a mouthful, and so
they were renamed to just "auto traits". The feature flag's name wasn't
updated, though, so that's what this PR does.

There are some other spots in the compiler that still refer to OIBITs,
but I don't think changing those now is worth it since they are internal
and not particularly relevant to this PR.

Also see <https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/opt-in.2C.20built-in.20traits.20(auto.20traits).20feature.20name>.
2020-11-23 14:14:06 -08:00
bors d9a105fdd4 Auto merge of #78439 - lzutao:rm-clouldabi, r=Mark-Simulacrum
Drop support for all cloudabi targets

`cloudabi` is a tier-3 target, and [it is no longer being maintained upstream][no].

This PR drops supports for cloudabi targets. Those targets are:
* aarch64-unknown-cloudabi
* armv7-unknown-cloudabi
* i686-unknown-cloudabi
* x86_64-unknown-cloudabi

Since this drops supports for a target, I'd like somebody to tag `relnotes` label to this PR.

Some other issues:
* The tidy exception for `cloudabi` crate is still remained because
  * `parking_lot v0.9.0` and `parking_lot v0.10.2` depends on `cloudabi v0.0.3`.
  * `parking_lot v0.11.0` depends on `cloudabi v0.1.0`.

[no]: https://github.com/NuxiNL/cloudabi#note-this-project-is-unmaintained
2020-11-23 19:01:19 +00:00
takashiidobe c5c3d7bdf4 Fix typo in keyword docs for traits 2020-11-23 10:51:30 -05:00
Alexis Bourget e31e627238 Add doc for 'as _' about '_' and its possibilities and problems 2020-11-23 09:18:13 +01:00
bors 1823a87986 Auto merge of #76226 - CDirkx:const-ipaddr, r=dtolnay
Stabilize `IpAddr::is_ipv4` and `is_ipv6` as const

Insta-stabilize the methods `is_ipv4` and `is_ipv6` of `std::net::IpAddr` as const, in the same way as [PR#76198](https://github.com/rust-lang/rust/pull/76198).

Possible because of the recent stabilization of const control flow.

Part of #76225 and #76205.
2020-11-23 04:47:25 +00:00
bors f32459c7ba Auto merge of #79172 - a1phyr:cold_abort, r=Mark-Simulacrum
Add #[cold] attribute to `std::process::abort` and `alloc::alloc::handle_alloc_error`
2020-11-23 02:25:13 +00:00
Christiaan Dirkx 4613bc96a4 Bump version to 1.50.0 2020-11-23 01:40:26 +01:00
Christiaan Dirkx 3f8fdf83ff Stabilize `IpAddr::is_ipv4` and `is_ipv6` as const
Insta-stabilize the methods `is_ipv4` and `is_ipv6` of `IpAddr`.

Possible because of the recent stabilization of const control flow.

Also adds a test for these methods in a const context.
2020-11-23 01:33:46 +01:00
bors 32da90b431 Auto merge of #79319 - m-ou-se:rollup-d9n5viq, r=m-ou-se
Rollup of 10 pull requests

Successful merges:

 - #76941 (Add f{32,64}::is_subnormal)
 - #77697 (Split each iterator adapter and source into individual modules)
 - #78305 (Stabilize alloc::Layout const functions)
 - #78608 (Stabilize refcell_take)
 - #78793 (Clean up `StructuralEq` docs)
 - #79267 (BTreeMap: address namespace conflicts)
 - #79293 (Add test for eval order for a+=b)
 - #79295 (BTreeMap: fix minor testing mistakes in #78903)
 - #79297 (BTreeMap: swap the names of NodeRef::new and Root::new_leaf)
 - #79299 (Stabilise `then`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2020-11-22 23:59:48 +00:00
Lzu Tao 6bfe27a3e0 Drop support for cloudabi targets 2020-11-22 17:11:41 -05:00
Mara Bos 41c033b2f7
Rollup merge of #79299 - varkor:stabilise-then, r=m-ou-se
Stabilise `then`

Stabilises the lazy variant of https://github.com/rust-lang/rust/issues/64260 now that the FCP [has ended](https://github.com/rust-lang/rust/issues/64260#issuecomment-731636203).

I've kept the original feature gate `bool_to_option` for the strict variant (`then_some`), and created a new insta-stable feature gate `lazy_bool_to_option` for `then`.
2020-11-22 23:01:08 +01:00
bors a0d664bae6 Auto merge of #79219 - shepmaster:beta-bump, r=Mark-Simulacrum
Bump bootstrap compiler version

r? `@Mark-Simulacrum`

/cc `@pietroalbini`
2020-11-22 21:38:03 +00:00
ThinkChaos 5c6689baff Stabilize refcell_take 2020-11-22 20:13:31 +01:00
Mikhail Zabaluev 674dd623ee Reduce branching in write_vectored for BufWriter
Do what write does and optimize for the most likely case:
slices are much smaller than the buffer. If a slice does not fit
completely in the remaining capacity of the buffer, it is left out
rather than buffered partially. Special treatment is only left for
oversized slices that are written directly to the underlying writer.
2020-11-22 17:05:14 +02:00
Mikhail Zabaluev 00deeb35c8 Fix is_write_vectored in LineWriterShim
Now that BufWriter always claims to support vectored writes,
look through it at the wrapped writer to decide whether to
use vectored writes for LineWriter.
2020-11-22 17:05:14 +02:00
Mikhail Zabaluev 9fc44239ec Make is_write_vectored return true for BufWriter
BufWriter provides an efficient implementation of
write_vectored also when the underlying writer does not
support vectored writes.
2020-11-22 17:05:13 +02:00
Mikhail Zabaluev 53196a8bcf Optimize write_vectored for BufWriter
If the underlying writer does not support efficient vectored output,
do it differently: always try to coalesce the slices in the buffer
until one comes that does not fit entirely. Flush the buffer before
the first slice if needed.
2020-11-22 17:05:13 +02:00
varkor cf32afcf48 Stabilise `then` 2020-11-22 13:45:14 +00:00
bors 5d5ff84130 Auto merge of #77872 - Xaeroxe:stabilize-clamp, r=scottmcm
Stabilize clamp

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

Clamp has been merged and unstable for about a year and a half now. How do we feel about stabilizing this?
2020-11-22 10:50:04 +00:00
bors 3adedb8f4c Auto merge of #79237 - alexcrichton:update-backtrace, r=Mark-Simulacrum
std: Update the bactrace crate submodule

This commit updates the `library/backtrace` submodule which primarily
pulls in support for split-debuginfo on macOS, avoiding the need for
`dsymutil` to get run to get line numbers and filenames in backtraces.
2020-11-21 18:05:07 +00:00
bors 502c477b34 Auto merge of #79003 - petrochenkov:innertest, r=estebank
rustc_expand: Mark inner `#![test]` attributes as soft-unstable

Custom inner attributes are feature gated (https://github.com/rust-lang/rust/issues/54726) except for attributes having name `test` literally, which are not gated for historical reasons.

`#![test]` is an inner proc macro attribute, so it has all the issues described in https://github.com/rust-lang/rust/issues/54726 too.
This PR gates it with the `soft_unstable` lint.
2020-11-21 05:52:16 +00:00
Alex Crichton f99410bb4b std: Update the backtrace crate submodule
This commit updates the `library/backtrace` submodule which primarily
pulls in support for split-debuginfo on macOS, avoiding the need for
`dsymutil` to get run to get line numbers and filenames in backtraces.
2020-11-20 11:56:07 -08:00
Jacob Kiesel fb6ceac46b We missed 1.49.0, so bump version to 1.50.0 2020-11-20 10:37:22 -07:00
Vadim Petrochenkov 993bb072ff rustc_expand: Mark inner `#![test]` attributes as soft-unstable 2020-11-20 19:35:03 +03:00
bors c9c57fadc4 Auto merge of #79205 - rust-lang:jdm-patch-1, r=m-ou-se
Extend meta parameters to all generated code in compat_fn.

Fixes https://github.com/rust-lang/rust/issues/79203. This addresses a regression from 7e2032390c for UWP targets.
2020-11-20 13:42:44 +00:00