Commit graph

1828 commits

Author SHA1 Message Date
Jethro Beekman
eb6f2d4be0 Revert "SGX mutex is movable"
This reverts commit 30b82e0f96.
2021-07-27 12:10:24 +02:00
bors
0ded6adf66 Auto merge of #87430 - devnexen:netbsd_ucred_enabled, r=joshtriplett
netbsd enabled ucred
2021-07-26 00:22:45 +00:00
bors
2b4196e977 Auto merge of #84111 - bstrie:hashfrom, r=joshtriplett
Stabilize `impl From<[(K, V); N]> for HashMap` (and friends)

In addition to allowing HashMap to participate in Into/From conversion, this adds the long-requested ability to use constructor-like syntax for initializing a HashMap:
```rust
let map = HashMap::from([
    (1, 2),
    (3, 4),
    (5, 6)
]);
```
This addition is highly motivated by existing precedence, e.g. it is already possible to similarly construct a Vec from a fixed-size array:
```rust
let vec = Vec::from([1, 2, 3]);
```
...and it is already possible to collect a Vec of tuples into a HashMap (and vice-versa):
```rust
let vec = Vec::from([(1, 2)]);
let map: HashMap<_, _> = vec.into_iter().collect();
let vec: Vec<(_, _)> = map.into_iter().collect();
```
...and of course it is likewise possible to collect a fixed-size array of tuples into a HashMap ([but not vice-versa just yet](https://github.com/rust-lang/rust/issues/81615)):
```rust
let arr = [(1, 2)];
let map: HashMap<_, _> = std::array::IntoIter::new(arr).collect();
```
Therefore this addition seems like a no-brainer.

As for any impl, this would be insta-stable.
2021-07-24 22:31:14 +00:00
bstrie
1b83fedda4 Update std_collections_from_array stability version 2021-07-24 14:04:51 -04:00
Manish Goregaokar
5c63506bd8
Rollup merge of #87395 - ericonr:patch-1, r=joshtriplett
Clear up std::env::set_var panic section.

The "K" parameter was being referred to as "key", which wasn't
introduced anywhere.
2021-07-24 09:52:00 -07:00
David Carlier
42adaab699 netbsd enabled ucred 2021-07-24 16:21:19 +01:00
bors
1c66d11a34 Auto merge of #84589 - In-line:zircon-thread-name, r=JohnTitor
Implement setting thread name for Fuchsia
2021-07-24 07:40:34 +00:00
Érico Nogueira Rolim
74f01a4bbe Fix parameter names in std::env documentation.
The function parameters were renamed, but the documentation wasn't.
2021-07-23 17:20:45 -03:00
Yuki Okushi
f335bca8a5
Rollup merge of #87175 - inquisitivecrystal:inner-error, r=kennytm
Stabilize `into_parts()` and `into_error()`

This stabilizes `IntoInnerError`'s `into_parts()` and `into_error()` methods, currently gated behind the `io_into_inner_error_parts` feature. The FCP has [already completed.](https://github.com/rust-lang/rust/issues/79704#issuecomment-880652967)

Closes #79704.
2021-07-24 04:31:04 +09:00
Yuki Okushi
2038fa5849
Rollup merge of #87171 - Alexendoo:bufwriter-option, r=Mark-Simulacrum
Remove Option from BufWriter

Fixes #72925
2021-07-24 04:31:03 +09:00
Yuki Okushi
249a11f936
Rollup merge of #86790 - janikrabe:retain-iter-order-doc, r=m-ou-se
Document iteration order of `retain` functions

For `HashSet` and `HashMap`, this simply copies the comment from
`BinaryHeap::retain`.

For `BTreeSet` and `BTreeMap`, this adds an additional guarantee that
wasn't previously documented. I think that because these data structures
are inherently ordered and other functions guarantee ordered iteration,
it makes sense to provide this guarantee for `retain` as well.
2021-07-24 04:30:56 +09:00
Alex Macleod
8837bf1acd Remove Option from BufWriter
Fixes #72925
2021-07-22 20:59:06 +01:00
Guillaume Gomez
eb54ddd123
Rollup merge of #87279 - sunfishcode:document-unix-argv, r=RalfJung
Add comments explaining the unix command-line argument support.

Following up on #87236, add comments to the unix command-line argument
support explaining that the code doesn't mutate the system-provided
argc/argv, and that this is why the code doesn't need a lock or special
memory ordering.

r? ```@RalfJung```
2021-07-21 15:52:49 +02:00
bors
cf932aa584 Auto merge of #86847 - tlyu:stdin-forwarders, r=joshtriplett
add `Stdin::lines`, `Stdin::split` forwarder methods

Add forwarder methods `Stdin::lines` and `Stdin::split`, which consume
and lock a `Stdin` handle, and forward on to the corresponding `BufRead`
methods. This should make it easier for beginners to use those iterator
constructors without explicitly dealing with locks or lifetimes.

Replaces #86412.
~~Based on #86846 to get the tracking issue number for the `stdio_locked` feature.~~ Rebased after merge, so it's only one commit now.

r? `@joshtriplett`
`@rustbot` label +A-io +C-enhancement +D-newcomer-roadblock +T-libs-api
2021-07-21 06:06:37 +00:00
Dan Gohman
2a56a681c4 Add comments explaining the unix command-line argument support.
Following up on #87236, add comments to the unix command-line argument
support explaining that the code doesn't mutate the system-provided
argc/argv, and that this is why the code doesn't need a lock or special
memory ordering.
2021-07-19 07:16:37 -07:00
Guillaume Gomez
6df9df7e36
Rollup merge of #87236 - sunfishcode:avoid-locking-args, r=joshtriplett
Simplify command-line argument initialization on unix

Simplify Rust's command-line argument initialization code on unix:
 - The cleanup code isn't needed, because it was just zeroing out non-owning variables at runtime cleanup time. After 91c3eee173, Rust's command-line initialization code on unix no longer allocates `CString`s and a `Vec` at startup time.
 - The `Mutex` isn't needed; if there's somehow a call to `args()` before argument initialization has happened, the code returns return an empty list, which we can do with a null check.

With these changes, a simple cdylib that doesn't use threads avoids getting `pthread_mutex_lock`/`pthread_mutex_unlock` in its symbol table.
2021-07-19 11:37:45 +02:00
Guillaume Gomez
65b7aa98c7
Rollup merge of #87227 - bstrie:asm2arch, r=Amanieu
Move asm! and global_asm! to core::arch

Follow-up to https://github.com/rust-lang/stdarch/pull/1183 .

Implements the libs-api team decision from rust-lang/rust#84019 (comment) .

In order to not break nightly users, this PR also adds the newly-moved items to the prelude. However, a decision will need to be made before stabilization as to whether these items should remain in the prelude. I will file an issue for this separately.

Fixes #84019 .

r? `@Amanieu`
2021-07-19 11:37:44 +02:00
bstrie
f26fbe2453 Move asm! and global_asm! to core::arch 2021-07-18 18:30:58 -04:00
Yuki Okushi
07faa2e32c
Rollup merge of #87170 - xFrednet:clippy-5393-add-diagnostic-items, r=Manishearth,oli-obk
Add diagnostic items for Clippy

This adds a bunch of diagnostic items to `std`/`core`/`alloc` functions, structs and traits used in Clippy. The actual refactorings in Clippy to use these items will be done in a different PR in Clippy after the next sync.

This PR doesn't include all paths Clippy uses, I've only gone through the first 85 lines of Clippy's [`paths.rs`](ecf85f4bdc/clippy_utils/src/paths.rs) (after rust-lang/rust-clippy#7466) to get some feedback early on. I've also decided against adding diagnostic items to methods, as it would be nicer and more scalable to access them in a nicer fashion, like adding a `is_diagnostic_assoc_item(did, sym::Iterator, sym::map)` function or something similar (Suggested by `@camsteffen` [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/147480-t-compiler.2Fwg-diagnostics/topic/Diagnostic.20Item.20Naming.20Convention.3F/near/225024603))

There seems to be some different naming conventions when it comes to diagnostic items, some use UpperCamelCase (`BinaryHeap`) and some snake_case (`hashmap_type`). This PR uses UpperCamelCase for structs and traits and snake_case with the module name as a prefix for functions. Any feedback on is this welcome.

cc: rust-lang/rust-clippy#5393

r? `@Manishearth`
2021-07-18 14:21:57 +09:00
Dan Gohman
c3df0ae97f x.py fmt 2021-07-17 18:31:51 -07:00
Dan Gohman
9bb11ba511 Remove an unnecessary Mutex around argument initialization.
In the command-line argument initialization code, remove the Mutex
around the `ARGV` and `ARGC` variables, and simply check whether
ARGV is non-null before dereferencing it. This way, if either of
ARGV or ARGC is not initialized, we'll get an empty argument list.

This allows simple cdylibs to avoid having
`pthread_mutex_lock`/`pthread_mutex_unlock` appear in their symbol
tables if they don't otherwise use threads.
2021-07-17 13:35:38 -07:00
Dan Gohman
46010c4618 Remove args cleanup code.
As of 91c3eee173, the global ARGC and ARGV
no longer reference dynamically-allocated memory, so they don't need to
be cleaned up.
2021-07-17 13:35:27 -07:00
Jane Lusby
93b7aee2da rename assert_matches module 2021-07-16 09:18:14 -07:00
inquisitivecrystal
803f79db48 Stabilize into_parts() and into_error() 2021-07-15 16:44:56 -07:00
xFrednet
d38f2b0cc1 Added diagnostic items to structs and traits for Clippy 2021-07-15 23:57:02 +02:00
Yuki Okushi
b99f7edad2
Rollup merge of #87081 - a1phyr:add_wasi_ext_tracking_issue, r=dtolnay
Add tracking issue number to `wasi_ext`

Feature `wasi_ext` is tracked by #71213 but is was not in the source code.
2021-07-15 21:19:18 +09:00
Yuki Okushi
a5acb7b4ba
Rollup merge of #86947 - m-ou-se:assert-matches-to-submodule, r=yaahc
Move assert_matches to an inner module

Fixes #82913
2021-07-15 21:19:16 +09:00
Vadim Petrochenkov
6c9ea1e8a9 expand: Support helper attributes for built-in derive macros 2021-07-13 21:59:22 +03:00
Taylor Yu
339ce4fee8 add Stdin::lines, Stdin::split forwarder methods
Add forwarder methods `Stdin::lines` and `Stdin::split`, which consume
and lock a `Stdin` handle, and forward on to the corresponding `BufRead`
methods. This should make it easier for beginners to use those iterator
constructors without explicitly dealing with locks or lifetimes.
2021-07-12 23:43:42 -05:00
Yuki Okushi
bcacfe7c64
Rollup merge of #86846 - tlyu:stdio-locked-tracking, r=joshtriplett
stdio_locked: add tracking issue

Add the tracking issue number #86845 to the stability attributes for the implementation in #86799.

r? `@joshtriplett`
`@rustbot` label +A-io +C-cleanup +T-libs-api
2021-07-13 08:54:30 +09:00
Yuki Okushi
749a589746
Rollup merge of #86811 - soerenmeier:remove_remaining, r=yaahc
Remove unstable `io::Cursor::remaining`

Adding `io::Cursor::remaining` in #86037 caused a conflict with the implementation of `bytes::Buf` for `io::Cursor`, leading to an error in nightly, see https://github.com/rust-lang/rust/issues/86369#issuecomment-867723485.

This fixes the error by temporarily removing the `remaining` function.

r? `@yaahc`
2021-07-13 08:54:28 +09:00
Benoît du Garreau
6e47c8db73 Add tracking issue number to wasi_ext 2021-07-12 15:01:39 +02:00
Yuki Okushi
5541d1ac16
Rollup merge of #86951 - cyberia-ng:fp-negative-zero-sqrt-docs, r=Mark-Simulacrum
[docs] Clarify behaviour of f64 and f32::sqrt when argument is negative zero

From IEEE 754 section 6.3:
> Except that squareRoot(−0) shall be −0, every numeric squareRoot result shall have a positive sign.
2021-07-12 04:31:59 +09:00
bors
dfd7b8d03f Auto merge of #85953 - inquisitivecrystal:weak-linkat-in-fs-hardlink, r=joshtriplett
Fix linker error

Currently, `fs::hard_link` determines whether platforms have `linkat` based on the OS, and uses `link` if they don't. However, this heuristic does not work well if a platform provides `linkat` on newer versions but not on older ones. On old MacOS, this currently causes a linking error.

This commit fixes `fs::hard_link` by telling it to use `weak!` on macOS. This means that, on  that operating system, we now check for `linkat` at runtime and use `link` if it is not available.

Fixes #80804.

`@rustbot` label T-libs-impl
2021-07-10 21:42:40 +00:00
Aris Merchant
5999a5fbdc Make tests pass on old macos
On old macos systems, `fs::hard_link()` will follow symlinks.
This changes the test `symlink_hard_link` to exit early on
these systems, so that tests can pass.
2021-07-10 12:59:25 -07:00
Aris Merchant
fd0cb0cdc2 Change weak! and linkat! to macros 2.0
`weak!` is needed in a test in another module. With macros
1.0, importing `weak!` would require reordering module
declarations in `std/src/lib.rs`, which is a bit too
evil.
2021-07-10 12:55:09 -07:00
Yuki Okushi
0ca5fc2e33
Rollup merge of #87011 - RalfJung:thread-id-supply-shortage, r=nagisa
avoid reentrant lock acquire when ThreadIds run out

Discovered by `@bjorn3`
2021-07-11 01:15:40 +09:00
Ralf Jung
dbc2b55baf rename variable 2021-07-10 14:14:09 +02:00
Ralf Jung
2750d3ac6a avoid reentrant lock acquire when ThreadIds run out 2021-07-10 11:54:38 +02:00
Aris Merchant
5022c0638d Update docs for fs::hard_link 2021-07-09 23:24:36 -07:00
Aris Merchant
dc38d87505 Fix linker error
This makes `fs::hard_link` use weak! for some platforms,
thereby preventing a linker error.
2021-07-09 23:24:36 -07:00
Kornel
bc67f6bc95 Debug formatting of raw_arg() 2021-07-09 14:24:34 +01:00
Kornel
8f9d0f12eb Use AsRef in CommandExt for raw_arg 2021-07-09 14:09:48 +01:00
Kornel
d868da7796 Unescaped command-line arguments for Windows
Fixes #29494
2021-07-09 14:09:48 +01:00
Kornel
fcd5cecdcf Test escaping of trialing slashes in Windows command-line args 2021-07-09 14:09:48 +01:00
Guillaume Gomez
d12b16887b
Rollup merge of #86726 - sexxi-goose:use-diagnostic-item-for-rfc2229-migration, r=nikomatsakis
Use diagnostic items instead of lang items for rfc2229 migrations

This PR removes the `Send`, `UnwindSafe` and `RefUnwindSafe` lang items introduced in https://github.com/rust-lang/rust/pull/84730, and uses diagnostic items instead to check for `Send`, `UnwindSafe` and `RefUnwindSafe` traits for RFC2229 migrations.

r? ```@nikomatsakis```
2021-07-08 18:30:33 +02:00
Mara Bos
e3044432c7 Move [debug_]assert_matches to mod {core, std}::assert. 2021-07-08 02:33:36 +02:00
cyberia
a853a49425 Clarify behaviour of f64 and f32::sqrt when argument is negative zero 2021-07-07 18:22:17 +01:00
Yuki Okushi
9aee3c2883
Rollup merge of #86916 - godmar:@godmar/thread-yield-documentation-fix, r=joshtriplett
rewrote documentation for thread::yield_now()

The old documentation suggested the use of yield_now for repeated
polling instead of discouraging it; it also made the false claim that
channels are implemented using yield_now. (They are not, except for
a corner case).
2021-07-07 12:17:44 +09:00
Yuki Okushi
9bbc470e97
Rollup merge of #80918 - yoshuawuyts:int-log2, r=m-ou-se
Add Integer::log variants

_This is another attempt at landing https://github.com/rust-lang/rust/pull/70835, which was approved by the libs team but failed on Android tests through Bors. The text copied here is from the original issue. The only change made so far is the addition of non-`checked_` variants of the log methods._

_Tracking issue: #70887_

---

This implements `{log,log2,log10}` methods for all integer types. The implementation was provided by `@substack` for use in the stdlib.

_Note: I'm not big on math, so this PR is a best effort written with limited knowledge. It's likely I'll be getting things wrong, but happy to learn and correct. Please bare with me._

## Motivation
Calculating the logarithm of a number is a generally useful operation. Currently the stdlib only provides implementations for floats, which means that if we want to calculate the logarithm for an integer we have to cast it to a float and then back to an int.

> would be nice if there was an integer log2 instead of having to either use the f32 version or leading_zeros() which i have to verify the results of every time to be sure

_— [`@substack,` 2020-03-08](https://twitter.com/substack/status/1236445105197727744)_

At higher numbers converting from an integer to a float we also risk overflows. This means that Rust currently only provides log operations for a limited set of integers.

The process of doing log operations by converting between floats and integers is also prone to rounding errors. In the following example we're trying to calculate `base10` for an integer. We might try and calculate the `base2` for the values, and attempt [a base swap](https://www.rapidtables.com/math/algebra/Logarithm.html#log-rules) to arrive at `base10`. However because we're performing intermediate rounding we arrive at the wrong result:

```rust
// log10(900) = ~2.95 = 2
dbg!(900f32.log10() as u64);

// log base change rule: logb(x) = logc(x) / logc(b)
// log2(900) / log2(10) = 9/3 = 3
dbg!((900f32.log2() as u64) / (10f32.log2() as u64));
```
_[playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=6bd6c68b3539e400f9ca4fdc6fc2eed0)_

This is somewhat nuanced as a lot of the time it'll work well, but in real world code this could lead to some hard to track bugs. By providing correct log implementations directly on integers we can help prevent errors around this.

## Implementation notes

I checked whether LLVM intrinsics existed before implementing this, and none exist yet. ~~Also I couldn't really find a better way to write the `ilog` function. One option would be to make it a private method on the number, but I didn't see any precedent for that. I also didn't know where to best place the tests, so I added them to the bottom of the file. Even though they might seem like quite a lot they take no time to execute.~~

## References

- [Log rules](https://www.rapidtables.com/math/algebra/Logarithm.html#log-rules)
- [Rounding error playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=6bd6c68b3539e400f9ca4fdc6fc2eed0)
- [substack's tweet asking about integer log2 in the stdlib](https://twitter.com/substack/status/1236445105197727744)
- [Integer Logarithm, A. Jaffer 2008](https://people.csail.mit.edu/jaffer/III/ilog.pdf)
2021-07-07 12:17:32 +09:00