From 364066f09c801acd45c656a345301f8cdb1e5870 Mon Sep 17 00:00:00 2001 From: Matthew Woodcraft Date: Sat, 27 Nov 2021 17:31:21 +0000 Subject: [PATCH] Say that bare trait objects are rejected in the 2021 edition --- src/types/trait-object.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/types/trait-object.md b/src/types/trait-object.md index acc856563..3526b7add 100644 --- a/src/types/trait-object.md +++ b/src/types/trait-object.md @@ -14,15 +14,14 @@ number of [auto traits]. Trait objects implement the base trait, its auto traits, and any [supertraits] of the base trait. -Trait objects are written as the optional keyword `dyn` followed by a set of -trait bounds, but with the following restrictions on the trait bounds. All -traits except the first trait must be auto traits, there may not be more than -one lifetime, and opt-out bounds (e.g. `?Sized`) are not allowed. Furthermore, +Trait objects are written as the keyword `dyn` followed by a set of trait +bounds, but with the following restrictions on the trait bounds. All traits +except the first trait must be auto traits, there may not be more than one +lifetime, and opt-out bounds (e.g. `?Sized`) are not allowed. Furthermore, paths to traits may be parenthesized. For example, given a trait `Trait`, the following are all trait objects: -* `Trait` * `dyn Trait` * `dyn Trait + Send` * `dyn Trait + Send + Sync` @@ -32,6 +31,12 @@ For example, given a trait `Trait`, the following are all trait objects: * `dyn 'static + Trait`. * `dyn (Trait)` +> **Edition Differences**: Before the 2021 edition, the `dyn` keyword may be +> omitted. +> +> Note: For clarity, it is recommended to always use the `dyn` keyword on your +> trait objects unless your codebase supports compiling with Rust 1.26 or lower. + > **Edition Differences**: In the 2015 edition, if the first bound of the > trait object is a path that starts with `::`, then the `dyn` will be treated > as a part of the path. The first path can be put in parenthesis to get @@ -41,9 +46,6 @@ For example, given a trait `Trait`, the following are all trait objects: > Beginning in the 2018 edition, `dyn` is a true keyword and is not allowed in > paths, so the parentheses are not necessary. -> Note: For clarity, it is recommended to always use the `dyn` keyword on your -> trait objects unless your codebase supports compiling with Rust 1.26 or lower. - Two trait object types alias each other if the base traits alias each other and if the sets of auto traits are the same and the lifetime bounds are the same. For example, `dyn Trait + Send + UnwindSafe` is the same as