Commit Graph

3720 Commits

Author SHA1 Message Date
bors 9a7b7d5e50 Auto merge of #98180 - notriddle:notriddle/rustdoc-fn, r=petrochenkov,GuillaumeGomez
Improve the function pointer docs

This is #97842 but for function pointers instead of tuples. The concept is basically the same.

* Reduce duplicate impls; show `fn (T₁, T₂, …, Tₙ)` and include a sentence saying that there exists up to twelve of them.
* Show `Copy` and `Clone`.
* Show auto traits like `Send` and `Sync`, and blanket impls like `Any`.

https://notriddle.com/notriddle-rustdoc-test/std/primitive.fn.html
2022-07-19 19:36:57 +00:00
Michael Howell ddb5a2638a Use `T` for all the function primitive docs lists 2022-07-19 08:52:25 -07:00
Michael Howell 5271e32c46 Improve the function pointer docs
* Reduce duplicate impls; show only the `fn (T)` and include a sentence
  saying that there exists up to twelve of them.
* Show `Copy` and `Clone`.
* Show auto traits like `Send` and `Sync`, and blanket impls like `Any`.
2022-07-19 08:52:24 -07:00
bors a289cfcfb3 Auto merge of #99462 - matthiaskrgr:rollup-ihhwaru, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #98028 (Add E0790 as more specific variant of E0283)
 - #99384 (use body's param-env when checking if type needs drop)
 - #99401 (Avoid `Symbol` to `&str` conversions)
 - #99419 (Stabilize `core::task::ready!`)
 - #99435 (Revert "Stabilize $$ in Rust 1.63.0")
 - #99438 (Improve suggestions for `NonZeroT` <- `T` coercion error)
 - #99441 (Update mdbook)
 - #99453 (⬆️ rust-analyzer)
 - #99457 (use `par_for_each_in` in `par_body_owners` and `collect_crate_mono_items`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-07-19 13:49:56 +00:00
Matthias Krüger e6a100baa2
Rollup merge of #99438 - WaffleLapkin:dont_wrap_in_non_zero, r=compiler-errors
Improve suggestions for `NonZeroT` <- `T` coercion error

Currently, when encountering a type mismatch error with `NonZeroT` and `T` (for example `NonZeroU8` and `u8`) we errorneusly suggest wrapping expression in `NonZeroT`:
```text
error[E0308]: mismatched types
 --> ./t.rs:7:35
  |
7 |     let _: std::num::NonZeroU64 = 1;
  |            --------------------   ^ expected struct `NonZeroU64`, found integer
  |            |
  |            expected due to this
  |
help: try wrapping the expression in `std::num::NonZeroU64`
  |
7 |     let _: std::num::NonZeroU64 = std::num::NonZeroU64(1);
  |                                   +++++++++++++++++++++ +
```

I've removed this suggestion and added suggestions to call `new` (for `Option<NonZeroT>` <- `T` case) or `new` and `unwrap` (for `NonZeroT` <- `T` case):

```text
error[E0308]: mismatched types
 --> ./t.rs:7:35
  |
7 |     let _: std::num::NonZeroU64 = 1;
  |            --------------------   ^ expected struct `NonZeroU64`, found integer
  |            |
  |            expected due to this
  |
help: Consider calling `NonZeroU64::new`
  |
7 |     let _: std::num::NonZeroU64 = NonZeroU64::new(1).unwrap();
  |                                   ++++++++++++++++ ++++++++++

error[E0308]: mismatched types
 --> ./t.rs:8:43
  |
8 |     let _: Option<std::num::NonZeroU64> = 1;
  |            ----------------------------   ^ expected enum `Option`, found integer
  |            |
  |            expected due to this
  |
  = note: expected enum `Option<NonZeroU64>`
             found type `{integer}`
help: Consider calling `NonZeroU64::new`
  |
8 |     let _: Option<std::num::NonZeroU64> = NonZeroU64::new(1);
  |                                           ++++++++++++++++ +
```

r? `@compiler-errors`
2022-07-19 13:30:49 +02:00
Matthias Krüger 7d754976c4
Rollup merge of #99419 - yoshuawuyts:stabilize-task-ready, r=Mark-Simulacrum
Stabilize `core::task::ready!`

This stabilizes `core::task::ready!` for Rust 1.64. The FCP for stabilization was just completed here https://github.com/rust-lang/rust/issues/70922#issuecomment-1186231855. Thanks!

Closes #70922

cc/ ``@rust-lang/libs-api``
2022-07-19 13:30:47 +02:00
bors 8bd12e8cca Auto merge of #98912 - nrc:provider-it, r=yaahc
core::any: replace some generic types with impl Trait

This gives a cleaner API since the caller only specifies the concrete type they usually want to.

r? `@yaahc`
2022-07-19 11:28:20 +00:00
Antoine PLASKOWSKI 94f633b002 int_macros was only using to_xe_bytes_doc and not from_xe_bytes_doc 2022-07-19 08:32:08 +02:00
Dylan DPC e301cd39ad
Rollup merge of #99434 - timvermeulen:skip_next_non_fused, r=scottmcm
Fix `Skip::next` for non-fused inner iterators

`iter.skip(n).next()` will currently call `nth` and `next` in succession on `iter`, without checking whether `nth` exhausts the iterator. Using `?` to propagate a `None` value returned by `nth` avoids this.
2022-07-19 11:38:58 +05:30
Dylan DPC 9f6a2fde34
Rollup merge of #99335 - Dav1dde:fromstr-docs, r=JohnTitor
Use split_once in FromStr docs

Current implementation:

```rust
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let coords: Vec<&str> = s.trim_matches(|p| p == '(' || p == ')' )
                                 .split(',')
                                 .collect();

        let x_fromstr = coords[0].parse::<i32>()?;
        let y_fromstr = coords[1].parse::<i32>()?;

        Ok(Point { x: x_fromstr, y: y_fromstr })
    }
```

Creating the vector is not necessary, `split_once` does the job better.

Alternatively we could also remove `trim_matches` with `strip_prefix` and `strip_suffix`:

```rust
        let (x, y) = s
            .strip_prefix('(')
            .and_then(|s| s.strip_suffix(')'))
            .and_then(|s| s.split_once(','))
            .unwrap();
```

The question is how much 'correctness' is too much and distracts from the example. In a real implementation you would also not unwrap (or originally access the vector without bounds checks), but implementing a custom Error and adding a `From<ParseIntError>` and implementing the `Error` trait adds a lot of code to the example which is not relevant to the `FromStr` trait.
2022-07-19 11:38:53 +05:30
Maybe Waffle 7163e7ff65 Suggest a fix for `NonZero*` <- `*` coercion error 2022-07-19 00:13:29 +04:00
Tim Vermeulen e52837c362 Add note to test about `Unfuse` 2022-07-18 21:53:35 +02:00
Tim Vermeulen 50c612faef Fix `Skip::next` for non-fused inner iterators 2022-07-18 21:10:47 +02:00
Dylan DPC 5ccdf1f6f7
Rollup merge of #98839 - 5225225:assert_transmute_copy_size, r=thomcc
Add assertion that `transmute_copy`'s U is not larger than T

This is called out as a safety requirement in the docs, but because knowing this can be done at compile time and constant folded (just like the `align_of` branch is removed), we can just panic here.

I've looked at the asm (using `cargo-asm`) of a function that both is correct and incorrect, and the panic is completely removed, or is unconditional, without needing build-std.

