From dc509bd8488d7a8ef35c7bd1bb07245294fc66ff Mon Sep 17 00:00:00 2001 From: Tiger0202 Date: Fri, 8 Dec 2023 08:32:38 -0800 Subject: [PATCH] Document object unsafety of async-fn-in-trait `async fn` in traits, and return-position `impl Trait` in traits, were stabilized by . The object-safety error E0038 points to the Reference, so the Reference should mention this new criterion. --- src/items/traits.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/items/traits.md b/src/items/traits.md index 828a8a3..a74d7cb 100644 --- a/src/items/traits.md +++ b/src/items/traits.md @@ -72,8 +72,8 @@ Object safe traits can be the base trait of a [trait object]. A trait is * It must not have any associated constants. * It must not have any associated types with generics. * All associated functions must either be dispatchable from a trait object or be explicitly non-dispatchable: - * Dispatchable functions require: - * Not have any type parameters (although lifetime parameters are allowed), + * Dispatchable functions must: + * Not have any type parameters (although lifetime parameters are allowed). * Be a [method] that does not use `Self` except in the type of the receiver. * Have a receiver with one of the following types: * `&Self` (i.e. `&self`) @@ -82,7 +82,10 @@ Object safe traits can be the base trait of a [trait object]. A trait is * [`Rc`] * [`Arc`] * [`Pin

`] where `P` is one of the types above - * Does not have a `where Self: Sized` bound (receiver type of `Self` (i.e. `self`) implies this). + * Not have an opaque return type; that is, + * Not be an `async fn` (which has a hidden `Future` type). + * Not have a return position `impl Trait` type (`fn example(&self) -> impl Trait`). + * Not have a `where Self: Sized` bound (receiver type of `Self` (i.e. `self`) implies this). * Explicitly non-dispatchable functions require: * Have a `where Self: Sized` bound (receiver type of `Self` (i.e. `self`) implies this).