Skip to content

Commit 9ee10b4

Browse files
committed
rfc, self_in_typedefs: update consistency of self + unresolved question
1 parent 65657d0 commit 9ee10b4

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

text/0000-self-in-typedefs.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,32 @@ that it refers to `_Bar` and not `Foo`. To be consistent with the desugared
609609
form, the sugared variant should have the same meaning and so `Self` refers
610610
to `Bar` there.
611611

612+
Let's now consider an alternative possible syntax:
613+
614+
```rust
615+
impl Trait for Foo {
616+
type Bar = struct /* there is no ident here */ {
617+
outer: Option<Box<Self>>,
618+
inner: Option<Box<Self::Item>>,
619+
}
620+
}
621+
```
622+
623+
Notice here in particular that there is no identifier after the keyword
624+
`struct`. Because of this, it is reasonable to say that the `struct`
625+
assigned to the associated type `Bar` is not directly nameable as `Bar`.
626+
Instead, a user must qualify `Bar` with `Self::Bar`. With this in mind,
627+
we arrive at the following interpretation:
628+
629+
```rust
630+
impl Trait for Foo {
631+
type Bar = struct /* there is no ident here */ {
632+
outer: Option<Box<Foo>>,
633+
inner: Option<Box<Foo::Bar>>,
634+
}
635+
}
636+
```
637+
612638
### Conclusion
613639

614640
We've now examined a few cases and seen that indeed, the meaning of `Self` is
@@ -696,4 +722,8 @@ is preferred.
696722
# Unresolved questions
697723
[unresolved]: #unresolved-questions
698724

699-
There are no unresolved questions.
725+
+ This syntax creates ambiguity if we ever permit types to be declared directly
726+
within impls (for example, as the value for an associated type). Do we ever want
727+
to support that, and if so, how should we resolve the ambiguity? **A** possible,
728+
interpretation and way to solve the ambiguity consistently is discussed in the
729+
rationale.

0 commit comments

Comments
 (0)