I don't expect this to cause much breakage in the wild. I scanned through https://miri.saethlin.dev/ub for issues that would look like this (error: Undefined Behavior: memory access failed: alloc1768 has size 1, so pointer to 8 bytes starting at offset 0 is out-of-bounds), but couldn't find any.

That doesn't rule out it happening in crates tested that fail earlier for some other reason, though, but it indicates that doing this is rare, if it happens at all. A crater run for this would need to be build and test, since this is a runtime thing.

Also added a few more transmute_copy tests.
2022-07-18 21:14:42 +05:30
Yoshua Wuyts 454313fe83 stabilize `core::task::ready!` 2022-07-18 16:04:52 +02:00
bors 9ed0bf9f2b Auto merge of #99223 - saethlin:panicless-split-mut, r=Mark-Simulacrum
Rearrange slice::split_mut to remove bounds check

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

Turns out that all we need to do here is reorder the bounds checks to convince LLVM that all the bounds checks can be removed. It seems like LLVM just fails to propagate the original length information past the first bounds check and into the second one. With this implementation it doesn't need to, each check can be proven inbounds based on the one immediately previous.

I've gradually convinced myself that this implementation is unambiguously better based on the above logic, but maybe this is still deserving of a codegen test?

Also the mentioned borrowck limitation no longer seems to exist.
2022-07-18 10:16:58 +00:00
David Herberth c1c1abc08a Use split_once in FromStr docs 2022-07-18 08:57:43 +02:00
Yuki Okushi 7c98c92ebc
Rollup merge of #99374 - TethysSvensson:patch-1, r=Dylan-DPC
Fix doc for `rchunks_exact`

`rchunks_exact` is not a more optimized version of `chunks`, but of `rchunks`.
2022-07-18 08:40:02 +09:00
Yuki Okushi 796bc7cae3
Rollup merge of #98383 - m-ou-se:remove-memory-order-restrictions, r=joshtriplett
Remove restrictions on compare-exchange memory ordering.

We currently don't allow the failure memory ordering of compare-exchange operations to be stronger than the success ordering, as was the case in C++11 when its memory model was copied to Rust. However, this restriction was lifted in C++17 as part of [p0418r2](https://wg21.link/p0418r2). It's time  we lift the restriction too.

| Success | Failure | Before | After |
|---------|---------|--------|-------|
| Relaxed | Relaxed | ✔️ | ✔️ |
| Relaxed | Acquire |                 | ✔️ |
| Relaxed | SeqCst  |                 | ✔️ |
| Acquire | Relaxed | ✔️ | ✔️ |
| Acquire | Acquire | ✔️ | ✔️ |
| Acquire | SeqCst  |                 | ✔️ |
| Release | Relaxed | ✔️ | ✔️ |
| Release | Acquire |                 | ✔️ |
| Release | SeqCst  |                 | ✔️ |
| AcqRel  | Relaxed | ✔️ | ✔️ |
| AcqRel  | Acquire | ✔️ | ✔️ |
| AcqRel  | SeqCst  |                 | ✔️ |
| SeqCst  | Relaxed | ✔️ | ✔️ |
| SeqCst  | Acquire | ✔️ | ✔️ |
| SeqCst  | SeqCst  | ✔️ | ✔️ |
| \*      | Release |                 |                 |
| \*      | AcqRel  |                 |                 |

Fixes https://github.com/rust-lang/rust/issues/68464
2022-07-18 08:39:57 +09:00
Michael Howell 1169832f2f rustdoc: extend `#[doc(tuple_variadic)]` to fn pointers
The attribute is also renamed `fake_variadic`.
2022-07-17 16:32:06 -07:00
Tethys Svensson 8c58de5e2c
Fix for `rchunks_exact` doc
`rchunks_exact` is not a more optimized version of `chunks`, but of `rchunks`.
2022-07-17 14:18:36 +02:00
Yuki Okushi 50527690e2
Rollup merge of #99306 - JohnTitor:stabilize-future-poll-fn, r=joshtriplett
Stabilize `future_poll_fn`

FCP is done: https://github.com/rust-lang/rust/issues/72302#issuecomment-1179620512
Closes #72302

r? `@joshtriplett` as you started FCP

Signed-off-by: Yuki Okushi <jtitor@2k36.org>
2022-07-17 13:08:52 +09:00
bors db41351753 Auto merge of #98866 - nagisa:nagisa/align-offset-wroom, r=Mark-Simulacrum
Add a special case for align_offset /w stride != 1

This generalizes the previous `stride == 1` special case to apply to any
situation where the requested alignment is divisible by the stride. This
in turn allows the test case from #98809 produce ideal assembly, along
the lines of:

    leaq 15(%rdi), %rax
    andq $-16, %rax

This also produces pretty high quality code for situations where the
alignment of the input pointer isn’t known:

    pub unsafe fn ptr_u32(slice: *const u32) -> *const u32 {
        slice.offset(slice.align_offset(16) as isize)
    }

    // =>

    movl %edi, %eax
    andl $3, %eax
    leaq 15(%rdi), %rcx
    andq $-16, %rcx
    subq %rdi, %rcx
    shrq $2, %rcx
    negq %rax
    sbbq %rax, %rax
    orq  %rcx, %rax
    leaq (%rdi,%rax,4), %rax

Here LLVM is smart enough to replace the `usize::MAX` special case with
a branch-less bitwise-OR approach, where the mask is constructed using
the neg and sbb instructions. This appears to work across various
architectures I’ve tried.

This change ends up introducing more branches and code in situations
where there is less knowledge of the arguments. For example when the
requested alignment is entirely unknown. This use-case was never really
a focus of this function, so I’m not particularly worried, especially
since llvm-mca is saying that the new code is still appreciably faster,
despite all the new branching.

Fixes #98809.
Sadly, this does not help with #72356.
2022-07-16 23:28:28 +00:00
Simonas Kazlauskas 62a182cf7f Add a special case for align_offset /w stride != 1
This generalizes the previous `stride == 1` special case to apply to any
situation where the requested alignment is divisible by the stride. This
in turn allows the test case from #98809 produce ideal assembly, along
the lines of:

    leaq 15(%rdi), %rax
    andq $-16, %rax

This also produces pretty high quality code for situations where the
alignment of the input pointer isn’t known:

    pub unsafe fn ptr_u32(slice: *const u32) -> *const u32 {
        slice.offset(slice.align_offset(16) as isize)
    }

    // =>

    movl %edi, %eax
    andl $3, %eax
    leaq 15(%rdi), %rcx
    andq $-16, %rcx
    subq %rdi, %rcx
    shrq $2, %rcx
    negq %rax
    sbbq %rax, %rax
    orq  %rcx, %rax
    leaq (%rdi,%rax,4), %rax

Here LLVM is smart enough to replace the `usize::MAX` special case with
a branch-less bitwise-OR approach, where the mask is constructed using
the neg and sbb instructions. This appears to work across various
architectures I’ve tried.

This change ends up introducing more branches and code in situations
where there is less knowledge of the arguments. For example when the
requested alignment is entirely unknown. This use-case was never really
a focus of this function, so I’m not particularly worried, especially
since llvm-mca is saying that the new code is still appreciably faster,
despite all the new branching.

