about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2022-10-16 10:38:48 +0200
committerRalf Jung <post@ralfj.de>2022-10-16 11:34:24 +0200
commit73d655e9c2106566f328de28aeff6fd3a8ee8e21 (patch)
treeca86087ce5a6a185ee6491b860e6155afc189ab3
parentedabf59ca4646b3fc1a961c26431215001043f6a (diff)
downloadrust-73d655e9c2106566f328de28aeff6fd3a8ee8e21.tar.gz
rust-73d655e9c2106566f328de28aeff6fd3a8ee8e21.zip
remove redundant Send impls for references
also move them next to the trait they are implementing
-rw-r--r--library/core/src/marker.rs13
-rw-r--r--src/test/ui/async-await/async-fn-nonsend.stderr2
2 files changed, 7 insertions, 8 deletions
diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs
index d5ed52124e2..bb10caee6e2 100644
--- a/library/core/src/marker.rs
+++ b/library/core/src/marker.rs
@@ -44,6 +44,12 @@ impl<T: ?Sized> !Send for *const T {}
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T: ?Sized> !Send for *mut T {}
 
+// Most instances arise automatically, but this instance is needed to link up `T: Sync` with
+// `&T: Send` (and it also removes the unsound default instance `T Send` -> `&T: Send` that would
+// otherwise exist).
+#[stable(feature = "rust1", since = "1.0.0")]
+unsafe impl<T: Sync + ?Sized> Send for &T {}
+
 /// Types with a constant size known at compile time.
 ///
 /// All type parameters have an implicit bound of `Sized`. The special syntax
@@ -680,13 +686,6 @@ pub struct PhantomData<T: ?Sized>;
 
 impls! { PhantomData }
 
-mod impls {
-    #[stable(feature = "rust1", since = "1.0.0")]
-    unsafe impl<T: Sync + ?Sized> Send for &T {}
-    #[stable(feature = "rust1", since = "1.0.0")]
-    unsafe impl<T: Send + ?Sized> Send for &mut T {}
-}
-
 /// Compiler-internal trait used to indicate the type of enum discriminants.
 ///
 /// This trait is automatically implemented for every type and does not add any
diff --git a/src/test/ui/async-await/async-fn-nonsend.stderr b/src/test/ui/async-await/async-fn-nonsend.stderr
index 40ad46b4862..a7b872fe444 100644
--- a/src/test/ui/async-await/async-fn-nonsend.stderr
+++ b/src/test/ui/async-await/async-fn-nonsend.stderr
@@ -27,7 +27,7 @@ error: future cannot be sent between threads safely
 LL |     assert_send(non_sync_with_method_call());
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `non_sync_with_method_call` is not `Send`
    |
-   = help: the trait `Send` is not implemented for `dyn std::fmt::Write`
+   = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `dyn std::fmt::Write`
 note: future is not `Send` as this value is used across an await
   --> $DIR/async-fn-nonsend.rs:46:14
    |