From feba2435b10de6e8c259356d21451de4276ee5b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Tue, 5 May 2026 09:23:19 +0200 Subject: [PATCH 1/2] Fix grammar rules containing bounds --- src/items/type-aliases.md | 2 +- src/paths.md | 2 +- src/types/impl-trait.md | 4 ++-- src/types/trait-object.md | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) 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..fa33c106bc 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] From e8c2309e7ad12d1321718f2f9f4a5307c618f87f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Tue, 5 May 2026 10:04:18 +0200 Subject: [PATCH 2/2] Revise section about `dyn` in Rust 2015 --- src/types/trait-object.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/types/trait-object.md b/src/types/trait-object.md index fa33c106bc..b66c2536c3 100644 --- a/src/types/trait-object.md +++ b/src/types/trait-object.md @@ -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.