Commit graph

7896 commits

Author SHA1 Message Date
Mara Bos
9299e6915d Round timeouts up to infinite in futex_wait on DragonFlyBSD. 2022-05-03 12:37:52 +02:00
Mara Bos
8ee9b93c4f Add #[cfg] in cfg_if for linux in unix/futex. 2022-05-03 12:37:52 +02:00
Mara Bos
7b7d1d6c48 Don't use futexes on netbsd.
The latest NetBSD release doesn't include the futex syscall yet.
2022-05-03 12:26:17 +02:00
Yoshiki Matsuda
3d12fd0faf ignore a doctest for the non-exported macro 2022-05-03 18:33:56 +09:00
Yonggang Luo
2e69549043
Update library/core/src/ffi/mod.rs
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2022-05-03 10:42:46 +08:00
The 8472
a68a5d219d This aligns the inline attributes of existing __iterator_get_unchecked with those of next() on adapters that have both.
It improves the performance of iterators using unchecked access when building in incremental mode
(due to the larger CGU count?). It might negatively affect incremental compile times for better runtime results,
but considering that the equivalent `next()` implementations also are `#[inline]` and usually are more complex this
should be ok.

```
./x.py bench library/core -i --stage 0 --test-args bench_trusted_random_access

OLD: 119,172 ns/iter
NEW:  17,714 ns/iter
```
2022-05-02 20:54:46 +02:00
The 8472
e3db41bf97 add benchmark 2022-05-02 20:54:46 +02:00
Adrian Palacios
9b36a47831 Fix typo in offset_from documentation 2022-05-02 14:41:21 +00:00
Pyry Kontio
dea776512b Fix nits 2022-05-02 23:29:02 +09:00
bors
6b6c1ffacc Auto merge of #96596 - scottmcm:limited-calloc, r=Mark-Simulacrum
Tweak the vec-calloc runtime check to only apply to shortish-arrays

r? `@Mark-Simulacrum`

`@nbdd0121` pointed out in https://github.com/rust-lang/rust/pull/95362#issuecomment-1114085395 that LLVM currently doesn't constant-fold the `IsZero` check for long arrays, so that seems like a reasonable justification for limiting it.

It appears that it's based on length, not byte size, (https://godbolt.org/z/4s48Y81dP), so that's what I used in the PR.  Maybe it's a ["the number of inlining shall be three"](https://youtu.be/s4wnuiCwTGU?t=320) sort of situation.

Certainly there's more that could be done here -- that generated code that checks long arrays byte-by-byte is highly suboptimal, for example -- but this is an easy, low-risk tweak.
2022-05-02 09:05:22 +00:00
Thom Chiovoloni
0812759840
Avoid use of rand::thread_rng in stdlib benchmarks 2022-05-02 00:08:21 -07:00
Scott McMurray
2830dbd64f Tweak the calloc optimization to only apply to shortish-arrays 2022-05-01 22:28:11 -07:00
Austin Kiekintveld
55a7d18189 Add comment 2022-05-01 19:07:36 -07:00
Austin Kiekintveld
a05df2ea19 Fix formatting 2022-05-01 19:02:28 -07:00
Yuki Okushi
ab1ae48cce
Rollup merge of #96568 - EliasHolzmann:fmt_doc_fixes, r=joshtriplett
std::fmt: Various fixes and improvements to documentation

This PR contains the following changes:

- **Added argument index comments to examples for specifying precision**

  The examples for specifying the precision have comments explaining which
  argument the specifier is referring to. However, for implicit positional
  arguments, the examples simply refer to "next arg". To simplify following the
  comments, "next arg" was supplemented with the actual resulting argument index.

- **Fixed documentation for specifying precision via `.*`**

  The documentation stated that in case of the syntax `{<arg>:<spec>.*}`, "the
  `<arg>` part refers to the value to print, and the precision must come in the
  input preceding `<arg>`". This is not correct: the <arg> part does indeed refer
  to the value to print, but the precision does not come in the input preciding
  arg, but in the next implicit input (as if specified with {}).

  Fixes #96413.

- **Fix the grammar documentation**

  According to the grammar documented, the format specifier `{: }` should not be
  legal because of the whitespace it contains. However, in reality, this is
  perfectly fine because the actual implementation allows spaces before the
  closing brace. Fixes #71088.

  Also, the exact meaning of most of the terminal symbols was not specified, for
  example the meaning of `identifier`.

- **Removed reference to Formatter::buf and other private fields**

  Formatter::buf is not a public field and therefore isn't very helpful in user-
  facing documentation. Also, the other public fields of Formatter were removed
  during stabilization of std::fmt (4af3494bb0) and can only be accessed via
  getters.

- **Improved list of formatting macros**

  Two improvements:
  1. write! can not only receive a `io::Write`, but also a `fmt::Write` as first argument.
  2. The description texts now contain links to the actual macros for easier
     navigation.
2022-05-02 10:41:58 +09:00
Yuki Okushi
f58135449e
Rollup merge of #96567 - alex-semenyuk:fix_docs_for_logs_func, r=Mark-Simulacrum
Fix docs for u32 and i32 logs func

Closes #96545
2022-05-02 10:41:57 +09:00
Yuki Okushi
1785f1549c
Rollup merge of #96222 - jmaargh:john-mark/clarify-from-raw-parts-docs, r=JohnTitor
Clarify docs for `from_raw_parts` on `Vec` and `String`

Closes #95427

Original safety explanation for `from_raw_parts` was unclear on safety for consuming a C string. This clarifies when doing so is safe.
2022-05-02 10:41:55 +09:00
Yuki Okushi
ddfc65dae0
Rollup merge of #94126 - ssomers:alloc_prep_1, r=Mark-Simulacrum
Classify BinaryHeap & LinkedList unit tests as such

All but one of these so-called integration test case are unit tests, just like btree's were (#75531). In addition, reunite the unit tests of linked_list that were split off during #23104 because they needed to remain unit tests (they were later moved to the separate file they are in during #63207). The two sets could remain separate files, but I opted to merge them back together, more or less in the order they used to be, apart from one duplicate name `test_split_off` and one duplicate tiny function `list_from`.
2022-05-02 10:41:54 +09:00
Austin Kiekintveld
df4457e20b
Relax memory ordering used in SameMutexCheck
`SameMutexCheck` only requires atomicity for `self.addr`, but does not need ordering of other memory accesses in either the success or failure case. Using `Relaxed`, the code still correctly handles the case when two threads race to store an address.
2022-05-01 16:46:19 -07:00
Austin Kiekintveld
63a90efe2f
Relax memory ordering used in min_stack
`min_stack` does not provide any synchronization guarantees to its callers, and only requires atomicity for `MIN` itself, so relaxed memory ordering is sufficient.
2022-05-01 15:55:54 -07:00
bors
4dd8b420c0 Auto merge of #96521 - petrochenkov:docrules, r=notriddle,GuillaumeGomez
rustdoc: Resolve doc links referring to `macro_rules` items

cc https://github.com/rust-lang/rust/issues/81633

UPD: the fallback to considering *all* `macro_rules` in the crate for unresolved names is not removed in this PR, it will be removed separately and will be run through crater.
2022-05-01 20:28:10 +00:00
Loïc BRANSTETT
a98abe83eb Improve codegen of String::retain method.
Using unwrap_unchecked helps the optimizer to not generate panicking
path, that will never be taken for valid UTF-8 like string.

Using encode_utf8 saves us a call to a memcpy, as the optimizer is
unable to realize that ch_len <= 4 and so can generate much better
assembly code.

https://rust.godbolt.org/z/z73ohenfc
2022-05-01 19:25:14 +02:00
Elias Holzmann
f3b86c37eb std::fmt: Improved list of formatting macros
Two improvements:
1. write! can not only receive a `io::Write`, but also a `fmt::Write` as first argument.
2. The description texts now contain links to the actual macros for easier
   navigation.
2022-05-01 15:27:41 +02:00
Elias Holzmann
c70f3ab5e5 std::fmt: Removed reference to Formatter::buf and other private fields
Formatter::buf is not a public field and therefore isn't very helpful in user-
facing documentation. Also, the other public fields of Formatter were made
private during stabilization of std::fmt (4af3494bb0) and can now only be read
via accessor methods.
2022-05-01 15:27:41 +02:00
Elias Holzmann
79d9afda13 std::fmt: Fix the grammar documentation
According to the grammar documented, the format specifier `{: }` should not be
legal because of the whitespace it contains. However, in reality, this is
perfectly fine because the actual implementation allows spaces before the
closing brace. Fixes #71088.

Also, the exact meaning of most of the terminal symbols was not specified, for
example the meaning of `identifier`.
2022-05-01 15:27:41 +02:00
Elias Holzmann
afd80a21b0 std::fmt: Added argument index comments to examples for specifying precision
The examples for specifying the precision have comments explaining which
argument the specifier is referring to. However, for implicit positional
arguments, the examples simply talk about "next arg". To make it easier for
readers to follow the comments, "next arg" was supplemented with the actual
resulting argument index.
2022-05-01 15:27:40 +02:00
Elias Holzmann
1288883932 std::fmt: Fixed documentation for specifying precision via .*
The documentation stated that in case of the syntax `{<arg>:<spec>.*}`, "the
`<arg>` part refers to the value to print, and the precision must come in the
input preceding `<arg>`". This is not correct: the <arg> part does indeed refer
to the value to print, but the precision does not come in the input preciding
arg, but in the next implicit input (as if specified with {}).

Fixes #96413.
2022-05-01 15:26:15 +02:00
bors
508e0584e3 Auto merge of #96376 - scottmcm:do-yeet, r=oli-obk
Add `do yeet` expressions to allow experimentation in nightly

Two main goals for this:
- Ensure that trait restructuring in https://github.com/rust-lang/rust/issues/84277#issuecomment-1066120333 doesn't accidentally close us off from the possibility of doing this in future, as sketched in https://rust-lang.github.io/rfcs/3058-try-trait-v2.html#possibilities-for-yeet
- Experiment with the *existence* of syntax for this, to be able to weight the syntax-vs-library tradeoffs better than we can right now.  Notably the syntax (with `do`) and name in this PR are not intended as candidates for stabilization, but they make a good v0 PR for adding this with minimal impact to compiler maintenance or priming one possible name choice over another.

r? `@oli-obk`
The lang `second` for doing this: https://github.com/rust-lang/lang-team/issues/160#issuecomment-1107896716

Tracking issues
- Lang, https://github.com/rust-lang/rust/issues/96373
- Libs-api, https://github.com/rust-lang/rust/issues/96374
2022-05-01 13:10:21 +00:00
bors
f75d884046 Auto merge of #96078 - udoprog:refcounted-str-to-u8, r=dtolnay
Implement str to [u8] conversion for refcounted containers

