Commit Graph

4136 Commits

Author SHA1 Message Date
Dylan DPC
f4afb9d9ec
Rollup merge of #103127 - SUPERCILEX:inline-const-uninit, r=scottmcm
Make transpose const and inline

r? `@scottmcm`

- These should have been const from the beginning since we're never going to do more than a transmute.
- Inline these always because that's what every other method in MaybeUninit which simply casts does. :) Ok, but a stronger justification is that because we're taking in arrays by `self`, not inlining would defeat the whole purpose of using `MaybeUninit` due to the copying.
2022-10-19 14:05:52 +05:30
bors
84365fff0a Auto merge of #103225 - matthiaskrgr:rollup-1zkv87y, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #103166 (Optimize `slice_iter.copied().next_chunk()`)
 - #103176 (Fix `TyKind::is_simple_path`)
 - #103178 (Partially fix `src/test/run-make/coverage-reports` when cross-compiling)
 - #103198 (Update cargo)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-10-19 05:41:14 +00:00
Matthias Krüger
d6eb7bca09
Rollup merge of #103166 - the8472:copied-next-chunk, r=m-ou-se
Optimize `slice_iter.copied().next_chunk()`

```
OLD:
test iter::bench_copied_array_chunks                               ... bench:         371 ns/iter (+/- 7)
NEW:
test iter::bench_copied_array_chunks                               ... bench:          31 ns/iter (+/- 0)
```

The default `next_chunk` implementation suffers from having to assemble the array byte by byte via `next()`, checking the `Option<&T>` and then dereferencing `&T`. The specialization copies the chunk directly from the slice.
2022-10-19 07:15:30 +02:00
The 8472
873a18e221 specialize slice_iter.copied().next_chunk() 2022-10-19 00:02:00 +02:00
Matthias Krüger
18431b66ce
Rollup merge of #102507 - scottmcm:more-binary-search-docs, r=m-ou-se
More slice::partition_point examples

After seeing the discussion of `binary_search` vs `partition_point` in #101999, I thought some more example code could be helpful.
2022-10-18 21:18:46 +02:00
Matthias Krüger
d2644e538c
Rollup merge of #101889 - tspiteri:redoc-uint-adc-sbb, r=m-ou-se
doc: rewrite doc for uint::{carrying_add,borrowing_sub}

