Commit Graph

9094 Commits

Author SHA1 Message Date
Jay3332
ba3b3bcc17
Fix typo in concat_bytes documentation
This fixes the typo `&[u8, _]` -> `&[u8; _]`
2022-09-12 21:40:28 -04:00
Guillaume Gomez
7fc3183520
Rollup merge of #100291 - WaffleLapkin:cstr_const_methods, r=oli-obk
constify some `CStr` methods

This PR marks the following public APIs as `const`:
```rust
impl CStr {
    // feature(const_cstr_from_bytes)
    pub const fn from_bytes_until_nul(bytes: &[u8]) -> Result<&CStr, FromBytesUntilNulError>;
    pub const fn from_bytes_with_nul(bytes: &[u8]) -> Result<&Self, FromBytesWithNulError>;

    // feature(const_cstr_to_bytes)
    pub const fn to_bytes(&self) -> &[u8];
    pub const fn to_bytes_with_nul(&self) -> &[u8];
    pub const fn to_str(&self) -> Result<&str, str::Utf8Error>;
}
```

r? ```@oli-obk``` (use of `const_eval_select` :P )
cc ```@mina86``` (you've asked for this <3 )
2022-09-12 22:47:14 +02:00
Maybe Waffle
cb02b647dc constify CStr methods 2022-09-12 16:29:12 +04:00
Dylan DPC
10af4fb530
Rollup merge of #101671 - LingMan:ieee_754, r=Dylan-DPC
Fix naming format of IEEE 754 standard

Currently the documentation of f64::min refers to "IEEE-754 2008" while the documentation of f64::minimum refers to "IEEE 754-2019".
Note that one has the format IEEE,hyphen,number,space,year while the other is IEEE,space,number,hyphen,year. The official IEEE site [1] uses the later format and it is also the one most commonly used throughout the codebase.

Update all comments and - more importantly - documentation to consistently use the official format.

[1] https://standards.ieee.org/ieee/754/4211/
2022-09-12 15:21:32 +05:30
Dylan DPC
93177758fc
Rollup merge of #100767 - kadiwa4:escape_ascii, r=jackh726
Remove manual <[u8]>::escape_ascii

`@rustbot` label: +C-cleanup
2022-09-12 15:21:30 +05:30
bors
3194958217 Auto merge of #100251 - compiler-errors:tuple-trait-2, r=jackh726
Implement `std::marker::Tuple`

Split out from #99943 (https://github.com/rust-lang/rust/pull/99943#pullrequestreview-1064459183).

Implements part of rust-lang/compiler-team#537
r? `@jackh726`
2022-09-12 03:24:29 +00:00
bors
98e1f041b6 Auto merge of #101442 - joboet:null_check_tcs, r=thomcc
Check if TCS is a null pointer on SGX

The `EENTER` instruction only checks if the TCS is aligned, not if it zero. Saying the address returned is a `NonNull<u8>` (for which `Tcs` is a type alias) is unsound. As well-behaved runners will not put the TCS at address zero, so the definition of `Tcs` is correct. However, `std` should check the address before casting it to a `NonNull`.

ping `@jethrogb` `@raoulstrackx`
`@rustbot` label I-unsound
2022-09-11 22:19:24 +00:00
bors
59e7a308e4 Auto merge of #101299 - saethlin:vecdeque-drain-drop, r=thomcc
Remove &[T] from vec_deque::Drain

Fixes https://github.com/rust-lang/rust/issues/60076

I don't know what the right approach is here. There were a few suggestions in the issue, and they all seem a bit thorny to implement. So I just picked one that was kind of familiar.
2022-09-11 19:50:41 +00:00
joboet
2fa58080cb
std: check if TCS is a null pointer 2022-09-11 12:15:32 +02:00
bors
56b625be68 Auto merge of #101482 - joboet:netbsd_parker, r=sanxiyn
Optimize thread parking on NetBSD

As the futex syscall is not present in the latest stable release, NetBSD cannot use the efficient thread parker and locks Linux uses. Currently, it therefore relies on a pthread-based parker, consisting of a mutex and semaphore which protect a state variable. NetBSD however has more efficient syscalls available: [`_lwp_park`](https://man.netbsd.org/_lwp_park.2) and [`_lwp_unpark`](https://man.netbsd.org/_lwp_unpark.2). These already provide the exact semantics of `thread::park` and `Thread::unpark`, but work with thread ids. In `std`, this ID is here stored in an atomic state variable, which is also used to optimize cases were the parking token is already available at the time `thread::park` is called.

r? `@m-ou-se`
2022-09-11 04:07:17 +00:00
LingMan
fd21df7182 Fix naming format of IEEE 754 standard
Currently the documentation of f64::min refers to "IEEE-754 2008" while the documentation of
f64::minimum refers to "IEEE 754-2019".
Note that one has the format IEEE,hyphen,number,space,year while the other is
IEEE,space,number,hyphen,year. The official IEEE site [1] uses the later format and it is also the
one most commonly used throughout the codebase.

Update all comments and - more importantly - documentation to consistently use the official format.

[1] https://standards.ieee.org/ieee/754/4211/
2022-09-11 04:13:33 +02:00
bors
abd4d2ef0d Auto merge of #101643 - ChrisDenton:alloc-link-kernel32, r=thomcc
Explicitly link kernel32.lib from alloc
2022-09-11 01:44:09 +00:00
Ben Kimock
54684c438f Alternate approach; just modify Drain 2022-09-10 17:52:34 -04:00
Ben Kimock
25f4cb59d3 Remove &[T] from vec_deque::Drain 2022-09-10 17:52:34 -04:00
joboet
81b11ed698
std: optimize thread parking on NetBSD 2022-09-10 20:03:15 +02:00
Dylan DPC
33d54c4f73
Rollup merge of #101606 - akhi3030:patch-1, r=Dylan-DPC
doc: fix minor typo
2022-09-10 18:56:07 +05:30
Chris Denton
931e851144
Explicitly link kernel32.lib from alloc 2022-09-10 11:57:36 +01:00
bors
5197c96c49 Auto merge of #101483 - oli-obk:guaranteed_opt, r=fee1-dead
The `<*const T>::guaranteed_*` methods now return an option for the unknown case

cc https://github.com/rust-lang/rust/issues/53020#issuecomment-1236932443

I chose `0` for "not equal" and `1` for "equal" and left `2` for the unknown case so backends can just forward to raw pointer equality and it works 

r? `@fee1-dead` or `@lcnr`

cc `@rust-lang/wg-const-eval`
2022-09-10 09:50:21 +00:00
bors
395e56f398 Auto merge of #101617 - Dylan-DPC:rollup-iiy4ipc, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #101366 (Restore old behaviour on broken UNC paths)
 - #101492 (Suggest adding array lengths to references to arrays if possible)
 - #101529 (Fix the example code and doctest for Formatter::sign_plus)
 - #101573 (update `ParamKindOrd`)
 - #101612 (Fix code generation of `Rvalue::Repeat` with 128 bit values)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-09-09 23:06:40 +00:00
Dylan DPC
fcdd5016c5
Rollup merge of #101529 - mousetail:patch-2, r=thomcc
Fix the example code and doctest for Formatter::sign_plus

The provided example to the `sign_plus` method on `fmt` was broken, it displays the `-` sign twice for negative numbers.

This pull request should fix the issue by `.abs()` ing the number so that the negative sign appears only once. It is just one possible solution to the issue, not sure if it's the best. However, this one will behave as expected when combined with fill and alignment operators.
2022-09-09 22:02:17 +05:30
Dylan DPC
d9609c7c26
Rollup merge of #101366 - ChrisDenton:unc-forward-slash, r=m-ou-se
Restore old behaviour on broken UNC paths

This fixes #101358 by restoring the behaviour from previous stable Rust versions. I'm not convinced this is ultimately right but I think it's less wrong and maybe this should be backported to beta?

r? libs
2022-09-09 22:02:16 +05:30
Oli Scherer
f632dbe46f The <*const T>::guaranteed_* methods now return an option for the unknown case 2022-09-09 15:16:04 +00:00
Guillaume Gomez
ff21ccfba1
Rollup merge of #101529 - mousetail:patch-2, r=thomcc
Fix the example code and doctest for Formatter::sign_plus

The provided example to the `sign_plus` method on `fmt` was broken, it displays the `-` sign twice for negative numbers.

This pull request should fix the issue by `.abs()` ing the number so that the negative sign appears only once. It is just one possible solution to the issue, not sure if it's the best. However, this one will behave as expected when combined with fill and alignment operators.
2022-09-09 15:36:37 +02:00
Guillaume Gomez
3ec332fc82
Rollup merge of #101495 - bjorn3:pause-no-sse2, r=Mark-Simulacrum
Compile spin_loop_hint as pause on x86 even without sse2 enabled

The x86 `pause` instruction was introduced with sse2, but because it is encoded as `rep nop`, it works just fine on cpu's without sse2 support. It just doesn't do anything.
2022-09-09 15:36:36 +02:00
joboet
262193e044
std: use futex-based locks and thread parker on Hermit 2022-09-09 11:56:50 +02:00
Akhilesh Singhania
1933b74dbd
doc: fix minor typo 2022-09-09 11:30:40 +02:00
Matthias Krüger
bdfbc3597b
Rollup merge of #101556 - compiler-errors:tweak-generator-print, r=jackh726
Tweak future opaque ty pretty printing

1. The `Return` type of a generator doesn't need to be a lang item just for diagnostic printing of types
2. We shouldn't suppress the `Output = Ty` of a opaque future if the type is a int or float var.
2022-09-09 07:02:32 +02:00
bors
7200da0217 Auto merge of #93873 - Stovent:big-ints, r=m-ou-se
Reimplement `carrying_add` and `borrowing_sub` for signed integers.

As per the discussion in #85532, this PR reimplements `carrying_add` and `borrowing_sub` for signed integers.

It also adds unit tests for both unsigned and signed integers, emphasing on the behaviours of the methods.
2022-09-09 00:59:08 +00:00
Michael Goulet
2c4dc4f494
Rollup merge of #101423 - mkroening:hermit-warnings, r=sanxiyn
Fix hermit warnings

This fixes two `unused_imprt` and one `dead_code` warning for hermit.
2022-09-08 14:41:08 -07:00
Dylan DPC
7064344ba4
Rollup merge of #101422 - mkroening:hermit-file-time, r=joshtriplett
Hermit: Add File::set_time stub

This is not supported on hermit yet. This change is required for compiling std.
2022-09-08 11:55:07 +05:30
Michael Goulet
2c94102df5 Generator return doesn't need to be a lang item 2022-09-08 02:52:57 +00:00
bors
c2804e6ec2 Auto merge of #101544 - matthiaskrgr:rollup-4urx917, r=matthiaskrgr
Rollup of 14 pull requests

Successful merges:

 - #101343 (Add -api-level to pm command)
 - #101416 (stdio: Document no support for writing to non-blocking stdio/stderr)
 - #101435 (Remove unnecessary `EMIT_MIR_FOR_EACH_BITWIDTH`)
 - #101493 (Pass ImplTraitContext as &mut to avoid the need of ImplTraitContext::reborrow)
 - #101502 (Do not suggest a semicolon for a macro without `!`)
 - #101503 (Add debug calls)
 - #101506 (rustdoc: remove unused CSS `#main-content > .since`)
 - #101507 (rustdoc: remove unused CSS `#main-content > table td`)
 - #101521 (Rustdoc-Json: More accurate struct type.)
 - #101525 (Fix typo in pass_manager.rs)
 - #101534 (rustdoc: remove unused mobile CSS `.rustdoc { flex-direction }`)
 - #101535 (Fix error printing mistake in tidy)
 - #101536 (Add documentation for Attr::is_doc_comment)
 - #101538 (rustdoc: remove unused CSS `.content .methods > div`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-09-07 21:17:30 +00:00
bors
9682b5d3a3 Auto merge of #101476 - ChrisDenton:BCryptRandom-fix, r=thomcc
Open a BCrypt algorithm handle

Fixes #101474, supplants #101456.

Replaces use of a pseduo handle with manually opening a algorithm handle.

Most interesting thing here is the atomics.

r? `@thomcc`
2022-09-07 18:54:03 +00:00
Maurits van Riezen
5fbe485ecc
Typo 2022-09-07 17:53:47 +02:00
Maurits van Riezen
0a9b49c794
Add doctest 2022-09-07 16:36:32 +02:00
Usama Arif
dfbc1f712d stdio: Document no support for writing to non-blocking stdio/stderr
Printing to stdio/stderr that have been opened with non-blocking
(O_NONBLOCK in linux) can result in an error, which is not handled
by std::io module causing a panic.

Signed-off-by: Usama Arif <usama.arif@bytedance.com>
2022-09-07 14:22:57 +01:00
Chris Denton
832c7af0ea
Don't break windows/rand for miri 2022-09-07 14:00:15 +01:00
Maurits van Riezen
1dac6da408
This example was broken
The provided example to the `sign_plus` method on `fmt` is broken, it displays the `-` sign twice for negative numbers.
2022-09-07 14:01:30 +02:00
Yuki Okushi
923dae5c9f
Rollup merge of #101481 - ChrisDenton:uwp-fix, r=thomcc
Fix compile errors for uwp-windows-msvc targets

Fixes #101480
2022-09-07 07:43:53 +09:00
Chris Denton
b2e4f9dcb3
Open a BCrypt algorithm handle 2022-09-06 19:29:58 +01:00
bjorn3
d8b382105f
Compile spin_loop_hint as pause on x86 even without sse2 enabled
The x86 `pause` instruction was introduced with sse2, but because it is encoded as `rep nop`, it works just fine on cpu's without sse2 support. It just doesn't do anything.
2022-09-06 20:08:04 +02:00
bors
380addd7d2 Auto merge of #100733 - scottmcm:inline-from-from-identity, r=m-ou-se
Inline `<T as From<T>>::from`

I noticed (in https://github.com/rust-lang/rust/pull/100693#issuecomment-1218520141) that the MIR for <https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=67097e0494363ee27421a4e3bdfaf513> has inlined most stuff
```
scope 5 (inlined <Result<i32, u32> as Try>::branch)
```
```
scope 8 (inlined <Result<i32, u32> as Try>::from_output)
```

But yet the do-nothing `from` call was still there:
```
_17 = <u32 as From<u32>>::from(move _18) -> bb9;
```

So let's give this a try and see what perf has to say.
2022-09-06 14:33:31 +00:00
Chris Denton
774e71228c
Fix compile errors for uwp-windows-msvc targets 2022-09-06 14:57:42 +01:00
Dylan DPC
00db13fcc9
Rollup merge of #101412 - WaffleLapkin:improve_std_ptr_code_leftovers, r=scottmcm
Some more cleanup in `core`

- remove some integer casts from slice iter (proposed in https://github.com/rust-lang/rust/pull/100819#discussion_r951113196)
- replace `as usize` casts with `usize::from` in slice sort (proposed in https://github.com/rust-lang/rust/pull/100822#discussion_r950768698)

r? `@scottmcm`
2022-09-06 16:34:44 +05:30
Dylan DPC
24f998932e
Rollup merge of #101287 - Adam-Gleave:doc_bool_then_some, r=scottmcm
Document eager evaluation of `bool::then_some` argument

I encountered this earlier today and thought maybe `bool::then_some` could use a little addition to the documentation.

It's pretty obvious with familiarity and from looking at the implementation, but the argument for `then_some` is eagerly evaluated, which means if you do the following (as I did), you can have a problem:

```rust
// Oops!
let _ = something
    .has_another_thing()
    .then_some(something.another_thing_or_panic());
```

A note, similar to other methods with eagerly-evaluated arguments and a lazy alternative (`Option::or`, for example), could help point this out to people who forget (like me)!
2022-09-06 16:34:43 +05:30
Yuki Okushi
c6f6b1821d
Rollup merge of #101426 - beetrees:dup-no-stdio, r=thomcc
Don't duplicate file descriptors into stdio fds

Ensures that file descriptors are never duplicated into the stdio fds even if a stdio fd has been closed.
2022-09-06 08:36:09 +09:00
Yuki Okushi
ff124c6ae8
Rollup merge of #101404 - joboet:always_cleanup_stdout, r=joshtriplett
Fix cleanup for uninitialized stdout

Fixes #101375 by disabling buffering even if the buffer was not initialized yet.
2022-09-06 08:36:05 +09:00
Takayuki Maeda
3955dc3480 separate the receiver from arguments in HIR under /clippy 2022-09-05 22:25:57 +09:00
bors
6e4a9ab650 Auto merge of #101439 - Dylan-DPC:rollup-2wf1mtj, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #101142 (Improve HIR stats)
 - #101367 (Suggest `{Option,Result}::{copied,clone}()` to satisfy type mismatch)
 - #101391 (more clippy::perf fixes)
 - #101409 (Don't fire `rust_2021_incompatible_closure_captures` in `edition = 2021` crates)
 - #101420 (Fix `hir::Local` doc to match with the variable name used: `init`)
 - #101429 (Don't suggest reborrow if usage is inside a closure)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-09-05 09:48:49 +00:00
Dylan DPC
e4534fe6fe
Rollup merge of #101391 - matthiaskrgr:perf0309, r=oli-obk
more clippy::perf fixes
2022-09-05 14:15:52 +05:30