This seems motivated to complete the APIs for shared containers since we already have similar allocation-free conversions for strings like `From<Box<[u8]>> for Box<str>`.

Insta-stable since it's a new trait impl?
2022-05-01 06:41:59 +00:00
David Tolnay
100006bec9
Bump shared_from_str to Rust 1.62.0 2022-04-30 23:40:35 -07:00
bors
61469b682c Auto merge of #96490 - dtolnay:writetmpbackport, r=Mark-Simulacrum
Make [e]println macros eagerly drop temporaries (for backport)

This PR extracts the subset of #96455 which is only the parts necessary for fixing the 1.61-beta regressions in #96434.

My larger PR #96455 contains a few other changes relative to the pre-#94868 behavior; those are not necessary to backport into 1.61.

argument position | before #94868 | after #94868 | after this PR
--- |:---:|:---:|:---:
`write!($tmp, "…", …)` | 😡 | 😡 | 😡
`write!(…, "…", $tmp)` | 😡 | 😡 | 😡
`writeln!($tmp, "…", …)` | 😡 | 😡 | 😡
`writeln!(…, "…", $tmp)` | 😡 | 😡 | 😡
`print!("…", $tmp)` | 😡 | 😡 | 😡
`println!("…", $tmp)` | 😺 | 😡 | 😺
`eprint!("…", $tmp)` | 😡 | 😡 | 😡
`eprintln!("…", $tmp)` | 😺 | 😡 | 😺
`panic!("…", $tmp)` | 😺 | 😺 | 😺
2022-05-01 03:18:53 +00:00
bors
bf611439e3 Auto merge of #95362 - scottmcm:calloc-arrays, r=Mark-Simulacrum
Support arrays of zeros in Vec's __rust_alloc_zeroed optimization

I happened to notice in https://users.rust-lang.org/t/any-advantage-of-box-u64-16-16-16-over-vec-u64/73500/3?u=scottmcm that the calloc optimization wasn't applying to vectors-of-arrays, so here's the easy fix for that.
2022-05-01 00:50:46 +00:00
Scott McMurray
e094ee5f10 Add do yeet expressions to allow experimentation in nightly
Using an obviously-placeholder syntax.  An RFC would still be needed before this could have any chance at stabilization, and it might be removed at any point.

But I'd really like to have it in nightly at least to ensure it works well with try_trait_v2, especially as we refactor the traits.
2022-04-30 17:40:27 -07:00
Vadim Petrochenkov
6083db7c4e Fix some links in the standard library 2022-05-01 00:02:34 +03:00
julio
15386dcb6e add aliases for std::fs::canonicalize 2022-04-30 11:02:22 -07:00
bors
579d26876d Auto merge of #96348 - overdrivenpotato:inline-location, r=the8472
Inline core::panic::Location methods

This avoids the overhead of a function call when used.
2022-04-30 16:33:12 +00:00
alexey semenyuk
6ee70bc6b3
Fix documentation for log functions int 2022-04-29 23:21:50 +00:00
alexey semenyuk
ec90f9dd33
Fix documentation for log functions unsigned int 2022-04-29 23:16:53 +00:00
Mara Bos
1b9c7e6f1a Disable pthread thread parker on futex platforms. 2022-04-29 16:45:17 +02:00
Mara Bos
c4c69143a9 Always return false in futex_wake on {Free,DragonFly}BSD. 2022-04-29 16:45:17 +02:00
Mara Bos
0b4df22f55 Update libc dependency of std to 0.2.125. 2022-04-29 16:45:17 +02:00
Mara Bos
04b0bc97bb Use futex-based locks and thread parker on FreeBSD. 2022-04-29 16:45:17 +02:00
bors
f1d8a7d662 Auto merge of #96489 - shepmaster:revert-vec-from-array-ref, r=yaahc
Revert "impl From<&[T; N]> and From<&mut [T; N]> for Vec<T>"

This reverts commit 5dd702763a.
2022-04-29 14:39:14 +00:00
Mara Bos
69f0bcb26d Use futex-based locks and thread parker on DragonFlyBSD. 2022-04-29 16:30:54 +02:00
Mara Bos
2dfad1e3f8 Use futex-based locks and thread parker on NetBSD. 2022-04-29 16:30:54 +02:00
Mara Bos
afe1a256ce Use futex-based locks and thread parker on OpenBSD. 2022-04-29 16:30:54 +02:00
Dylan DPC
cd5dc49379
Rollup merge of #96492 - joshtriplett:revert-std-ffi-re-export, r=yaahc
Revert "Re-export core::ffi types from std::ffi"

This reverts commit 9aed829fe6.

Fixes https://github.com/rust-lang/rust/issues/96435 , a regression
in crates doing `use std::ffi::*;` and `use std::os::raw::*;`.

