Skip to content

Commit dc509bd

Browse files
Document object unsafety of async-fn-in-trait
`async fn` in traits, and return-position `impl Trait` in traits, were stabilized by <rust-lang/rust#115822>. The object-safety error E0038 points to the Reference, so the Reference should mention this new criterion.
1 parent 6d5d304 commit dc509bd

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/items/traits.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ Object safe traits can be the base trait of a [trait object]. A trait is
7272
* It must not have any associated constants.
7373
* It must not have any associated types with generics.
7474
* All associated functions must either be dispatchable from a trait object or be explicitly non-dispatchable:
75-
* Dispatchable functions require:
76-
* Not have any type parameters (although lifetime parameters are allowed),
75+
* Dispatchable functions must:
76+
* Not have any type parameters (although lifetime parameters are allowed).
7777
* Be a [method] that does not use `Self` except in the type of the receiver.
7878
* Have a receiver with one of the following types:
7979
* `&Self` (i.e. `&self`)
@@ -82,7 +82,10 @@ Object safe traits can be the base trait of a [trait object]. A trait is
8282
* [`Rc<Self>`]
8383
* [`Arc<Self>`]
8484
* [`Pin<P>`] where `P` is one of the types above
85-
* Does not have a `where Self: Sized` bound (receiver type of `Self` (i.e. `self`) implies this).
85+
* Not have an opaque return type; that is,
86+
* Not be an `async fn` (which has a hidden `Future` type).
87+
* Not have a return position `impl Trait` type (`fn example(&self) -> impl Trait`).
88+
* Not have a `where Self: Sized` bound (receiver type of `Self` (i.e. `self`) implies this).
8689
* Explicitly non-dispatchable functions require:
8790
* Have a `where Self: Sized` bound (receiver type of `Self` (i.e. `self`) implies this).
8891

0 commit comments

Comments
 (0)