Skip to content

Commit d661270

Browse files
committed
Note down some semantic restrictions on dyn-Trait and impl-Trait
Furthermore, drop rule `type.trait-object.name` entirely and parts of `type.trait-object.bounds` since they mixed syntax & semantics and tried to redescribe the grammar in prose which didn't add value, were too ambiguous & incomplete.
1 parent def41e9 commit d661270

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

src/types/impl-trait.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ fn foo(arg: impl Trait) {
2323
fn bar() -> impl Trait {
2424
}
2525
```
26+
27+
r[type.impl-trait.bounds]
28+
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`).
29+
2630
r[type.impl-trait.param]
2731
## Anonymous type parameters
2832

src/types/trait-object.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@ A *trait object* is an opaque value of another type that implements a set of tra
1414
r[type.trait-object.impls]
1515
Trait objects implement the base trait, its auto traits, and any [supertraits] of the base trait.
1616

17-
r[type.trait-object.name]
18-
Trait objects are written as the keyword `dyn` followed by a set of trait bounds, but with the following restrictions on the trait bounds.
19-
20-
r[type.trait-object.constraint]
21-
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.
17+
r[type.trait-object.bounds]
18+
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.
2219

2320
For example, given a trait `Trait`, the following are all trait objects:
2421

0 commit comments

Comments
 (0)