Skip to content

Commit 954f3d4

Browse files
authored
Merge pull request #1111 from mattheww/2021-11_bare_trait
Say that bare trait objects are rejected in the 2021 edition
2 parents 24d6292 + 364066f commit 954f3d4

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/types/trait-object.md

+10-8
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ number of [auto traits].
1414
Trait objects implement the base trait, its auto traits, and any [supertraits]
1515
of the base trait.
1616

17-
Trait objects are written as the optional keyword `dyn` followed by a set of
18-
trait bounds, but with the following restrictions on the trait bounds. All
19-
traits except the first trait must be auto traits, there may not be more than
20-
one lifetime, and opt-out bounds (e.g. `?Sized`) are not allowed. Furthermore,
17+
Trait objects are written as the keyword `dyn` followed by a set of trait
18+
bounds, but with the following restrictions on the trait bounds. All traits
19+
except the first trait must be auto traits, there may not be more than one
20+
lifetime, and opt-out bounds (e.g. `?Sized`) are not allowed. Furthermore,
2121
paths to traits may be parenthesized.
2222

2323
For example, given a trait `Trait`, the following are all trait objects:
2424

25-
* `Trait`
2625
* `dyn Trait`
2726
* `dyn Trait + Send`
2827
* `dyn Trait + Send + Sync`
@@ -32,6 +31,12 @@ For example, given a trait `Trait`, the following are all trait objects:
3231
* `dyn 'static + Trait`.
3332
* `dyn (Trait)`
3433

34+
> **Edition Differences**: Before the 2021 edition, the `dyn` keyword may be
35+
> omitted.
36+
>
37+
> Note: For clarity, it is recommended to always use the `dyn` keyword on your
38+
> trait objects unless your codebase supports compiling with Rust 1.26 or lower.
39+
3540
> **Edition Differences**: In the 2015 edition, if the first bound of the
3641
> trait object is a path that starts with `::`, then the `dyn` will be treated
3742
> 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:
4146
> Beginning in the 2018 edition, `dyn` is a true keyword and is not allowed in
4247
> paths, so the parentheses are not necessary.
4348
44-
> Note: For clarity, it is recommended to always use the `dyn` keyword on your
45-
> trait objects unless your codebase supports compiling with Rust 1.26 or lower.
46-
4749
Two trait object types alias each other if the base traits alias each other and
4850
if the sets of auto traits are the same and the lifetime bounds are the same.
4951
For example, `dyn Trait + Send + UnwindSafe` is the same as

0 commit comments

Comments
 (0)