Commit Graph

6846 Commits

Author SHA1 Message Date
Matthias Krüger
c03bf54dd1
Rollup merge of #93392 - GKFX:char-docs, r=scottmcm
Clarify documentation on char::MAX

As mentioned in https://github.com/rust-lang/rust/issues/91836#issuecomment-994106874, the documentation on `char::MAX` is not quite correct – USVs are not "only ones within a certain range", they are code points _outside_ a certain range. I have corrected this and given the actual numbers as there is no reason to hide them.
2022-01-31 06:58:32 +01:00
Matthias Krüger
76857fb3fb
Rollup merge of #93347 - WaffleLapkin:better_char_decode_utf16_size_hint, r=dtolnay
Make `char::DecodeUtf16::size_hist` more precise

New implementation takes into account contents of `self.buf` and rounds lower bound up instead of down.

Fixes #88762
Revival of #88763
2022-01-31 06:58:31 +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
bors
e58e7b10e1 Auto merge of #90891 - nbdd0121:format, r=Mark-Simulacrum
Create `core::fmt::ArgumentV1` with generics instead of fn pointer

Split from (and prerequisite of) #90488, as this seems to have perf implication.

`@rustbot` label: +T-libs
2022-01-31 00:04:46 +00:00
George Bateman
9aaf52b66a
(#93392) Update char::MAX docs and core::char::MAX 2022-01-30 23:10:24 +00:00
George Bateman
4d4ec97e0a
Document char validity 2022-01-30 22:16:41 +00:00
Simonas Kazlauskas
78efb075d9 review the total_cmp documentation
The documentation has been restructured to split out a brief summary
paragraph out from the following elaborating paragraphs.

I also attempted my hand at wording improvements and adding articles
where I felt them missing, but being non-native english speaker these
may need more thorough review.
2022-01-30 23:20:54 +02:00
Amanieu d'Antras
f738669b63 Clarify safety of PanicInfo::can_unwind 2022-01-30 21:33:51 +01:00
est31
cde240c1e8 core: Remove some redundant {}s from the sorting code 2022-01-30 18:32:24 +01: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
Samuel E. Moelius III
96d96a7ac4 Use optflag for --report-time
Essentially, what is described here:
https://github.com/rust-lang/rust/issues/64888#issuecomment-1008047228

There is one difference. The comment proposes to add a
`--report-time-color` option. This change instead uses libtest's
existing `--color` option for that purpose.
2022-01-30 10:25:40 -05:00
est31
105a7461b9 Remove deprecated and unstable slice_partition_at_index functions
They have been deprecated since commit 01ac5a97c9
which was part of the 1.49.0 release, so from the point of nightly,
11 releases ago.
2022-01-30 16:19:03 +01:00
Maybe Waffle
17cd2cd592 Fix an edge case in chat::DecodeUtf16::size_hint
There are cases, when data in the buf might or might not be an error.
2022-01-30 15:32:21 +03: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
Matthias Krüger
6e2593d343
Rollup merge of #93256 - EFanZh:patch-1, r=joshtriplett
Make `join!` description more accurate
2022-01-30 00:04:10 +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
Gary Guo
a832f5f7bc Create core::fmt::ArgumentV1 with generics instead of fn pointer 2022-01-29 13:52:19 +00: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
Matthias Krüger
37e9cb34e5
Rollup merge of #93236 - woppopo:const_nonnull_new, r=oli-obk
Make `NonNull::new` `const`

Tracking issue: #93235
2022-01-29 14:46:31 +01:00
Matthias Krüger
9e86a434a7
Rollup merge of #92274 - woppopo:const_deallocate, r=oli-obk
Add `intrinsics::const_deallocate`

Tracking issue: #79597
Related: #91884

This allows deallocation of a memory allocated by `intrinsics::const_allocate`. At the moment, this can be only used to reduce memory usage, but in the future this may be useful to detect memory leaks (If an allocated memory remains after evaluation, raise an error...?).
2022-01-29 14:46:30 +01:00
woppopo
9728cc4e26 Document about some behaviors of const_(de)allocate and add some tests. 2022-01-29 19:13:23 +09: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
27f68212ab
Rollup merge of #93404 - rust-lang:scottmcm-patch-1, r=wesleywiser
Fix a typo from #92899

Just happened to notice this in passing
2022-01-28 15:20:30 +01:00
Matthias Krüger
cfe03006b7
Rollup merge of #93356 - pierwill:partialord-headline, r=dtolnay
Edit docs introduction for `std::cmp::PartialOrd`

This makes `PartialOrd` consistent with the other three traits in this module, which all include links to their corresponding mathematical concepts on Wikipedia.

<img width="500" alt="Screen Shot 2022-01-26 at 10 24 23 PM" src="https://user-images.githubusercontent.com/19642016/151291720-decd85ed-cd6e-4be0-84a9-619b98ceb386.png">
2022-01-28 15:20:27 +01:00
Matthias Krüger
25cd639a4b
Rollup merge of #93353 - kellerkindt:saturating_int_assign_impl, r=joshtriplett
Unimpl {Add,Sub,Mul,Div,Rem,BitXor,BitOr,BitAnd}<$t> for Saturating<$t>

Tracking issue #92354

Analog to 9648b313cc #93208 reduce `saturating_int_assign_impl` (#93208) to:

```rust
let mut value = Saturating(2u8);
value += 3u8;
value -= 1u8;
value *= 2u8;
value /= 2u8;
value %= 2u8;
value ^= 255u8;
value |= 123u8;
value &= 2u8;
```

See https://github.com/rust-lang/rust/pull/93208#issuecomment-1022564429
2022-01-28 15:20:26 +01: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
Matthias Krüger
9f15c4d08b
Rollup merge of #93158 - haraldh:wasi_sock_accept, r=dtolnay
wasi: implement `sock_accept` and enable networking

With the addition of `sock_accept()` to snapshot1, simple networking via a passed `TcpListener` is possible. This PR implements the basics to make a simple server work.

See also:
* [wasmtime tracking issue](https://github.com/bytecodealliance/wasmtime/issues/3730)
* [wasmtime PR](https://github.com/bytecodealliance/wasmtime/pull/3711)

TODO:
* [ ] Discussion of `SocketAddr` return value for `::accept()`

```rust
        Ok((
            TcpStream::from_inner(unsafe { Socket::from_raw_fd(fd as _) }),
            // WASI has no concept of SocketAddr yet
            // return an unspecified IPv4Addr
            SocketAddr::new(Ipv4Addr::UNSPECIFIED.into(), 0),
        ))
```
2022-01-28 15:20:22 +01:00
Matthias Krüger
db6ca25325
Rollup merge of #92611 - Amanieu:asm-reference, r=m-ou-se
Add links to the reference and rust by example for asm! docs and lints

These were previously removed in #91728 due to broken links.

cc ``@ehuss`` since this updates the rust-by-example submodule
2022-01-28 15:20:21 +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
Amanieu d'Antras
9a814b8ba6 Update stdarch submodule 2022-01-28 12:46:22 +00: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
yuhaixin.hx
0b8c9fbf0b add allow_fail field in TestDesc to pass check 2022-01-28 19:40:49 +08:00
yuhaixin.hx
6562069ebe remove allow_fail test flag 2022-01-28 18:31:49 +08:00
Amanieu d'Antras
2188c551cd Move unstable is_{arch}_feature_detected! macros to std::arch 2022-01-28 09:51:46 +00:00
woppopo
cdd0873db6 Add a test case for using NonNull::new in const context 2022-01-28 18:41:35 +09:00
Maybe Waffle
2c97d1012e Fix wrong assumption in DecodeUtf16::size_hint
`self.buf` can contain a surrogate, but only a leading one.
2022-01-28 12:40:59 +03:00
woppopo
7a7144f413 test_const_allocate_at_runtime 2022-01-28 17:27:33 +09:00
pierwill
7c7509bc3b Edit docs introduction for std::cmp::PartialOrd
This makes `PartialOrd` consistent with the other three traits in this
module, which all include links to their respective mathematical concepts
on Wikipedia.
2022-01-28 00:46:04 -06:00
Tomoaki Kawada
da0d506ace kmc-solid: Implement FileDesc::duplicate 2022-01-28 15:02:44 +09:00
scottmcm
81b4e51c41
Fix a typo from #92899
Just happened to notice this in passing
2022-01-28 01:35:33 +00:00
George Bateman
2fb617ca0f
Clarify documentation on char::MAX 2022-01-27 22:13:01 +00:00
Matthias Krüger
54f357836e
Rollup merge of #92899 - cameron1024:zip-docs, r=dtolnay
Mention std::iter::zip in Iterator::zip docs

Closes https://github.com/rust-lang/rust/issues/91960

I'm not sure about the wording. I think it's alright, but happy to change.
2022-01-27 22:32:23 +01: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
David Tolnay
857ea1e7eb
Touch up PR 92899 Iterator::zip docs 2022-01-27 12:41:03 -08: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
Jubilee Young
cde7bdc678 Sync rust-lang/portable-simd@03f6fbb21e 2022-01-27 11:23:40 -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
cameron
f27758e8d7 mention std::iter::zip in Iterator::zip docs 2022-01-27 06:47:52 +00:00
Michael Watzko
a6c0a3d9c2 Unimpl {Add,Sub,Mul,Div,Rem,BitXor,BitOr,BitAnd}<$t> for Saturating<$t>
Analog to 9648b313cc #93208
2022-01-26 23:49:54 +01: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
Matthias Krüger
e2b2bfe10c
Rollup merge of #92256 - fee1-dead:improve-selection-err, r=oli-obk
Improve selection errors for `~const` trait bounds
2022-01-26 23:45:22 +01:00
Matthias Krüger
1dd0ac1f6a
Rollup merge of #91861 - juniorbassani:use-from-array-in-collections-examples, r=yaahc
Replace iterator-based construction of collections by `Into<T>`

Just a few quality of life improvements in the doc examples. I also removed some `Vec`s in favor of arrays.
2022-01-26 23:45:19 +01:00
Maybe Waffle
9c8cd1ff37 Add a test for char::DecodeUtf16::size_hint 2022-01-27 00:50:34 +03:00
Maybe Waffle
cd4245d318 Make char::DecodeUtf16::size_hist more precise
New implementation takes into account contents of `self.buf` and rounds
lower bound up instead of down.
2022-01-27 00:30:33 +03: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
woppopo
29932db09b const_deallocate: Don't deallocate memory allocated in an another const. Does nothing at runtime.
`const_allocate`:  Returns a null pointer at runtime.
2022-01-26 13:06:09 +09:00
Ralf Jung
53d2401f3f make Windows abort_internal Miri-compatible 2022-01-25 12:44:40 -05:00
Deadbeef
8b76cad0a7
Add a minimal working append_const_msg argument 2022-01-26 00:48:08 +11:00
Chris Denton
84c0c9d20d
Avoid double panics when using TempDir in tests 2022-01-25 10:36:10 +00:00
Michael Watzko
9648b313cc Impl {Add,Sub,Mul,Div,Rem,BitXor,BitOr,BitAnd}Assign<$t> for Wrapping<$t>
Analog to 1c0dc1810d #92356
2022-01-25 08:43:30 +01: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
EFanZh
571356c24a
Make join! description more accurate 2022-01-24 16:17:40 +08: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
woppopo
5e97fc9aa2 Make NonNull::new const 2022-01-23 23:04:39 +09:00
bors
16c1a9dd7c Auto merge of #93220 - matthiaskrgr:rollup-9bkrlk0, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #90666 (Stabilize arc_new_cyclic)
 - #91122 (impl Not for !)
 - #93068 (Fix spacing for `·` between stability and source)
 - #93103 (Tweak `expr.await` desugaring `Span`)
 - #93113 (Unify search input and buttons size)
 - #93168 (update uclibc instructions for new toolchain, add link from platforms doc)
 - #93185 (rustdoc: Make some `pub` items crate-private)
 - #93196 (Remove dead code from build_helper)

Failed merges:

 - #93188 (rustdoc: fix bump down typing search on Safari)

r? `@ghost`
`@rustbot` modify labels: rollup
2022-01-23 09:16:32 +00:00
woppopo
aa6795e2d4 Add intrinsics::const_deallocate 2022-01-23 15:13:44 +09:00
Matthias Krüger
55a1f8b955
Rollup merge of #91122 - dtolnay:not, r=m-ou-se
impl Not for !

The lack of this impl caused trouble for me in some degenerate cases of macro-generated code of the form `if !$cond {...}`, even without `feature(never_type)` on a stable compiler. Namely if `$cond` contains a `return` or `break` or similar diverging expression, which would otherwise be perfectly legal in boolean position, the code previously failed to compile with:

```console
error[E0600]: cannot apply unary operator `!` to type `!`
   --> library/core/tests/ops.rs:239:8
    |
239 |     if !return () {}
    |        ^^^^^^^^^^ cannot apply unary operator `!`
```
2022-01-23 01:09:41 +01:00
Matthias Krüger
59d9ad98b6
Rollup merge of #90666 - bdbai:arc_new_cyclic, r=m-ou-se
Stabilize arc_new_cyclic

This stabilizes feature `arc_new_cyclic` as the implementation has been merged for one year and there is no unresolved questions. The FCP is not started yet.

Closes #75861 .

``@rustbot`` label +T-libs-api
2022-01-23 01:09:40 +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
00e191c72d
Update stabilization version of arc_new_cyclic 2022-01-22 15:48:42 +00: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
Matthias Krüger
ffd199d768
Rollup merge of #85967 - atopia:update-l4re-target, r=petrochenkov
add support for the l4-bender linker on the x86_64-unknown-l4re-uclibc tier 3 target

This PR contains the work by ```@humenda``` to update support for the `x86_64-unknown-l4re-uclibc` tier 3 target (published at [humenda/rust](https://github.com/humenda/rust)), rebased and adapted to current rust in follow up commits by myself. The publishing of the rebased changes is authorized and preferred by the original author. As the goal was to distort the original work as little as possible, individual commits introduce changes that are incompatible to the newer code base that the changes were rebased on. These incompatibilities have been remedied in follow up commits, so that the PR as a whole should result in a clean update of the target.
If you prefer another strategy to mainline these changes while preserving attribution, please let me know.
2022-01-22 15:32:48 +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
Benjamin Lamowski
660d993c64 adapt L4Bender implementation
- Fix style errors.

- L4-bender does not yet support dynamic linking.

- Stack unwinding is not yet supported for x86_64-unknown-l4re-uclibc.
  For now, just abort on panics.

- Use GNU-style linker options where possible. As suggested by review:
    - Use standard GNU-style ld syntax for relro flags.
    - Use standard GNU-style optimization flags and logic.
    - Use standard GNU-style ld syntax for --subsystem.

- Don't read environment variables in L4Bender linker. Thanks to
  CARGO_ENCODED_RUSTFLAGS introduced in #9601, l4-bender's arguments can
  now be passed from the L4Re build system without resorting to custom
  parsing of environment variables.
2022-01-21 16:50:33 +01: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
Matthias Krüger
98cb33894c
Rollup merge of #89747 - Amanieu:maybeuninit_bytes, r=m-ou-se
Add MaybeUninit::(slice_)as_bytes(_mut)

This adds methods to convert between `MaybeUninit<T>` and a slice of `MaybeUninit<u8>`. This is safe since `MaybeUninit<u8>` can correctly handle padding bytes in any `T`.

These methods are added:
```rust
impl<T> MaybeUninit<T> {
	pub fn as_bytes(&self) -> &[MaybeUninit<u8>];
	pub fn as_bytes_mut(&mut self) -> &mut [MaybeUninit<u8>];
	pub fn slice_as_bytes(this: &[MaybeUninit<T>]) -> &[MaybeUninit<u8>];
	pub fn slice_as_bytes_mut(this: &mut [MaybeUninit<T>]) -> &mut [MaybeUninit<u8>];
}
```
2022-01-20 17:10:30 +01:00
Hans Kratz
0a6c9adc4a
Fix compilation for a few tier 2 targets 2022-01-20 16:35:16 +01:00
Jakob Degen
4de76184aa Remove unnecessary unsafe code in Arc deferred initialization examples. 2022-01-20 06:21:51 -05: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
David Tolnay
3136c5f752
Update stabilization version of impl Not for ! 2022-01-19 23:30:55 -08:00
bors
74fbbefea8 Auto merge of #92138 - AngelicosPhosphoros:try_smarter_vec_from_iter_48994_2, r=Mark-Simulacrum
Improve capacity estimation in Vec::from_iter

Iterates on the attempt made in #53086.

Closes #48994
2022-01-20 06:50:14 +00:00
Amanieu d'Antras
5c96dcf961 Add MaybeUninit::as_bytes 2022-01-19 21:27:29 +00:00
Amanieu d'Antras
5eb6fff824 Add links to the reference and rust by example for asm! docs and lints 2022-01-19 20:00:10 +00: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
Matthias Krüger
dfbb6b246d
Rollup merge of #92630 - steffahn:lift_bounds_on_BuildHasherDefault, r=yaahc
Change PhantomData type for `BuildHasherDefault` (and more)

Changes `PhantomData<H>` to `PhantomData<fn() -> H>` for `BuildHasherDefault`. This preserves the covariance of `H`, while it lifts the currently inferred unnecessary bounds like [`H: Send` for `BuildHasherDefault<H>: Send`](https://doc.rust-lang.org/1.57.0/std/hash/struct.BuildHasherDefault.html#impl-Send), etc.

_Edit:_ Also does a similar change for `iter::Empty` and `future::Pending`.
2022-01-19 19:19:47 +01: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
AngelicosPhosphoros
ea570c689c Improve estimation of capacity in Vec::from_iter
Closes #48994
2022-01-19 09:47:49 -05:00
Matthias Krüger
d5bc168d65
Rollup merge of #93051 - m-ou-se:is-some-with, r=yaahc
Add Option::is_some_with and Result::is_{ok,err}_with

See https://github.com/rust-lang/rust/issues/62358#issuecomment-1015827777
2022-01-19 10:42:20 +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
2a4381d8ea
Rollup merge of #89621 - digama0:patch-2, r=yaahc
doc: guarantee call order for sort_by_cached_key

`slice::sort_by_cached_key` takes a caching function `f: impl FnMut(&T) -> K`, which means that the order that calls to the caching function are made is user-visible. This adds a clause to the documentation to promise the current behavior, which is that `f` is called on all elements of the slice from left to right, unless the slice has len < 2 in which case `f` is not called.

For example, this can be used to ensure that the following code is a correct way to involve the index of the element in the sort key:
```rust
let mut index = 0;
slice.sort_by_cached_key(|x| (my_key(index, x), index += 1).0);
```
2022-01-19 10:42:13 +01:00
Mara Bos
5fee3e7a9c Fix is_some_with tests. 2022-01-19 00:12:35 +01:00
Mara Bos
45dee47fec Improve is_err_with example. 2022-01-18 22:53:43 +01:00
Mara Bos
148234ff73 Add is_some_with tracking issue number. 2022-01-18 22:18:16 +01:00
Mara Bos
aaebae973f Add Result::{is_ok_with, is_err_with}. 2022-01-18 22:17:44 +01:00
Mara Bos
282224edf1 Add Option::is_some_with. 2022-01-18 22:17:34 +01:00
Matthias Krüger
f851a849cb
Rollup merge of #93035 - Amanieu:stdarch_fix, r=Mark-Simulacrum
Fix stdarch submodule pointing to commit outside tree

PR #93016 was merged with the stdarch submodule pointing to a commit in
a PR branch and not in master. This was due to a circular dependency
between the rust and stdarch changes which would cause the other to fail
to build.

cc #75109
2022-01-18 22:00:52 +01:00
Matthias Krüger
63376bb0fa
Rollup merge of #93026 - klensy:f-typo, r=scottmcm
fix typo in `max` description for f32/f64
2022-01-18 22:00:51 +01:00
Amanieu d'Antras
3db479ed07 Fix stdarch submodule pointing to commit outside tree
PR #93016 was merged with the stdarch submodule pointing to a commit in
a PR branch and not in master. This was due to a circular dependency
between the rust and stdarch changes which would cause the other to fail
to build.

cc #75109
2022-01-18 15:25:38 +00:00
Júnior Bassani
8936659297
Replace iterator-based construction of collections by Into<T> 2022-01-18 12:18:02 -03:00
klensy
51cd00c32f fix typo in max description for f32/f64 2022-01-18 10:30:32 +03: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
6a5663ed82
Rollup merge of #92870 - llogiq:atomic_bool_sym, r=Manishearth
add `rustc_diagnostic_item` attribute to `AtomicBool` type

I wanted to use this in clippy and found that it didn't work. So hopefully this addition will fix it.
2022-01-18 04:42:04 +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
Matthias Krüger
68d47def01
Rollup merge of #92960 - scottmcm:carrying-bignum, r=Mark-Simulacrum
Use `carrying_{mul|add}` in `num::bignum`

Now that we have (unstable) methods for this, we don't need the bespoke trait methods for it in the `bignum` implementation.

cc #85532
2022-01-17 20:07:10 +01:00
Matthias Krüger
731af70217
Rollup merge of #92956 - scottmcm:nonzero-log2, r=dtolnay
Add `log2` and `log10` to `NonZeroU*`

This version is nice in that it doesn't need to worry about zeros, and thus doesn't have any error cases.

cc `int_log` tracking issue #70887

(I didn't add them to `NonZeroI*` despite it being on `i*` since allowing negatives bring back the error cases again.)
2022-01-17 20:07:09 +01: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
Matthias Krüger
9612038a7e
Rollup merge of #92981 - RalfJung:const_ptr_offset_from, r=dtolnay
fix const_ptr_offset_from tracking issue

The old tracking issue #41079 was for exposing those functions at all, and got closed when they were stabilized. We had nothing tracking their `const`ness so I opened a new tracking issue: https://github.com/rust-lang/rust/issues/92980.
2022-01-17 06:08:19 +01:00
Matthias Krüger
7bdd978c24
Rollup merge of #92977 - kornelski:popdoc, r=dtolnay
Docs: recommend VecDeque instead of Vec::remove(0)

Suggestion based on a [discussion](https://internals.rust-lang.org/t/should-vec-have-a-try-remove-mut-self-usize-option-t-function/15964/9?u=kornel) where user needlessly struggled with `remove(0)` and accidentally created a quadratic cost.
2022-01-17 06:08:18 +01:00
Matthias Krüger
775fe37ca9
Rollup merge of #92953 - azdavis:azdavis-copy-example, r=dtolnay
Copy an example to PartialOrd as well

In https://github.com/rust-lang/rust/pull/88202 I added an example for deriving PartialOrd on enums, but only later did I realize that I actually put the example on Ord.

This copies the example to PartialOrd as well, which is where I intended for it to be.

We could also delete the example on Ord, but I see there's already some highly similar examples shared between Ord and PartialOrd, so I figured we could leave it.

I also changed some type annotations in an example from `x : T` to the more common style (in Rust) of `x: T`.
2022-01-17 06:08:17 +01:00
Kornel
c2807525a5 Help optimize out backtraces when disabled 2022-01-17 02:21:24 +00:00
Amanieu d'Antras
fe9dc6e62a Change TerminatorKind::Abort to call the panic handler instead of
aborting immediately.

The panic handler is called with a special flag which forces it to abort
after calling the panic hook.
2022-01-17 00:39:34 +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
Ralf Jung
bb1423e019 fix const_ptr_offset_from tracking issue 2022-01-16 15:21:42 -05:00
Kornel
361ef2aadc Docs: recommend VecDeque instead of Vec::remove(0) 2022-01-16 17:53:05 +00:00
Matthias Krüger
039d6dc289
Rollup merge of #92706 - umanwizard:btree, r=dtolnay
Clarify explicitly that BTree{Map,Set} are ordered.

One of the main reasons one would want to use a BTree{Map,Set} rather than a Hash{Map,Set} is because they maintain their keys in sorted order; but this was never explicitly stated in the top-level docs (it was only indirectly alluded to there, and stated explicitly in the docs for `iter`, `values`, etc.)

This PR states the ordering guarantee more prominently.
2022-01-16 16:58:16 +01: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
26c06cf8e2 Auto merge of #92356 - kellerkindt:saturating_int_assign_impl, r=dtolnay
Add {Add,Sub,Mul,Div,Rem,BitXor,BitOr,BitAnd}{,Assign}<$t> to Saturat…

Tracking issue #92354
2022-01-16 05:23:44 +00:00
David Tolnay
bfe0a4e06e
Touch up stray comment in PR 92953 2022-01-15 20:44:47 -08:00
Ariel Davis
828febf9e0 Clear up discriminants with more examples 2022-01-15 20:24:38 -08:00
Scott McMurray
e0e15c9747 Use carrying_{mul|add} in num::bignum
Now that we have (unstable) methods for this, we don't need the bespoke trait methods for it in the `bignum` implementation.
2022-01-15 20:22:34 -08:00
David Tolnay
ad6408dd7a
Tweak btree iterator wording to not use 'yield'
Yield means something else in the context of generators, which are
sufficiently close to iterators that it's better to avoid the
terminology collision here.
2022-01-15 19:28:21 -08: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
Scott McMurray
3dfcc66d48 Add log2 and log10 to NonZeroU*
This version is nice in that it doesn't need to worry about zeros, and thus doesn't have any error cases.
2022-01-15 17:14:13 -08:00
Ariel Davis
8f33b4eed1 Copy an example to PartialOrd as well 2022-01-15 16:25:09 -08:00
Matthias Krüger
784e4ba9a4
Rollup merge of #92879 - compiler-errors:into_iter_unsound, r=dtolnay
Add Sync bound to allocator parameter in vec::IntoIter

The `A: Sync` bound was forgotten in 8725e4c337 (diff-b78c3ab6d37f4ede32195707528f8a76c49d4557cc9d3a7a09417b5157729b9fR3132)

Similar `unsafe impl Sync` in that commit _do_ include the `A: Sync` bound (and around the alloc lib), so I think this was just an honest mistake.

Here's an example of the unsoundness:  https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=16cbfeff7c934ae72ab632c1476fdd8b

`@steffahn` found this, I'm just putting up the fix cause nobody else did :^)

Fixes #92633
2022-01-15 11:28:27 +01: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
f511360fd2
Rollup merge of #92747 - swenson:bignum-bit-length-optimization, r=scottmcm
Simplification of BigNum::bit_length

As indicated in the comment, the BigNum::bit_length function could be
optimized by using CLZ, which is often a single instruction instead a
loop.

I think the code is also simpler now without the loop.

I added some additional tests for Big8x3 and Big32x40 to ensure that
there were no regressions.
2022-01-15 11:28:22 +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
1d9ab77eb7
Rollup merge of #92382 - clarfonthey:const_convert, r=scottmcm
Extend const_convert to rest of blanket core::convert impls

This adds constness to all the blanket impls in `core::convert` under the existing `const_convert` feature, tracked by #88674.

Existing impls under that feature:

```rust
impl<T> const From<T> for T;
impl<T, U> const Into<U> for T where U: ~const From<T>;

impl<T> const ops::Try for Option<T>;
impl<T> const ops::FromResidual for Option<T>;

impl<T, E> const ops::Try for Result<T, E>;
impl<T, E, F> const ops::FromResidual<Result<convert::Infallible, E>> for Result<T, F> where F: ~const From<E>;
```

Additional impls:

```rust
impl<T: ?Sized, U: ?Sized> const AsRef<U> for &T where T: ~const AsRef<U>;
impl<T: ?Sized, U: ?Sized> const AsRef<U> for &mut T where T: ~const AsRef<U>;
impl<T: ?Sized, U: ?Sized> const AsMut<U> for &mut T where T: ~const AsMut<U>;

impl<T, U> const TryInto<U> for T where U: ~const TryFrom<T>;
impl<T, U> const TryFrom<U> for T where U: ~const Into<T>;
```
2022-01-15 02:25:14 +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
Michael Goulet
7debb5c785 Add Sync bound to allocator parameter in vec::IntoIter 2022-01-13 20:55:21 -08:00
Andre Bogus
5431d5b58e Add rustc_diagnostic_item attribute to AtomicBool 2022-01-13 23:32:49 +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
Matthias Krüger
677f8f0f4f
Rollup merge of #92328 - camelid:sentence, r=scottmcm
Tweak sentence in `transmute` docs
2022-01-12 07:12:05 +01:00
Brennan Vincent
65d47347ad Address review comments 2022-01-11 12:08:46 -07: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
Christopher Swenson
0589cace8c Simplify BigNum::bit_length() with log2()
Thank you to @scottmcm for suggesting the handy `log2()` function.
2022-01-10 15:31:11 -08: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
Christopher Swenson
424f38f211 Simplification of BigNum::bit_length
As indicated in the comment, the BigNum::bit_length function could be
optimized by using CLZ, which is often a single instruction instead a
loop.

I think the code is also simpler now without the loop.

I added some additional tests for Big8x3 and Big32x40 to ensure that
there were no regressions.
2022-01-10 14:18:28 -08: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
Brennan Vincent
9057a6d66a Clarify explicitly that BTree{Map,Set} are ordered. 2022-01-09 18:01:44 -05: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
Matthias Krüger
0871a38adf
Rollup merge of #92671 - WaffleLapkin:atomic_from_mut_unique_ref, r=m-ou-se
Make `Atomic*::from_mut` return `&mut Atomic*`

```rust
impl Atomic* {
    pub fn from_mut(v: &mut bool) -> &mut Self;
    //                               ^^^^---- previously was just a &
}
```

This PR makes `from_mut` atomic methods tracked in #76314 return unique references to atomic types, instead of shared ones. This makes `from_mut` and `get_mut` inverses of each other, allowing to undo either of them by the other.

r? `@RalfJung`
(as Ralf was [concerned](https://github.com/rust-lang/rust/issues/76314#issuecomment-955062593) about this)
2022-01-09 13:38:33 +01:00
Matthias Krüger
295ef3a336
Rollup merge of #92657 - Kixunil:ptr_as_const_mut, r=m-ou-se
Implemented const casts of raw pointers

This adds `as_mut()` method for `*const T` and `as_const()` for `*mut T`
which are intended to make casting of consts safer. This was discussed
in the [internals discussion][discussion].

Given that this is a simple change and multiple people agreed to it including `@RalfJung` I decided to go ahead and open the PR.

[discussion]: https://internals.rust-lang.org/t/casting-constness-can-be-risky-heres-a-simple-fix/15933
2022-01-09 13:38:33 +01: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
bors
23ce5fc465 Auto merge of #92068 - fee1-dead:libcore2021, r=m-ou-se
Switch all libraries to the 2021 edition

The fix for https://github.com/rust-lang/rust/issues/88638#issuecomment-996620107 is to simply add const-stability for these functions.

r? `@m-ou-se`

Closes #88638.
2022-01-08 21:41:48 +00:00
Martin Habovstiak
1a96623513 Implemented const casts of raw pointers
This adds `as_mut()` method for `*const T` and `as_const()` for `*mut T`
which are intended to make casting of consts safer. This was discussed
in the [internals discussion][discussion].

[discussion]: https://internals.rust-lang.org/t/casting-constness-can-be-risky-heres-a-simple-fix/15933
2022-01-08 18:04:51 +01: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
Maybe Waffle
2b03ed19f6 Make Atomic*::from_mut return &mut Atomic* 2022-01-08 16:57:20 +03: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
Eric Huss
d43c9ad5d3
Rollup merge of #92600 - asquared31415:float-must-use, r=joshtriplett
Add some missing `#[must_use]` to some `f{32,64}` operations

This PR adds `#[must_use]` to the following methods:
 - `f32::recip`
 - `f32::max`
 - `f32::min`
 - `f32::maximum`
 - `f32::minimum`
 and their equivalents in `f64`.
 These methods all produce a new value without modifying the original and so are pointless to call without using the result.
2022-01-07 20:21:00 -08:00
Eric Huss
0bd7e2ff2e
Rollup merge of #92568 - Mark-Simulacrum:non-exhaustive-variant-count, r=the8472
Add note about non_exhaustive to variant_count

Since `variant_count` isn't returning something opaque, I thought it makes sense to explicitly call out that its return value may change for some enums.

cc #73662
2022-01-07 20:20:59 -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
Frank Steffahn
731bbae816 Also change PhantomData parameter of iter::Empty, and future::Pending 2022-01-07 01:53:51 +01:00
Yoshua Wuyts
3632f41c78 Stabilize #[feature(available_parallelism)] 2022-01-07 01:07:10 +01:00
Frank Steffahn
a043acd0b2 change PhantomData type for BuildHasherDefault 2022-01-07 00:39:48 +01:00
Matthias Krüger
fcae1d64d9
Rollup merge of #92620 - steffahn:remove_unused_ExtendDefault_struct, r=Mark-Simulacrum
Remove unused `ExtendDefault` struct

As noted in https://github.com/rust-lang/rust/pull/77850#issuecomment-1002272054, this struct is no longer used.
2022-01-06 23:15:23 +01:00
Frank Steffahn
d5d752ab1e remove unused ExtendDefault struct 2022-01-06 18:49:55 +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
asquared31415
dd364ed226 add some missing must use to float ops 2022-01-06 00:20:58 -05: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
Matthias Krüger
c570fcb0c4
Rollup merge of #92574 - luojia65:riscv-kernel-dev-rust, r=Amanieu
Add RISC-V detection macro and more architecture instructions

This pull request includes:

- Update `stdarch` dependency to include ratified RISC-V supervisor and hypervisor instruction intrinsics which is useful in Rust kernel development
- Add macro `is_riscv_feature_detected!`
- Modify impl of `core::hint::spin_loop` to comply with latest version of `core::arch`

After this update, users may now develop RISC-V kernels and user applications more freely.

r? `@Amanieu`
2022-01-05 15:05:48 +01:00
Matthias Krüger
051d591edf
Rollup merge of #92483 - ksqsf:master, r=dtolnay
Stabilize `result_cloned` and `result_copied`

Tracking issue: #63168

The FCP is now completed.
2022-01-05 15:05:47 +01:00
Matthias Krüger
84e48a41d3
Rollup merge of #92388 - SpriteOvO:master, r=Mark-Simulacrum
Fix a minor mistake in `String::try_reserve_exact` examples

The examples of `String::try_reserve_exact` didn't actually use `try_reserve_exact`, which was probably a minor mistake, and this PR fixed it.
2022-01-05 15:05:45 +01:00
Matthias Krüger
56d11a446b
Rollup merge of #92092 - saethlin:fix-sort-guards-sb, r=danielhenrymantilla
Drop guards in slice sorting derive src pointers from &mut T, which is invalidated by interior mutation in comparison

I tried to run https://github.com/rust-lang/miri-test-libstd on `alloc` with `-Zmiri-track-raw-pointers`, and got a failure on the test `slice::panic_safe`. The test failure has nothing to do with panic safety, it's from how the test tests for panic safety.

I minimized the test failure into this very silly program:
```rust
use std::cell::Cell;
use std::cmp::Ordering;

#[derive(Clone)]
struct Evil(Cell<usize>);

fn main() {
    let mut input = vec![Evil(Cell::new(0)); 3];

    // Hits the bug pattern via CopyOnDrop in core
    input.sort_unstable_by(|a, _b| {
        a.0.set(0);
        Ordering::Less
    });

    // Hits the bug pattern via InsertionHole in alloc
    input.sort_by(|_a, b| {
        b.0.set(0);
        Ordering::Less
    });
}
```

To fix this, I'm just removing the mutability/uniqueness where it wasn't required.
2022-01-05 15:05:44 +01: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
Matthias Krüger
a0262fdf1f
Rollup merge of #92322 - alper:add_debug_trait_documentation, r=dtolnay
Add another implementation example to Debug trait

As per the discussion in: #92276
2022-01-05 11:26:05 +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
Mario Carneiro
06b17a2181
Clarify that ordering is unspecified 2022-01-04 21:32:20 -08:00
Mark Rousskov
57b59af9fb Add note about non_exhaustive to variant_count 2022-01-04 21:58:36 -05:00
bors
5883b87563 Auto merge of #92560 - matthiaskrgr:rollup-jeli7ip, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #91587 (core::ops::unsize: improve docs for DispatchFromDyn)
 - #91907 (Allow `_` as the length of array types and repeat expressions)
 - #92515 (RustWrapper: adapt for an LLVM API change)
 - #92516 (Do not use deprecated -Zsymbol-mangling-version in bootstrap)
 - #92530 (Move `contains` method of Option and Result lower in docs)
 - #92546 (Update books)
 - #92551 (rename StackPopClean::None to Root)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-01-04 23:01:49 +00:00
David Tolnay
4df1a5561a
Touch up Debug example from PR 92322 2022-01-04 14:28:28 -08:00
Matthias Krüger
af49d81e04
Rollup merge of #92530 - dtolnay:contains, r=yaahc
Move `contains` method of Option and Result lower in docs

Follow-up to #92444 trying to get the `Option` and `Result` rustdocs in better shape.

This addresses the request in https://github.com/rust-lang/rust/issues/62358#issuecomment-645676285. The `contains` methods are previously too high up in the docs on both `Option` and `Result` &mdash; stuff like `ok` and `map` and `and_then` should all be featured higher than `contains`. All of those are more ubiquitously useful than `contains`.
2022-01-04 21:23:10 +01:00
Matthias Krüger
d49c692eeb
Rollup merge of #91587 - nrc:dispatchfromdyn-docs, r=yaahc
core::ops::unsize: improve docs for DispatchFromDyn

Docs-only PR, improves documentation for DispatchFromDyn.
2022-01-04 21:23:05 +01:00
Mario Carneiro
b9f008b1ee
Update wording 2022-01-04 12:18:54 -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
c7125ba0fa
Rollup merge of #91884 - woppopo:const_box, r=oli-obk
Constify `Box<T, A>` methods

Tracking issue: none yet

Most of the methods bounded on `~const`. `intrinsics::const_eval_select` is used for handling an allocation error.

<details><summary>Constified API</summary>

```rust
impl<T, A: Allocator> Box<T, A> {
    pub const fn new_in(x: T, alloc: A) -> Self
    where
        A: ~const Allocator + ~const Drop;
    pub const fn try_new_in(x: T, alloc: A) -> Result<Self, AllocError>
    where
        T: ~const Drop,
        A: ~const Allocator + ~const Drop;
    pub const fn new_uninit_in(alloc: A) -> Box<mem::MaybeUninit<T>, A>
    where
        A: ~const Allocator + ~const Drop;
    pub const fn try_new_uninit_in(alloc: A) -> Result<Box<mem::MaybeUninit<T>, A>, AllocError>
    where
        A: ~const Allocator + ~const Drop;
    pub const fn new_zeroed_in(alloc: A) -> Box<mem::MaybeUninit<T>, A>
    where
        A: ~const Allocator + ~const Drop;
    pub const fn try_new_zeroed_in(alloc: A) -> Result<Box<mem::MaybeUninit<T>, A>, AllocError>
    where
        A: ~const Allocator + ~const Drop;
    pub const fn pin_in(x: T, alloc: A) -> Pin<Self>
    where
        A: 'static,
        A: 'static + ~const Allocator + ~const Drop,
    pub const fn into_boxed_slice(boxed: Self) -> Box<[T], A>;
    pub const fn into_inner(boxed: Self) -> T
    where
        Self: ~const Drop,
}

impl<T, A: Allocator> Box<MaybeUninit<T>, A> {
    pub const unsafe fn assume_init(self) -> Box<T, A>;
    pub const fn write(mut boxed: Self, value: T) -> Box<T, A>;
    pub const unsafe fn from_raw_in(raw: *mut T, alloc: A) -> Self;
    pub const fn into_raw_with_allocator(b: Self) -> (*mut T, A);
    pub const fn into_unique(b: Self) -> (Unique<T>, A);
    pub const fn allocator(b: &Self) -> &A;
    pub const fn leak<'a>(b: Self) -> &'a mut T
    where
        A: 'a;
    pub const fn into_pin(boxed: Self) -> Pin<Self>
    where
        A: 'static;
}

unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> const Drop for Box<T, A>;
impl<T: ?Sized, A: Allocator> const From<Box<T, A>> for Pin<Box<T, A>>
where
    A: 'static;
impl<T: ?Sized, A: Allocator> const Deref for Box<T, A>;
impl<T: ?Sized, A: Allocator> const DerefMut for Box<T, A>;
impl<T: ?Sized, A: Allocator> const Unpin for Box<T, A> where A: 'static;
```

</details>

<details><summary>Example</summary>

```rust
pub struct ConstAllocator;

unsafe impl const Allocator for ConstAllocator {
    fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
        unsafe {
            let ptr = core::intrinsics::const_allocate(layout.size(), layout.align());
            Ok(NonNull::new_unchecked(ptr as *mut [u8; 0] as *mut [u8]))
        }
    }

    unsafe fn deallocate(&self, _ptr: NonNull<u8>, _layout: Layout) {
        /* do nothing */
    }

    fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
        self.allocate(layout)
    }

    unsafe fn grow(
        &self,
        _ptr: NonNull<u8>,
        _old_layout: Layout,
        _new_layout: Layout,
    ) -> Result<NonNull<[u8]>, AllocError> {
        unimplemented!()
    }

    unsafe fn grow_zeroed(
        &self,
        _ptr: NonNull<u8>,
        _old_layout: Layout,
        _new_layout: Layout,
    ) -> Result<NonNull<[u8]>, AllocError> {
        unimplemented!()
    }

    unsafe fn shrink(
        &self,
        _ptr: NonNull<u8>,
        _old_layout: Layout,
        _new_layout: Layout,
    ) -> Result<NonNull<[u8]>, AllocError> {
        unimplemented!()
    }

    fn by_ref(&self) -> &Self
    where
        Self: Sized,
    {
        self
    }
}

#[test]
fn const_box() {
    const VALUE: u32 = {
        let mut boxed = Box::new_in(1u32, ConstAllocator);
        assert!(*boxed == 1);

        *boxed = 42;
        assert!(*boxed == 42);

        *boxed
    };

    assert!(VALUE == 42);
}
```

</details>
2022-01-04 16:34:14 +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