Commit Graph

2826 Commits

Author SHA1 Message Date
Matthias Krüger
a3deca4675
Rollup merge of #93493 - GKFX:char-docs-2, r=scottmcm
Document valid values of the char type

As discussed at #93392, the current documentation on what constitutes a valid char isn't very detailed and is partly on the MAX constant rather than the type itself.

This PR expands on that information, stating the actual numerical range, giving examples of what won't work, and also mentions how a `char` might be a valid USV but still not be a defined character (terminology checked against [Unicode 14.0, table 2-3](https://www.unicode.org/versions/Unicode14.0.0/ch02.pdf#M9.61673.TableTitle.Table.22.Types.of.Code.Points)).
2022-02-02 07:11:07 +01:00
Dan Gohman
f88fb2a9a5 x.py fmt 2022-02-01 15:10:59 -08:00
Dan Gohman
656d2a3a12 Use From/Into rather than the traits they replaced. 2022-02-01 14:58:11 -08:00
Dan Gohman
89544e9001 Fix errors. 2022-02-01 14:38:23 -08:00
Dan Gohman
6ef7ee36c2 Fix unresolved doc links. 2022-02-01 14:37:15 -08:00
Dan Gohman
8516895170 Fix two copy+pastos. 2022-02-01 14:27:54 -08:00
Dan Gohman
713bb19ca3 Add missing pub keywords. 2022-02-01 14:23:03 -08:00
Dan Gohman
ca42a1bece Update the documentation for {As,Into,From}Raw{Fd,Handle,Socket}.
This change weakens the descriptions of the
`{as,into,from}_raw_{fd,handle,socket}` descriptions from saying that
they *do* express ownership relations to say that they are *typically used*
in ways that express ownership relations. This needed needed since, for
example, std's own [`RawFd`] implements `{As,From,Into}Fd` without any of
the ownership relationships.

This adds proper `# Safety` comments to `from_raw_{fd,handle,socket}`,
adds the requirement that raw handles be not opened with the
`FILE_FLAG_OVERLAPPED` flag, and merges the `OwnedHandle::from_raw_handle`
comment into the main `FromRawHandle::from_raw_handle` comment.

And, this changes `HandleOrNull` and `HandleOrInvalid` to not implement
`FromRawHandle`, since they are intended for limited use in FFI situations,
and not for generic use, and they have constraints that are stronger than
the those of `FromRawHandle`.

[`RawFd`]: https://doc.rust-lang.org/stable/std/os/unix/io/type.RawFd.html
2022-02-01 14:05:43 -08:00
George Bateman
d372baf3f9
Fix annotation of code blocks 2022-02-01 21:44:53 +00:00
bors
2681f253bc Auto merge of #93442 - yaahc:Termination-abstraction, r=Mark-Simulacrum
Change Termination::report return type to ExitCode

Related to https://github.com/rust-lang/rust/issues/43301

The goal of this change is to minimize the forward compatibility risks in stabilizing Termination. By using the opaque type `ExitCode` instead of an `i32` we leave room for us to evolve the API over time to provide what cross-platform consistency we can / minimize footguns when working with exit codes, where as stabilizing on `i32` would limit what changes we could make in the future in how we represent and construct exit codes.
2022-02-01 20:05:46 +00:00
Chris Denton
1bc8f0b49f
Link try_exists docs to Path::exists 2022-02-01 18:40:29 +00:00
Matthias Krüger
019c140244
Rollup merge of #93436 - dcsommer:master, r=Mark-Simulacrum
Update compiler_builtins to fix duplicate symbols in `armv7-linux-androideabi` rlib

I ran `./x.py dist --host= --target=armv7-linux-androideabi` before this diff:
```
$ nm build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/armv7-linux-androideabi/lib/libcompiler_builtins-3d9661a82c59c66a.rlib 2> /dev/null | grep __sync_fetch_and_add_4 | wc -l
2
```
And after:
```
$ nm build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/armv7-linux-androideabi/lib/libcompiler_builtins-ffd2745070943321.rlib 2> /dev/null | grep __sync_fetch_and_add_4 | wc -l
1
```
Fixes #93310

See also https://github.com/rust-lang/compiler-builtins/issues/449 and https://github.com/rust-lang/compiler-builtins/pull/450
2022-02-01 16:08:06 +01:00
Matthias Krüger
741b62af07
Rollup merge of #92584 - lcnr:query-stable-lint, r=estebank
add rustc lint, warning when iterating over hashmaps 2

first introduced in #89558 and reverted in #90380 due to its perf impact

r? ``@estebank``
2022-02-01 16:08:03 +01:00
lcnr
a1a30f7548 add a rustc::query_stability lint 2022-02-01 10:15:59 +01:00
Eric Huss
8a70ea2394
Rollup merge of #93504 - solid-rs:fix-kmc-solid-stack-size, r=nagisa
kmc-solid: Increase the default stack size

This PR increases the default minimum stack size on the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets to 64KiB (Arm) and 128KiB (AArch64).

This value was chosen as a middle ground between supporting a relatively complex program (e.g., an application using a full-fledged off-the-shelf web server framework) with no additional configuration and minimizing resource consumption for the embedded platform that doesn't support lazily-allocated pages nor over-commitment (i.e., wasted stack spaces are wasted physical memory). If the need arises, the users can always set the `RUST_MIN_STACK` environmental variable to override the default stack size or use the platform API directly.
2022-01-31 20:12:59 -08:00
Eric Huss
8604161d75
Rollup merge of #93090 - jyn514:errorkind-asstr, r=dtolnay
`impl Display for io::ErrorKind`

