Rollup merge of #153038 - pthariensflame:syncview-rename, r=Amanieu

core::sync: rename `Exclusive` to `SyncView` and make improvements

This PR implements the renaming of `core::sync::Exclusive` to `SyncView` as decided in rust-lang/rust#98407.  To preserve the ability to search for the old name, it adds `Exclusive` as a `doc_alias`.

It also makes the following additional changes:

- Converting the `get_mut` method to being an instance of `AsMut::as_mut`.  In the process, it makes both the new `impl AsMut` and the existing `impl AsRef` `const`, and it also renames `get_pin_mut` to `as_pin_mut` for consistency.  This direction follows a suggestion from rust-lang/rust#98407.
- Adding an `as_pin` method that can only be used when the wrapped type implements `Sync`, to complete the square of access methods.
- Making as many of the existing `impl`s `const` as possible; this involved making the existing `impl Default` no longer derived.
- Adding `impl`s for `AsyncFnOnce`, `AsyncFnMut`, and `AsyncFn`, akin to the existing `impls` for `FnOnce`, `FnMut`, and `Fn`.

It does not yet do the following, which may be desirable:

- Fixing/improving the documentation to address the concern pointed out in rust-lang/rust#146245.

It previously did the following, but this was removed after discussion:
- Adding an `impl` for (`const`) `Iterator`, which felt in line with the existing `impl`s for `Future` and `Coroutine`.
This commit is contained in:
Jacob Pratt
2026-04-09 02:31:08 -04:00
committed by GitHub
8 changed files with 427 additions and 335 deletions
@@ -4,11 +4,11 @@
fn f() {}
fn g() {
become std::sync::Exclusive::new(f)() //~ error: tail calls can only be performed with function definitions or pointers
become std::sync::SyncView::new(f)() //~ error: tail calls can only be performed with function definitions or pointers
}
fn h() {
become (&mut &std::sync::Exclusive::new(f))() //~ error: tail calls can only be performed with function definitions or pointers
become (&mut &std::sync::SyncView::new(f))() //~ error: tail calls can only be performed with function definitions or pointers
}
fn i() {
@@ -1,18 +1,18 @@
error: tail calls can only be performed with function definitions or pointers
--> $DIR/callee_is_weird.rs:7:12
|
LL | become std::sync::Exclusive::new(f)()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | become std::sync::SyncView::new(f)()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: callee has type `Exclusive<fn() {f}>`
= note: callee has type `SyncView<fn() {f}>`
error: tail calls can only be performed with function definitions or pointers
--> $DIR/callee_is_weird.rs:11:12
|
LL | become (&mut &std::sync::Exclusive::new(f))()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | become (&mut &std::sync::SyncView::new(f))()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: callee has type `&Exclusive<fn() {f}>`
= note: callee has type `&SyncView<fn() {f}>`
error: tail calls can only be performed with function definitions or pointers
--> $DIR/callee_is_weird.rs:22:12
+1 -1
View File
@@ -387,7 +387,7 @@ LL | fn in_impl_Fn_return_in_return() -> &'static impl Fn() -> impl Debug { pani
where A: std::marker::Tuple, F: Fn<A>, F: ?Sized;
- impl<Args, F, A> Fn<Args> for Box<F, A>
where Args: std::marker::Tuple, F: Fn<Args>, A: Allocator, F: ?Sized;
- impl<F, Args> Fn<Args> for Exclusive<F>
- impl<F, Args> Fn<Args> for SyncView<F>
where F: Sync, F: Fn<Args>, Args: std::marker::Tuple;
error: unconstrained opaque type
@@ -12,7 +12,7 @@ LL | x = unconstrained_map();
where A: std::marker::Tuple, F: Fn<A>, F: ?Sized;
- impl<Args, F, A> Fn<Args> for Box<F, A>
where Args: std::marker::Tuple, F: Fn<Args>, A: Allocator, F: ?Sized;
- impl<F, Args> Fn<Args> for Exclusive<F>
- impl<F, Args> Fn<Args> for SyncView<F>
where F: Sync, F: Fn<Args>, Args: std::marker::Tuple;
note: required by a bound in `unconstrained_map`
--> $DIR/well-formed-in-relate.rs:21:25