Fixes #98809.
Sadly, this does not help with #72356.
2022-07-17 01:27:37 +03:00
Ben Kimock c9373903e7 Rearrange slice::split_mut to remove bounds check 2022-07-16 12:26:37 -04:00
Yuki Okushi 083a253e53
Rollup merge of #99277 - joshtriplett:stabilize-core-cstr-alloc-cstring, r=Mark-Simulacrum
Stabilize `core::ffi::CStr`, `alloc::ffi::CString`, and friends

Stabilize the `core_c_str` and `alloc_c_string` feature gates.

Change `std::ffi` to re-export these types rather than creating type
aliases, since they now have matching stability.
2022-07-16 17:53:04 +09:00
Yuki Okushi 084ad59622
Stabilize `future_poll_fn`
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
2022-07-16 10:04:14 +09:00
Aaron Hill ef8e322b14
Mark stabilized intrinsics with `rustc_allowed_through_unstable_modules`
Fixes #99286

PR #95956 accidentally made these intrinsics unstable when
accessed through the unstable path segment 'std::intrinsics'
2022-07-15 11:18:40 -05:00
Josh Triplett d6b7480c2a Stabilize `core::ffi::CStr`, `alloc::ffi::CString`, and friends
Stabilize the `core_c_str` and `alloc_c_string` feature gates.

Change `std::ffi` to re-export these types rather than creating type
aliases, since they now have matching stability.
2022-07-15 03:10:35 -07:00
bors 24699bcbad Auto merge of #95956 - yaahc:stable-in-unstable, r=cjgillot
Support unstable moves via stable in unstable items

part of https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/moving.20items.20to.20core.20unstably and a blocker of https://github.com/rust-lang/rust/pull/90328.

The libs-api team needs the ability to move an already stable item to a new location unstably, in this case for Error in core. Otherwise these changes are insta-stable making them much harder to merge.

This PR attempts to solve the problem by checking the stability of path segments as well as the last item in the path itself, which is currently the only thing checked.
2022-07-14 13:42:09 +00:00
Dylan DPC 103b8602b7
Rollup merge of #98315 - joshtriplett:stabilize-core-ffi-c, r=Mark-Simulacrum
Stabilize `core::ffi:c_*` and rexport in `std::ffi`

This only stabilizes the base types, not the non-zero variants, since
those have their own separate tracking issue and have not gone through
FCP to stabilize.
2022-07-14 14:14:20 +05:30
Josh Triplett d431338b25 Stabilize `core::ffi:c_*` and rexport in `std::ffi`
This only stabilizes the base types, not the non-zero variants, since
those have their own separate tracking issue and have not gone through
FCP to stabilize.
2022-07-13 19:28:20 -07:00
Scott McMurray a32305a80f Re-optimize `Layout::array`
This way it's one check instead of two, so hopefully it'll be better

Nightly:
```
layout_array_i32:
	movq	%rdi, %rax
	movl	$4, %ecx
	mulq	%rcx
	jo	.LBB1_2
	movabsq	$9223372036854775805, %rcx
	cmpq	%rcx, %rax
	jae	.LBB1_2
	movl	$4, %edx
	retq
.LBB1_2:
	…
```

This PR:
```
	movq	%rcx, %rax
	shrq	$61, %rax
	jne	.LBB2_1
	shlq	$2, %rcx
	movl	$4, %edx
	movq	%rcx, %rax
	retq
.LBB2_1:
	…
```
2022-07-13 17:07:41 -07:00
bors 87588a2afd Auto merge of #99136 - CAD97:layout-faster, r=scottmcm
Take advantage of known-valid-align in layout.rs

An attempt to improve perf by `@nnethercote's` approach suggested in #99117
2022-07-13 21:01:20 +00:00
Dylan DPC 1e7d04b23b
Rollup merge of #99011 - oli-obk:UnsoundCell, r=eddyb
`UnsafeCell` blocks niches inside its nested type from being available outside

fixes #87341

This implements the plan by `@eddyb` in https://github.com/rust-lang/rust/issues/87341#issuecomment-886083646

Somewhat related PR (not strictly necessary, but that cleanup made this PR simpler): #94527
2022-07-13 19:32:34 +05:30
Ralf Jung 7b4149474b mention mitigation in the docs 2022-07-12 11:56:35 -04:00
Ralf Jung 84ff4da726 mem::uninitialized: mitigate many incorrect uses of this function 2022-07-12 10:05:47 -04:00
Christopher Durham 11694905b4 Remove duplication of layout size check 2022-07-11 17:58:42 -04:00
Ralf Jung 1b3870e427 remove a dubious example 2022-07-11 11:36:18 -04:00
Ralf Jung eed5df52f6
typo
Co-authored-by: Ben Kimock <kimockb@gmail.com>
2022-07-11 09:49:55 -04:00
SOFe 01a9ff0e85
Clarify that [iu]size bounds were only defined for the target arch 2022-07-11 15:08:38 +08:00
Christopher Durham 079d3eb22f Take advantage of known-valid-align in layout.rs 2022-07-10 20:34:39 -04:00
Matthias Krüger 342b666d59
Rollup merge of #99094 - AldaronLau:atomic-ptr-extra-space, r=Dylan-DPC
Remove extra space in AtomicPtr::new docs
2022-07-11 00:33:48 +02:00
bors 268be96d6d Auto merge of #99112 - matthiaskrgr:rollup-uv2zk4d, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #99045 (improve print styles)
 - #99086 (Fix display of search result crate filter dropdown)
 - #99100 (Fix binary name in help message for test binaries)
 - #99103 (Avoid some `&str` to `String` conversions)
 - #99109 (fill new tracking issue for `feature(strict_provenance_atomic_ptr)`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-07-10 11:35:12 +00:00
Maybe Waffle e9292b7652 fill new tracking issue for `feature(strict_provenance_atomic_ptr)` 2022-07-10 13:17:33 +04:00
bors 4ec97d991b Auto merge of #95295 - CAD97:layout-isize, r=scottmcm
Enforce that layout size fits in isize in Layout

As it turns out, enforcing this _in APIs that already enforce `usize` overflow_ is fairly trivial. `Layout::from_size_align_unchecked` continues to "allow" sizes which (when rounded up) would overflow `isize`, but these are now declared as library UB for `Layout`, meaning that consumers of `Layout` no longer have to check this before making an allocation.

(Note that this is "immediate library UB;" IOW it is valid for a future release to make this immediate "language UB," and there is an extant patch to do so, to allow Miri to catch this misuse.)

See also #95252, [Zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Layout.20Isn't.20Enforcing.20The.20isize.3A.3AMAX.20Rule).
Fixes https://github.com/rust-lang/rust/issues/95334

Some relevant quotes:

`@eddyb,` https://github.com/rust-lang/rust/pull/95252#issuecomment-1078513769

> [B]ecause of the non-trivial presence of both of these among code published on e.g. crates.io:
>
>   1. **`Layout` "producers" / `GlobalAlloc` "users"**: smart pointers (including `alloc::rc` copies with small tweaks), collections, etc.
>   2. **`Layout` "consumers" / `GlobalAlloc` "providers"**: perhaps fewer of these, but anything built on top of OS APIs like `mmap` will expose `> isize::MAX` allocations (on 32-bit hosts) if they lack extra checks
>
> IMO the only responsible option is to enforce the `isize::MAX` limit in `Layout`, which:
>
>   * makes `Layout` _sound_ in terms of only ever allowing allocations where `(alloc_base_ptr: *mut u8).offset(size)` is never UB
>   * frees both "producers" and "consumers" of `Layout` from manually reimplementing the checks
>     * manual checks can be risky, e.g. if the final size passed to the allocator isn't the one being checked
>     * this applies retroactively, fixing the overall soundness of existing code with zero transition period or _any_ changes required from users (as long as going through `Layout` is mandatory, making a "choke point")
>
>
> Feel free to quote this comment onto any relevant issue, I might not be able to keep track of developments.

