-
Notifications
You must be signed in to change notification settings - Fork 593
Fix grammar rules containing or pertaining to bounds #2257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
2d391df
f68a527
def41e9
d661270
362c0ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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] | ||
|
|
@@ -23,6 +23,10 @@ fn foo(arg: impl Trait) { | |
| fn bar() -> impl Trait { | ||
| } | ||
| ``` | ||
|
|
||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm mirroring the structure of the section about trait object types here with the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking more closely at this, I agree the ".name" rules don't really make sense. Generally we don't want to have an English description of the syntax (which is often very imprecise). I'm thinking we can just drop these two |
||
| r[type.impl-trait.bounds] | ||
| There must be at least one trait bound, no more than one `use<..>` bound, and no more than one opt-out bound (e.g., `?Sized`). | ||
|
|
||
| r[type.impl-trait.param] | ||
| ## Anonymous type parameters | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,22 +3,22 @@ r[type.trait-object] | |
|
|
||
| r[type.trait-object.syntax] | ||
| ```grammar,types | ||
| TraitObjectType -> `dyn`? Bounds | ||
| TraitObjectType -> Bounds[^bare-2021] | `dyn`[^dyn-2018] Bounds? | ||
|
|
||
| TraitObjectTypeOneBound -> `dyn`? TraitBound | ||
| TraitObjectTypeOneBound -> TraitBound[^bare-2021] | `dyn`[^dyn-2018] TraitBound? | ||
| ``` | ||
|
|
||
| [^bare-2021]: See [type.trait-object.syntax-edition2021]. | ||
| [^dyn-2018]: See [type.trait-object.syntax-edition2018]. | ||
|
|
||
| r[type.trait-object.intro] | ||
| A *trait object* is an opaque value of another type that implements a set of traits. The set of traits is made up of a [dyn compatible] *base trait* plus any number of [auto traits]. | ||
|
|
||
| r[type.trait-object.impls] | ||
| Trait objects implement the base trait, its auto traits, and any [supertraits] of the base trait. | ||
|
|
||
| r[type.trait-object.name] | ||
| Trait objects are written as the keyword `dyn` followed by a set of trait bounds, but with the following restrictions on the trait bounds. | ||
|
|
||
| r[type.trait-object.constraint] | ||
| There may not be more than one non-auto trait, no more than one lifetime, and opt-out bounds (e.g. `?Sized`) are not allowed. Furthermore, paths to traits may be parenthesized. | ||
| r[type.trait-object.bounds] | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed it to |
||
| There must be at least one trait bound, there may not be more than one non-auto trait, no more than one lifetime, and opt-out bounds (e.g., `?Sized`) and `use<..>` bounds are not allowed. | ||
|
|
||
| For example, given a trait `Trait`, the following are all trait objects: | ||
|
|
||
|
|
@@ -33,11 +33,13 @@ For example, given a trait `Trait`, the following are all trait objects: | |
|
|
||
| r[type.trait-object.syntax-edition2021] | ||
| > [!EDITION-2021] | ||
| > Before the 2021 edition, the `dyn` keyword may be omitted. | ||
| > Before the 2021 edition, the `dyn` keyword may be omitted. In the 2021 edition and beyond, the `dyn` keyword is required semantically. | ||
|
|
||
| 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], [LIFETIME_TOKEN], `for`, `(` or `?` to be interpreted as a keyword instead of a regular identifier. | ||
| > | ||
| > Most notably, `dyn`, `dyn::T` and `dyn<T>` will all be treated as type paths. As such, if you want a trait object type with the trait `::module::Trait`, you need to put the path in parentheses and 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. | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.