We can re-add this re-export once the `core::ffi` types
are stable, and thus the `std::os::raw` types can become re-exports as
well, which will avoid the conflict. (Type aliases to the same type
still conflict, but re-exports of the same type don't.)
2022-04-29 11:23:14 +02:00
Dylan DPC
db1ec25224
Rollup merge of #96481 - aDotInTheVoid:hashmap-docs-monospace, r=joshtriplett
HashMap doc: Don't use monospace font for 'Entry Api'
2022-04-29 11:23:13 +02:00
bors
ddb7fbe843 Auto merge of #96441 - ChrisDenton:sync-pipes, r=m-ou-se
Windows: Make stdin pipes synchronous

Stdin pipes do not need to be used asynchronously within the standard library. This is a first step in making pipes mostly synchronous.

r? `@m-ou-se`
2022-04-29 03:06:45 +00:00
bors
baaa3b6829 Auto merge of #96393 - joboet:pthread_parker, r=thomcc
std: directly use pthread in UNIX parker implementation

`Mutex` and `Condvar` are being replaced by more efficient implementations, which need thread parking themselves (see #93740). Therefore we should use the `pthread` synchronization primitives directly. Also, we can avoid allocating the mutex and condition variable because the `Parker` struct is being placed in an `Arc` anyways.

This basically is just a copy of the current `Mutex` and `Condvar` code, which will however be removed (again, see #93740). An alternative implementation could be to use dedicated private `OsMutex` and `OsCondvar` types, but all the other platforms supported by std actually have their own thread parking primitives.

I used `Pin` to guarantee a stable address for the `Parker` struct, while the current implementation does not, rather using extra unsafe declaration. Since the thread struct is shared anyways, I assumed this would not add too much clutter while being clearer.
2022-04-28 21:58:08 +00:00
Serial
09b0b8b6e2 Add more diagnostic items 2022-04-28 16:42:20 -04:00
Dylan DPC
2c1d58b8cc
Rollup merge of #96480 - user-simon:patch-1, r=Dylan-DPC
Fixed grammatical error in example comment

Added missing "we" in sentence.
2022-04-28 20:13:03 +02:00
Dylan DPC
0cbf3b2b30
Rollup merge of #96433 - petrochenkov:delim, r=nnethercote
rustc_ast: Harmonize delimiter naming with `proc_macro::Delimiter`

Compiler cannot reuse `proc_macro::Delimiter` directly due to extra impls, but can at least use the same naming.

After this PR the only difference between these two enums is that `proc_macro::Delimiter::None` is turned into `token::Delimiter::Invisible`.
It's my mistake that the invisible delimiter is called `None` on stable, during the stabilization I audited the naming and wrote the docs, but missed the fact that the `None` naming gives a wrong and confusing impression about what this thing is.

cc https://github.com/rust-lang/rust/pull/96421
r? ``@nnethercote``
2022-04-28 20:13:02 +02:00
joboet
550273361d
std: simplify UNIX parker timeouts 2022-04-28 12:31:19 +02:00
bors
3bfeffd55b Auto merge of #95904 - paolobarbolini:vecdeque-specextend, r=the8472
Add VecDeque::extend from vec::IntoIter and slice::Iter specializations

Inspired from the [`Vec` `SpecExtend` implementation](027a232755/library/alloc/src/vec/spec_extend.rs), but without the specialization for `TrustedLen` which I'll look into in the future.

Should help #95632 and https://github.com/KillingSpark/zstd-rs/pull/17

## Benchmarks

Before

```
test vec_deque::bench_extend_bytes    ... bench:         862 ns/iter (+/- 10)
test vec_deque::bench_extend_vec      ... bench:         883 ns/iter (+/- 19)
```

After

```
test vec_deque::bench_extend_bytes    ... bench:           8 ns/iter (+/- 0)
test vec_deque::bench_extend_vec      ... bench:          24 ns/iter (+/- 1)

```
2022-04-28 09:27:21 +00:00
Vadim Petrochenkov
2733ec1be3 rustc_ast: Harmonize delimiter naming with proc_macro::Delimiter 2022-04-28 10:04:29 +03:00
Paolo Barbolini
c126f7fc8b Add VecDeque::extend from vec::IntoIter and slice::Iter specializations 2022-04-28 06:13:54 +02:00
Dylan DPC
6f6fe3e651
Rollup merge of #96466 - compiler-errors:error-collect-array, r=davidtwco
Better error messages when collecting into `[T; n]`

Fixes #96461
2022-04-28 02:40:35 +02:00
Dylan DPC
c4dd0d3bb7
Rollup merge of #96397 - AronParker:issue-96368-fix, r=dtolnay
Make EncodeWide implement FusedIterator

[`EncodeUtf16`](https://doc.rust-lang.org/std/str/struct.EncodeUtf16.html) and [`EncodeWide`](https://doc.rust-lang.org/std/os/windows/ffi/struct.EncodeWide.html) currently serve similar purposes: They convert from UTF-8 to UTF-16 and WTF-8 to WTF-16, respectively. `EncodeUtf16` wraps a &str, whereas `EncodeWide` wraps an &OsStr.

When Iteration has concluded, these iterators wrap an empty slice, which will forever yield `None` values. Hence, `EncodeUtf16` rightfully implements `FusedIterator`. However, `EncodeWide` in contrast does not, even though it serves an almost identical purpose.

This PR attempts to fix that issue. I consider this change minor and non-controversial, hence why I have not added a RFC/FCP. Please let me know if the stability attribute is wrong or contains a wrong version number. Thanks in advance.

Fixes https://github.com/rust-lang/rust/issues/96368
2022-04-28 02:40:33 +02:00
Josh Triplett
07ea143f96 Revert "Re-export core::ffi types from std::ffi"
This reverts commit 9aed829fe6.

Fixes https://github.com/rust-lang/rust/issues/96435 , a regression
in crates doing `use std::ffi::*;` and `use std::os::raw::*;`.

We can re-add this re-export once the `core::ffi` types
are stable, and thus the `std::os::raw` types can become re-exports as
well, which will avoid the conflict. (Type aliases to the same type
still conflict, but re-exports of the same type don't.)
2022-04-27 14:01:04 -07:00
Josh Triplett
42d96bb2f6 Remove use of reverted std::ffi::c_char 2022-04-27 14:01:04 -07:00
David Tolnay
3a8f81aac9
Make [e]println macros eagerly drop temporaries (for backport) 2022-04-27 13:22:41 -07:00
Jake Goulding
762bb1f506 Revert "impl From<&[T; N]> and From<&mut [T; N]> for Vec<T>"
This reverts commit 5dd702763a.
2022-04-27 15:56:29 -04:00
Paolo Barbolini
84b8898d63 Add VecDeque::extend benchmark 2022-04-27 21:10:20 +02:00
Nixon Enraght-Moony
d34f8d269a HashMap doc: Don't use monospace font for 'Entry Api' 2022-04-27 17:59:29 +01:00
Simon
332f326334
Fixed grammatical error in example comment 2022-04-27 17:27:02 +02:00
Chris Denton
1e7c15634d
Note the importance of using sync pipes 2022-04-27 13:56:59 +01:00
Thayne McCombs
f7ac8e7aef Add tracking issue number for mutex_unpoison 2022-04-27 00:05:34 -06:00
Michael Goulet
83d701e569 Better error messages when collecting into [T; n] 2022-04-26 21:37:10 -07:00
bors
bb85bcaca9 Auto merge of #96195 - sunfishcode:sunfishcode/handle-or-error-type, r=joshtriplett
Define a dedicated error type for `HandleOrNull` and `HandleOrInvalid`.

Define `NullHandleError` and `InvalidHandleError` types, that implement std::error::Error, and use them as the error types in `HandleOrNull` and `HandleOrInvalid`,

This addresses [this concern](https://github.com/rust-lang/rust/issues/87074#issuecomment-1080031167).

This is the same as #95387.

r? `@joshtriplett`
2022-04-27 03:42:59 +00:00
Chris Denton
949b978ec9
Windows: Make stdin pipes synchronous
Stdin pipes do not need to be used asynchronously within the standard library.
2022-04-26 16:31:27 +01:00
Chris Denton
b89b056742
Add set_inheritable for Windows Handles 2022-04-26 15:56:26 +01:00
Guillaume Gomez
223f107b48
Rollup merge of #96415 - ehuss:git-io, r=bjorn3
Remove references to git.io

The git.io service is shutting down soon (see https://github.blog/changelog/2022-04-25-git-io-deprecation/). This removes the references of those short links with the actual destination.
2022-04-26 13:22:31 +02:00
Guillaume Gomez
2b8bf0d530
Rollup merge of #95949 - SoniEx2:patch-5, r=m-ou-se
Implement Default for AssertUnwindSafe

Trait impls are still insta-stable yeah...?
2022-04-26 13:22:27 +02:00
Guillaume Gomez
eaf8beb3f3
Rollup merge of #94022 - jongiddy:cow-into-owned-docs, r=Dylan-DPC
Clarify that `Cow::into_owned` returns owned data

Two sections of the `Cow::into_owned` docs imply that `into_owned` returns a `Cow`. Clarify that it returns the underlying owned object, either cloned or extracted from the `Cow`.
2022-04-26 13:22:26 +02:00
Thayne McCombs
fc38388bc1 Add functions to un-poison Mutex and RwLock
See discussion at https://internals.rust-lang.org/t/unpoisoning-a-mutex/16521/3
2022-04-26 01:35:04 -06:00
Eric Huss
159b95d5bb Remove references to git.io 2022-04-25 17:05:58 -07:00
Dylan DPC
93db30aa7f
Rollup merge of #96149 - est31:remove_unused_macro_matchers, r=petrochenkov
Remove unused macro rules

Removes rules of internal macros that weren't triggered.
2022-04-26 01:21:20 +02:00
Dylan DPC
51b86848ff
Rollup merge of #90312 - r00ster91:search, r=Dylan-DPC
Fix some confusing wording and improve slice-search-related docs

This adds more links between `contains` and `binary_search` because I do think they have some relevant connections. If your (big) slice happens to be sorted and you know it, surely you should be using `[3; 100].binary_search(&5).is_ok()` over `[3; 100].contains(&5)`?
This also fixes the confusing "searches this sorted X" wording which just sounds really weird because it doesn't know whether it's actually sorted. It should be but it may not be. The new wording should make it clearer that you will probably want to sort it and in the same sentence it also mentions the related function `contains`.
Similarly, this mentions `binary_search` on `contains`' docs.
This also fixes some other minor stuff and inconsistencies.
2022-04-26 01:21:20 +02:00
Aron Parker
fc6af819c4 Make EncodeWide implement FusedIterator 2022-04-25 18:38:47 +02:00
joboet
54daf496e2
std: directly use pthread in UNIX parker implementation
Mutex and Condvar are being replaced by more efficient implementations, which need thread parking themselves (see #93740). Therefore use the pthread synchronization primitives directly. Also, avoid allocating because the Parker struct is being placed in an Arc anyways.
2022-04-25 15:19:50 +02:00
bors
756ffb8d0b Auto merge of #95246 - ChrisDenton:command-args, r=joshtriplett
Windows Command: Don't run batch files using verbatim paths

Fixes #95178

Note that the first commit does some minor refactoring (moving command line argument building to args.rs). The actual changes are in the second.
2022-04-25 07:28:09 +00:00
Matthias Krüger
b7e67a6ad9
Rollup merge of #96107 - Gumichocopengin8:test/vec-deque, r=Mark-Simulacrum
[test] Add test cases for untested functions for VecDeque

Added test cases of the following functions
- get
- get_mut
- swap
- reserve_exact
- try_reserve_exact
- try_reserve
- contains
- rotate_left
- rotate_right
- binary_search
- binary_search_by
- binary_search_by_key
2022-04-25 00:11:00 +02:00
bors
18f314e702 Auto merge of #94609 - esp-rs:esp-idf-stat-type-fixes, r=Mark-Simulacrum
espidf: fix stat

Marking as draft as currently dependant on [a libc fix](https://github.com/rust-lang/libc/pull/2708) and release.
2022-04-24 19:16:20 +00:00
Keita Nonaka
a40cd2aa8b test: add test cases for VecDeque 2022-04-24 11:43:07 -07:00
Marko Mijalkovic
92a584177d Inline core::panic::Location methods 2022-04-23 14:41:47 -04:00
bors
6b4563bf93 Auto merge of #90602 - mbartlett21:const-intoiterator, r=oli-obk
Unstably constify `impl<I: Iterator> IntoIterator for I`

This constifies the default `IntoIterator` implementation under the `const_intoiterator_identity` feature.

Tracking Issue: #90603
2022-04-23 15:41:45 +00:00
bors
1e9aa8a96b Auto merge of #95971 - workingjubilee:no-weird-fp-in-const, r=oli-obk
No "weird" floats in const fn {from,to}_bits

I suspect this code is subtly incorrect and that we don't even e.g. use x87-style floats in CTFE, so I don't have to guard against that case. A future PR will be hopefully removing them from concern entirely, anyways. But at the moment I wanted to get this rolling because small questions like that one seem best answered by review.

r? `@oli-obk`
cc `@eddyb` `@thomcc`
2022-04-23 13:00:54 +00:00
Nilstrieb
521bb810be Link to correct as_mut in docs for pointer::as_ref
It previously linked to the unstable const-mut-cast method instead of
the `mut` counterpart for `as_ref`.
2022-04-23 13:42:26 +02:00
bjorn3
cbc0a15ba1 Use const initializer for LOCAL_PANIC_COUNT
This reduces the size of the __getit function for LOCAL_PANIC_COUNT and should
speed up accesses of LOCAL_PANIC_COUNT a bit.
2022-04-23 12:06:36 +02:00
bors
64c5deb0e3 Auto merge of #96314 - AronParker:issue-96297-fix, r=thomcc
Reduce allocations for path conversions on Windows

Previously, UTF-8 to UTF-16 Path conversions on Windows unnecessarily allocate twice, as described in #96297. This commit fixes that issue.
2022-04-23 04:17:50 +00:00
Jubilee Young
4da8682523 Remove unnecessary const-time x87-related checks 2022-04-22 19:34:33 -07:00
Jubilee Young
bb555b828c Fix comments for float classify 2022-04-22 18:34:34 -07:00
bors
8834629b86 Auto merge of #94887 - dylni:move-normpath-crate-impl-to-libstd, r=ChrisDenton
Improve Windows path prefix parsing

This PR fixes improves parsing of Windows path prefixes. `parse_prefix` now supports both types of separators on Windows (`/` and `\`).
2022-04-23 00:58:22 +00:00
Aron Parker
6cfdeaf1a1 Remove redundant type annotation 2022-04-22 11:42:53 +02:00
Aron Parker
9a9d5534f0 Reduce allocations for path conversions on Windows
Previously, UTF-8 to UTF-16 Path conversions on Windows unnecessarily allocate twice, as described in #96297. This commit fixes that issue.
2022-04-22 11:02:04 +02:00
Yonggang Luo
1d5948f473 library/core: Fixes implement of c_uint, c_long, c_ulong
Fixes: aa67016624 ("make memcmp return a value of c_int_width instead of i32")
Introduce c_num_definition to getting the cfg_if logic easier to maintain
Add newlines for easier code reading

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
2022-04-21 17:18:32 +08:00
Dylan DPC
e2543d7a4e
Rollup merge of #96228 - mbartlett21:patch-4, r=thomcc
Fix locations for intrinsics impls and change to links

These still referred to `rustc_mir`.
2022-04-21 01:14:16 +02:00
Dylan DPC
1e43aae0ef
Rollup merge of #96193 - djkoloski:fuchsia_current_exe, r=tmandry
[fuchsia] Add implementation for `current_exe`

This implementation returns a best attempt at the current exe path. On
fuchsia, fdio will always use `argv[0]` as the process name and if it is
not set then an error will be returned. Because this is not guaranteed
to be the case, this implementation returns an error if `argv` does not
contain any elements.
2022-04-21 01:14:14 +02:00
Dylan DPC
2443cf2c6a
Rollup merge of #96234 - goffrie:eloop, r=thomcc
remove_dir_all_recursive: treat ELOOP the same as ENOTDIR

On older Linux kernels (I tested on 4.4, corresponding to Ubuntu 16.04), opening a symlink using `O_DIRECTORY | O_NOFOLLOW` returns `ELOOP` instead of `ENOTDIR`. We should handle it the same, since a symlink is still not a directory and needs to be `unlink`ed.
2022-04-20 18:26:06 +02:00
Dylan DPC
41235ef98a
Rollup merge of #96206 - m-ou-se:wasm-futex-locks, r=alexcrichton
Use sys::unix::locks::futex* on wasm+atomics.

This removes the wasm-specific lock implementations and instead re-uses the implementations from sys::unix.

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

cc ``@alexcrichton``
2022-04-20 18:26:05 +02:00
Dylan DPC
01d4731735
Rollup merge of #96168 - chris-morgan:AddrParseError-description-improvements, r=joshtriplett
Improve AddrParseError description

The existing description was incorrect for socket addresses, and misleading: users would see “invalid IP address syntax” and suppose they were supposed to provide an IP address rather than a socket address.

I contemplated making it two variants (IP, socket), but realised we can do still better for the IPv4 and IPv6 types, so here it is as six.

I contemplated more precise error descriptions (e.g. “invalid IPv6 socket address syntax: expected a decimal scope ID after %”), but that’s a more invasive change, and probably not worthwhile anyway.
2022-04-20 18:26:04 +02:00
Dylan DPC
53f028d790
Rollup merge of #96167 - CAD97:weak-dlsym-less-ptr-crime, r=thomcc
Replace sys/unix/weak AtomicUsize with AtomicPtr

Should fix #96163. Can't easily test on Windows though...
2022-04-20 18:26:03 +02:00
bors
d39864d64e Auto merge of #96135 - petrochenkov:doclink6, r=GuillaumeGomez
rustdoc: Optimize and refactor doc link resolution

One more subset of https://github.com/rust-lang/rust/pull/94857 that should bring perf improvements rather than regressions + a couple more optimizations on top of it.
It's better to read individual commits and their descriptions to understand the changes.
The `may_have_doc_links` optimization is not *very* useful here, but it's much more important for https://github.com/rust-lang/rust/pull/94857.

Closes https://github.com/rust-lang/rust/issues/96079
2022-04-20 13:34:48 +00:00
mbartlett21
4879875c76
Change file locations to be links to GitHub 2022-04-20 13:14:32 +10:00
Geoffry Song
cff3f1e8d5 remove_dir_all_recursive: treat ELOOP the same as ENOTDIR 2022-04-20 00:50:03 +00:00
Dan Gohman
0a1ce8277c Make BorrowedFd::borrow_raw a const fn.
Making `BorrowedFd::borrow_raw` a const fn allows it to be used to
create a constant `BorrowedFd<'static>` holding constants such as
`AT_FDCWD`. This will allow [`rustix::fs::cwd`] to become a const fn.

For consistency, make similar changes to `BorrowedHandle::borrow_raw`
and `BorrowedSocket::borrow_raw`.

[`rustix::fs::cwd`]: https://docs.rs/rustix/latest/rustix/fs/fn.cwd.html
2022-04-19 17:22:54 -07:00
mbartlett21
671a8723c6
Fix locations for intrinsics impls 2022-04-20 09:28:07 +10:00
Dylan DPC
da1ddf371c
Rollup merge of #96205 - m-ou-se:emscripten-futex-locks, r=thomcc
Use futex locks on emscripten.

This switches Emscripten to the futex-based lock implementations, away from pthread.

Tracking issue: https://github.com/rust-lang/rust/issues/93740
2022-04-19 22:57:44 +02:00
David Koloski
eb6b6a877e [fuchsia] Add implementation for current_exe
This implementation returns a best attempt at the current exe path. On
fuchsia, fdio will always use `argv[0]` as the process name and if it is
not set then an error will be returned. Because this is not guaranteed
to be the case, this implementation returns an error if `argv` does not
contain any elements.
2022-04-19 16:50:24 -04:00
jmaargh
4dda047de3 Clarify docs for from_raw_parts
Original safety explanation for from_raw_parts was
unclear on safety for consuming a C string. This
clarifies when doing so is safe.
2022-04-19 21:12:55 +01:00
Vadim Petrochenkov
f5ca02c334 proc_macro: Add a workaround for rustdoc 2022-04-19 22:49:27 +03:00
Scott Mabin
3569d43b50 espidf: fix stat
* corect type usage with new type definitions in libc
2022-04-19 17:00:09 +01:00
Dylan DPC
35188440b5
Rollup merge of #96089 - ojeda:no-vec-no_global_oom_handling, r=Mark-Simulacrum
`alloc`: make `vec!` unavailable under `no_global_oom_handling`

`alloc`: make `vec!` unavailable under `no_global_oom_handling`

The `vec!` macro has 3 rules, but two are not usable under
`no_global_oom_handling` builds of the standard library
(even with a zero size):

```rust
let _ = vec![42];    // Error: requires `exchange_malloc` lang_item.
let _ = vec![42; 0]; // Error: cannot find function `from_elem`.
```

Thus those two rules should not be available to begin with.

The remaining one, with an empty matcher, is just a shorthand for
`new()` and may not make as much sense to have alone, since the
idea behind `vec!` is to enable `Vec`s to be defined with the same
syntax as array expressions. Furthermore, the documentation can be
confusing since it shows the other rules.

Thus perhaps it is better and simpler to disable `vec!` entirely
under `no_global_oom_handling` environments, and let users call
`new()` instead:

```rust
let _: Vec<i32> = vec![];
let _: Vec<i32> = Vec::new();
```

Notwithstanding this, a `try_vec!` macro would be useful, such as
the one introduced in https://github.com/rust-lang/rust/pull/95051.

If the shorthand for `new()` is deemed worth keeping on its own,
then it may be interesting to have a separate `vec!` macro with
a single rule and different, simpler documentation.

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2022-04-19 14:43:19 +02:00
Mara Bos
06a8f05b0c Use futex locks on emscripten. 2022-04-19 09:24:51 +02:00
Mara Bos
8f2913cc24 Use futex locks on wasm+atomics. 2022-04-19 09:21:54 +02:00
Mara Bos
65987ae8f5 Make std::sys::wasm::futex consistent with unix::futex. 2022-04-19 09:21:54 +02:00
Mara Bos
6abdd0b6d4 Make std::sys::unix::futex consistent on emscripten. 2022-04-19 09:19:29 +02:00
Chris Morgan
0255398ff7 Improve AddrParseError description
The existing description was incorrect for socket addresses, and
misleading: users would see “invalid IP address syntax” and suppose they
were supposed to provide an IP address rather than a socket address.

I contemplated making it two variants (IP, socket), but realised we can
do still better for the IPv4 and IPv6 types, so here it is as six.

I contemplated more precise error descriptions (e.g. “invalid IPv6
socket address syntax: expected a decimal scope ID after %”), but that’s
a more invasive change, and probably not worthwhile anyway.
2022-04-19 13:02:20 +10:00
Dan Gohman
890125d73e Add a comment explaining the (()) idiom for empty structs. 2022-04-18 16:53:50 -07:00
Dan Gohman
f934043c17 Split NotHandle into NullHandleError and InvalidHandleError.
Also, make the display messages more specific, and remove the `Copy`
implementation.
2022-04-18 16:53:50 -07:00
Dan Gohman
67994b77fd Move the Error impl for NotHandle out of platform-independent code. 2022-04-18 16:53:49 -07:00
Dan Gohman
5b3023c564 Fix an incorrect word in a comment. 2022-04-18 16:53:38 -07:00
Dan Gohman
703a33673d Define a dedicated error type for HandleOrNull and HandleOrInvalid.
Define a `NotHandle` type, that implements `std::error::Error`, and use
it as the error type in `HandleOrNull` and `HandleOrInvalid`.
2022-04-18 16:53:36 -07:00
bors
d5ae66c12c Auto merge of #92287 - JulianKnodt:slice_remainder, r=yaahc
Add slice::remainder

This adds a remainder function to the Slice iterator, so that a caller can access unused
elements if iteration stops.

Addresses #91733
2022-04-18 23:34:24 +00:00
est31
3c1e1661e7 Remove unused macro rules 2022-04-18 23:28:06 +02:00
Dylan DPC
55e399771e
Rollup merge of #96156 - est31:use_from_le_bytes, r=Dylan-DPC
Replace u8to64_le macro with u64::from_le_bytes

The macro was a reimplementation of the function.
2022-04-18 18:22:07 +02:00
Dylan DPC
a6ad1394f3
Rollup merge of #96136 - thomcc:lifetime-wording, r=RalfJung
Reword clarification on lifetime for ptr->ref safety docs

I believe the current wording of the safety comment is somewhat misleading, and that this is more accurate. Suggested by `@CAD97` in this thread on the topic https://rust-lang.zulipchat.com/#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/Lifetime.20of.20reference.20pointer.20docs.20issue

Just to check that this is correct, CC `@RalfJung.`

I suppose it's open for interpretation as to whether or not this is more clear. I think it is.
2022-04-18 18:22:04 +02:00
Ralf Jung
74d77d058b mark ptr-int-transmute test as no_run 2022-04-18 10:04:31 -04:00
bors
6fd7e9010d Auto merge of #96042 - m-ou-se:one-reentrant-mutex, r=Amanieu
Use a single ReentrantMutex implementation on all platforms.

This replaces all platform specific ReentrantMutex implementations by the one I added in #95727 for Linux, since that one does not depend on any platform specific details.

r? `@Amanieu`
2022-04-18 12:15:39 +00:00
Mara Bos
94f00e396a Remove forgotten reexport of ReentrantMutex in sys::unsupported. 2022-04-18 13:10:36 +02:00
CAD97
620c0a4d5b Replace sys/unix/weak AtomicUsize with AtomicPtr 2022-04-17 23:33:56 -05:00
bors
e27d9df431 Auto merge of #93530 - anonion0:pthread_sigmask_fix, r=JohnTitor
fix error handling for pthread_sigmask(3)

Errors from `pthread_sigmask(3)` were handled using `cvt()`, which expects a return value of `-1` on error and uses `errno`.
However, `pthread_sigmask(3)` returns `0` on success and an error number otherwise.

Fix it by replacing `cvt()` with `cvt_nz()`.
2022-04-17 22:54:55 +00:00
est31
9e7a319f01 Replace u8to64_le macro with u64::from_le_bytes
The macro was a reimplementation of the function.
2022-04-17 22:55:33 +02:00
bors
ec77f25243 Auto merge of #96139 - erikdesjardins:revertinl2, r=Mark-Simulacrum
Revert: Make TLS __getit #[inline(always)] on non-Windows

re #96132

r? `@Mark-Simulacrum`
2022-04-17 20:32:08 +00:00
Lukas Lueg
3615cb476b Expand core::hint::unreachable_unchecked() docs
Fixes #95865
2022-04-17 20:58:36 +02:00
kadmin
494901ced6 Add slice::remainder
This adds a remainder function to the Slice iterator, so that a caller can access unused
elements if iteration stops.
2022-04-17 17:19:45 +00:00
Ralf Sager
e6aafbc707 move import to fix warning with emscripten target 2022-04-17 09:42:15 +02:00
Erik Desjardins
b0d9c42c46 Revert "Auto merge of #94373 - erikdesjardins:getitinl, r=Mark-Simulacrum"
This reverts commit 035a717ee8, reversing
changes made to 761e888485.
2022-04-17 02:15:45 -04:00
bors
ac8b11810f Auto merge of #96010 - eduardosm:Unique-on-top-of-NonNull, r=m-ou-se,tmiasko
Implement `core::ptr::Unique` on top of `NonNull`

Removes the use `rustc_layout_scalar_valid_range_start` and some `unsafe` blocks.
2022-04-17 05:26:08 +00:00
dylni
fb9731ea13 Remove unnecessary function 2022-04-17 01:23:47 -04:00
dylni
e87082293e Improve Windows path prefix parsing 2022-04-17 01:23:46 -04:00
Thom Chiovoloni
be30e40440
Reword clarification on lifetime for ptr->ref safety docs 2022-04-16 21:39:43 -07:00
bors
43a71dc732 Auto merge of #96002 - nnethercote:speed-up-Vec-clear-2, r=m-ou-se
Speed up Vec::clear().

Currently it just calls `truncate(0)`. `truncate()` is (a) not marked as
`#[inline]`, and (b) more general than needed for `clear()`.

This commit changes `clear()` to do the work itself. This modest change
was first proposed in rust-lang#74172, where the reviewer rejected it because
there was insufficient evidence that `Vec::clear()`'s performance
mattered enough to justify the change. Recent changes within rustc have
made `Vec::clear()` hot within `macro_parser.rs`, so the change is now
clearly worthwhile.

Although it doesn't show wins on CI perf runs, this seems to be because they
use PGO. But not all platforms currently use PGO. Also, local builds don't use
PGO, and `truncate` sometimes shows up in an over-represented fashion in local
profiles. So local profiling will be made easier by this change.

Note that this will also benefit `String::clear()`, because it just
calls `Vec::clear()`.

Finally, the commit removes the `vec-clear.rs` codegen test. It was
added in #52908. From before then until now, `Vec::clear()` just called
`Vec::truncate()` with a zero length. The body of Vec::truncate() has
changed a lot since then. Now that `Vec::clear()` is doing actual work
itself, and not just calling `Vec::truncate()`, it's not surprising that
its generated code includes a load and an icmp. I think it's reasonable
to remove this test.

r? `@m-ou-se`
2022-04-17 03:08:45 +00:00
Matthew Woodcraft
16c81fa9a6 Document the numeric value returned by string parsing for floats 2022-04-16 22:03:24 +01:00
Matthew Woodcraft
6fa061c5f9 Document rounding for floating-point primitive operations
State that the four primitive operations honour IEEE 754 roundTiesToEven.

Documenting under "Primitive Type f32"; f64 refers to that.
2022-04-16 21:58:36 +01:00
Giles Cope
bf02d1ea5f
No need to check the assert all the time. 2022-04-16 19:30:23 +01:00
Dylan DPC
4ed7627117
Rollup merge of #96081 - eduardosm:masks_usize_size_agnostic, r=yaahc
Make some `usize`-typed masks definitions agnostic to the size of `usize`

Some masks where defined as
```rust
const NONASCII_MASK: usize = 0x80808080_80808080u64 as usize;
```
where it was assumed that `usize` is never wider than 64, which is currently true.

To make those constants valid in a hypothetical 128-bit target, these constants have been redefined in an `usize`-width-agnostic way
```rust
const NONASCII_MASK: usize = usize::from_ne_bytes([0x80; size_of::<usize>()]);
```

There are already some cases where Rust anticipates the possibility of supporting 128-bit targets, such as not implementing `From<usize>` for `u64`.
2022-04-16 14:26:01 +02:00
Dylan DPC
bd007ba928
Rollup merge of #96038 - beyarkay:patch-1, r=m-ou-se
docs: add link from zip to unzip

The docs for `Iterator::unzip` explain that it is kind of an inverse operation to `Iterator::zip` and guide the reader to the `zip` docs, but the `zip` docs don't let the user know that they can undo the `zip` operation with `unzip`. This change modifies the docs to help the user find `unzip`.
2022-04-16 14:25:58 +02:00
Mara Bos
4212de63ab Use a single ReentrantMutex implementation on all platforms. 2022-04-16 11:30:22 +02:00
Dylan DPC
f559cf98b5
Rollup merge of #96099 - clarfonthey:maybeuninit_array_cleanup, r=dtolnay
MaybeUninit array cleanup

* Links `MaybeUninit::uninit_array` to meta-tracking issue
* Links `MaybeUninit::array_assume_init` to meta-tracking issue
* Unstably constifies `MaybeUninit::array_assume_init`

Another thing worth mentioning: this splits the const feature flag for `maybe_uninit_uninit_array` into `const_maybe_uninit_uninit_array` to avoid weird cases where only one gets stabilised.

Note that it may be desired to keep the `array_assume_init` method linked to its dedicated issue, but at least for now, I decided to link to the meta-tracking issue so that all of the methods lead users to the same place. But I can revert that bit if desired.

The meta-tracking issue that I filed is #96097.
2022-04-16 07:12:49 +02:00
Dylan DPC
04ccba8728
Rollup merge of #96070 - Gumichocopengin8:test/btree-map, r=thomcc
[test] Add test cases for untested functions for BTreeMap

- add `pop_first()`, `pop_last()`, `get_key_value()` and `try_insert()` test cases
2022-04-16 07:12:48 +02:00
Dylan DPC
ea131bca17
Rollup merge of #95961 - RalfJung:gather-scatter, r=workingjubilee
implement SIMD gather/scatter via vector getelementptr

Fixes https://github.com/rust-lang/portable-simd/issues/271

However, I don't *really* know what I am doing here... Cc ``@workingjubilee`` ``@calebzulawski``

I didn't do anything for cranelift -- ``@bjorn3`` not sure if it's okay for that backend to temporarily break. I'm happy to cherry-pick a patch that adds cranelift support. :)
2022-04-16 07:12:45 +02:00
Miguel Ojeda
8cec88ba76 alloc: make vec! unavailable under no_global_oom_handling
The `vec!` macro has 3 rules, but two are not usable under
`no_global_oom_handling` builds of the standard library
(even with a zero size):

```rust
let _ = vec![42];    // Error: requires `exchange_malloc` lang_item.
let _ = vec![42; 0]; // Error: cannot find function `from_elem`.
```

Thus those two rules should not be available to begin with.

The remaining one, with an empty matcher, is just a shorthand for
`new()` and may not make as much sense to have alone, since the
idea behind `vec!` is to enable `Vec`s to be defined with the same
syntax as array expressions. Furthermore, the documentation can be
confusing since it shows the other rules.

Thus perhaps it is better and simpler to disable `vec!` entirely
under `no_global_oom_handling` environments, and let users call
`new()` instead:

```rust
let _: Vec<i32> = vec![];
let _: Vec<i32> = Vec::new();
```

Notwithstanding this, a `try_vec!` macro would be useful, such as
the one introduced in https://github.com/rust-lang/rust/pull/95051.

If the shorthand for `new()` is deemed worth keeping on its own,
then it may be interesting to have a separate `vec!` macro with
a single rule and different, simpler documentation.

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2022-04-16 06:31:41 +02:00
Raekye
d5f96e6ade Change as_uninit_* methods on NonNull from taking self by
reference to taking `self` by value. This is consistent with the methods
of the same names on primitive pointers. The returned lifetime was
already previously unbounded.
2022-04-15 21:21:02 -04:00
ltdk
63a8652961 MaybeUninit array cleanup
* Links MaybeUninit::uninit_array to meta-tracking issue
* Links MaybeUninit::array_assume_init to meta-tracking issue
* Unstably constifies MaybeUninit::array_assume_init
2022-04-15 20:53:50 -04:00
bors
bb1a03c4fc Auto merge of #95224 - mjbshaw:patch-1, r=yaahc
Optimize RcInnerPtr::inc_strong()/inc_weak() instruction count

Inspired by this internals thread: https://internals.rust-lang.org/t/rc-optimization-on-64-bit-targets/16362

[The generated assembly is a bit smaller](https://rust.godbolt.org/z/TeTnf6144) and is a more efficient usage of the CPU's instruction cache. `unlikely` doesn't impact any of the small artificial tests I've done, but I've included it in case it might help more complex scenarios when this is inlined.
2022-04-15 23:15:51 +00:00
Dylan DPC
aa978addb3
Rollup merge of #96040 - m-ou-se:futex-u32, r=Amanieu
Use u32 instead of i32 for futexes.

This changes futexes from i32 to u32. The [Linux man page](https://man7.org/linux/man-pages/man2/futex.2.html) uses `uint32_t` for them, so I'm not sure why I used i32 for them. Maybe because I first used them for thread parkers, where I used -1, 0, and 1 as the states.

(Wasm's `memory.atomic.wait32` does use `i32`, because wasm doesn't support `u32`.)

It doesn't matter much, but using the unsigned type probably results in fewer surprises when shifting bits around or using comparison operators.

r? ```@Amanieu```
2022-04-15 20:50:50 +02:00
Dylan DPC
224afadb3b
Rollup merge of #96034 - Gumichocopengin8:test/btree-set, r=Dylan-DPC
[test] Add test cases of untested functions for BTreeSet

- add [`is_superset()`](https://doc.rust-lang.org/std/collections/struct.BTreeSet.html#method.is_superset) and [`remove()`](https://doc.rust-lang.org/std/collections/struct.BTreeSet.html#method.remove) test cases for BTreeSet since these functions has no test cases.
2022-04-15 20:50:49 +02:00
Dylan DPC
20bf34f8c5
Rollup merge of #94461 - jhpratt:2024-edition, r=pnkfelix
Create (unstable) 2024 edition

[On Zulip](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Deprecating.20macro.20scoping.20shenanigans/near/272860652), there was a small aside regarding creating the 2024 edition now as opposed to later. There was a reasonable amount of support and no stated opposition.

This change creates the 2024 edition in the compiler and creates a prelude for the 2024 edition. There is no current difference between the 2021 and 2024 editions. Cargo and other tools will need to be updated separately, as it's not in the same repository. This change permits the vast majority of work towards the next edition to proceed _now_ instead of waiting until 2024.

For sanity purposes, I've merged the "hello" UI tests into a single file with multiple revisions. Otherwise we'd end up with a file per edition, despite them being essentially identical.

````@rustbot```` label +T-lang +S-waiting-on-review

Not sure on the relevant team, to be honest.
2022-04-15 20:50:43 +02:00
Dylan DPC
27e2d811e6
Rollup merge of #94457 - jhpratt:stabilize-derive_default_enum, r=davidtwco
Stabilize `derive_default_enum`

This stabilizes `#![feature(derive_default_enum)]`, as proposed in [RFC 3107](https://github.com/rust-lang/rfcs/pull/3107) and tracked in #87517. In short, it permits you to `#[derive(Default)]` on `enum`s, indicating what the default should be by placing a `#[default]` attribute on the desired variant (which must be a unit variant in the interest of forward compatibility).

```````@rustbot``````` label +S-waiting-on-review +T-lang
2022-04-15 20:50:43 +02:00
bors
1e6fe5855a Auto merge of #94079 - petrochenkov:cstr, r=joshtriplett
library: Move `CStr` to libcore, and `CString` to liballoc

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

Interesting points:
- Stability:
    - To make `CStr(ing)` from libcore/liballoc unusable without enabling features I had to make these structures unstable, and reexport them from libstd using stable type aliases instead of `pub use` reexports. (Because stability of `use` items is not checked.)
- Relying on target ABI in libcore is ok:
    - https://github.com/rust-lang/rust/pull/94079#issuecomment-1044263371
- `trait CStrExt` (UPDATE: used only in `cfg(bootstrap)` mode, otherwise lang items are used instead)
    - https://github.com/rust-lang/rust/pull/94079#issuecomment-1047863450
- `strlen`
    - https://github.com/rust-lang/rust/pull/94079#issuecomment-1047863450

Otherwise it's just a code move + some minor hackery usual for liballoc in `cfg(test)` mode.
2022-04-15 15:47:17 +00:00
Eduardo Sánchez Muñoz
93ae6f80e3 Make some usize-typed masks definition agnostic to the size of usize
Some masks where defined as
```rust
const NONASCII_MASK: usize = 0x80808080_80808080u64 as usize;
```
where it was assumed that `usize` is never wider than 64, which is currently true.

To make those constants valid in a hypothetical 128-bit target, these constants have been redefined in an `usize`-width-agnostic way
```rust
const NONASCII_MASK: usize = usize::from_ne_bytes([0x80; size_of::<usize>()]);
```

There are already some cases where Rust anticipates the possibility of supporting 128-bit targets, such as not implementing `From<usize>` for `u64`.
2022-04-15 17:04:59 +02:00
John-John Tedro
594be707c4 Implement str to [u8] conversion for refcounted containers 2022-04-15 15:38:37 +02:00
bors
69a5ae35fe Auto merge of #95841 - ChrisDenton:pipe-server, r=m-ou-se
Windows: Use a pipe relay for chaining pipes

Fixes #95759

This fixes the issue by chaining pipes synchronously and manually pumping messages between them. It's not ideal but it has the advantage of not costing anything if pipes are not chained ("don't pay for what you don't use") and it also avoids breaking existing code that rely on our end of the pipe being asynchronous (which includes rustc's own testing framework).

Libraries can avoid needing this by using their own pipes to chain commands.
2022-04-15 13:19:25 +00:00
Keita Nonaka
3f46ba6028 chore: formatting 2022-04-15 01:30:05 -07:00
Keita Nonaka
3f2f4a35ed test: add try_insert() test cases for BTreeSet 2022-04-15 01:12:00 -07:00
Keita Nonaka
e1626020d3 test: add get_key_value() test cases for BTreeSet 2022-04-15 00:04:03 -07:00
Keita Nonaka
4117e8c2d3 test: add pop_first() pop_last() test cases for BTreeSet 2022-04-14 23:40:05 -07:00
Vadim Petrochenkov
6eaec56ef7 library: Remove definitions and reexports of strlen from libstd 2022-04-14 21:57:01 +03:00
Vadim Petrochenkov
afa2e6f2ff Fix targets not supporting target_has_atomic = "ptr" 2022-04-14 21:53:11 +03:00
Vadim Petrochenkov
7f3cc2fbbf library: Use type aliases to make CStr(ing) in libcore/liballoc unstable 2022-04-14 21:53:11 +03:00
Vadim Petrochenkov
5bee741a08 library: Move CStr to libcore, and CString to liballoc 2022-04-14 21:53:11 +03:00
Eduardo Sánchez Muñoz
2a91eeac1a Implement core::ptr::Unique on top of NonNull
Removes the use `rustc_layout_scalar_valid_range_start` and some `unsafe` blocks.
2022-04-14 19:35:40 +02:00
Mara Bos
7a35c0f52d Use u32 instead of i32 for futexes. 2022-04-14 11:44:12 +02:00
Boyd Kane
d73e32867f
Remove trailing whitespace
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2022-04-14 11:19:49 +02:00
Boyd Kane
f6d957701f
docs: add link from zip to unzip
The docs for `Iterator::unzip` explain that it is kind of an inverse operation to `Iterator::zip` and guide the reader to the `zip` docs, but the `zip` docs don't let the user know that they can undo the `zip` operation with `unzip`. This change modifies the docs to help the user find `unzip`.
2022-04-14 09:51:47 +02:00
Jacob Pratt
4fbe73e0b7
Remove use of #[rustc_deprecated] 2022-04-14 01:33:13 -04:00
Jacob Pratt
8ff5e3cf99
Bump stdarch 2022-04-14 01:33:11 -04:00
Keita Nonaka
50c339e8f5 test: add remove() test cases for BTreeSet 2022-04-13 22:19:08 -07:00
Keita Nonaka
21d3f8444a test: add is_superset test cases for BTreeSet 2022-04-13 22:09:03 -07:00
bors
dc4bfcbdff Auto merge of #95958 - jhpratt:bump-stdarch, r=Dylan-DPC
Update stdarch

library/stdarch bcbe0106...d215afe9 (7):
  - Add the rdm target feature to the sqrdmlsh intrinsic. (rust-lang/stdarch#1285)
  - Remove use of `#[rustc_deprecated]`
  - Remove feature gates for stabilized features
  - Change remaining _undefined_ functions to zero-init
  - Use SPDX license format and update packed_simd crate link (rust-lang/stdarch#1297)
  - Fix broken links (rust-lang/stdarch#1294)
  - Import the asm macro in std_detect (rust-lang/stdarch#1290)
2022-04-13 18:44:35 +00:00
bors
0d13f6afeb Auto merge of #96015 - Dylan-DPC:rollup-vhdprid, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #93217 (Improve Rustdoc UI for scraped examples with multiline arguments, fix overflow in line numbers)
 - #95885 (Improve error message in case of missing checksum)
 - #95962 (Document that DirEntry holds the directory open)
 - #95991 (fix: wrong trait import suggestion for T:)
 - #96005 (Add missing article to fix "few" to "a few".)
 - #96006 (Add a missing article)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-04-13 16:04:06 +00:00
Dylan DPC
e95f2db98f
Rollup merge of #96006 - hkBst:patch-2, r=Dylan-DPC
Add a missing article

Add a missing article
2022-04-13 17:35:37 +02:00
Dylan DPC
e8050c0b0a
Rollup merge of #96005 - hkBst:patch-1, r=Dylan-DPC
Add missing article to fix "few" to "a few".

Add missing article to fix "few" (not many) to "a few" (some).
2022-04-13 17:35:35 +02:00
Dylan DPC
032358bd30
Rollup merge of #95962 - sourcefrog:doc-direntry, r=Dylan-DPC
Document that DirEntry holds the directory open

I had a bug where holding onto DirEntry structs caused file descriptor exhaustion, and thought it would be good to document this.
2022-04-13 17:35:33 +02:00
bors
ab33f71a8b Auto merge of #95727 - m-ou-se:futex-reentrantmutex, r=Amanieu
Replace ReentrantMutex by a futex-based one on Linux.

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

r? `@Amanieu`
2022-04-13 13:42:19 +00:00
Marijn Schouten
c008d45187
Add a missing article
Add a missing article
2022-04-13 13:33:09 +02:00
Marijn Schouten
212e98bc3e
Add missing article to fix "few" to "a few".
Add missing article to fix "few" (not many) to "a few" (some).
2022-04-13 13:24:28 +02:00
Nicholas Nethercote
9c59d04d55 Speed up Vec::clear().
Currently it just calls `truncate(0)`. `truncate()` is (a) not marked as
`#[inline]`, and (b) more general than needed for `clear()`.

This commit changes `clear()` to do the work itself. This modest change
was first proposed in rust-lang#74172, where the reviewer rejected it because
there was insufficient evidence that `Vec::clear()`'s performance
mattered enough to justify the change. Recent changes within rustc have
made `Vec::clear()` hot within `macro_parser.rs`, so the change is now
clearly worthwhile.

Although it doesn't show wins on CI perf runs, this seems to be because they
use PGO. But not all platforms currently use PGO. Also, local builds don't use
PGO, and `truncate` sometimes shows up in an over-represented fashion in local
profiles. So local profiling will be made easier by this change.

Note that this will also benefit `String::clear()`, because it just
calls `Vec::clear()`.

Finally, the commit removes the `vec-clear.rs` codegen test. It was
added in #52908. From before then until now, `Vec::clear()` just called
`Vec::truncate()` with a zero length. The body of Vec::truncate() has
changed a lot since then. Now that `Vec::clear()` is doing actual work
itself, and not just calling `Vec::truncate()`, it's not surprising that
its generated code includes a load and an icmp. I think it's reasonable
to remove this test.
2022-04-13 15:39:35 +10:00
Dylan DPC
633c391225
Rollup merge of #95984 - wcampbell0x2a:fix-spelling, r=thomcc
Fix spelling in docs for `can_not_overflow`

Introduced in https://github.com/rust-lang/rust/pull/95399
2022-04-13 05:54:13 +02:00
Dylan DPC
6aa875aa96
Rollup merge of #95914 - c410-f3r:meta-vars, r=petrochenkov
Implement tuples using recursion

Because it is c00l3r™, requires less repetition and can be used as a reference for external people.

This change is non-essential and I am not sure about potential performance impacts so feel free to close this PR if desired.

r? `@petrochenkov`
2022-04-12 23:16:58 +02:00
Caio
23bf977758 Implement tuples using recursion 2022-04-12 16:23:36 -03:00
wcampbell
9ea89e1d3d Fix spelling in docs for can_not_overflow 2022-04-12 13:29:56 -04:00
Ralf Jung
e886dc52ee portable-simd: use simd_arith_offset to avoid ptr-int transmutation 2022-04-12 11:09:26 -04:00
fee1-dead
1d76dd9ee7
Rollup merge of #95947 - cuviper:default-box, r=dtolnay
`impl const Default for Box<[T]>` and `Box<str>`

The unstable `const_default_impls` (#87864) already include empty `Vec<T>` and `String`. Now we extend that concept to `Box<[T]>` and `Box<str>` as well.

This obviates a hack in `rustc_ast`'s `P::<[T]>::new`.
2022-04-12 22:44:45 +10:00
fee1-dead
cdbdf1ef2e
Rollup merge of #95900 - o01eg:fix-wasm-doc, r=Mark-Simulacrum
Fix documentation for wasm32-unknown-unknown

Fixes https://github.com/rust-lang/rust/issues/76526#issuecomment-1094208720
2022-04-12 22:44:44 +10:00
Jubilee Young
83581796b2 Ban subnormals and NaNs in const {from,to}_bits 2022-04-12 02:27:25 -07:00
Jubilee Young
b200483412 Rectify float classification impls for weird FPUs
Careful handling does its best to take care of both Armv7's
"unenhanced" Neon as well as the x87 FPU.
2022-04-12 02:27:25 -07:00
Mara Bos
d4e44a6391 Add missing unsafe marker.
This is now necessary because of deny(unsafe_op_in_unsafe_fn).
2022-04-12 08:44:39 +02:00
Mara Bos
8a2c9a9615 Allow cvt_nz to be unused on some platforms. 2022-04-12 08:44:39 +02:00
Mara Bos
5b2591299a Add #[deny(unsafe_op_in_unsafe_fn)] to thread_local!(const).
This avoids 'unused unsafe' warnings when using this feature inside std.
2022-04-12 08:44:39 +02:00
Mara Bos
83e8b9e4dd Add debug asserts to futex ReentrantMutex impl. 2022-04-12 08:44:39 +02:00
Mara Bos
43651aa34f Initialize thread local with const{}. 2022-04-12 08:44:39 +02:00
Mara Bos
319a9b0f71 Move current_thread_unique_ptr to the only module that uses it. 2022-04-12 08:44:39 +02:00
Mara Bos
ebebe6f837 Make current_thread_unique_ptr work during thread destruction.
Otherwise we can't use println!() within atexit handlers etc.
2022-04-12 08:44:38 +02:00
Mara Bos
bd61bec67d Add futex-based ReentrantMutex on Linux. 2022-04-12 08:44:38 +02:00
Mara Bos
c62c8cb82d Add current_thread_unique_ptr() in std::sys_common. 2022-04-12 08:41:42 +02:00
bors
4e1927db3c Auto merge of #95399 - gilescope:plan_b, r=scottmcm
Faster parsing for lower numbers for radix up to 16 (cont.)

( Continuation of https://github.com/rust-lang/rust/pull/83371 )

With LingMan's change I think this is potentially ready.
2022-04-12 05:54:50 +00:00
Martin Pool
7cdef0876d Document that DirEntry holds the directory open 2022-04-11 19:00:29 -07:00
Jacob Pratt
2638e969c8
Bump stdarch 2022-04-11 21:40:31 -04:00
bors
36f4ded69e Auto merge of #93408 - liangyongrui:master, r=scottmcm
fix Layout struct member naming style
2022-04-12 00:18:51 +00:00
Soni L
8d5a4963df
Implement Default for AssertUnwindSafe
Trait impls are still insta-stable yeah...?
2022-04-11 17:56:27 -03:00
Josh Stone
a2902ebe57 impl const Default for Box<[T]> and Box<str> 2022-04-11 12:14:18 -07:00
Dylan DPC
ae6f75a0c3
Rollup merge of #95895 - CAD97:patch-2, r=Dylan-DPC
Clarify str::from_utf8_unchecked's invariants

Specifically, make it clear that it is immediately UB to pass ill-formed UTF-8 into the function. The previous wording left space to interpret that the UB only occurred when calling another function, which "assumes that `&str`s are valid UTF-8."

This does not change whether str being UTF-8 is a safety or a validity invariant. (As per previous discussion, it is a safety invariant, not a validity invariant.) It just makes it clear that valid UTF-8 is a precondition of str::from_utf8_unchecked, and that emitting an Abstract Machine fault (e.g. UB or a sanitizer error) on invalid UTF-8 is a valid thing to do.

If user code wants to create an unsafe `&str` pointing to ill-formed UTF-8, it must be done via transmutes. Also, just, don't.

Zulip discussion: https://rust-lang.zulipchat.com/#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/str.3A.3Afrom_utf8_unchecked.20Safety.20requirement
2022-04-11 20:00:44 +02:00
Dylan DPC
82a6463b1c
Rollup merge of #95894 - nyanpasu64:fix-pin-docs, r=Dylan-DPC
Fix formatting error in pin.rs docs

Not sure if there's more formatting issues I missed; I kinda lost interest reading midway through.
2022-04-11 20:00:43 +02:00
Dylan DPC
a15ac30162
Rollup merge of #95801 - m-ou-se:futex-rwlock, r=Amanieu
Replace RwLock by a futex based one on Linux

This replaces the pthread-based RwLock on Linux by a futex based one.

This implementation is similar to [the algorithm](https://gist.github.com/kprotty/3042436aa55620d8ebcddf2bf25668bc) suggested by `@kprotty,` but modified to prefer writers and spin before sleeping. It uses two futexes: One for the readers to wait on, and one for the writers to wait on. The readers futex contains the state of the RwLock: The number of readers, a bit indicating whether writers are waiting, and a bit indicating whether readers are waiting. The writers futex is used as a simple condition variable and its contents are meaningless; it just needs to be changed on every notification.

Using two futexes rather than one has the obvious advantage of allowing a separate queue for readers and writers, but it also means we avoid the problem a single-futex RwLock would have of making it hard for a writer to go to sleep while the number of readers is rapidly changing up and down, as the writers futex is only changed when we actually want to wake up a writer.

It always prefers writers, as we decided [here](https://github.com/rust-lang/rust/issues/93740#issuecomment-1070696128).

To be able to prefer writers, it relies on futex_wake to return the number of awoken threads to be able to handle write-unlocking while both the readers-waiting and writers-waiting bits are set. Instead of waking both and letting them race, it first wakes writers and only continues to wake the readers too if futex_wake reported there were no writers to wake up.

r? `@Amanieu`
2022-04-11 20:00:41 +02:00
O01eg
3f4bbd50fd
Fix documentation for wasm32-unknown-unknown 2022-04-11 19:16:51 +03:00
Mara Bos
8339381741 Use is_ or has_ prefix for pure -> bool functions. 2022-04-11 14:52:02 +02:00
Mara Bos
c4a4f48c52 Use compare_exchange_weak in futex rwlock implementation. 2022-04-11 14:29:32 +02:00
Mara Bos
1f2c2bb24f Add comments to futex rwlock implementation. 2022-04-11 14:27:06 +02:00
Mara Bos
7c28791565 Add doc comments to futex operations. 2022-04-11 14:26:52 +02:00
Matthias Krüger
5b8e2ea520
Rollup merge of #95917 - RalfJung:thin-box-test, r=dtolnay
thin_box test: import from std, not alloc

Importing from `alloc` makes [Miri fail](https://github.com/rust-lang/miri-test-libstd/runs/5964922742?check_suite_focus=true), probably due to the hack that we used to resolve https://github.com/rust-lang/miri-test-libstd/issues/4. There might be better ways around this, but for now this is the easiest thing to do -- no other alloc integration test is importing from `alloc::`.
2022-04-11 12:06:58 +02:00
Matthias Krüger
e25bc303f1
Rollup merge of #95743 - yaahc:binary-search-clarification, r=Mark-Simulacrum
Update binary_search example to instead redirect to partition_point

Inspired by discussion in the tracking issue for `Result::into_ok_or_err`: https://github.com/rust-lang/rust/issues/82223#issuecomment-1067098167

People are surprised by us not providing a `Result<T, T> -> T` conversion, and the main culprit for this confusion seems to be the `binary_search` API. We should instead redirect people to the equivalent API that implicitly does that `Result<T, T> -> T` conversion internally which should obviate the need for the `into_ok_or_err` function and give us time to work towards a more general solution that applies to all enums rather than just `Result` such as making or_patterns usable for situations like this via postfix `match`.

I choose to duplicate the example rather than simply moving it from `binary_search` to partition point because most of the confusion seems to arise when people are looking at `binary_search`. It makes sense to me to have the example presented immediately rather than requiring people to click through to even realize there is an example. If I had to put it in only one place I'd leave it in `binary_search` and remove it from `partition_point` but it seems pretty obviously relevant to `partition_point` so I figured the best option would be to duplicate it.
2022-04-11 12:06:52 +02:00
Giles Cope
3ee7bb19c6
better def of is signed in tests. 2022-04-11 07:37:53 +01:00
liangyongrui
03b2588837 fix Layout struct member naming style 2022-04-11 13:35:18 +08:00
Ralf Jung
dbc0afa215 thin_box test: import from std, not alloc 2022-04-10 22:59:51 -04:00
Christopher Durham
b92cd1a32c
Clarify str::from_utf8_unchecked's invariants
Specifically, make it clear that it is immediately UB to pass ill-formed UTF-8 into the function. The previous wording left space to interpret that the UB only occurred when calling another function, which "assumes that `&str`s are valid UTF-8."

This does not change whether str being UTF-8 is a safety or a validity invariant. (As per previous discussion, it is a safety invariant, not a validity invariant.) It just makes it clear that valid UTF-8 is a precondition of str::from_utf8_unchecked, and that emitting an Abstract Machine fault (e.g. UB or a sanitizer error) on invalid UTF-8 is a valid thing to do.

If user code wants to create an unsafe `&str` pointing to ill-formed UTF-8, it must be done via transmutes. Also, just, don't.
2022-04-10 15:04:57 -05:00
nyanpasu64
bb3a071df8
Fix formatting error in pin.rs docs 2022-04-10 12:41:31 -07:00
Dylan DPC
c0655dec7e
Rollup merge of #95566 - eduardosm:std_char_consts_and_methods, r=Mark-Simulacrum
Avoid duplication of doc comments in `std::char` constants and functions

For those consts and functions, only the summary is kept and a reference to the `char` associated const/method is included.

Additionaly, re-exported functions have been converted to function definitions that call the previously re-exported function. This makes it easier to add a deprecated attribute to these functions in the future.
2022-04-10 21:03:34 +02:00
Giles Cope
79e8653656
No need to use Default 2022-04-10 18:20:13 +01:00
Giles Cope
515906a669
Use Add, Sub, Mul traits instead of unsafe 2022-04-10 18:13:48 +01:00
bors
7af93292c2 Auto merge of #95621 - saethlin:remove-mpsc-transmute, r=RalfJung
Remove ptr-int transmute in std::sync::mpsc

Since https://github.com/rust-lang/rust/pull/95340 landed, Miri with `-Zmiri-check-number-validity` produces an error on the test suites of some crates which implement concurrency tools<sup>*</sup>, because it seems like such crates tend to use `std::sync::mpsc` in their tests. This fixes the problem by storing pointer bytes in a pointer.

<sup>*</sup> I have so far seen errors in the test suites of `once_cell`, `parking_lot`, and `crossbeam-utils`.
(just updating the list for fun, idk)
Also `threadpool`, `async-lock`, `futures-timer`, `fragile`, `scoped_threadpool`, `procfs`, `slog-async`, `scheduled-thread-pool`, `tokio-threadpool`, `mac`, `futures-cpupool`, `ntest`, `actix`, `zbus`, `jsonrpc-client-transports`, `fail`, `libp2p-gossipsub`, `parity-send-wrapper`, `async-broadcast,` `libp2p-relay`, `http-client`, `mockito`, `simple-mutex`, `surf`, `pollster`, and `pulse`. Then I turned the bot off.
2022-04-10 08:57:32 +00:00
Dylan DPC
7726265ae0
Rollup merge of #95831 - redzic:xor-uppercase, r=workingjubilee
Use bitwise XOR in to_ascii_uppercase

This saves an instruction compared to the previous approach, which
was to unset the fifth bit with bitwise OR.

Comparison of generated assembly on x86: https://godbolt.org/z/GdfvdGs39

This can also affect autovectorization, saving SIMD instructions as well: https://godbolt.org/z/cnPcz75T9

Not sure if `u8::to_ascii_lowercase` should also be changed, since using bitwise OR for that function does not require an extra bitwise negate since the code is setting a bit rather than unsetting a bit. `char::to_ascii_uppercase` already uses XOR, so no change seems to be required there.
2022-04-09 18:26:30 +02:00
Dylan DPC
2464ea2510
Rollup merge of #95817 - oconnor663:doc_comment2, r=yaahc
hide another #[allow] directive from a docs example

This is a repeat for Rc of e0e64a8930,
which cleaned up the same thing for Arc.
2022-04-09 18:26:29 +02:00
Dylan DPC
5092946041
Rollup merge of #95805 - c410-f3r:meta-vars, r=petrochenkov
Left overs of #95761

These are just nits. Feel free to close this PR if all modifications are not worth merging.

* `#![feature(decl_macro)]` is not needed anymore in `rustc_expand`
* `tuple_impls` does not require `$Tuple:ident`. I guess it is there to enhance readability?

r? ```@petrochenkov```
2022-04-09 18:26:27 +02:00
Dylan DPC
e4b4bf1535
Rollup merge of #95361 - scottmcm:valid-align, r=Mark-Simulacrum
Make non-power-of-two alignments a validity error in `Layout`

Inspired by the zulip conversation about how `Layout` should better enforce `size <= isize::MAX as usize`, this uses an N-variant enum on N-bit platforms to require at the validity level that the existing invariant of "must be a power of two" is upheld.

This was MIRI can catch it, and means there's a more-specific type for `Layout` to store than just `NonZeroUsize`.

It's left as `pub(crate)` here; a future PR could consider giving it a tracking issue for non-internal usage.
2022-04-09 18:26:25 +02:00
Dylan DPC
1ced0b61a4
Rollup merge of #94794 - mlodato517:mlodato517-clarify-string-indexing-docs, r=Mark-Simulacrum
Clarify indexing into Strings

**This Commit**
Adds some clarity around indexing into Strings.

**Why?**
I was reading through the `Range` documentation and saw an
implementation for `SliceIndex<str>`. I was surprised to see this and
went to read the [`String`][0] documentation and, to me, it seemed to
say (at least) three things:

1. you cannot index into a `String`
2. indexing into a `String` could not be constant-time
3. indexing into a `String` does not have an obvious return type

I absolutely agree with the last point but the first two seemed
contradictory to the documentation around [`SliceIndex<str>`][1]
which mention:

1. you can do substring slicing (which is probably different than
   "indexing" but, because the method is called `index` and I associate
   anything with square brackets with "indexing" it was enough to
   confuse me)
2. substring slicing is constant-time (this may be algorithmic ignorance
   on my part but if `&s[i..i+1]` is O(1) then it seems confusing that
   `&s[i]` _could not possibly_ be O(1))

So I was hoping to clarify a couple things and, hopefully, in this PR
review learn a little more about the nuances here that confused me in
the first place.

[0]: https://doc.rust-lang.org/stable/std/string/struct.String.html#utf-8
[1]: https://doc.rust-lang.org/stable/std/slice/trait.SliceIndex.html#impl-SliceIndex%3Cstr%3E
2022-04-09 18:26:25 +02:00
Mark Lodato
9cf35a6c06 Rework String UTF-8 Documentation
**This Commit**
Adds some clarity around indexing into Strings and the constraints
driving various decisions there.

**Why?**
The [`String` documentation][0] mentions how `String`s can't be indexed
but `Range` has an implementation for `SliceIndex<str>`. This can be
confusing. There are also several statements to explain the lack of
`String` indexing:

- the inability to index into a `String` is an implication of UTF-8
  encoding
- indexing into a `String` could not be constant-time with UTF-8
  encoding
- indexing into a `String` does not have an obvious return type

This last statement made sense but the first two seemed contradictory to
the documentation around [`SliceIndex<str>`][1] which mention:

- one can index into a `String` with a `Range` (also called substring
  slicing but it uses the same syntax and the method name is `index`)
- `Range` indexing into a `String` is constant-time

To resolve this seeming contradiction the documentation is reworked to
more clearly explain what factors drive the decision to disallow
indexing into a `String` with a single number.

[0]: https://doc.rust-lang.org/stable/std/string/struct.String.html#utf-8
[1]: https://doc.rust-lang.org/stable/std/slice/trait.SliceIndex.html#impl-SliceIndex%3Cstr%3E
2022-04-09 09:27:32 -04:00
Dylan DPC
af895b0715
Rollup merge of #95802 - RalfJung:unused-win, r=Dylan-DPC
fix unused constant warning on some Windows targets

When none of those `cfg_if!` apply (and on Miri), the constant remains unused.
2022-04-09 12:52:06 +02:00
Dylan DPC
e232cb42e6
Rollup merge of #95308 - bjorn3:more_stable_proc_macro, r=Mark-Simulacrum
Reduce the amount of unstable features used in libproc_macro

This makes it easier to adapt the source for stable when copying it into rust-analyzer to load rustc compiled proc macros.
2022-04-09 12:52:02 +02:00
Dylan DPC
8d7392232c
Rollup merge of #95787 - yaahc:panic-doc-update-v2, r=dtolnay
reword panic vs result section to remove recoverable vs unrecoverable framing

Based on feedback from the Error Handling FAQ: https://github.com/rust-lang/project-error-handling/issues/50#issuecomment-1090876982

r? ````@dtolnay````
2022-04-09 05:58:44 +02:00
Ben Kimock
dec73f58d8 Remove ptr-int transmute in std::sync::mpsc
Since https://github.com/rust-lang/rust/pull/95340 landed, Miri with
-Zmiri-check-number-validity produces an error on the test suites of
some crates which implement concurrency tools, because it seems like
such crates tend to use std::sync::mpsc in their tests. This fixes the
problem by storing pointer bytes in a pointer.
2022-04-08 23:28:31 -04:00
Scott McMurray
fe0c08a4f2 Make non-power-of-two alignments a validity error in Layout
Inspired by the zulip conversation about how `Layout` should better enforce `size < isize::MAX as usize`, this uses an N-variant enum on N-bit platforms to require at the validity level that the existing invariant of "must be a power of two" is upheld.

This was MIRI can catch it, and means there's a more-specific type for `Layout` to store than just `NonZeroUsize`.
2022-04-08 20:17:38 -07:00
Redzic
1e6365d075 Use bitwise XOR in to_ascii_uppercase
This saves an instruction compared to the previous approach, which
was to unset the fifth bit with bitwise OR.
2022-04-08 20:06:54 -05:00
Jack O'Connor
c1023e9e5f hide another #[allow] directive from a docs example
This is a repeat for Rc of e0e64a8930,
which cleaned up the same thing for Arc.
2022-04-08 10:29:50 -07:00
Jane Lusby
a87a0d089e Add ThinBox type for 1 stack pointer sized heap allocated trait objects
Relevant commit messages from squashed history in order:

Add initial version of ThinBox

update test to actually capture failure

swap to middle ptr impl based on matthieu-m's design

Fix stack overflow in debug impl

The previous version would take a `&ThinBox<T>` and deref it once, which
resulted in a no-op and the same type, which it would then print causing
an endless recursion. I've switched to calling `deref` by name to let
method resolution handle deref the correct number of times.

I've also updated the Drop impl for good measure since it seemed like it
could be falling prey to the same bug, and I'll be adding some tests to
verify that the drop is happening correctly.

add test to verify drop is behaving

add doc examples and remove unnecessary Pointee bounds

ThinBox: use NonNull

ThinBox: tests for size

Apply suggestions from code review

Co-authored-by: Alphyr <47725341+a1phyr@users.noreply.github.com>

use handle_alloc_error and fix drop signature

update niche and size tests

add cfg for allocating APIs

check null before calculating offset

add test for zst and trial usage

prevent optimizer induced ub in drop and cleanup metadata gathering

account for arbitrary size and alignment metadata

Thank you nika and thomcc!

Update library/alloc/src/boxed/thin.rs

Co-authored-by: Josh Triplett <josh@joshtriplett.org>

Update library/alloc/src/boxed/thin.rs

Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2022-04-08 09:00:16 -07:00
Mara Bos
307aa588f4
Fix typo in futex rwlock.
Co-authored-by: Amanieu d'Antras <amanieu@gmail.com>
2022-04-08 16:07:07 +02:00
Caio
e946aa3a74 Left overs of #95761 2022-04-08 10:30:24 -03:00
Ralf Jung
9c977530b5 fix some unused constant warning on some Windows targets 2022-04-08 08:36:56 -04:00