`@Gankra,` https://github.com/rust-lang/rust/pull/95252#issuecomment-1078556371

> As someone who spent way too much time optimizing libcollections checks for this stuff and tried to splatter docs about it everywhere on the belief that it was a reasonable thing for people to manually take care of: I concede the point, it is not reasonable. I am wholy spiritually defeated by the fact that _liballoc_ of all places is getting this stuff wrong. This isn't throwing shade at the folks who implemented these Rc features, but rather a statement of how impractical it is to expect anyone out in the wider ecosystem to enforce them if _some of the most audited rust code in the library that defines the very notion of allocating memory_ can't even reliably do it.
>
> We need the nuclear option of Layout enforcing this rule. Code that breaks this rule is _deeply_ broken and any "regressions" from changing Layout's contract is a _correctness_ fix. Anyone who disagrees and is sufficiently motivated can go around our backs but the standard library should 100% refuse to enable them.

cc also `@RalfJung` `@rust-lang/wg-allocators.` Even though this technically supersedes #95252, those potential failure points should almost certainly still get nicer panics than just "unwrap failed" (which they would get by this PR).

It might additionally be worth recommending to users of the `Layout` API that they should ideally use `.and_then`/`?` to complete the entire layout calculation, and then `panic!` from a single location at the end of `Layout` manipulation, to reduce the overhead of the checks and optimizations preserving the exact location of each `panic` which are conceptually just one failure: allocation too big.

