Skip to content

Commit 7b807ac

Browse files
committed
Revise section about dyn in Rust 2015
1 parent 8fec524 commit 7b807ac

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/types/trait-object.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ r[type.trait-object.syntax-edition2021]
3737
3838
r[type.trait-object.syntax-edition2018]
3939
> [!EDITION-2018]
40-
> 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 around this. As such, if you want a trait object with the trait `::your_module::Trait`, you should write it as `dyn (::your_module::Trait)`.
40+
> In the 2015 edition, `dyn` must be followed by [PathIdentSegment][grammar-PathIdentSegment], [LIFETIME_OR_LABEL][grammar-LIFETIME_OR_LABEL], `for`, `(` or `?` to be interpreted as the start of a trait object type. Otherwise, it will be interpreted as a regular identifier.
41+
>
42+
> Most notably, `dyn`, `dyn::T` and `dyn<T>` will all be treated as type paths. The first path can be put in parenthesis to get around this. As such, if you want a trait object with the trait `::module::Trait`, you should write it as `dyn (::module::Trait)`.
4143
>
4244
> Beginning in the 2018 edition, `dyn` is a true keyword and is not allowed in paths, so the parentheses are not necessary.
4345

0 commit comments

Comments
 (0)