Reword the documentation for bigint helper methods `uint::{carrying_add,borrowing_sub}` (#85532).

The examples were also rewritten to demonstrate how the methods can be used in bignum arithmetic. No loops are used in the examples, but the variable names were chosen to include indices so that it is clear how this can be used in a loop if required.

Also, previously `carrying_add` had an example to say that if the input carry is false, the method is equivalent to `overflowing_add`. While the note was kept, the example was removed and an extra note was added to make sure this equivalence is not assumed for signed integers as well.
2022-10-18 21:18:46 +02:00
Yuki Okushi
b411b8861c
Rollup merge of #103163 - SUPERCILEX:uninit-array-assume2, r=scottmcm
Remove all uses of array_assume_init

See https://github.com/rust-lang/rust/pull/103134#discussion_r997462733

r? `@scottmcm`
2022-10-18 21:21:32 +09:00
Yuki Okushi
e04bbcb9b1
Rollup merge of #103159 - cuviper:check_pow-final-try_opt, r=Mark-Simulacrum
Remove the redundant `Some(try_opt!(..))` in `checked_pow`

The final return value doesn't need to be tried at all -- we can just
return the checked option directly. The optimizer can probably figure
this out anyway, but there's no need to make it work here.
2022-10-18 21:21:31 +09:00
The 8472
963d6f757c add a benchmark for slice_iter.copied().array_chunks() 2022-10-17 23:40:21 +02:00
Alex Saveau
55d71c61b8
Remove all uses of array_assume_init
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-10-17 13:03:54 -07:00
Josh Stone
d7fd1d57ec Remove the redundant Some(try_opt!(..)) in checked_pow
The final return value doesn't need to be tried at all -- we can just
return the checked option directly. The optimizer can probably figure
this out anyway, but there's no need to make it work here.
2022-10-17 11:21:50 -07:00
Sky
9a7e527e28
Fix typo in ReverseSearcher docs 2022-10-17 13:14:15 -04:00
Thayne McCombs
63a7fdf61b Fix types in documentation for Alignment::as_usize and Alignmnet::as_nonzero 2022-10-16 23:44:06 -06:00
Alex Saveau
1a1ebb080f
Make transpose const and inline
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-10-16 17:51:38 -07:00
Matthias Krüger
0602d6484b
Rollup merge of #103109 - RalfJung:phantom-data-impl, r=thomcc
PhantomData: inline a macro that is used only once

I suspect this macro used to have more uses, but right now it just obfuscates the code.
2022-10-16 22:36:06 +02:00
Matthias Krüger
bdfc262742
Rollup merge of #103102 - H4x5:len_utf16_docs, r=scottmcm
Clarify the possible return values of `len_utf16`

`char::len_utf16` always return 1 or 2. Clarify this in the docs, in the same way as `char::len_utf8`.
2022-10-16 22:36:06 +02:00
Sky
a6372525ce
Clarify the possible return values of len_utf16 2022-10-16 11:06:19 -04:00
Ralf Jung
73d655e9c2 remove redundant Send impls for references
also move them next to the trait they are implementing
2022-10-16 11:34:24 +02:00
Ralf Jung
ddd5e983d1 PhantomData: inline a macro that is used only once 2022-10-16 10:37:51 +02:00
Yuki Okushi
166f664037
Rollup merge of #102023 - SUPERCILEX:maybeuninit-transpose, r=scottmcm
Add MaybeUninit array transpose From impls

See discussion in https://github.com/rust-lang/rust/pull/101179 and https://github.com/rust-lang/rust/issues/96097. I believe this solution offers the simplest implementation with minimal future API regret.

`@RalfJung` mind doing a correctness review?
2022-10-16 11:41:12 +09:00
Yuki Okushi
cbc0a73c95
Rollup merge of #101717 - Pointerbender:unsafecell-memory-layout, r=Amanieu
Add documentation about the memory layout of `UnsafeCell<T>`

The documentation for `UnsafeCell<T>` currently does not make any promises about its memory layout. This PR adds this documentation, namely that the memory layout of `UnsafeCell<T>` is the same as the memory layout of its inner `T`.

# Use case
Without this layout promise, the following cast would not be legally possible:

```rust
fn example<T>(ptr: *mut T) -> *const UnsafeCell<T> {
  ptr as *const UnsafeCell<T>
}
```

A use case where this can come up involves FFI. If Rust receives a pointer over a FFI boundary which provides shared read-write access (with some form of custom synchronization), and this pointer is managed by some Rust struct with lifetime `'a`, then it would greatly simplify its (internal) API and safety contract if a `&'a UnsafeCell<T>` can be created from a raw FFI pointer `*mut T`. A lot of safety checks can be done when receiving the pointer for the first time through FFI (non-nullness, alignment, initialize uninit bytes, etc.) and these properties can then be encoded into the `&UnsafeCell<T>` type. Without this documentation guarantee, this is not legal today outside of the standard library.

# Caveats
Casting in the opposite direction is still not valid, even with this documentation change:

```rust
fn example2<T>(ptr: &UnsafeCell<T>) -> &mut T {
  let t = ptr as *const UnsafeCell<T> as *mut T;
  unsafe { &mut *t }
}
```

This is because the only legal way to obtain a mutable pointer to the contents of the shared reference is through [`UnsafeCell::get`](https://doc.rust-lang.org/std/cell/struct.UnsafeCell.html#method.get) and [`UnsafeCell::raw_get`](https://doc.rust-lang.org/std/cell/struct.UnsafeCell.html#method.raw_get). Although there might be a desire to also make this legal at some point in the future, that part is outside the scope of this PR. Also see this relevant [Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/transmuting.20.26.20-.3E.20.26mut).

# Alternatives
Instead of adding a new documentation promise, it's also possible to add a new method to `UnsafeCell<T>` with signature `pub fn from_ptr_bikeshed(ptr: *mut T) -> *const UnsafeCell<T>` which indirectly only allows one-way casting to `*const UnsafeCell<T>`.
2022-10-16 11:41:12 +09:00
Alex Saveau
393434c29e
Add MaybeUninit array transpose impls
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-10-15 15:57:19 -07:00
Scott McMurray
5b9a02a87d More slice::partition_point examples 2022-10-15 14:03:56 -07:00
Ryan Lopopolo
95040a70d7
Stabilize duration_checked_float
Tracking issue:

- https://github.com/rust-lang/rust/issues/83400
2022-10-15 12:02:13 -07:00
bors
8147e6e427 Auto merge of #103069 - matthiaskrgr:rollup-xxsx6sk, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #102092 (refactor: use grep -E/-F instead of fgrep/egrep)
 - #102781 (Improved documentation for `std::io::Error`)
 - #103017 (Avoid dropping TLS Key on sgx)
 - #103039 (checktools: fix comments)
 - #103045 (Remove leading newlines from integer primitive doc examples)
 - #103047 (Update browser-ui-test version to fix some flaky tests)
 - #103054 (Clean up rust-logo rustdoc GUI test)
 - #103059 (Fix `Duration::{try_,}from_secs_f{32,64}(-0.0)`)
 - #103067 (More alphabetical sorting)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-10-14 22:56:53 +00:00
Matthias Krüger
03a521b4fe
Rollup merge of #103059 - beetrees:duration-from-negative-zero, r=thomcc
Fix `Duration::{try_,}from_secs_f{32,64}(-0.0)`

Make `Duration::{try_,}from_secs_f{32,64}(-0.0)` return `Duration::ZERO` (as they did before #90247) instead of erroring/panicking.

I'll update this PR to remove the `#![feature(duration_checked_float)]` if #102271 is merged before this PR.

Tracking issue for `try_from_secs_f{32,64}`: #83400
2022-10-14 23:43:46 +02:00
Matthias Krüger
1a5d8a5c59
Rollup merge of #103045 - lukas-code:blank-lines, r=GuillaumeGomez
Remove leading newlines from integer primitive doc examples

fixes https://github.com/rust-lang/rust/issues/103043

```@rustbot``` label +A-docs
2022-10-14 23:43:44 +02:00
bors
bf15a9e526 Auto merge of #101030 - woppopo:const_location, r=scottmcm
Constify `Location` methods

Tracking issue: #102911

Example: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=4789884c2f16ec4fb0e0405d86b794f5
2022-10-14 20:15:51 +00:00
beetrees
c9948f5c5f
Fix Duration::{try_,}from_secs_f{32,64}(-0.0) 2022-10-14 16:07:09 +01:00
Lukas Markeffsky
b8bb40664c remove leading newlines from integer primitive doc examples 2022-10-14 12:14:29 +02:00
Rageking8
7122abaddf more dupe word typos 2022-10-14 12:57:56 +08:00
bors
4891d57f7a Auto merge of #102919 - luojia65:update-stdarch, r=Amanieu
library: update stdarch submodule

It has been one month since we update `stdarch`  submodule into main branch Rust, it includes various fixes in code and more neat documents. This pull request also adds missing features to ensure we can build latest stdarch submodule.

The documents after this pull request:
<details>

![图片](https://user-images.githubusercontent.com/40385009/195123337-a6c4cfaa-a7b9-4574-b524-c43683e6540c.png)
</details>

Comparing to current nightly:
<details>

![图片](https://user-images.githubusercontent.com/40385009/195123430-e047cff1-a925-4d2d-ae1c-da9769383a9c.png)
</details>

r? `@Amanieu`
2022-10-13 12:03:46 +00:00
luojia65
59fea7ecf4 library: update stdarch submodule
add feature target_feature_11 and riscv_target_feature
2022-10-13 09:41:16 +08:00
Pointerbender
ddd119b2fe expand documentation on type conversion w.r.t. UnsafeCell 2022-10-12 23:34:13 +02:00
bors
538f118da1 Auto merge of #102732 - RalfJung:assert_unsafe_precondition2, r=bjorn3
nicer errors from assert_unsafe_precondition

This makes the errors shown by cargo-careful nicer, and since `panic_no_unwind` is `nounwind noreturn` it hopefully doesn't have bad codegen impact. Thanks to `@bjorn3` for the hint!

Would be nice if we could somehow supply our own (static) message to print, currently it always prints `panic in a function that cannot unwind`. But still, this is better than before.
2022-10-12 14:39:43 +00:00
Markus Reiter
36dbb07daf
Update docs for CStr::from_ptr. 2022-10-12 13:46:20 +02:00
Markus Reiter
328f81713c
Make CStr::from_ptr const. 2022-10-12 13:01:30 +02:00
Dylan DPC
d8091f8991
Rollup merge of #102578 - lukas-code:ilog-panic, r=m-ou-se
Panic for invalid arguments of `{integer primitive}::ilog{,2,10}` in all modes

Decision made in https://github.com/rust-lang/rust/issues/100422#issuecomment-1245864700

resolves https://github.com/rust-lang/rust/issues/100422

tracking issue: https://github.com/rust-lang/rust/issues/70887

r? `@m-ou-se`
2022-10-12 11:11:25 +05:30
Ralf Jung
38c78a9ac1 reorder panicking.rs to put main entry points at the top 2022-10-11 22:47:31 +02:00
Ralf Jung
b61e742a39 use panic_fmt_nounwind for assert_unsafe_precondition 2022-10-11 22:47:31 +02:00
Ralf Jung
66282cb47d add panic_fmt_nounwind for panicing without unwinding, and use it for panic_no_unwind 2022-10-11 22:47:31 +02:00
Matthias Krüger
d10b47ef69
Rollup merge of #102445 - jmillikin:cstr-is-empty, r=Mark-Simulacrum
Add `is_empty()` method to `core::ffi::CStr`.

ACP: https://github.com/rust-lang/libs-team/issues/106

Tracking issue: https://github.com/rust-lang/rust/issues/102444
2022-10-11 18:59:48 +02:00
Matthias Krüger
d13f7aef70
Rollup merge of #101774 - Riolku:atomic-update-aba, r=m-ou-se
Warn about safety of `fetch_update`

Specifically as it relates to the ABA problem.

`fetch_update` is a useful function, and one that isn't provided by, say, C++. However, this does not mean the function is magic. It is implemented in terms of `compare_exchange_weak`, and in particular, suffers from the ABA problem. See the following code, which is a naive implementation of `pop` in a lock-free queue:

```rust
fn pop(&self) -> Option<i32> {
    self.front.fetch_update(Ordering::Relaxed, Ordering::Acquire, |front| {
        if front == ptr::null_mut() {
            None
        }
        else {
            Some(unsafe { (*front).next })
        }
    }.ok()
}
```

This code is unsound if called from multiple threads because of the ABA problem. Specifically, suppose nodes are allocated with `Box`. Suppose the following sequence happens:

```
Initial: Queue is X -> Y.

Thread A: Starts popping, is pre-empted.
Thread B: Pops successfully, twice, leaving the queue empty.
Thread C: Pushes, and `Box` returns X (very common for allocators)
Thread A: Wakes up, sees the head is still X, and stores Y as the new head.
```

But `Y` is deallocated. This is undefined behaviour.

Adding a note about this problem to `fetch_update` should hopefully prevent users from being misled, and also, a link to this common problem is, in my opinion, an improvement to our docs on atomics.
2022-10-11 18:59:46 +02:00
Yuki Okushi
ff903bbb71
Rollup merge of #102258 - cjgillot:core-kappa, r=m-ou-se
Remove unused variable in float formatting.
2022-10-11 18:37:52 +09:00
woppopo
a53e3acca9 Change tracking issue from #76156 to #102911 2022-10-11 06:40:37 +00:00
bors
0265a3e93b Auto merge of #96711 - emilio:inline-slice-clone, r=nikic
slice: #[inline] a couple iterator methods.

The one I care about and actually saw in the wild not getting inlined is
clone(). We ended up doing a whole function call for something that just
copies two pointers.

I ended up marking as_slice / as_ref as well because make_slice is
inline(always) itself, and is also the kind of think that can kill
performance in hot loops if you expect it to get inlined. But happy to
undo those.
2022-10-10 12:09:21 +00:00
Dylan DPC
7e16f9f1ea
Rollup merge of #99696 - WaffleLapkin:uplift, r=fee1-dead
Uplift `clippy::for_loops_over_fallibles` lint into rustc

This PR, as the title suggests, uplifts [`clippy::for_loops_over_fallibles`] lint into rustc. This lint warns for code like this:
```rust
for _ in Some(1) {}
for _ in Ok::<_, ()>(1) {}
```
i.e. directly iterating over `Option` and `Result` using `for` loop.

There are a number of suggestions that this PR adds (on top of what clippy suggested):
1. If the argument (? is there a better name for that expression) of a `for` loop is a `.next()` call, then we can suggest removing it (or rather replacing with `.by_ref()` to allow iterator being used later)
   ```rust
    for _ in iter.next() {}
    // turns into
    for _ in iter.by_ref() {}
    ```
2. (otherwise) We can suggest using `while let`, this is useful for non-iterator, iterator-like things like [async] channels
   ```rust
   for _ in rx.recv() {}
   // turns into
   while let Some(_) = rx.recv() {}
   ```
3. If the argument type is `Result<impl IntoIterator, _>` and the body has a `Result<_, _>` type, we can suggest using `?`
   ```rust
   for _ in f() {}
   // turns into
   for _ in f()? {}
   ```
4. To preserve the original behavior and clear intent, we can suggest using `if let`
   ```rust
   for _ in f() {}
   // turns into
   if let Some(_) = f() {}
   ```
(P.S. `Some` and `Ok` are interchangeable depending on the type)

I still feel that the lint wording/look is somewhat off, so I'll be happy to hear suggestions (on how to improve suggestions :D)!

Resolves #99272

[`clippy::for_loops_over_fallibles`]: https://rust-lang.github.io/rust-clippy/master/index.html#for_loops_over_fallibles
2022-10-10 13:43:40 +05:30
Scott McMurray
0718aeceb3 From<Alignment> for usize & NonZeroUsize 2022-10-09 15:44:49 -07:00
Pointerbender
9c37c801ad expand documentation on type conversion w.r.t. UnsafeCell 2022-10-09 22:32:23 +02:00
Yuki Okushi
38db483af7
Rollup merge of #102072 - scottmcm:ptr-alignment-type, r=thomcc
Add `ptr::Alignment` type

Essentially no new code here, just exposing the previously-`pub(crate)` `ValidAlign` type under the name from the ACP.

ACP: https://github.com/rust-lang/libs-team/issues/108
Tracking Issue: https://github.com/rust-lang/rust/issues/102070

r? ``@ghost``
2022-10-10 00:09:40 +09:00
Maybe Waffle
7434b9f0d1 fixup lint name 2022-10-09 13:07:21 +00:00
Maybe Waffle
75ae20a42f allow for_loop_over_fallibles in a core test 2022-10-09 13:07:20 +00:00
Michael Howell
c58886d428
Rollup merge of #102812 - est31:remove_lazy, r=dtolnay
Remove empty core::lazy and std::lazy

PR #98165 with commits 7c360dc117 and c1a2db3372 has moved all of the components of these modules into different places, namely {std,core}::sync and {std,core}::cell. The empty modules remained. As they are unstable, we can simply remove them.
2022-10-08 18:15:01 -07:00
Matthias Krüger
e6f6ad0576
Rollup merge of #99880 - compiler-errors:escape-ascii-is-not-exact-size-iterator, r=thomcc
`EscapeAscii` is not an `ExactSizeIterator`

Fixes #99878

Do we want/need `EscapeAscii` to be an `ExactSizeIterator`? I guess we could precompute the length of the output if so?
2022-10-08 23:32:02 +02:00
bors
8796e7a9cf Auto merge of #102315 - RalfJung:assert_unsafe_precondition, r=thomcc
add a few more assert_unsafe_precondition

Add debug-assertion checking for `ptr.read()`, `ptr.write(_)`, and `unreachable_unchecked.`

This is quite useful for [cargo-careful](https://github.com/RalfJung/cargo-careful).
2022-10-08 17:59:45 +00:00
est31
4d9d7bf312 Remove empty core::lazy and std::lazy
PR #98165 with commits 7c360dc117 and c1a2db3372
has moved all of the components of these modules into different places,
namely {std,core}::sync and {std,core}::cell. The empty
modules remained. As they are unstable, we can simply remove them.
2022-10-08 15:55:15 +02:00
woppopo
f0b8167a4e Fix test (location_const_file) 2022-10-08 11:48:53 +00:00
bors
8b0c05d9ad Auto merge of #102091 - RalfJung:const_err, r=oli-obk
make const_err a hard error

This lint has been deny-by-default with future incompat wording since [Rust 1.51](https://github.com/rust-lang/rust/pull/80394) and the stable release of this week starts showing it in cargo's future compat reports. I can't wait to finally get rid of at least some of the mess in our const-err-reporting-code. ;)

r? `@oli-obk`
Fixes https://github.com/rust-lang/rust/issues/71800
Fixes https://github.com/rust-lang/rust/issues/100114
2022-10-07 20:50:51 +00:00
Dylan DPC
2592609574
Rollup merge of #102300 - scottmcm:simpler-fold-closures, r=Mark-Simulacrum
Use a macro to not have to copy-paste `ConstFnMutClosure::new(&mut fold, NeverShortCircuit::wrap_mut_2_imp)).0` everywhere

Also use that macro to replace a bunch of places that had custom closure-wrappers.

+35 -114 sounds good to me.
2022-10-07 22:05:29 +05:30
Ralf Jung
fd59d44f58 make const_err a hard error 2022-10-07 18:08:49 +02:00
Ralf Jung
6f6433428f add a few more assert_unsafe_precondition 2022-10-07 14:35:12 +02:00
Ralf Jung
17d78c4ef9 poll_fn and Unpin: fix pinning 2022-10-06 13:51:10 +02:00
Matthias Krüger
f55fef165e
Rollup merge of #102647 - oli-obk:tilde_const_bounds, r=fee1-dead
Only allow ~const bounds for traits with #[const_trait]

r? `@fee1-dead`
2022-10-04 18:26:39 +02:00
Dylan DPC
c1d4003506
Rollup merge of #101189 - daxpedda:ready-into-inner, r=joshtriplett
Implement `Ready::into_inner()`

Tracking issue: #101196.

This implements a method to unwrap the value inside a `Ready` outside an async context.
See https://docs.rs/futures/0.3.24/futures/future/struct.Ready.html#method.into_inner for previous work.

This was discussed in [Zulip beforehand](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/.60Ready.3A.3Ainto_inner.28.29.60):
> An example I'm hitting right now:
I have a cross-platform library that provides a functions that returns a `Future`. The only reason why it returns a `Future` is because the WASM platform requires it, but the native doesn't, to make a cross-platform API that is equal for all I just return a `Ready` on the native targets.
>
> Now I would like to expose native-only functions that aren't async, that users can use to avoid having to deal with async when they are targeting native. With `into_inner` that's easily solvable now.
>
> I want to point out that some internal restructuring could be used to solve that problem too, but in this case it's not that simple, the library uses internal traits that return the `Future` already and playing around with that would introduce unnecessary `cfg` in a lot more places. So it is really only a quality-of-life feature.
2022-10-04 16:11:00 +05:30
Oli Scherer
33bcea8f61 Only allow ~const bounds for traits with #[const_trait] 2022-10-04 08:06:54 +00:00
Matthias Krüger
17c65826d3
Rollup merge of #102628 - H4x5:master, r=scottmcm
Change the parameter name of From::from to `value`

The `From` trait is currently defined as:
```rust
pub trait From<T>: Sized {
    fn from(_: T) -> Self;
}
```

The name of the argument is `_`. I am proposing to change it to `value`, ie.
```rust
pub trait From<T>: Sized {
    fn from(value: T) -> Self;
}
```

This would be more consistent with the `TryFrom`, which looks like this:
```rust
pub trait TryFrom<T>: Sized {
    type Error;
    fn try_from(value: T) -> Result<Self, Self::Error>;
}
```

The reason for this proposal is twofold:
1. Consistency with the rest of the standard library. The `TryFrom` trait uses `value`, and no `From` implementation uses the default name (as it is quite useless).
2. When generating trait implementations with rust-analyzer/IntelliJ, the parameter name is copied, and it always has to be changed.

Optionally, another name like `x` could be used. I only propose `value` for consistency with `TryFrom`.

Changing parameter names is not a breaking change.

Note: this was originally posted as an internals thread [here](https://internals.rust-lang.org/t/change-the-argument-name-of-from-from/17480)
2022-10-04 06:14:12 +02:00
bors
1f1defc2f6 Auto merge of #99099 - Stargateur:phantomdata_debug, r=joshtriplett
Add T to PhantomData impl Debug

This add debug information for `PhantomData`, I believe it's make sense to add this to debug impl of `PhantomData` since `T` is what define what is the `PhantomData` just write `"PhantomData"` is not very useful for debugging.

Alternative:

* `PhantomData::<{}>`
* `PhantomData { t: "str_type" }`

`@rustbot` label +T-libs-api -T-libs
2022-10-04 00:56:14 +00:00
bors
f83e0266cf Auto merge of #102632 - matthiaskrgr:rollup-h8s3zmo, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #98218 (Document the conditional existence of `alloc::sync` and `alloc::task`.)
 - #99216 (docs: be less harsh in wording for Vec::from_raw_parts)
 - #99460 (docs: Improve AsRef / AsMut docs on blanket impls)
 - #100470 (Tweak `FpCategory` example order.)
 - #101040 (Fix `#[derive(Default)]` on a generic `#[default]` enum adding unnecessary `Default` bounds)
 - #101308 (introduce `{char, u8}::is_ascii_octdigit`)
 - #102486 (Add diagnostic struct for const eval error in `rustc_middle`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-10-03 20:22:18 +00:00
Matthias Krüger
a5488826a9
Rollup merge of #101308 - nerdypepper:feature/is-ascii-octdigit, r=joshtriplett
introduce `{char, u8}::is_ascii_octdigit`

This feature adds two new APIs: `char::is_ascii_octdigit` and `u8::is_ascii_octdigit`, under the feature gate `is_ascii_octdigit`. These methods are shorthands for `char::is_digit(self, 8)` and `u8::is_digit(self, 8)`:

```rust
// core::char

impl char {
    pub fn is_ascii_octdigit(self) -> bool;
}

// core::num

impl u8 {
    pub fn is_ascii_octdigit(self) -> bool;
}
```

---

Couple of things I need help understanding:

- `const`ness: have I used the right attribute in this case?
- is there a way to run the tests for `core::char` alone, instead of `./x.py test library/core`?
2022-10-03 20:58:56 +02:00
Matthias Krüger
c7f1b8e41d
Rollup merge of #100470 - reitermarkus:patch-1, r=joshtriplett
Tweak `FpCategory` example order.

Follow same order for variable declarations and assertions.
2022-10-03 20:58:55 +02:00
Matthias Krüger
eedb51210c
Rollup merge of #99460 - JanBeh:PR_asref_asmut_docs, r=joshtriplett
docs: Improve AsRef / AsMut docs on blanket impls

There are several issues with the current state of `AsRef` and `AsMut` as [discussed here on IRLO](https://internals.rust-lang.org/t/semantics-of-asref/17016). See also #39397, #45742, #73390, #98905, and the FIXMEs [here](https://github.com/rust-lang/rust/blob/1.62.0/library/core/src/convert/mod.rs#L509-L515) and [here](https://github.com/rust-lang/rust/blob/1.62.0/library/core/src/convert/mod.rs#L530-L536). These issues are difficult to fix. This PR aims to update the documentation to better reflect the status-quo and to give advice on how `AsRef` and `AsMut` should be used.

In particular:

- Explicitly mention that `AsRef` and `AsMut` do not auto-dereference generally for all dereferencable types (but only if inner type is a shared and/or mutable reference)
- Give advice to not use `AsRef` or `AsMut` for the sole purpose of dereferencing
- Suggest providing a transitive `AsRef` or `AsMut` implementation for types which implement `Deref`
- Add new section "Reflexivity" in documentation comments for `AsRef` and `AsMut`
- Provide better example for `AsMut`
- Added heading "Relation to `Borrow`" in `AsRef`'s docs to improve structure
2022-10-03 20:58:54 +02:00
H4x5
8dcecdb487
Change the parameter name of From::from to value 2022-10-03 13:36:57 -04:00
Matthias Krüger
3374a7d6f8
Rollup merge of #102607 - WaffleLapkin:docky_docky_slice_from_ptr_range, r=joshtriplett
Improve documentation of `slice::{from_ptr_range, from_ptr_range_mut}`

Document panic conditions (`T` is a ZST) and sync docs of shared/unique version.

cc `@wx-csy`
2022-10-03 19:12:18 +02:00
Matthias Krüger
cdd0ba8f41
Rollup merge of #102569 - eduardosm:from_str-example, r=joshtriplett
Improve `FromStr` example

The `from_str` implementation from the example had an `unwrap` that would make it panic on invalid input strings. Instead of panicking, it nows returns an error to better reflect the intented behavior of the `FromStr` trait.
2022-10-03 19:12:17 +02:00
Maybe Waffle
2cd5fafd25 Sync docs of slice::{from_ptr_range, from_ptr_range_mut} 2022-10-03 00:44:50 +00:00
Maybe Waffle
bc1216e046 Document when slice::from_ptr_range[_mut] panic 2022-10-03 00:41:54 +00:00
Lukas Markeffsky
b7dae8a5e2 remove unneeded attributes 2022-10-02 15:15:40 +02:00
bors
91931ec2fc Auto merge of #98354 - camsteffen:is-some-and-by-value, r=m-ou-se
Change `is_some_and` to take by value

Consistent with other function-accepting `Option` methods.

Tracking issue: #93050

r? `@m-ou-se`
2022-10-02 12:48:15 +00:00
Lukas Markeffsky
6acc29f88b add tests for panicking integer logarithms 2022-10-02 14:25:36 +02:00
Lukas Markeffsky
69cafc0699 always panic for invalid integer logarithm 2022-10-02 14:24:56 +02:00
bors
756e7be5eb Auto merge of #102548 - nikic:inline-cell-replace, r=scottmcm
Mark Cell::replace() as #[inline]

Giving this a try based on https://github.com/rust-lang/rust/issues/102539#issuecomment-1264398807.
2022-10-02 09:53:07 +00:00
Eduardo Sánchez Muñoz
9c7c232a50 Improve FromStr example
The `from_str` implementation from the example had an `unwrap` that would make it panic on invalid input strings. Instead of panicking, it nows returns an error to better reflect the intented behavior of the `FromStr` trait.
2022-10-02 11:32:56 +02:00
bors
c2590e6e89 Auto merge of #102535 - scottmcm:optimize-split-at-partition-point, r=thomcc
Tell LLVM that `partition_point` returns a valid fencepost

This was already done for a successful `binary_search`, but this way `partition_point` can get similar optimizations.

Demonstration that nightly can't do this optimization today, and leaves in the panicking path: <https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=e1074cd2faf5f68e49cffd728ded243a>

r? `@thomcc`
2022-10-02 07:11:15 +00:00
Matthias Krüger
baba8391c3
Rollup merge of #102405 - hkBst:patch-3, r=Mark-Simulacrum
Remove a FIXME whose code got moved away in #62883.

Remove a FIXME whose code got moved away in https://github.com/rust-lang/rust/pull/62883.
2022-10-02 03:16:39 +02:00
Cameron Steffen
4f12de0660 Change feature name to is_some_and 2022-10-01 11:45:52 -05:00
Cameron Steffen
2f83134e37 Change is_some_and to take by value 2022-10-01 11:45:52 -05:00
Nikita Popov
49eaa0f6ac Mark Cell::replace() as #[inline] 2022-10-01 17:30:54 +02:00
Scott McMurray
c7af338e6f Tell LLVM that partition_point returns a valid fencepost
This was already done for a successful `binary_search`, but this way `partition_point` can get similar optimizations.
2022-09-30 23:39:15 -07:00
bors
877877a19a Auto merge of #102520 - matthiaskrgr:rollup-7nreat0, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #102276 (Added more const_closure functionality)
 - #102382 (Manually order `DefId` on 64-bit big-endian)
 - #102421 (remove the unused :: between trait and type to give user correct diag…)
 - #102495 (Reinstate `hir-stats.rs` test for stage 1.)
 - #102505 (rustdoc: remove no-op CSS `h3.variant, .sub-variant h4 { border-bottom: none }`)
 - #102506 (Specify `DynKind::Dyn`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-09-30 17:47:57 +00:00
onestacked
10739d475e Add back ConstFnMutClosure::new, fix formatting 2022-09-30 17:41:01 +02:00
onestacked
9a641a533c Fixed Documentation for wrap_mut_2_imp 2022-09-30 17:16:59 +02:00
onestacked
b73241aa5b Added more const_closure functionality. 2022-09-30 17:16:59 +02:00
beetrees
e409ce2159
Fix integer overflow in format!("{:.0?}", Duration::MAX) 2022-09-29 23:06:22 +01:00
Dylan DPC
34f02c3e8d
Rollup merge of #102452 - granolocks:grammar-tweak, r=thomcc
fix minor ungrammatical sentence

This fixes an innocuous ungrammatical sentence in example code in the  `TryFrom` documentation.
2022-09-29 18:13:21 +05:30
Dylan DPC
b6d1c15076
Rollup merge of #102435 - GuillaumeGomez:improve-iterator-reduce-example, r=thomcc,vacuus
Improve example of Iterator::reduce

Fixes #81819.

I took your example `@bstrie` from https://github.com/rust-lang/rust/issues/81819 and applied it here.

r? `@thomcc`
2022-09-29 18:13:20 +05:30
Dylan DPC
609152aa8a
Rollup merge of #102342 - jmillikin:nonzero-negation, r=scottmcm
Add negation methods for signed non-zero integers.

Performing negation with defined wrapping semantics (such as `wrapping_neg()`) on a non-zero integer currently requires unpacking to a primitive and re-wrapping. Since negation of non-zero signed integers always produces a non-zero result, it is safe to implement the various `*_neg()` methods for `NonZeroI{N}`.

I'm not sure what to do about the `#[unstable(..., issue = "none")]` here -- should I file a tracking issue, or is that handled by the Rust dev team?

ACP: https://github.com/rust-lang/libs-team/issues/105
2022-09-29 18:13:19 +05:30
Gabe Koss
06624e8c5a fix minor ungrammatical sentence 2022-09-29 00:20:05 -04:00
Yuki Okushi
8e4869e862
Rollup merge of #102368 - beetrees:nano-niche, r=joshtriplett
Add a niche to `Duration`, unix `SystemTime`, and non-apple `Instant`

As the nanoseconds fields is always between `0` and `(NANOS_PER_SEC - 1)` inclusive, use the `rustc_layout_scalar_valid_range` attributes to create a niche in the nanosecond field of `Duration` and `Timespec` (which is used to implement unix `SystemTime` and non-apple unix `Instant`; windows `Instant` is implemented with `Duration` and therefore will also benefit). This change has the benefit of making `Option<T>` the same size as `T` for the previously mentioned types. Also shrinks the nanoseconds field of `Timespec` to a `u32` as nanoseconds do not need the extra range of an `i64`, shrinking `Timespec` by 4 bytes on 32-bit platforms.

r? ```@joshtriplett```
2022-09-29 11:42:05 +09:00
John Millikin
9d5e3a1f45 Add is_empty() method to core::ffi::CStr. 2022-09-29 07:55:12 +09:00
Guillaume Gomez
49b25d3412 Improve example of Iterator::reduce 2022-09-29 00:44:53 +02:00