Probably deserves a T-lang and/or T-libs-api FCP (this technically solidifies the [objects must be no larger than `isize::MAX`](https://rust-lang.github.io/unsafe-code-guidelines/layout/scalars.html#isize-and-usize) rule further, and the UCG document says this hasn't been RFCd) and a crater run. Ideally, no code exists that will start failing with this addition; if it does, it was _likely_ (but not certainly) causing UB.

Changes the raw_vec allocation path, thus deserves a perf run as well.

I suggest hiding whitespace-only changes in the diff view.
2022-07-10 08:54:32 +00:00
Konrad Borowski 0753fd117b Partially stabilize const_slice_from_raw_parts
This doesn't stabilize methods working on mutable pointers.
2022-07-09 23:20:02 +02:00
Jeron Aldaron Lau 4944b5769b Remove extra space in AtomicPtr::new docs 2022-07-09 14:20:34 -05:00
Ralf Jung 2e0ca9472b add a concrete example 2022-07-09 10:48:43 -04:00
Ralf Jung f6247ffa5a clarify how write_bytes can lead to UB due to invalid values 2022-07-09 09:38:07 -04:00
Dylan DPC 3c35da224b
Rollup merge of #99070 - tamird:update-tracking-issue, r=RalfJung
Update integer_atomics tracking issue

Updates #32976.
Updates #99069.

r? ``@RalfJung``
2022-07-09 11:28:09 +05:30
Tamir Duberstein a491d4582d
Update integer_atomics tracking issue
Updates #32976.
Updates #99069.
2022-07-08 17:52:04 -04:00
Jane Lusby 0715616b51 add rt flag to allowed internal unstable for RustcEncodable/Decodable 2022-07-08 21:18:15 +00:00
Jane Lusby b55453dbad add opt in attribute for stable-in-unstable items 2022-07-08 21:18:15 +00:00
Jane Losare-Lusby d68cb1f9a3 revert changes to unicode stability 2022-07-08 21:18:15 +00:00
Jane Lusby e7fe5456c5 Support unstable moves via stable in unstable items 2022-07-08 21:18:13 +00:00
Matthias Krüger 9c6bcb60f3
Rollup merge of #98718 - yoshuawuyts:stabilize-into-future, r=yaahc
Stabilize `into_future`

https://github.com/rust-lang/rust/issues/67644 has been labeled with [S-tracking-ready-to-stabilize](https://github.com/rust-lang/rust/labels/S-tracking-ready-to-stabilize) - which mentions someone needs to file a stabilization PR. So hence this PR!  Thanks!

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

r? ``@joshtriplett``
2022-07-08 08:00:37 +02:00
Oli Scherer 2a899dc1cf `UnsafeCell` now has no niches, ever. 2022-07-07 10:46:22 +00:00
Guillaume Gomez 77ec591727
Rollup merge of #98939 - GuillaumeGomez:rustdoc-disamb-impls, r=notriddle
rustdoc: Add more semantic information to impl IDs

Take over of #92745.

I fixed the last remaining issue for the links in the sidebar (mentioned by `@jsha)` and fixed the few links broken in the std/core docs.

cc `@camelid`
r? `@notriddle`
2022-07-06 20:43:27 +02:00
Guillaume Gomez 4755173cf6
Rollup merge of #96935 - thomcc:atomicptr-strict-prov, r=dtolnay
Allow arithmetic and certain bitwise ops on AtomicPtr

This is mainly to support migrating from `AtomicUsize`, for the strict provenance experiment.

This is a pretty dubious set of APIs, but it should be sufficient to allow code that's using `AtomicUsize` to manipulate a tagged pointer atomically. It's under a new feature gate, `#![feature(strict_provenance_atomic_ptr)]`, but I'm not sure if it needs its own tracking issue. I'm happy to make one, but it's not clear that it's needed.

I'm unsure if it needs changes in the various non-LLVM backends. Because we just cast things to integers anyway (and were already doing so), I doubt it.

API change proposal: https://github.com/rust-lang/libs-team/issues/60

Fixes #95492
2022-07-06 20:43:23 +02:00
Guillaume Gomez 53db831d62 Fix links in std/core documentation 2022-07-05 21:33:39 +02:00
Nick Cameron 0c72be3e1a core::any: replace some unstable generic types with impl Trait
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2022-07-05 15:06:31 +01:00
Dylan DPC 8fa1ed8f12
Rollup merge of #97712 - RalfJung:untyped, r=scottmcm
ptr::copy and ptr::swap are doing untyped copies

The consensus in https://github.com/rust-lang/rust/issues/63159 seemed to be that these operations should be "untyped", i.e., they should treat the data as raw bytes, should work when these bytes violate the validity invariant of `T`, and should exactly preserve the initialization state of the bytes that are being copied. This is already somewhat implied by the description of "copying/swapping size*N bytes" (rather than "N instances of `T`").

The implementations mostly already work that way (well, for LLVM's intrinsics the documentation is not precise enough to say what exactly happens to poison, but if this ever gets clarified to something that would *not* perfectly preserve poison, then I strongly assume there will be some way to make a copy that *does* perfectly preserve poison). However, I had to adjust `swap_nonoverlapping`; after ``@scottmcm's`` [recent changes](https://github.com/rust-lang/rust/pull/94212), that one (sometimes) made a typed copy. (Note that `mem::swap`, which works on mutable references, is unchanged. It is documented as "swapping the values at two mutable locations", which to me strongly indicates that it is indeed typed. It is also safe and can rely on `&mut T` pointing to a valid `T` as part of its safety invariant.)

On top of adding a test (that will be run by Miri), this PR then also adjusts the documentation to indeed stably promise the untyped semantics. I assume this means the PR has to go through t-libs (and maybe t-lang?) FCP.

Fixes https://github.com/rust-lang/rust/issues/63159
2022-07-05 16:04:31 +05:30
5225225 5f5ca88958 Add size assert in transmute_copy 2022-07-03 10:46:20 +01:00
bors ada8c80bed Auto merge of #98673 - pietroalbini:pa-bootstrap-update, r=Mark-Simulacrum
Bump bootstrap compiler

r? `@Mark-Simulacrum`
2022-07-03 06:55:50 +00:00
Ben Kimock 7919e4208b Fix slice::ChunksMut aliasing 2022-07-03 00:15:15 -04:00
Pietro Albini 6b2d3d5f3c
update cfg(bootstrap)s 2022-07-01 15:48:23 +02:00
Thom Chiovoloni e65ecee90e
Rename AtomicPtr::fetch_{add,sub}{,_bytes} 2022-07-01 06:21:19 -07:00
Thom Chiovoloni 2f872afdb5
Allow arithmetic and certain bitwise ops on AtomicPtr
This is mainly to support migrating from AtomicUsize, for the strict
provenance experiment.

Fixes #95492
2022-07-01 06:21:18 -07:00
bors ca1e68b322 Auto merge of #98730 - matthiaskrgr:rollup-2c4d4x5, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #97629 ([core] add `Exclusive` to sync)
 - #98503 (fix data race in thread::scope)
 - #98670 (llvm-wrapper: adapt for LLVMConstExtractValue removal)
 - #98671 (Fix source sidebar bugs)
 - #98677 (For diagnostic information of Boolean, remind it as use the type: 'bool')
 - #98684 (add test for 72793)
 - #98688 (interpret: add From<&MplaceTy> for PlaceTy)
 - #98695 (use "or pattern")
 - #98709 (Remove unneeded methods declaration for old web browsers)
 - #98717 (get rid of tidy 'unnecessarily ignored' warnings)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-07-01 11:09:35 +00:00
Matthias Krüger 0e71d1f237
Rollup merge of #97629 - guswynn:exclusive_struct, r=m-ou-se
[core] add `Exclusive` to sync

(discussed here: https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Adding.20.60SyncWrapper.60.20to.20std)

`Exclusive` is a wrapper that exclusively allows mutable access to the inner value if you have exclusive access to the wrapper. It acts like a compile time mutex, and hold an unconditional `Sync` implementation.

## Justification for inclusion into std
- This wrapper unblocks actual problems:
  - The example that I hit was a vector of `futures::future::BoxFuture`'s causing a central struct in a script to be non-`Sync`. To work around it, you either write really difficult code, or wrap the futures in a needless mutex.
- Easy to maintain: this struct is as simple as a wrapper can get, and its `Sync` implementation has very clear reasoning
- Fills a gap: `&/&mut` are to `RwLock` as `Exclusive` is to `Mutex`

## Public Api
```rust
// core::sync
#[derive(Default)]
struct Exclusive<T: ?Sized> { ... }

impl<T: ?Sized> Sync for Exclusive {}

impl<T> Exclusive<T> {
    pub const fn new(t: T) -> Self;
    pub const fn into_inner(self) -> T;
}

impl<T: ?Sized> Exclusive<T> {
    pub const fn get_mut(&mut self) -> &mut T;
    pub const fn get_pin_mut(Pin<&mut self>) -> Pin<&mut T>;
    pub const fn from_mut(&mut T) -> &mut Exclusive<T>;
    pub const fn from_pin_mut(Pin<&mut T>) -> Pin<&mut Exclusive<T>>;
}

impl<T: Future> Future for Exclusive { ... }

impl<T> From<T> for Exclusive<T> { ... }
impl<T: ?Sized> Debug for Exclusive { ... }
```

## Naming
This is a big bikeshed, but I felt that `Exclusive` captured its general purpose quite well.

## Stability and location
As this is so simple, it can be in `core`. I feel that it can be stabilized quite soon after it is merged, if the libs teams feels its reasonable to add. Also, I don't really know how unstable feature work in std/core's codebases, so I might need help fixing them

## Tips for review
The docs probably are the thing that needs to be reviewed! I tried my best, but I'm sure people have more experience than me writing docs for `Core`

### Implementation:
The API is mostly pulled from https://docs.rs/sync_wrapper/latest/sync_wrapper/struct.SyncWrapper.html (which is apache 2.0 licenesed), and the implementation is trivial:
- its an unsafe justification for pinning
- its an unsafe justification for the `Sync` impl (mostly reasoned about by ````@danielhenrymantilla```` here: https://github.com/Actyx/sync_wrapper/pull/2)
- and forwarding impls, starting with derivable ones and `Future`
2022-06-30 19:55:50 +02:00
The 8472 3fcf84a68e clarify that ExactSizeIterator::len returns the remaining length 2022-06-30 19:45:36 +02:00
Yoshua Wuyts 992cfc1683 Stabilize `into_future` 2022-06-30 17:22:41 +02:00
Christopher Durham 344b99bd9f
nit
Co-authored-by: scottmcm <scottmcm@users.noreply.github.com>
2022-06-30 00:17:21 -04:00
Christopher Durham c4b4c64804 Revert isize::MAX changes to Layout helpers
The isize::MAX is enforced by the constructor; let it handle it.
2022-06-29 23:17:15 -04:00
Dylan DPC 375ab3e44f
Rollup merge of #98516 - dlrobertson:uefi_va_list, r=joshtriplett
library: fix uefi va_list type definition

For uefi the `va_list` should always be the void pointer variant.

Related to: https://github.com/rust-lang/rust/issues/44930
2022-06-29 17:59:34 +05:30
Dylan DPC 3f2ba25159
Rollup merge of #98479 - leocth:atomic-bool-fetch-not, r=joshtriplett
Add `fetch_not` method on `AtomicBool`

This PR adds a `fetch_not` method on `AtomicBool` performs the NOT operation on the inner value.
Internally, this just calls the `fetch_xor` method with the value `true`.

[See this IRLO discussion](https://internals.rust-lang.org/t/could-we-have-fetch-not-for-atomicbool-s/16881)
2022-06-29 17:59:32 +05:30
Mara Bos a898f41379 Only enable new cmpxchg memory orderings in cfg(not(bootstrap)).
(The bootstrap/beta compiler doesn't support them yet.)
2022-06-29 12:00:06 +02:00
Mara Bos a7434da9be Remove restrictions on compare-exchange memory ordering. 2022-06-29 12:00:06 +02:00
Dylan DPC 45740acd34
Rollup merge of #97423 - m-ou-se:memory-ordering-intrinsics, r=tmiasko
Simplify memory ordering intrinsics

This changes the names of the atomic intrinsics to always fully include their memory ordering arguments.

```diff
- atomic_cxchg
+ atomic_cxchg_seqcst_seqcst

- atomic_cxchg_acqrel
+ atomic_cxchg_acqrel_release

- atomic_cxchg_acqrel_failrelaxed
+ atomic_cxchg_acqrel_relaxed

// And so on.
```

- `seqcst` is no longer implied
- The failure ordering on chxchg is no longer implied in some cases, but now always explicitly part of the name.
- `release` is no longer shortened to just `rel`. That was especially confusing, since `relaxed` also starts with `rel`.
- `acquire` is no longer shortened to just `acq`, such that the names now all match the `std::sync::atomic::Ordering` variants exactly.
- This now allows for more combinations on the compare exchange operations, such as `atomic_cxchg_acquire_release`, which is necessary for #68464.
- This PR only exposes the new possibilities through unstable intrinsics, but not yet through the stable API. That's for [a separate PR](https://github.com/rust-lang/rust/pull/98383) that requires an FCP.

Suffixes for operations with a single memory order:

| Order   | Before       | After      |
|---------|--------------|------------|
| Relaxed | `_relaxed`   | `_relaxed` |
| Acquire | `_acq`       | `_acquire` |
| Release | `_rel`       | `_release` |
| AcqRel  | `_acqrel`    | `_acqrel`  |
| SeqCst  | (none)       | `_seqcst`  |

Suffixes for compare-and-exchange operations with two memory orderings:

| Success | Failure | Before                   | After              |
|---------|---------|--------------------------|--------------------|
| Relaxed | Relaxed | `_relaxed`               | `_relaxed_relaxed` |
| Relaxed | Acquire |                       | `_relaxed_acquire` |
| Relaxed | SeqCst  |                       | `_relaxed_seqcst`  |
| Acquire | Relaxed | `_acq_failrelaxed`       | `_acquire_relaxed` |
| Acquire | Acquire | `_acq`                   | `_acquire_acquire` |
| Acquire | SeqCst  |                       | `_acquire_seqcst`  |
| Release | Relaxed | `_rel`                   | `_release_relaxed` |
| Release | Acquire |                       | `_release_acquire` |
| Release | SeqCst  |                       | `_release_seqcst`  |
| AcqRel  | Relaxed | `_acqrel_failrelaxed`    | `_acqrel_relaxed`  |
| AcqRel  | Acquire | `_acqrel`                | `_acqrel_acquire`  |
| AcqRel  | SeqCst  |                       | `_acqrel_seqcst`   |
| SeqCst  | Relaxed | `_failrelaxed`           | `_seqcst_relaxed`  |
| SeqCst  | Acquire | `_failacq`               | `_seqcst_acquire`  |
| SeqCst  | SeqCst  | (none)                   | `_seqcst_seqcst`   |
2022-06-29 10:28:18 +05:30
Dylan DPC ff223ff297
Rollup merge of #98430 - camsteffen:flatten-refactor, r=joshtriplett
Refactor iter adapters with less macros

Just some code cleanup. Introduced a util `and_then_or_clear` for each of chain, flatten and fuse iter adapter impls. This reduces code nicely for flatten, but admittedly the other modules are more of a lateral move replacing macros with a function. But I think consistency across the modules and avoiding macros when possible is good.
2022-06-28 15:30:05 +05:30
Mara Bos 4982a59986 Rename/restructure memory ordering intrinsics. 2022-06-28 08:58:27 +02:00
Matthias Krüger f266821d8f
Rollup merge of #98587 - RalfJung:core-tests, r=thomcc
libcore tests: avoid int2ptr casts

We don't need any of these pointers to actually be dereferenceable so using `ptr::invalid` should be fine. And then we can run Miri with strict provenance enforcement on the tests.
2022-06-27 22:35:14 +02:00
Ralf Jung 8c977cfda8 libcore tests: avoid int2ptr casts 2022-06-27 13:30:44 -04:00
Wilfred Hughes 1c1ae78db7
Fix spelling in SAFETY comment
"can not" should be "cannot", and add punctuation.
2022-06-26 19:17:34 -07:00
Matthias Krüger e8a2e265b5
Rollup merge of #97908 - iago-lito:stabilize_nonzero_checked_ops_constness, r=scottmcm
Stabilize NonZero* checked operations constness.

Partial stabilization for #97547 (continued).
2022-06-26 19:47:02 +02:00
bors 788ddedb0d Auto merge of #98190 - nnethercote:optimize-derive-Debug-code, r=scottmcm
Improve `derive(Debug)`

r? `@ghost`
2022-06-26 15:00:04 +00:00
scottmcm 2339bb20a6
Update `since` to 1.64 (since we're after 1.63) 2022-06-26 08:45:53 +00:00
leocth 9c5ae20c59 forgot about the feature flag in the doctest 2022-06-26 10:49:05 +08:00
Dan Robertson 3b117c4823 library: fix uefi va_list type definition
For uefi the va_list should always be the void pointer variant.
2022-06-25 21:19:09 -04:00
leocth 0df7364cdf temporarily remove tests because I'm not sure if we need them 2022-06-26 00:06:50 +08:00
leocth 7d5f236c3d Add feature gate `#![atomic_bool_fetch_not]` 2022-06-25 18:31:01 +08:00
bors 1aabd8a4a6 Auto merge of #93700 - rossmacarthur:ft/iter-next-chunk, r=m-ou-se
Add `Iterator::next_chunk`

See also https://github.com/rust-lang/rust/pull/92393

### Prior art

-  [`Itertools::next_tuple()`](https://docs.rs/itertools/latest/itertools/trait.Itertools.html#method.next_tuple)

### Unresolved questions

- Should we also add `next_chunk_back` to `DoubleEndedIterator`?
- Should we rather call this `next_array()` or `next_array_chunk`?
2022-06-25 09:40:54 +00:00
leocth dcfe92e193 add `fetch_not` method on `AtomicBool` 2022-06-25 11:19:08 +08:00
Nicholas Nethercote 5b54363961 Optimize the code produced by `derive(Debug)`.
This commit adds new methods that combine sequences of existing
formatting methods.
- `Formatter::debug_{tuple,struct}_field[12345]_finish`, equivalent to a
  `Formatter::debug_{tuple,struct}` + N x `Debug{Tuple,Struct}::field` +
  `Debug{Tuple,Struct}::finish` call sequence.
- `Formatter::debug_{tuple,struct}_fields_finish` is similar, but can
  handle any number of fields by using arrays.

These new methods are all marked as `doc(hidden)` and unstable. They are
intended for the compiler's own use.

Special-casing up to 5 fields gives significantly better performance
results than always using arrays (as was tried in #95637).

The commit also changes the `Debug` deriving code to use these new methods. For
example, where the old `Debug` code for a struct with two fields would be like
this:
```
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
    match *self {
	Self {
	    f1: ref __self_0_0,
	    f2: ref __self_0_1,
	} => {
	    let debug_trait_builder = &mut ::core::fmt::Formatter::debug_struct(f, "S2");
	    let _ = ::core::fmt::DebugStruct::field(debug_trait_builder, "f1", &&(*__self_0_0));
	    let _ = ::core::fmt::DebugStruct::field(debug_trait_builder, "f2", &&(*__self_0_1));
	    ::core::fmt::DebugStruct::finish(debug_trait_builder)
	}
    }
}
```
the new code is like this:
```
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
    match *self {
	Self {
	    f1: ref __self_0_0,
	    f2: ref __self_0_1,
	} => ::core::fmt::Formatter::debug_struct_field2_finish(
	    f,
	    "S2",
	    "f1",
	    &&(*__self_0_0),
	    "f2",
	    &&(*__self_0_1),
	),
    }
}
```
This shrinks the code produced for `Debug` instances
considerably, reducing compile times and binary sizes.

Co-authored-by: Scott McMurray <scottmcm@users.noreply.github.com>
2022-06-24 09:40:15 +10:00
Gus Wynn 029f9aa3bf add tracking issue for exclusive 2022-06-23 08:52:13 -07:00
Cameron Steffen 6587dda39e Refactor iter adapters with less macros 2022-06-22 17:44:39 -05:00
Yuki Okushi 25b84491f7
Rollup merge of #97516 - RalfJung:atomics, r=joshtriplett
clarify how Rust atomics correspond to C++ atomics

``@cbeuw`` noted in https://github.com/rust-lang/miri/pull/1963 that the correspondence between C++ atomics and Rust atomics is not quite as obvious as one might think, since in Rust I can use `get_mut` to treat previously non-atomic data as atomic. However, I think using C++20 `atomic_ref`, we can establish a suitable relation between the two -- or do you see problems with that ``@cbeuw?`` (I recall you said there was some issue, but it was deep inside that PR and Github makes it impossible to find...)

Cc ``@thomcc;`` not sure whom else to ping for atomic memory model things.
2022-06-22 15:16:11 +09:00
Ralf Jung 4768bfc6ef
hedge our bets
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2022-06-21 16:54:54 -07:00
Yuki Okushi b20aff2b33
Rollup merge of #97269 - RalfJung:transmute, r=m-ou-se
adjust transmute const stabilization version

With 1.46, this became callable only in `const`/`static` items.

Only since 1.56 is this callable in `const fn`: [changelog](https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1560-2021-10-21)

Also see [Zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/transmute.20const.20fn.20stabilization).
2022-06-21 20:08:08 +09:00
Ross MacArthur bbdff1fff4
Add `Iterator::next_chunk` 2022-06-21 08:57:02 +02:00
bors 0887113991 Auto merge of #98307 - matthiaskrgr:rollup-rb3huha, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #98235 (Drop magic value 3 from code)
 - #98267 (Don't omit comma when suggesting wildcard arm after macro expr)
 - #98276 (Mention formatting macros when encountering `ArgumentV1` method in const)
 - #98296 (Add a link to the unstable book page on Generator doc comment)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-06-20 22:34:50 +00:00
Josh Triplett bded8fcfc0 Add `[f32]::sort_floats` and `[f64]::sort_floats`
It's inconvenient to sort a slice or Vec of floats, compared to sorting
integers. To simplify numeric code, add a convenience method to `[f32]`
and `[f64]` to sort them using `sort_unstable_by` with `total_cmp`.
2022-06-20 14:58:29 -07:00
Matthias Krüger dfa933d420
Rollup merge of #98296 - JohnTitor:generator-unstable-book-link, r=Dylan-DPC
Add a link to the unstable book page on Generator doc comment

This makes it easier to jump into the Generator section on the unstable book.

Signed-off-by: Yuki Okushi <jtitor@2k36.org>
2022-06-20 20:13:12 +02:00
Matthias Krüger 5eb7238928
Rollup merge of #98276 - compiler-errors:const-format-macro, r=oli-obk
Mention formatting macros when encountering `ArgumentV1` method in const

Also open to just closing this if it's overkill. There are a lot of other distracting error messages around, so maybe it's not worth fixing just this one.

Fixes #93665
2022-06-20 20:13:11 +02:00
bors 5750a6aa27 Auto merge of #93765 - zhangyunhao116:heapsort, r=m-ou-se
Optimize heapsort

The new implementation is about 10% faster than the previous one(sorting random 1000 items).
2022-06-20 18:09:30 +00:00
Yuki Okushi 51cc665b33
Add a link to the unstable book page on Generator doc comment
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
2022-06-20 23:19:50 +09:00
Dylan DPC 625c929a9f
Rollup merge of #96719 - mbartlett21:patch-4, r=Dylan-DPC
Fix the generator example for `pin!()`

The previous generator example is not actually self-referential, since the reference is created after the yield.

CC #93178 (tracking issue)
2022-06-20 14:56:36 +02:00
Dylan DPC fd9ca0c25e
Rollup merge of #93080 - SkiFire13:itermut-as_mut_slice, r=m-ou-se
Implement `core::slice::IterMut::as_mut_slice` and `impl<T> AsMut<[T]> for IterMut<'_, T>`

As per [the zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/.60std.3A.3Aslice.3A.3AIterMut.3A.3Aas_mut_slice.60), the `AsMut` impl has been commented out, with a comment near the `#[unstable(...)]` to uncomment it when `as_mut_slice` gets stabilized.
2022-06-20 14:56:33 +02:00
zhangyunhao 98507f202d Optimize heapsort 2022-06-20 08:30:27 +00:00
Mara Bos c867529461
Show #![feature] in example. 2022-06-20 10:00:55 +02:00
Michael Goulet 5373d738e8 Mention formatting macros when encountering ArgumentV1::new in const 2022-06-19 20:18:08 -07:00
Yuki Okushi 761f83f683
Rollup merge of #98257 - kadiwa4:into_future_doc_typos, r=Dylan-DPC
Fix typos in `IntoFuture` docs
2022-06-20 07:37:43 +09:00
Yuki Okushi 9d4e08e725
Rollup merge of #95534 - jyn514:std-mem-copy, r=joshtriplett
Add `core::mem::copy` to complement `core::mem::drop`.

This is useful for combinators. I didn't add `clone` since you can already
use `Clone::clone` in its place; copy has no such corresponding function.
2022-06-20 07:37:40 +09:00
Joshua Nelson 9ac6277bad Add `core::mem::copy` to complement `core::mem::drop`.
This is useful for combinators. I didn't add `clone` since you can already
use `Clone::clone` in its place; copy has no such corresponding function.
2022-06-19 16:43:19 -05:00
KaDiWa4 f0144aea74
typos in `IntoFuture` docs 2022-06-19 17:13:48 +02:00
bors 5fb8a39266 Auto merge of #97367 - WaffleLapkin:stabilize_checked_slice_to_str_conv, r=dtolnay
Stabilize checked slice->str conversion functions

This PR stabilizes the following APIs as `const` functions in Rust 1.63:
```rust
// core::str

pub const fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error>;

impl Utf8Error {
    pub const fn valid_up_to(&self) -> usize;
    pub const fn error_len(&self) -> Option<usize>;
}
```

Note that the `from_utf8_mut` function is not stabilized as unique references (`&mut _`) are [unstable in const context].

FCP: https://github.com/rust-lang/rust/issues/91006#issuecomment-1134593095

[unstable in const context]: https://github.com/rust-lang/rust/issues/57349
2022-06-19 05:51:42 +00:00
Matthias Krüger f351f347b8
Rollup merge of #98165 - WaffleLapkin:once_things_renamings, r=m-ou-se
once cell renamings

This PR does the renamings proposed in https://github.com/rust-lang/rust/issues/74465#issuecomment-1153703128

- Move/rename `lazy::{OnceCell, Lazy}` to `cell::{OnceCell, LazyCell}`
- Move/rename `lazy::{SyncOnceCell, SyncLazy}` to `sync::{OnceLock, LazyLock}`

(I used `Lazy...` instead of `...Lazy` as it seems to be more consistent, easier to pronounce, etc)

```@rustbot``` label +T-libs-api -T-libs
2022-06-19 00:17:13 +02:00
Paolo Barbolini ce3b6f505e Expose iter::ByRefSized as unstable feature and use it 2022-06-18 00:03:54 +02:00
Yuki Okushi cf68fd7e8d
Rollup merge of #97675 - nvzqz:unsized-needs-drop, r=dtolnay
Make `std::mem::needs_drop` accept `?Sized`

This change attempts to make `needs_drop` work with types like `[u8]` and `str`.

This enables code in types like `Arc<T>` that was not possible before, such as https://github.com/rust-lang/rust/pull/97676.
2022-06-17 07:16:55 +09:00
Maybe Waffle 7c360dc117 Move/rename `lazy::{OnceCell, Lazy}` to `cell::{OnceCell, LazyCell}` 2022-06-16 19:53:59 +04:00
bors 6ec3993ef4 Auto merge of #97842 - notriddle:notriddle/tuple-docs, r=jsha,GuillaumeGomez
Improve the tuple and unit trait docs

* Reduce duplicate impls; show only the `(T,)` and include a sentence saying that there exists ones up to twelve of them.
* Show `Copy` and `Clone`.
* Show auto traits like `Send` and `Sync`, and blanket impls like `Any`.

Here's the new version:

* <https://notriddle.com/notriddle-rustdoc-test/std/primitive.tuple.html>
* <https://notriddle.com/notriddle-rustdoc-test/std/primitive.unit.html>
2022-06-16 11:13:30 +00:00
Yuki Okushi b91c4d5b45
Rollup merge of #98059 - tmiasko:inline-const-eval-select, r=Amanieu
Inline `const_eval_select`

To avoid circular link time dependency between core and compiler
builtins when building with `-Zshare-generics`.

r? ```@Amanieu```
2022-06-16 07:24:41 +09:00
Michael Howell 2bbf44f655 rustdoc: change "variadic tuple" notation to look less like real syntax 2022-06-14 12:21:38 -07:00
Meziu 4e808f87cc
Horizon OS STD support
Co-authored-by: Ian Chamberlain <ian.h.chamberlain@gmail.com>
Co-authored-by: Mark Drobnak <mark.drobnak@gmail.com>
2022-06-13 20:44:39 -07:00
Tomasz Miąsko 8a8404bc2b Inline `const_eval_select`
To avoid circular link time dependency between core and compiler
builtins when building with `-Zshare-generics`.
2022-06-13 17:10:40 +02:00
Imbolc acda8866cc
Document an edge case of `str::split_once` 2022-06-13 13:35:49 +03:00
Michael Goulet 5dccf4e5fc
Rollup merge of #97950 - eggyal:issue-97945, r=Dylan-DPC
Clarify `#[derive(PartialEq)]` on enums

Fixes #97945
2022-06-12 17:35:41 -07:00
Dylan DPC a24ca03660
Rollup merge of #97992 - m-ou-se:stabilize-scoped-threads, r=joshtriplett
Stabilize scoped threads.

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

FCP finished here: https://github.com/rust-lang/rust/issues/93203#issuecomment-1152249466
2022-06-12 12:14:29 +02:00
Michael Howell 36fb094d25 Add docs to `maybe_tuple_doc!` 2022-06-11 21:47:03 -07:00
Michael Howell 22c39aa835 Update library/core/src/primitive_docs.rs 2022-06-11 21:45:23 -07:00
bors c08b235a5c Auto merge of #97996 - matthiaskrgr:rollup-bvbjlid, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #97904 (Small grammar fix in the compile_error documentation)
 - #97943 (line 1352, change `self` to `*self`, other to `*other`)
 - #97969 (Make -Cpasses= only apply to pre-link optimization)
 - #97990 (Add more eslint checks)
 - #97994 (feat(fix): update some links in `hir.rs`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-06-11 17:49:22 +00:00
Michael Howell 28bd1a4847 docs: make all the variadic impls use `(T, ...)` exactly 2022-06-11 10:32:39 -07:00
Michael Howell c1487550ca Add test case for #trait-implementations-1 link 2022-06-11 09:54:23 -07:00
Michael Howell 3fd16648fe Re-add explicit list of traits to tuple docs, with limit notes 2022-06-11 09:54:23 -07:00
Michael Howell 090c68ba5c Use relative path for addressing things in rust-lang/rust
Co-authored-by: Jacob Hoffman-Andrews <github@hoffman-andrews.com>
2022-06-11 09:54:23 -07:00
Michael Howell 9b31323b8f Fix incorrectly spelled "variadic" 2022-06-11 09:54:20 -07:00
Matthias Krüger 39de4e4b6f
Rollup merge of #97943 - Warrenren:master, r=Dylan-DPC
line 1352, change `self` to `*self`, other to `*other`

The current code will not results bug, but it difficult to understand. These code result to call &f32::partial_cmp(), and the performance will be lower than the changed code. I'm not sure why the current code don't use (*self) (*other), if you have some idea, please let me know.
2022-06-11 18:05:33 +02:00
Matthias Krüger 4b7ec84c31
Rollup merge of #97904 - est31:master, r=Dylan-DPC
Small grammar fix in the compile_error documentation
2022-06-11 18:05:32 +02:00
Mara Bos ae0a533b0b Stabilize scoped threads. 2022-06-11 15:01:52 +02:00
Benjamin Herr 74ef14830f Fix typos in Provider API docs 2022-06-10 20:58:27 -07:00
Warrenren 9e1e476186
Update cmp.rs
line 1352, delete parentheses for reviewers asking for it.
2022-06-11 11:04:27 +08:00
Matthias Krüger 30a8903821
Rollup merge of #97940 - GuillaumeGomez:relative-link, r=Dylan-DPC
Use relative links instead of linking to doc.rust-lang.org when possible

Part of https://github.com/rust-lang/rust/issues/97918.
2022-06-10 22:32:31 +02:00
Alan Egerton 7bbf914078
Clarify `#[derive(PartialEq)]` on enums
Fixes #97945
2022-06-10 16:26:00 +01:00
Warrenren 5e9e73cc9f
line 1352, change self to (*self), other to (*other)
The current code will not results bug, but it difficult to understand. These code result to call &f32::partial_cmp(), and the performance will be lower than the changed code. I'm not sure why the current code don't use (*self) (*other), if you have some idea, please let me know.
2022-06-10 19:08:03 +08:00
Guillaume Gomez 28ca3bdeb2 Use relative links instead of linking to doc.rust-lang.org when possible 2022-06-10 11:57:53 +02:00
Yuki Okushi a652a4303f
Rollup merge of #97876 - yoshuawuyts:into-future-docs, r=JohnTitor,yaahc
update docs for `std::future::IntoFuture`

Ref https://github.com/rust-lang/rust/issues/67644.

This updates the docs for `IntoFuture` providing a bit more guidance on how to use it. Thanks!
2022-06-10 17:22:29 +09:00
bors e9aff9c42c Auto merge of #91970 - nrc:provide-any, r=scottmcm
Add the Provider api to core::any

This is an implementation of [RFC 3192](https://github.com/rust-lang/rfcs/pull/3192) ~~(which is yet to be merged, thus why this is a draft PR)~~. It adds an API for type-driven requests and provision of data from trait objects. A primary use case is for the `Error` trait, though that is not implemented in this PR. The only major difference to the RFC is that the functionality is added to the `any` module, rather than being in a sibling `provide_any` module (as discussed in the RFC thread).

~~Still todo: improve documentation on items, including adding examples.~~

cc `@yaahc`
2022-06-10 01:10:59 +00:00
est31 97519bd202 Grammar fix in the compile_error documentation 2022-06-09 12:40:10 +02:00
Iago-lito 69e8e7e73b Stabilize NonZero* checked operations constness. 2022-06-09 09:17:06 +02:00