This avoids having to convert from `ErrorKind` to `Error` just to print the error message.
2022-01-31 20:12:56 -08:00
TheVoid
76aa92906b
Fix incorrect panic message in example 2022-02-01 10:19:08 +08:00
George Bateman
5357ec1473
(#93493) Add items from code review 2022-01-31 23:49:16 +00:00
Jane Lusby
19db85d6cd add inline attribute to new method 2022-01-31 11:57:17 -08:00
Tomoaki Kawada
1a77d6227c kmc-solid: Increase the default stack size 2022-01-31 17:39:38 +09:00
Matthias Krüger
4757a931cd
Rollup merge of #93494 - solid-rs:fix-kmc-solid-spawned-task-priority, r=Mark-Simulacrum
kmc-solid: Inherit the calling task's base priority in `Thread::new`

This PR fixes the initial priority calculation of spawned threads on the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets.

Fixes a spawned task (an RTOS object on top of which threads are implemented for this target; unrelated to async tasks) getting an unexpectedly higher priority if it's spawned by a task whose priority is temporarily boosted by a priority-protection mutex.
2022-01-31 07:00:47 +01:00
Matthias Krüger
cd27f1b56e
Rollup merge of #93471 - cuviper:direntry-file_type-stat, r=the8472
unix: Use metadata for `DirEntry::file_type` fallback

When `DirEntry::file_type` fails to match a known `d_type`, we should
fall back to `DirEntry::metadata` instead of a bare `lstat`, because
this is faster and more reliable on targets with `fstatat`.
2022-01-31 07:00:44 +01:00
Matthias Krüger
bc2c4feaeb
Rollup merge of #93462 - ChrisDenton:systime-doc, r=joshtriplett
Document `SystemTime` platform precision

Fixes #88822
2022-01-31 07:00:43 +01:00
Tomoaki Kawada
175219ad0c kmc-solid: SOLID_RTC_TIME::tm_mon is 1-based 2022-01-31 11:59:13 +09:00
Tomoaki Kawada
09233ce3c0 kmc-solid: Inherit the calling task's base priority in Thread::new
Fixes a spawned task getting an unexpectedly higher priority if it's
spawned by a task whose priority is temporarily boosted by a priority-
protection mutex.
2022-01-31 11:31:55 +09:00
George Bateman
4d4ec97e0a
Document char validity 2022-01-30 22:16:41 +00:00
Eric Huss
0610d4fa66
Rollup merge of #92887 - pietroalbini:pa-bootstrap-update, r=Mark-Simulacrum
Bootstrap compiler update

r? ``@Mark-Simulacrum``
2022-01-30 08:37:46 -08:00
Josh Stone
d70b9c03ec unix: Use metadata for DirEntry::file_type fallback
When `DirEntry::file_type` fails to match a known `d_type`, we should
fall back to `DirEntry::metadata` instead of a bare `lstat`, because
this is faster and more reliable on targets with `fstatat`.
2022-01-29 16:58:18 -08:00
Matthias Krüger
0d08bbc8c8
Rollup merge of #93459 - tavianator:dirent-copy-only-reclen, r=cuviper
fs: Don't copy d_name from struct dirent

The dirent returned from readdir() is only guaranteed to be valid for
d_reclen bytes on common platforms.  Since we copy the name separately
anyway, we can copy everything except d_name into DirEntry::entry.

Fixes #93384.
2022-01-30 00:04:16 +01:00
Matthias Krüger
329753e248
Rollup merge of #93414 - Amanieu:std_arch_detect, r=m-ou-se
Move unstable is_{arch}_feature_detected! macros to std::arch

These macros are unstable, except for `is_x86_feature_detected` which is still exported from the crate root for backwards-compatibility.

This should unblock the stabilization of `is_aarch64_feature_detected`.

r? ```@m-ou-se```
2022-01-30 00:04:14 +01:00
Tavian Barnes
d0c8b29ec6 fs: Add a regression test for #93384 2022-01-29 16:37:21 -05:00
Tavian Barnes
f8f4c40527 fs: Don't copy d_name from struct dirent
The dirent returned from readdir() is only guaranteed to be valid for
d_reclen bytes on common platforms.  Since we copy the name separately
anyway, we can copy everything except d_name into DirEntry::entry.

Fixes #93384.
2022-01-29 16:37:21 -05:00
Chris Denton
0189a21c19
Document SystemTime platform precision 2022-01-29 20:41:18 +00:00
Daniel Sommermann
746b3d87b3 Update compiler_builtins to fix duplicate symbols in armv7-linux-androideabi rlib
I ran `./x.py dist --host= --target=armv7-linux-androideabi` before this diff:
```
$ nm build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/armv7-linux-androideabi/lib/libcompiler_builtins-3d9661a82c59c66a.rlib 2> /dev/null | grep __sync_fetch_and_add_4 | wc -l
2
```
And after:
```
$ nm build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/armv7-linux-androideabi/lib/libcompiler_builtins-ffd2745070943321.rlib 2> /dev/null | grep __sync_fetch_and_add_4 | wc -l
1
```
Fixes #93310
2022-01-29 08:28:52 -08:00
Matthias Krüger
2836dcd2df
Rollup merge of #93410 - solid-rs:feat-kmc-solid-net-dup, r=dtolnay
kmc-solid: Implement `net::FileDesc::duplicate`

This PR implements `std::sys::solid::net::FileDesc::duplicate`, which was accidentally left out when this target was added by #86191.
2022-01-29 14:46:32 +01:00
bors
ca43894e0e Auto merge of #93351 - anp:fuchsia-remove-dir-all, r=tmandry
Bump libc and fix remove_dir_all on Fuchsia after CVE fix

With the previous `is_dir` impl, we would attempt to unlink
a directory in the None branch, but Fuchsia supports returning
ENOTEMPTY from unlinkat() without the AT_REMOVEDIR flag because
we don't currently differentiate unlinking files and directories
by default.

On the Fuchsia side I've opened https://fxbug.dev/92273 to discuss
whether this is the correct behavior, but it doesn't seem like
addressing the error code is necessary to make our tests happy.

Depends on https://github.com/rust-lang/libc/pull/2654 since we
apparently haven't needed to reference DT_UNKNOWN before this.
2022-01-29 09:01:01 +00:00
Jane Lusby
91ffbc43b1 Change Termination::report return type to ExitCode 2022-01-28 12:53:36 -08:00
Adam Perry
8c9944c50d Fix remove_dir_all on Fuchsia after CVE fix.
With the previous `is_dir` impl, we would attempt to unlink
a directory in the None branch, but Fuchsia supports returning
ENOTEMPTY from unlinkat() without the AT_REMOVEDIR flag because
we don't currently differentiate unlinking files and directories
by default.

On the Fuchsia side I've opened https://fxbug.dev/92273 to discuss
whether this is the correct behavior, but it doesn't seem like
addressing the error code is necessary to make our tests happy.

Updates std's libc crate to include DT_UNKNOWN for Fuchsia.
2022-01-28 20:38:39 +00:00
Matthias Krüger
4f2e2ceeb7
Rollup merge of #93295 - ChrisDenton:tempdir-double-panic, r=dtolnay
Avoid double panics when using `TempDir` in tests

`TempDir` could panic on drop if `remove_dir_all` returns an error. If this happens while already panicking, the test process would abort and therefore not show the test results.

This PR tries to avoid such double panics.
2022-01-28 15:20:25 +01:00
Matthias Krüger
18c8d0da64
Rollup merge of #93239 - Thomasdezeeuw:socketaddr_creation, r=m-ou-se
Add os::unix::net::SocketAddr::from_path

Creates a new SocketAddr from a path, supports both regular paths and
abstract namespaces.

Note that `SocketAddr::from_abstract_namespace` could be removed after this as `SocketAddr::unix` also supports abstract namespaces.

Updates #65275
Unblocks https://github.com/tokio-rs/mio/issues/1527

r? `@m-ou-se`
2022-01-28 15:20:23 +01:00
Pietro Albini
5b3462c556
update cfg(bootstrap)s 2022-01-28 15:01:07 +01:00
Thomas de Zeeuw
35f578fc78 Update tracking issue for unix_socket_creation 2022-01-28 15:00:17 +01:00
Harald Hoyer
d2a13693c2 wasi: enable TcpListener and TcpStream
With the addition of `sock_accept()` to snapshot1, simple networking via
a passed `TcpListener` is possible. This patch implements the basics to
make a simple server work.

Signed-off-by: Harald Hoyer <harald@profian.com>
2022-01-28 13:27:30 +01:00
Harald Hoyer
00cbc8d0c8 wasi: update to wasi 0.11.0
To make use of `sock_accept()`, update the wasi crate to `0.11.0`.

Signed-off-by: Harald Hoyer <harald@profian.com>
2022-01-28 13:27:29 +01:00
Amanieu d'Antras
2188c551cd Move unstable is_{arch}_feature_detected! macros to std::arch 2022-01-28 09:51:46 +00:00
Tomoaki Kawada
da0d506ace kmc-solid: Implement FileDesc::duplicate 2022-01-28 15:02:44 +09:00
Matthias Krüger
4af3930f28
Rollup merge of #91641 - dtolnay:cchar-if, r=Mark-Simulacrum
Define c_char using cfg_if rather than repeating 40-line cfg

Libstd has a 40-line cfg that defines the targets on which `c_char` is unsigned, and then repeats the same cfg with `not(…)` for the targets on which `c_char` is signed.

This PR replaces it with a `cfg_if!` in which an `else` takes care of the signed case.

I confirmed that `x.py doc library/std` inlines the type alias because c_char_definition is not a publicly accessible path:

![Screenshot from 2021-12-07 13-42-07](https://user-images.githubusercontent.com/1940490/145110596-f1058406-9f32-44ff-9a81-1dfd19b4a24f.png)
2022-01-27 22:32:23 +01:00
Jubilee Young
e96159e9af pub use std::simd::StdFloat;
Make available the remaining float intrinsics that require runtime support
from a platform's libm, and thus cannot be included in a no-deps libcore,
by exposing them through a sealed trait, `std::simd::StdFloat`.

We might use the trait approach a bit more in the future, or maybe not.
Ideally, this trait doesn't stick around, even if so.
If we don't need to intermesh it with std, it can be used as a crate,
but currently that is somewhat uncertain.
2022-01-27 11:50:58 -08:00
Thomas de Zeeuw
4acb8ac46c Use sockaddr_un in unix SocketAddr::from_path 2022-01-27 09:54:28 +01:00
Thomas de Zeeuw
ca9a3c9a9f Make sockaddr_un safe and use copy_nonoverlapping
The creation of libc::sockaddr_un is a safe operation, no need for it to
be unsafe.

This also uses the more performant copy_nonoverlapping instead of an
iterator.
2022-01-27 09:52:59 +01:00
Dan Gohman
47aaf79554 Add documentation about BorrowedFd::to_owned.
Following up on #88564, this adds documentation explaining why
`BorrowedFd::to_owned` returns another `BorrowedFd` rather than an
`OwnedFd`. And similar for `BorrowedHandle` and `BorrowedSocket`.
2022-01-26 16:27:46 -08:00
Matthias Krüger
253f64c9c6
Rollup merge of #92778 - tavianator:linux-readdir-no-r, r=joshtriplett
fs: Use readdir() instead of readdir_r() on Linux and Android

See #40021 for more details.  Fixes #86649.  Fixes #34668.
2022-01-26 23:45:23 +01:00
Артём Павлов [Artyom Pavlov]
e0bcf771d6 Improve Duration::try_from_secs_f32/64 accuracy by directly processing exponent and mantissa 2022-01-26 18:14:25 +03:00
Ralf Jung
53d2401f3f make Windows abort_internal Miri-compatible 2022-01-25 12:44:40 -05:00
Chris Denton
84c0c9d20d
Avoid double panics when using TempDir in tests 2022-01-25 10:36:10 +00:00
Matthias Krüger
687bb583c8
Rollup merge of #88794 - sunfishcode:sunfishcode/try-clone, r=joshtriplett
Add a `try_clone()` function to `OwnedFd`.

As suggested in #88564. This adds a `try_clone()` to `OwnedFd` by
refactoring the code out of the existing `File`/`Socket` code.

r? ``@joshtriplett``
2022-01-25 05:51:09 +01:00
Thomas de Zeeuw
c1cd200922 Rename SocketAddr::unix to from_path
And change it to disallow NULL bytes.
2022-01-24 18:02:37 +01:00
Matthias Krüger
144aeedcf3
Rollup merge of #93152 - ivmarkov:master, r=m-ou-se
Fix STD compilation for the ESP-IDF target (regression from CVE-2022-21658)

Commit 54e22eb7db broke the compilation of STD for the ESP-IDF embedded "unix-like" Tier 3 target, because the fix for [CVE-2022-21658](https://blog.rust-lang.org/2022/01/20/Rust-1.58.1.html) uses [libc flags](https://github.com/esp-rs/esp-idf-svc/runs/4892221554?check_suite_focus=true) which are not supported on the ESP-IDF platform.

This PR simply redirects the ESP-IDF compilation to the "classic" implementation, similar to REDOX. This should be safe because:
* Neither of the two filesystems supported by ESP-IDF (spiffs and fatfs) support [symlinks](https://github.com/natevw/fatfs/blob/master/README.md) in the first place
* There is no notion of fs permissions at all, as the ESP-IDF is an embedded platform that does not have the notion of users, groups, etc.
* Similarly, ESP-IDF has just one "process" - the firmware itself - which contains the user code and the "OS" fused together and running with all permissions
2022-01-24 12:29:51 +01:00
Matthias Krüger
b92a1e9c20
Rollup merge of #92513 - Xuanwo:path-buf, r=dtolnay
std: Implement try_reserve and try_reserve_exact on PathBuf

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

Signed-off-by: Xuanwo <github@xuanwo.io>
2022-01-24 12:29:50 +01:00
Chris Denton
ac02fcc4d8
Use NtCreateFile instead of NtOpenFile to open a file 2022-01-24 10:00:31 +00:00
Matthias Krüger
bb260e8950
Rollup merge of #92555 - m-ou-se:scoped-threads, r=Amanieu
Implement RFC 3151: Scoped threads.

This implements https://github.com/rust-lang/rfcs/pull/3151

r? `@Amanieu`
2022-01-23 20:13:02 +01:00
Thomas de Zeeuw
f2cdb57b94 Add os::unix::net::SocketAddr::unix
Creates a new SocketAddr from a path, supports both regular paths and
abstract namespaces.
2022-01-23 17:11:06 +01:00
bors
10c4c4afec Auto merge of #92998 - Amanieu:hashbrown12, r=Mark-Simulacrum
Update hashbrown to 0.12.0

[Changelog](https://github.com/rust-lang/hashbrown/blob/master/CHANGELOG.md#v0120---2022-01-17)
2022-01-22 23:39:21 +00:00
Mara Bos
465c405418 Add test for thread::Scope invariance. 2022-01-22 17:15:08 +01:00
Mara Bos
12cc7d9e15 Add tracking issue number for scoped_threads. 2022-01-22 16:03:23 +01:00
Mara Bos
e572c5a3d5 Simplify Send/Sync of std:🧵:Packet. 2022-01-22 16:02:18 +01:00
Matthias Krüger
9d7c8edd6c
Rollup merge of #92828 - Amanieu:unwind-abort, r=dtolnay
Print a helpful message if unwinding aborts when it reaches a nounwind function

This is implemented by routing `TerminatorKind::Abort` back through the panic handler, but with a special flag in the `PanicInfo` which indicates that the panic handler should *not* attempt to unwind the stack and should instead abort immediately.

This is useful for the planned change in https://github.com/rust-lang/lang-team/issues/97 which would make `Drop` impls `nounwind` by default.

### Code

```rust
#![feature(c_unwind)]

fn panic() {
    panic!()
}

extern "C" fn nounwind() {
    panic();
}

fn main() {
    nounwind();
}
```

### Before

```
$ ./test
thread 'main' panicked at 'explicit panic', test.rs:4:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Illegal instruction (core dumped)
```

### After

```
$ ./test
thread 'main' panicked at 'explicit panic', test.rs:4:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'panic in a function that cannot unwind', test.rs:7:1
stack backtrace:
   0:     0x556f8f86ec9b - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hdccefe11a6ac4396
   1:     0x556f8f88ac6c - core::fmt::write::he152b28c41466ebb
   2:     0x556f8f85d6e2 - std::io::Write::write_fmt::h0c261480ab86f3d3
   3:     0x556f8f8654fa - std::panicking::default_hook::{{closure}}::h5d7346f3ff7f6c1b
   4:     0x556f8f86512b - std::panicking::default_hook::hd85803a1376cac7f
   5:     0x556f8f865a91 - std::panicking::rust_panic_with_hook::h4dc1c5a3036257ac
   6:     0x556f8f86f079 - std::panicking::begin_panic_handler::{{closure}}::hdda1d83c7a9d34d2
   7:     0x556f8f86edc4 - std::sys_common::backtrace::__rust_end_short_backtrace::h5b70ed0cce71e95f
   8:     0x556f8f865592 - rust_begin_unwind
   9:     0x556f8f85a764 - core::panicking::panic_no_unwind::h2606ab3d78c87899
  10:     0x556f8f85b910 - test::nounwind::hade6c7ee65050347
  11:     0x556f8f85b936 - test::main::hdc6e02cb36343525
  12:     0x556f8f85b7e3 - core::ops::function::FnOnce::call_once::h4d02663acfc7597f
  13:     0x556f8f85b739 - std::sys_common::backtrace::__rust_begin_short_backtrace::h071d40135adb0101
  14:     0x556f8f85c149 - std::rt::lang_start::{{closure}}::h70dbfbf38b685e93
  15:     0x556f8f85c791 - std::rt::lang_start_internal::h798f1c0268d525aa
  16:     0x556f8f85c131 - std::rt::lang_start::h476a7ee0a0bb663f
  17:     0x556f8f85b963 - main
  18:     0x7f64c0822b25 - __libc_start_main
  19:     0x556f8f85ae8e - _start
  20:                0x0 - <unknown>
thread panicked while panicking. aborting.
Aborted (core dumped)
```
2022-01-22 15:32:49 +01:00
Amanieu d'Antras
537439c177 Disable test_try_reserve on Android 2022-01-22 13:51:57 +00:00
Matthias Krüger
081d65fa4a
Rollup merge of #93134 - tlyu:delete-stdin-split, r=Amanieu
delete `Stdin::split` forwarder

Part of #87096. Delete the `Stdin::split` forwarder because it's seen as too niche to expose at this level.

`@rustbot` label T-libs-api A-io
2022-01-21 22:03:19 +01:00
Matthias Krüger
9474c74fb6
Rollup merge of #93109 - JakobDegen:arc-docs, r=m-ou-se
Improve `Arc` and `Rc` documentation

This makes two changes (I can split the PR if necessary, but the changes are pretty small):
 1. A bunch of trait implementations claimed to be zero cost; however, they use the `Arc<T>: From<Box<T>>` impl which is definitely not free, especially for large dynamically sized `T`.
 2.  The code in deferred initialization examples unnecessarily used excessive amounts of `unsafe`. This has been reduced.
2022-01-21 22:03:18 +01:00
Matthias Krüger
701a8330e8
Rollup merge of #92586 - esp-rs:bugfix/allocation-alignment-espidf, r=yaahc
Set the allocation MIN_ALIGN for espidf to 4.

Closes https://github.com/esp-rs/rust/issues/99.

cc: `@ivmarkov`
2022-01-21 22:03:13 +01:00
Amanieu d'Antras
361a2f9a83 Update HashMap::try_reserve test to version from hashbrown 2022-01-21 17:20:38 +00:00
Amanieu d'Antras
88149d13e3 Update hashbrown to 0.12.0 2022-01-21 17:20:38 +00:00
Amanieu d'Antras
24588e6b3a Old versions of Android generate SIGSEGV from libc::abort 2022-01-21 15:44:57 +00:00
Tavian Barnes
3eeb3ca407 fs: Use readdir() instead of readdir_r() on Android
Bionic also guarantees that readdir() is thread-safe enough.
2022-01-21 07:59:14 -05:00
Tavian Barnes
bc04a4eac4 fs: Use readdir() instead of readdir_r() on Linux
readdir() is preferred over readdir_r() on Linux and many other
platforms because it more gracefully supports long file names.  Both
glibc and musl (and presumably all other Linux libc implementations)
guarantee that readdir() is thread-safe as long as a single DIR* is not
accessed concurrently, which is enough to make a readdir()-based
implementation of ReadDir safe.  This implementation is already used for
some other OSes including Fuchsia, Redox, and Solaris.

See #40021 for more details.  Fixes #86649.  Fixes #34668.
2022-01-21 07:59:14 -05:00
Tavian Barnes
c3e92fec94 fs: Implement more ReadDir methods in terms of name_cstr() 2022-01-21 07:59:14 -05:00
ivmarkov
495c7b31aa Fix STD compilation for the ESP-IDF target 2022-01-21 09:41:13 +02:00
Taylor Yu
fdf930ce01 delete Stdin::split forwarder 2022-01-20 15:37:44 -06:00
Matthias Krüger
dbc97490bb
Rollup merge of #93112 - pietroalbini:pa-cve-2022-21658-nightly, r=pietroalbini
Fix CVE-2022-21658

See https://blog.rust-lang.org/2022/01/20/cve-2022-21658.html. Patches reviewed by `@m-ou-se.`

r? `@ghost`
2022-01-20 17:10:43 +01:00
Matthias Krüger
1cb57e2d2b
Rollup merge of #92992 - kornelski:backtraceopt, r=Mark-Simulacrum
Help optimize out backtraces when disabled

The comment in `rust_backtrace_env` says:

>    // If the `backtrace` feature of this crate isn't enabled quickly return
>   // `None` so this can be constant propagated all over the place to turn
>  // optimize away callers.

but this optimization has regressed, because the only caller of this function had an alternative path that unconditionally (and pointlessly) asked for a full backtrace, so the disabled state couldn't propagate.

I've added a getter for the full format that respects the feature flag, so that the caller will now be able to really optimize out the disabled backtrace path. I've also made `rust_backtrace_env` trivially inlineable when backtraces are disabled.
2022-01-20 17:10:40 +01:00
Hans Kratz
0a6c9adc4a
Fix compilation for a few tier 2 targets 2022-01-20 16:35:16 +01:00
Jakob Degen
7bc47cfd92 Correct docs in Arc and Rc.
A number of trait implementations incorrectly claimed to be zero cost.
2022-01-20 04:54:03 -05:00
Joshua Nelson
f8ee57be2c impl Display for io::ErrorKind
This avoids having to convert from `ErrorKind` to `Error` just to print the error message.
2022-01-19 13:47:44 -06:00
Pietro Albini
32080ad6d0
Update std::fs::remove_dir_all documentation 2022-01-19 15:59:25 +01:00
Alex Crichton
cb748a27d2
Fix CVE-2022-21658 for WASI 2022-01-19 15:59:23 +01:00
Hans Kratz
54e22eb7db
Fix CVE-2022-21658 for UNIX-like 2022-01-19 15:59:22 +01:00
Chris Denton
5ab67bff1e
Fix CVE-2022-21658 for Windows 2022-01-19 15:59:21 +01:00
Matthias Krüger
3148a322d8
Rollup merge of #92124 - AngelicosPhosphoros:remove_extra_alloc_in_cstring_new_35838, r=Mark-Simulacrum
Little improves in CString `new` when creating from slice

Old code already contain optimization for cases with `&str` and `&[u8]` args. This commit adds a specialization for `&mut[u8]` too.

Also, I added usage of old slice in search for zero bytes instead of new buffer because it produce better code for constant inputs on Windows LTO builds. For other platforms, this wouldn't cause any difference because it calls `libc` anyway.

Inlined `_new` method into spec trait to reduce amount of code generated to `CString::new` callers.
2022-01-19 10:42:15 +01:00
Matthias Krüger
83b1a9452a
Rollup merge of #93016 - Amanieu:vec_spare_capacity, r=Mark-Simulacrum
Stabilize vec_spare_capacity

Closes #75017
2022-01-18 04:42:11 +01:00
Matthias Krüger
ae8f39e4d4
Rollup merge of #92866 - maxwase:does_exist_typo, r=Mark-Simulacrum
"Does exists" typos fix

Fixed some typos
2022-01-18 04:42:03 +01:00
Amanieu d'Antras
e012b9a78d Stabilize vec_spare_capacity
Closes #75017
2022-01-17 21:07:02 +00:00
bors
a34c079752 Auto merge of #92816 - tmiasko:rm-llvm-asm, r=Amanieu
Remove deprecated LLVM-style inline assembly

The `llvm_asm!` was deprecated back in #87590 1.56.0, with intention to remove
it once `asm!` was stabilized, which already happened in #91728 1.59.0. Now it
is time to remove `llvm_asm!` to avoid continued maintenance cost.

Closes #70173.
Closes #92794.
Closes #87612.
Closes #82065.

cc `@rust-lang/wg-inline-asm`

r? `@Amanieu`
2022-01-17 09:40:29 +00:00
Kornel
c2807525a5 Help optimize out backtraces when disabled 2022-01-17 02:21:24 +00:00
Amanieu d'Antras
528c4f9158 Add PanicInfo::can_unwind which indicates whether a panic handler is
allowed to trigger unwinding.
2022-01-17 00:39:28 +00:00
Matthias Krüger
cf4549c920
Rollup merge of #92619 - Alexendoo:macro-diagnostic-items, r=matthewjasper
Add diagnostic items for macros

For use in Clippy, it adds diagnostic items to all the stable public macros

Clippy has lints that look for almost all of these (currently by name or path), but there are a few that aren't currently part of any lint, I could remove those if it's preferred to add them as needed rather than ahead of time
2022-01-16 16:58:14 +01:00
bors
a0984b4e4c Auto merge of #92598 - Badel2:panic-update-hook, r=yaahc
Implement `panic::update_hook`

Add a new function `panic::update_hook` to allow creating panic hooks that forward the call to the previously set panic hook, without race conditions. It works by taking a closure that transforms the old panic hook into a new one, while ensuring that during the execution of the closure no other thread can modify the panic hook. This is a small function so I hope it can be discussed here without a formal RFC, however if you prefer I can write one.

Consider the following example:

```rust
let prev = panic::take_hook();
panic::set_hook(Box::new(move |info| {
    println!("panic handler A");
    prev(info);
}));
```

This is a common pattern in libraries that need to do something in case of panic: log panic to a file, record code coverage, send panic message to a monitoring service, print custom message with link to github to open a new issue, etc. However it is impossible to avoid race conditions with the current API, because two threads can execute in this order:

* Thread A calls `panic::take_hook()`
* Thread B calls `panic::take_hook()`
* Thread A calls `panic::set_hook()`
* Thread B calls `panic::set_hook()`

And the result is that the original panic hook has been lost, as well as the panic hook set by thread A. The resulting panic hook will be the one set by thread B, which forwards to the default panic hook. This is not considered a big issue because the panic handler setup is usually run during initialization code, probably before spawning any other threads.

Using the new `panic::update_hook` function, this race condition is impossible, and the result will be either `A, B, original` or `B, A, original`.

```rust
panic::update_hook(|prev| {
    Box::new(move |info| {
        println!("panic handler A");
        prev(info);
    })
});
```

I found one real world use case here: 988cf403e7/src/detection.rs (L32) the workaround is to detect the race condition and panic in that case.

The pattern of `take_hook` + `set_hook` is very common, you can see some examples in this pull request, so I think it's natural to have a function that combines them both. Also using `update_hook` instead of `take_hook` + `set_hook` reduces the number of calls to `HOOK_LOCK.write()` from 2 to 1, but I don't expect this to make any difference in performance.

### Unresolved questions:

* `panic::update_hook` takes a closure, if that closure panics the error message is "panicked while processing panic" which is not nice. This is a consequence of holding the `HOOK_LOCK` while executing the closure. Could be avoided using `catch_unwind`?

* Reimplement `panic::set_hook` as `panic::update_hook(|_prev| hook)`?
2022-01-16 02:18:42 +00:00
Matthias Krüger
d878ad0559
Rollup merge of #92863 - camelid:read_to_string-rm-mut, r=m-ou-se
Remove `&mut` from `io::read_to_string` signature

``@m-ou-se`` [realized][1] that because `Read` is implemented for `&mut impl
Read`, there's no need to take `&mut` in `io::read_to_string`.

Removing the `&mut` from the signature allows users to remove the `&mut`
from their calls (and thus pass an owned reader) if they don't use the
reader later.

r? `@m-ou-se`

[1]: https://github.com/rust-lang/rust/issues/80218#issuecomment-874322129
2022-01-15 11:28:24 +01:00
Matthias Krüger
1b241bb703
Rollup merge of #92775 - xfix:osstringext-inline, r=m-ou-se
Inline std::os::unix::ffi::OsStringExt methods

Those methods essentially do nothing at assembly level. On Unix systems, `OsString` is represented as a `Vec` without performing any transformations.
2022-01-15 11:28:23 +01:00
Matthias Krüger
d7e512c5c7
Rollup merge of #92684 - ibraheemdev:patch-10, r=m-ou-se
Export `tcp::IntoIncoming`

Added in #88339 but not publicly exported.
2022-01-15 02:25:16 +01:00
Matthias Krüger
558da934c1
Rollup merge of #92768 - ojeda:stabilize-maybe_uninit_extra, r=Mark-Simulacrum
Partially stabilize `maybe_uninit_extra`

This covers:

```rust
impl<T> MaybeUninit<T> {
    pub unsafe fn assume_init_read(&self) -> T { ... }
    pub unsafe fn assume_init_drop(&mut self) { ... }
}
```

It does not cover the const-ness of `write` under `const_maybe_uninit_write` nor the const-ness of `assume_init_read` (this commit adds `const_maybe_uninit_assume_init_read` for that).

FCP: https://github.com/rust-lang/rust/issues/63567#issuecomment-958590287.

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2022-01-14 07:47:33 +01:00
Maxwase
a7092f91a6 Typos fix 2022-01-14 00:17:11 +03:00
Scott Mabin
5296baeab1 Set the allocation MIN_ALIGN for espidf to 4. 2022-01-13 21:09:20 +00:00
Ibraheem Ahmed
f88b501914
fix stability attribute for tcp::IntoIncoming 2022-01-13 16:04:02 -05:00
Noah Lev
aa0ce4a20e Remove &mut from io::read_to_string signature
`@m-ou-se` [realized][1] that because `Read` is implemented for `&mut impl
Read`, there's no need to take `&mut` in `io::read_to_string`.

Removing the `&mut` from the signature allows users to remove the `&mut`
from their calls (and thus pass an owned reader) if they don't use the
reader later.

[1]: https://github.com/rust-lang/rust/issues/80218#issuecomment-874322129
2022-01-13 10:57:45 -08:00
Matthias Krüger
e045c79c2d
Rollup merge of #91938 - yaahc:error-reporter, r=m-ou-se
Add `std::error::Report` type

This is a continuation of https://github.com/rust-lang/rust/pull/90174, split into a separate PR since I cannot push to ```````@seanchen1991``````` 's fork
2022-01-13 08:11:18 +01:00
bors
256721ee51 Auto merge of #92553 - m-ou-se:thread-join-simplify, r=Mark-Simulacrum
Simpilfy thread::JoinInner.

`JoinInner`'s `native` field was an `Option`, but that's unnecessary.

Also, thanks to `Arc::get_mut`, there's no unsafety needed in `JoinInner::join()`.
2022-01-13 03:46:19 +00:00
Dan Gohman
83aebf8f7b Use the correct cvt for converting socket errors on Windows.
`WSADuplicateSocketW` returns 0 on success, which differs from
handle-oriented functions which return 0 on error. Use `sys::net::cvt`
to handle its return value, which handles the socket convention of
returning 0 on success, rather than `sys::cvt`, which handles the
handle-oriented convention of returning 0 on failure.
2022-01-12 11:41:48 -08:00
Tomasz Miąsko
000b36c505 Remove deprecated LLVM-style inline assembly 2022-01-12 18:51:31 +01:00
Matthias Krüger
286bb18a9b
Rollup merge of #92748 - david-perez:eliminate-boxed-wording-std-error, r=Mark-Simulacrum
Eliminate "boxed" wording in `std::error::Error` documentation

In commit 29403ee, documentation for the methods on `std::any::Any` was
modified so that they referred to the concrete value behind the trait
object as the "inner" value. This is a more accurate wording than
"boxed": while putting trait objects inside boxes is arguably the most
common use, they can also be placed behind other pointer types like
`&mut` or `std::sync::Arc`.

This commit does the same documentation changes for `std::error::Error`.
2022-01-12 07:12:15 +01:00
Matthias Krüger
37f061a2f8
Rollup merge of #92720 - rosik:patch-1, r=m-ou-se
Fix doc formatting for time.rs

The doc states that instants are not steady, but the word "not" wasn't highlighted in bold.
2022-01-12 07:12:13 +01:00
Matthias Krüger
5d904c17f6
Rollup merge of #92709 - joshtriplett:file-options-docs, r=Mark-Simulacrum
Improve documentation for File::options to give a more likely example

`File::options().read(true).open(...)` is equivalent to just
`File::open`. Change the example to set the `append` flag instead, and
then change the filename to something more likely to be written in
append mode.
2022-01-12 07:12:12 +01:00
Konrad Borowski
7e6d97bc39 Inline std::os::unix::ffi::OsStringExt methods 2022-01-11 19:33:46 +01:00
Miguel Ojeda
8680a44c0f Partially stabilize maybe_uninit_extra
This covers:

    impl<T> MaybeUninit<T> {
        pub unsafe fn assume_init_read(&self) -> T { ... }
        pub unsafe fn assume_init_drop(&mut self) { ... }
    }

It does not cover the const-ness of `write` under
`const_maybe_uninit_write` nor the const-ness of
`assume_init_read` (this commit adds
`const_maybe_uninit_assume_init_read` for that).

FCP: https://github.com/rust-lang/rust/issues/63567#issuecomment-958590287.

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2022-01-11 17:01:13 +01:00
bors
2e2c86eba2 Auto merge of #92070 - rukai:replace_vec_into_iter_with_array_into_iter, r=Mark-Simulacrum
Replace usages of vec![].into_iter with [].into_iter

`[].into_iter` is idiomatic over `vec![].into_iter` because its simpler and faster (unless the vec is optimized away in which case it would be the same)

So we should change all the implementation, documentation and tests to use it.

I skipped:
* `src/tools` - Those are copied in from upstream
* `src/test/ui` - Hard to tell if `vec![].into_iter` was used intentionally or not here and not much benefit to changing it.
*  any case where `vec![].into_iter` was used because we specifically needed a `Vec::IntoIter<T>`
*  any case where it looked like we were intentionally using `vec![].into_iter` to test it.
2022-01-11 14:23:24 +00:00
Josh Triplett
c91ad5d0f2 Improve documentation for File::options to give a more likely example
`File::options().read(true).open(...)` is equivalent to just
`File::open`. Change the example to set the `append` flag instead, and
then change the filename to something more likely to be written in
append mode.
2022-01-10 17:35:17 -05:00
david-perez
5786bbddc6 Eliminate "boxed" wording in std::error::Error documentation
In commit 29403ee, documentation for the methods on `std::any::Any` was
modified so that they referred to the concrete value behind the trait
object as the "inner" value. This is a more accurate wording than
"boxed": while putting trait objects inside boxes is arguably the most
common use, they can also be placed behind other pointer types like
`&mut` or `std::sync::Arc`.

This commit does the same documentation changes for `std::error::Error`.
2022-01-10 23:18:34 +01:00
bors
89b9f7b284 Auto merge of #92719 - matthiaskrgr:rollup-tc7oqys, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #92248 (Normalize struct tail type when checking Pointee trait)
 - #92357 (Fix invalid removal of newlines from doc comments)
 - #92602 (Make source links look cleaner)
 - #92636 (Normalize generator-local types with unevaluated constants)
 - #92693 (Release notes: add `Result::unwrap_{,err_}unchecked`)
 - #92702 (Clean up lang_items::extract)
 - #92717 (update miri)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-01-10 11:53:15 +00:00
Yaroslav Dynnikov
2ae616af30
Fix doc formatting for time.rs
The doc states that instants are not steady, but the word "not" wasn't highlighted in bold.
2022-01-10 14:22:45 +03:00
Matthias Krüger
a4ac4fae41
Rollup merge of #92602 - jsha:source-link-2, r=GuillaumeGomez
Make source links look cleaner

Change from syntaxy-looking [src] to the plain word "source".

Change the syntaxy-looking `[-]` at the top of the page to say "collapse".

Reduce opacity of rightside content.

Part of #59851

r? `@GuillaumeGomez`

Demo: https://rustdoc.crud.net/jsha/source-link-2/std/string/struct.String.html

[Discussed on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/display.20of.20source.20link).
2022-01-10 11:03:06 +01:00
Lamb
3a77bb86ff Compute most of Public/Exported access level in rustc_resolve
Mak DefId to AccessLevel map in resolve for export

hir_id to accesslevel in resolve and applied in privacy
using local def id
removing tracing probes
making function not recursive and adding comments

Move most of Exported/Public res to rustc_resolve

moving public/export res to resolve

fix missing stability attributes in core, std and alloc

move code to access_levels.rs

return for some kinds instead of going through them

Export correctness, macro changes, comments

add comment for import binding

add comment for import binding

renmae to access level visitor, remove comments, move fn as closure, remove new_key

fmt

fix rebase

fix rebase

fmt

fmt

fix: move macro def to rustc_resolve

fix: reachable AccessLevel for enum variants

fmt

fix: missing stability attributes for other architectures

allow unreachable pub in rustfmt

fix: missing impl access level + renaming export to reexport

Missing impl access level was found thanks to a test in clippy
2022-01-09 21:33:14 +00:00
Ibraheem Ahmed
1e53a905ba
export tcp::IntoIncoming 2022-01-08 23:48:50 -05:00
Lucas Kent
08829853d3 eplace usages of vec![].into_iter with [].into_iter 2022-01-09 14:09:25 +11:00
Jacob Hoffman-Andrews
962c0a4ee5 Make source links look cleaner
Change from syntaxy-looking [src] to the plain word "source".
2022-01-08 09:49:41 -05:00
Eric Huss
10010685a9
Rollup merge of #92632 - yoshuawuyts:stabilize-available-parallelism, r=joshtriplett
Implement stabilization of `#[feature(available_parallelism)]`

Stabilized in https://github.com/rust-lang/rust/issues/74479#issuecomment-984379800. Closes https://github.com/rust-lang/rust/issues/74479. Thanks!

cc/ ``@rust-lang/libs-api``
2022-01-07 20:21:01 -08:00
Badel2
0c58586c9c Add safety comments to panic::(set/take/update)_hook 2022-01-08 00:57:59 +01:00
Badel2
8ef3ce866e Change panic::update_hook to simplify usage
And to remove possibility of panics while changing the panic handler,
because that resulted in a double panic.
2022-01-08 00:57:59 +01:00
Jane Lusby
72cb1bd06d silence tidy errors 2022-01-07 13:59:27 -08:00
Ian Douglas Scott
a02639dc09 Implement TryFrom<char> for u8
Previously suggested in https://github.com/rust-lang/rfcs/issues/2854.

It makes sense to have this since `char` implements `From<u8>`. Likewise
`u32`, `u64`, and `u128` (since #79502) implement `From<char>`.
2022-01-07 12:28:47 -08:00
Badel2
8bdf5c3de6 Implement panic::update_hook 2022-01-07 17:28:20 +01:00
Yoshua Wuyts
3632f41c78 Stabilize #[feature(available_parallelism)] 2022-01-07 01:07:10 +01:00
Alex Macleod
7ea03db04a Add diagnostic items for macros 2022-01-06 14:59:33 +00:00
Matthias Krüger
2647ce2165
Rollup merge of #92288 - yescallop:patch-1, r=m-ou-se
Fix a pair of mistyped test cases in `std::net::ip`

These two test cases are not consistent with their comments, which I believe is unintended.
2022-01-06 12:01:00 +01:00
bors
f1ce0e6a00 Auto merge of #92587 - matthiaskrgr:rollup-qnwa8qx, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #92092 (Drop guards in slice sorting derive src pointers from &mut T, which is invalidated by interior mutation in comparison)
 - #92388 (Fix a minor mistake in `String::try_reserve_exact` examples)
 - #92442 (Add negative `impl` for `Ord`, `PartialOrd` on `LocalDefId`)
 - #92483 (Stabilize `result_cloned` and `result_copied`)
 - #92574 (Add RISC-V detection macro and more architecture instructions)
 - #92575 (ast: Always keep a `NodeId` in `ast::Crate`)
 - #92583 (⬆️ rust-analyzer)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-01-05 15:28:36 +00:00
Mara Bos
4cb73704e2
Mention *scoped* thread in panic message.
Co-authored-by: Amanieu d'Antras <amanieu@gmail.com>
2022-01-05 11:17:11 +00:00
Mara Bos
aa9c0881ef Note the invariance over 'env in Scope<'env>. 2022-01-05 12:14:32 +01:00
Mara Bos
5bd5781823 Fix missing .load() in Scope's Debug impl. 2022-01-05 12:14:32 +01:00
Mara Bos
a9efbaf3a5 Rename n_running_threads to num_running_threads. 2022-01-05 12:14:32 +01:00
Matthias Krüger
42a3acfdb1
Rollup merge of #92517 - ChrisDenton:explicit-path, r=dtolnay
Explicitly pass `PATH` to the Windows exe resolver

This allows for testing different `PATH`s without using the actual environment.
2022-01-05 11:26:07 +01:00
luojia65
06f4453027 Add is_riscv_feature_detected!; modify impl of hint::spin_loop
Update library/core/src/hint.rs

Co-authored-by: Amanieu d'Antras <amanieu@gmail.com>

Remove redundant config gate
2022-01-05 15:44:52 +08:00
Mara Bos
5b5746f081
Fix typo in Scope::spawn docs.
Co-authored-by: deltragon <m@dafert.at>
2022-01-04 18:43:23 +00:00
Mara Bos
c429ade760 Fix typo in is_running() docs.
Co-authored-by: Mattias Buelens <649348+MattiasBuelens@users.noreply.github.com>
2022-01-04 18:40:00 +01:00
Mara Bos
09e6665aba Fix typo in documentation. 2022-01-04 17:05:26 +01:00
Mara Bos
2c8cc70ea0
Use > rather than == for overflow check in scoped threads.
Co-authored-by: Jacob Lifshay <programmerjake@gmail.com>
2022-01-04 15:58:29 +00:00
Mara Bos
c5cb2def06 Fix variance of thread::Scope. 2022-01-04 16:57:16 +01:00
Matthias Krüger
b2d6ff4b6e
Rollup merge of #92525 - zohnannor:patch-1, r=camelid
intra-doc: Make `Receiver::into_iter` into a clickable link

The documentation on `std::sync::mpsc::Iter` and `std::sync::mpsc::TryIter` provides links to the corresponding `Receiver` methods, unlike `std::sync::mpsc::IntoIter` does.

This was left out in c59b188aae
Related to #29377
2022-01-04 16:34:19 +01:00
Matthias Krüger
4e4e1ec931
Rollup merge of #92456 - danielhenrymantilla:patch-1, r=petrochenkov
Make the documentation of builtin macro attributes accessible

`use ::std::prelude::v1::derive;` compiles on stable, so, AFAIK, there is no reason to have it be `#[doc(hidden)]`.

  - What it currently looks like for things such as `#[test]`, `#[derive]`, `#[global_allocator]`: https://doc.rust-lang.org/1.57.0/core/prelude/v1/index.html#:~:text=Experimental-,pub,-use%20crate%3A%3Amacros%3A%3Abuiltin%3A%3Aglobal_allocator

    <img width="767" alt="Screen Shot 2021-12-31 at 17 49 46" src="https://user-images.githubusercontent.com/9920355/147832999-cbd747a6-4607-4df6-8e57-c1675dcbc1c3.png">

    and in `::std` they're just straight `hidden`.

    <img width="452" alt="Screen Shot 2021-12-31 at 17 53 18" src="https://user-images.githubusercontent.com/9920355/147833105-c5ff8cd1-9e4d-4d2b-9621-b36aa3cfcb28.png">

  - Here is how it looks like with this PR (assuming the `Rustc{De,En}codable` ones are not reverted):

    <img width="778" alt="Screen Shot 2021-12-31 at 17 50 55" src="https://user-images.githubusercontent.com/9920355/147833034-84286342-dbf7-4e6e-9062-f39cd6c286a4.png">

    <img width="291" alt="Screen Shot 2021-12-31 at 17 52 54" src="https://user-images.githubusercontent.com/9920355/147833109-c92ed55c-51c6-40a2-9205-f834d1e349c0.png">

 Since this involves doc people to chime in, and since `jyn` is on vacation, I'll cc `@GuillaumeGomez` and tag the `rustdoc` team as well
2022-01-04 16:34:16 +01:00
Matthias Krüger
50a66b75dc
Rollup merge of #91754 - Patrick-Poitras:rm-4byte-minimum-stdio-windows, r=Mark-Simulacrum
Modifications to `std::io::Stdin` on Windows so that there is no longer a 4-byte buffer minimum in read().

This is an attempted fix of issue #91722, where a too-small buffer was passed to the read function of stdio on Windows. This caused an error to be returned when `read_to_end` or `read_to_string` were called. Both delegate to `std::io::default_read_to_end`, which creates a buffer that is of length >0, and forwards it to `std::io::Stdin::read()`. The latter method returns an error if the length of the buffer is less than 4, as there might not be enough space to allocate a UTF-16 character. This creates a problem when the buffer length is in `0 < N < 4`, causing the bug.

The current modification creates an internal buffer, much like the one used for the write functions

I'd also like to acknowledge the help of ``@agausmann`` and ``@hkratz`` in detecting and isolating the bug, and for suggestions that made the fix possible.

Couple disclaimers:

- Firstly, I didn't know where to put code to replicate the bug found in the issue. It would probably be wise to add that case to the testing suite, but I'm afraid that I don't know _where_ that test should be added.
- Secondly, the code is fairly fundamental to IO operations, so my fears are that this may cause some undesired side effects ~or performance loss in benchmarks.~ The testing suite runs on my computer, and it does fix the issue noted in #91722.
- Thirdly, I left the "surrogate" field in the Stdin struct, but from a cursory glance, it seems to be serving the same purpose for other functions. Perhaps merging the two would be appropriate.

Finally, this is my first pull request to the rust language, and as such some things may be weird/unidiomatic/plain out bad. If there are any obvious improvements I could do to the code, or any other suggestions, I would appreciate them.

Edit: Closes #91722
2022-01-04 16:34:14 +01:00
Mara Bos
4300bea0c2 Formatting. 2022-01-04 16:32:39 +01:00
Mara Bos
f5217792ed Simplify panicking mechanism of thread::scope.
It now panic!()s on its own, rather than resume_unwind'ing the panic
payload from the thread. Using resume_unwind skips the panic_handler,
meaning that the main thread would never have a panic handler run, which
can get confusing.
2022-01-04 16:10:14 +01:00
Mara Bos
da33da161b Add documentation for scoped threads. 2022-01-04 16:09:53 +01:00
Mara Bos
cc699e1b62 Add ScopedJoinHandle::is_running(). 2022-01-04 15:15:41 +01:00
Mara Bos
0e24ad537b Implement RFC 3151: Scoped threads. 2022-01-04 14:51:39 +01:00
Mara Bos
a45b3ac183 Simpilfy thread::JoinInner. 2022-01-04 14:08:44 +01:00
Daniel Henry-Mantilla
f20ccc0748 Make the documentation of builtin macro attributes accessible
- Do not `#[doc(hidden)]` the `#[derive]` macro attribute

  - Add a link to the reference section to `derive`'s inherent docs

  - Do the same for `#[test]` and `#[global_allocator]`

  - Fix `GlobalAlloc` link (why is it on `core` and not `alloc`?)

  - Try `no_inline`-ing the `std` reexports from `core`

  - Revert "Try `no_inline`-ing the `std` reexports from `core`"

  - Address PR review

  - Also document the unstable macros
2022-01-03 20:43:16 +01:00
zohnannor
ca3f9048a1
Make Receiver::into_iter into a clickable link
The documentation on `std::sync::mpsc::Iter` and `std::sync::mpsc::TryIter` provides links to the corresponding `Receiver` methods, unlike `std::sync::mpsc::IntoIter` does.

This was left out in c59b188aae
Related to #29377
2022-01-03 20:17:57 +03:00
Chris Denton
4145877731
Explicitly pass PATH to the Windows exe resolver 2022-01-03 12:55:42 +00:00
Xuanwo
edae82e5e4
std: Implement try_reserve and try_reserve_exact on PathBuf
Signed-off-by: Xuanwo <github@xuanwo.io>
2022-01-03 17:35:38 +08:00
bors
7b13c628a2 Auto merge of #92482 - matthiaskrgr:rollup-uso1zi0, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #84083 (Clarify the guarantees that ThreadId does and doesn't make.)
 - #91593 (Remove unnecessary bounds for some Hash{Map,Set} methods)
 - #92297 (Reduce compile time of rustbuild)
 - #92332 (Add test for where clause order)
 - #92438 (Enforce formatting for rustc_codegen_cranelift)
 - #92463 (Remove pronunciation guide from Vec<T>)
 - #92468 (Emit an error for `--cfg=)`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-01-02 00:20:04 +00:00
Matthias Krüger
5137f7c9db
Rollup merge of #91593 - upsuper-forks:hashmap-set-methods-bound, r=dtolnay
Remove unnecessary bounds for some Hash{Map,Set} methods

This PR moves `HashMap::{into_keys,into_values,retain}` and `HashSet::retain` from `impl` blocks with `K: Eq + Hash, S: BuildHasher` into the blocks without them. It doesn't seem to me there is any reason these methods need to be bounded by that. This change brings `HashMap::{into_keys,into_values}` on par with `HashMap::{keys,values,values_mut}` which are not bounded either.
2022-01-01 22:49:48 +01:00
Matthias Krüger
30ec1f0384
Rollup merge of #84083 - ltratt:threadid_doc_tweak, r=dtolnay
Clarify the guarantees that ThreadId does and doesn't make.

The existing documentation does not spell out whether `ThreadId`s are unique during the lifetime of a thread or of a process. I had to examine the source code to realise (pleasingly!) that they're unique for the lifetime of a process. That seems worth documenting clearly, as it's a strong guarantee.

Examining the way `ThreadId`s are created also made me realise that the `as_u64` method on `ThreadId` could be a trap for the unwary on those platforms where the platform's notion of a thread identifier is also a 64 bit integer (particularly if they happen to use a similar identifier scheme to `ThreadId`). I therefore think it's worth being even clearer that there's no relationship between the two.
2022-01-01 22:49:47 +01:00
bors
dd3ac41495 Auto merge of #92396 - xfix:remove-commandenv-apply, r=Mark-Simulacrum
Remove CommandEnv::apply

It's not being used and uses unsound set_var and remove_var functions. This is an internal function that isn't exported (even with `process_internals` feature), so this shouldn't break anything.

Also see #92365. Note that this isn't the only use of those methods in standard library, so that particular pull request will need more changes than just this to work (in particular, `test_capture_env_at_spawn` is using `set_var` and `remove_var`).
2022-01-01 20:45:37 +00:00
Josh Triplett
0d55bd1100 Make tidy check for magic numbers that spell things
Remove existing problematic cases.
2021-12-31 21:13:07 -08:00
David Tolnay
d29941e724
Remove needless allocation from example code of OsString 2021-12-30 12:45:02 -08:00
David Tolnay
1f62c24d5a
Fix some copy/paste hysteresis in OsString try_reserve docs
It appears `find_max_slow` comes from the BinaryHeap docs, where the
try_reserve example is a slow implementation of find_max. It has no
relevance to this code in OsString though.
2021-12-30 12:41:26 -08:00
Konrad Borowski
14fc9dcbba Remove CommandEnv::apply
It's not being used and uses unsound set_var and remove_var
functions.
2021-12-29 10:07:44 +01:00
Xuanwo
b07ae1c4d5
Address comments
Signed-off-by: Xuanwo <github@xuanwo.io>
2021-12-29 14:02:20 +08:00
Xuanwo
9166428be1
Update library/std/src/ffi/os_str.rs
Co-authored-by: David Tolnay <dtolnay@gmail.com>
2021-12-29 13:49:39 +08:00
Xuanwo
27b92c9f98
Implement support in wtf8
Signed-off-by: Xuanwo <github@xuanwo.io>
2021-12-28 11:53:14 +08:00
Xuanwo
013fbc6187
Fix windows build
Signed-off-by: Xuanwo <github@xuanwo.io>
2021-12-28 11:40:58 +08:00
Xuanwo
c40ac57efb
Add try_reserve for OsString
Signed-off-by: Xuanwo <github@xuanwo.io>
2021-12-28 11:28:05 +08:00
AngelicosPhosphoros
4b62a77e4d Little improves in CString new when creating from slice
Old code already contain optimization for cases with `&str` and `&[u8]` args. This commit adds a specialization for `&mut[u8]` too.

Also, I added usage of old slice in search for zero bytes instead of new buffer because it produce better code for Windows on LTO builds. For other platforms, this wouldn't cause any difference because it calls `libc` anyway.

Inlined `_new` method into spec trait to reduce amount of code generated to `CString::new` callers.
2021-12-27 12:26:30 +03:00
Hiroshi Kori
7a3a668bc9 fix typo: intialized -> initialized 2021-12-26 18:37:11 -08:00
Hiroshi Kori
7ddad349b1 fix typo: the use f.pad -> then use f.pad 2021-12-26 17:44:53 -08:00
Scallop Ye
e3ad30962e
Fix a pair of mistyped test cases in std::net::ip 2021-12-26 16:41:32 +08:00
Laurence Tratt
d66a9e16ba Language tweak. 2021-12-25 15:18:55 +00:00
Matthias Krüger
40c6720620
Rollup merge of #90625 - Milo123459:ref-unwind-safe, r=dtolnay
Add `UnwindSafe` to `Once`

Fixes #43469
2021-12-23 17:48:29 +01:00
Matthias Krüger
3afed8fc70
Rollup merge of #92208 - ChrisDenton:win-bat-cmd, r=dtolnay
Quote bat script command line

Fixes #91991

[`CreateProcessW`](https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw#parameters) should only be used to run exe files but it does have some (undocumented) special handling for files with `.bat` and `.cmd` extensions. Essentially those magic extensions will cause the parameters to be automatically rewritten. Example pseudo Rust code (note that `CreateProcess` starts with an optional application name followed by the application arguments):
```rust
// These arguments...
CreateProcess(None, `@"foo.bat` "hello world""`@,` ...);
// ...are rewritten as
CreateProcess(Some(r"C:\Windows\System32\cmd.exe"), `@""foo.bat` "hello world"""`@,` ...);
```

However, when setting the first parameter (the application name) as we now do, it will omit the extra level of quotes around the arguments:

```rust
// These arguments...
CreateProcess(Some("foo.bat"), `@"foo.bat` "hello world""`@,` ...);
// ...are rewritten as
CreateProcess(Some(r"C:\Windows\System32\cmd.exe"), `@"foo.bat` "hello world""`@,` ...);
```

This means the arguments won't be passed to the script as intended.

Note that running batch files this way is undocumented but people have relied on this so we probably shouldn't break it.
2021-12-23 00:28:56 +01:00
Matthias Krüger
12e4907728
Rollup merge of #92139 - dtolnay:backtrace, r=m-ou-se
Change Backtrace::enabled atomic from SeqCst to Relaxed

This atomic is not synchronizing anything outside of its own value, so we don't need the `Acquire`/`Release` guarantee that all memory operations prior to the store are visible after the subsequent load, nor the `SeqCst` guarantee of all threads seeing all of the sequentially consistent operations in the same order.

Using `Relaxed` reduces the overhead of `Backtrace::capture()` in the case that backtraces are not enabled.

## Benchmark

```rust
#![feature(backtrace)]

use std::backtrace::Backtrace;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::thread;
use std::time::Instant;

fn main() {
    let begin = Instant::now();
    let mut threads = Vec::new();
    for _ in 0..64 {
        threads.push(thread::spawn(|| {
            for _ in 0..10_000_000 {
                let _ = Backtrace::capture();
                static LOL: AtomicUsize = AtomicUsize::new(0);
                LOL.store(1, Ordering::Release);
            }
        }));
    }
    for thread in threads {
        let _ = thread.join();
    }
    println!("{:?}", begin.elapsed());
}
```

**Before:**&ensp;6.73 seconds
**After:**&ensp;5.18 seconds
2021-12-23 00:28:54 +01:00
Matthias Krüger
554ad50fa2
Rollup merge of #92117 - solid-rs:fix-kmc-solid-read-buf, r=yaahc
kmc-solid: Add `std::sys::solid::fs::File::read_buf`

This PR adds `std::sys::solid::fs::File::read_buf` to catch up with the changes introduced by #81156 and fix the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets..
2021-12-23 00:28:53 +01:00
Chris Denton
615604f0c7
Fix tests 2021-12-22 18:31:36 +00:00
Matthias Krüger
55b494445a
Rollup merge of #92129 - RalfJung:join-handle-docs, r=jyn514
JoinHandle docs: add missing 'the'
2021-12-21 08:33:42 +01:00
Matthias Krüger
3009dd7c5a
Rollup merge of #90345 - passcod:entry-insert, r=dtolnay
Stabilise entry_insert

This stabilises `HashMap:Entry::insert_entry` etc. Tracking issue #65225. It will need an FCP.

This was implemented in #64656 two years ago.

This PR includes the rename and change discussed in https://github.com/rust-lang/rust/issues/65225#issuecomment-910652430, happy to split if needed.
2021-12-21 08:33:37 +01:00
Tomoaki Kawada
874514c7b4 kmc-solid: Add std::sys::solid::fs::File::read_buf
Catching up with commit 3b263ceb5c
2021-12-21 11:18:35 +09:00
David Tolnay
a2fd84a125
Bump insert_entry stabilization to Rust 1.59 2021-12-20 13:14:06 -08:00
David Tolnay
984b10da16
Change Backtrace::enabled atomic from SeqCst to Relaxed 2021-12-20 12:34:10 -08:00
David Tolnay
91161ed110
impl RefUnwindSafe for Once 2021-12-20 11:49:47 -08:00
Ralf Jung
fbceb7ac3b JoinHandle docs: add missing 'the' 2021-12-20 18:30:29 +01:00
Matthias Krüger
efbefb673d
Rollup merge of #92030 - rukai:stdlib2021, r=m-ou-se
Update stdlib to the 2021 edition

progress towards https://github.com/rust-lang/rust/issues/88638

I couldnt find a way to run the 2018 style panic tests against 2018 so I just deleted them, maybe theres a way to do it that I missed though?
2021-12-18 10:26:40 +01:00
Matthias Krüger
e69acdaae4
Rollup merge of #92025 - devnexen:revert-91553-anc_data_dfbsd, r=kennytm
Revert "socket ancillary data implementation for dragonflybsd."

Reverts rust-lang/rust#91553
2021-12-18 10:26:39 +01:00
Lucas Kent
b656384d83 Update stdlib to the 2021 edition 2021-12-18 00:21:53 +11:00
Jane Lusby
5b3902fc65 attempt to make Report usable with Box dyn Error and fn main 2021-12-16 16:08:30 -08:00
Jane Lusby
9be1cc9b61 more docs improvements 2021-12-16 15:34:12 -08:00
Jane Lusby
078b112d94 add a panicking example 2021-12-16 14:22:35 -08:00
Jane Lusby
4420cc33d6 Update report output and fix examples 2021-12-16 14:06:28 -08:00
David CARLIER
78a3078c3f
Revert "socket ancillary data implementation for dragonflybsd." 2021-12-16 21:32:53 +00:00
Chris Denton
de764a7ccb
Quote bat script command line 2021-12-16 17:22:32 +00:00
Matthias Krüger
b742594f4a
Rollup merge of #91947 - ibraheemdev:io-error-other, r=joshtriplett
Add `io::Error::other`

This PR adds a small utility constructor, `io::Error::other`, a shorthand for `io::Error::new(io::ErrorKind::Other, err)`, something I find myself writing often.

For some concrete stats, a quick search on [grep.app](https://grep.app) shows that more than half of the uses of `io::Error::new` use `ErrorKind::Other`:
```
Error::new\((?:std::)?(?:io::)?ErrorKind:: => 3,898 results
Error::new\((?:std::)?(?:io::)?ErrorKind::Other => 2,186 results
```
2021-12-16 17:23:10 +01:00
Ayrton
c12f7efd01 Bump compiler-builtins to 0.1.66
Adds intrinsics for truncdfsf2 and truncdfsf2vsp on ARM.
2021-12-15 21:00:06 -05:00
PFPoitras
d49d1d4499 Modifications to buffer UTF-16 internally so that there is no longer a 4-byte buffer minimum. Include suggestions from @agausmann and @Mark-Simulacrum. 2021-12-15 18:35:29 -04:00