Skip to content

Commit 0730d53

Browse files
authored
Clarify that the Self must be in the type structure of the type or facet type in require (#6269)
It's not enough to have `Self` _somewhere_ in the facet type (after the `where`).
1 parent 26381f6 commit 0730d53

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

docs/design/generics/details.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5733,11 +5733,13 @@ interface CommonTypeWith(T:! type) {
57335733
says that if `Self` implements `CommonTypeWith(T)`, then `T` must implement
57345734
`CommonTypeWith(Self)`.
57355735

5736-
A `require`...`impls` constraint in an `interface`, or `constraint`, definition
5737-
must still use `Self` in some way. It can be an argument to either the
5738-
[type](#parameterized-types) or [interface](#parameterized-interfaces). The
5739-
`Self` can be omitted and will be implied as the type between `require impls`.
5740-
For example:
5736+
A `require <type> impls <facet type>` constraint in an `interface`, or
5737+
`constraint`, definition must still use `Self` as either the type, or as a
5738+
parameter to the [type](#parameterized-types) or an
5739+
[interface](#parameterized-interfaces) in the facet type. In particular, it
5740+
requires `Self` be part of the type structure of any `impl` that could satisfy
5741+
that `require`. If the `<type>` is omitted entirely, it will be implied to be
5742+
`Self`. For example:
57415743

57425744
- ✅ Allowed: `require impls Equatable`
57435745
- ✅ Allowed: `require Self impls Equatable`
@@ -5746,7 +5748,8 @@ For example:
57465748
- ✅ Allowed: `require impls CommonTypeWith(Self)`
57475749
- ✅ Allowed: `require Self impls CommonTypeWith(Self)`
57485750
- ❌ Error: `require i32 impls Equatable`
5749-
- ❌ Error: `require T impls Equatable` where `T` is some parameter to the
5751+
- ❌ Error: `require i32 impls Equatable where .Result = Self`
5752+
- ❌ Error: `require T impls Equatable` when `T` is some parameter to the
57505753
interface
57515754

57525755
This restriction allows the Carbon compiler to know where to look for facts

0 commit comments

Comments
 (0)