diff --git a/src/items/type-aliases.md b/src/items/type-aliases.md index c21981eb85..9a9dec0e26 100644 --- a/src/items/type-aliases.md +++ b/src/items/type-aliases.md @@ -4,7 +4,7 @@ r[items.type] r[items.type.syntax] ```grammar,items TypeAlias -> - `type` IDENTIFIER GenericParams? ( `:` Bounds )? + `type` IDENTIFIER GenericParams? ( `:` Bounds? )? WhereClause? ( `=` Type WhereClause?)? `;` ``` diff --git a/src/paths.md b/src/paths.md index cb36f3af20..2a141f2846 100644 --- a/src/paths.md +++ b/src/paths.md @@ -68,7 +68,7 @@ GenericArgsBinding -> IDENTIFIER GenericArgs? `=` Type GenericArgsBounds -> - IDENTIFIER GenericArgs? `:` Bounds + IDENTIFIER GenericArgs? `:` Bounds? ``` r[paths.expr.intro] diff --git a/src/types/impl-trait.md b/src/types/impl-trait.md index 68bee6c025..1a6ad5639c 100644 --- a/src/types/impl-trait.md +++ b/src/types/impl-trait.md @@ -3,9 +3,9 @@ r[type.impl-trait] r[type.impl-trait.syntax] ```grammar,types -ImplTraitType -> `impl` Bounds +ImplTraitType -> `impl` Bounds? -ImplTraitTypeOneBound -> `impl` TraitBound +ImplTraitTypeOneBound -> `impl` TraitBound? ``` r[type.impl-trait.intro] diff --git a/src/types/trait-object.md b/src/types/trait-object.md index 7b07b6a05c..b66c2536c3 100644 --- a/src/types/trait-object.md +++ b/src/types/trait-object.md @@ -3,9 +3,9 @@ r[type.trait-object] r[type.trait-object.syntax] ```grammar,types -TraitObjectType -> `dyn`? Bounds +TraitObjectType -> Bounds | `dyn` Bounds? -TraitObjectTypeOneBound -> `dyn`? TraitBound +TraitObjectTypeOneBound -> TraitBound | `dyn` TraitBound? ``` r[type.trait-object.intro] @@ -37,7 +37,9 @@ r[type.trait-object.syntax-edition2021] r[type.trait-object.syntax-edition2018] > [!EDITION-2018] -> 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)`. +> 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. +> +> Most notably, `dyn`, `dyn::T` and `dyn` 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)`. > > Beginning in the 2018 edition, `dyn` is a true keyword and is not allowed in paths, so the parentheses are not necessary.