Skip to content

Commit 66cc1bd

Browse files
committed
Use the reference POV and remove motivation and irrelevant info
1 parent 37b7eff commit 66cc1bd

File tree

4 files changed

+64
-82
lines changed

4 files changed

+64
-82
lines changed

src/glossary.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ items are defined in [implementations] and declared in [traits]. Only
3030
functions, constants, and type aliases can be associated. Contrast to a [free
3131
item].
3232

33+
### Blanket Implementation
34+
35+
Any implementation where a type appears [uncovered](#uncovered-type). `impl<T> Foo
36+
for T`, `impl<T> Bar<T> for T`, `impl<T> Bar<Vec<T>> for T`, and `impl<T> Bar<T>
37+
for Vec<T>` are considered blanket impls. However, `impl<T> Bar<Vec<T>> for
38+
Vec<T>` is not a blanket impl, as all instances of `T` which appear in this impl
39+
are covered by `Vec`.
40+
3341
### Bound
3442

3543
Bounds are constraints on a type or trait. For example, if a bound
@@ -65,6 +73,13 @@ For example, `2 + (3 * 4)` is an expression that returns the value 14.
6573
An [item] that is not a member of an [implementation], such as a *free
6674
function* or a *free const*. Contrast to an [associated item].
6775

76+
### Fundamental Type
77+
78+
Includes `&`, `&mut`, `Box` and `Pin`. Any time a type `T` is
79+
considered [local](#local-type), `&T`, `&mut T`, `Box<T>` and `Pin<T>` are also considered local.
80+
Fundamental types cannot [cover](#uncovered-type) other types. Any time the term "covered type" is
81+
used, the `T` in `&T`, `&mut T`, `Box<T>` and `Pin<T>` is not considered covered.
82+
6883
### Inhabited
6984

7085
A type is inhabited if it has constructors and therefore can be instantiated. An inhabited type is
@@ -87,6 +102,19 @@ A variable is initialized if it has been assigned a value and hasn't since been
87102
moved from. All other memory locations are assumed to be uninitialized. Only
88103
unsafe Rust can create such a memory without initializing it.
89104

105+
### Local Trait
106+
107+
A trait which was defined in the current crate. Whether a trait is
108+
local or not has nothing to do with type parameters. Given `trait Foo<T, U>`,
109+
`Foo` is always local, regardless of the types used for `T` or `U`.
110+
111+
### Local Type
112+
113+
A struct, enum, or union which was defined in the current crate.
114+
This is not affected by type parameters. `struct Foo` is considered local, but
115+
`Vec<Foo>` is not. `LocalType<ForeignType>` is local. Type aliases and trait
116+
aliases do not affect locality.
117+
90118
### Nominal types
91119

92120
Types that can be referred to by a path directly. Specifically [enums],
@@ -158,6 +186,12 @@ It allows a type to make certain promises about its behavior.
158186

159187
Generic functions and generic structs can use traits to constrain, or bound, the types they accept.
160188

189+
### Uncovered Type
190+
191+
A type which does not appear as a parameter to another type. For example,
192+
`T` is uncovered, but the `T` in `Vec<T>` is covered. This is only relevant for
193+
type parameters.
194+
161195
### Undefined behavior
162196

163197
Compile-time or run-time behavior that is not specified. This may result in,

src/items/coherence.md

Lines changed: 0 additions & 79 deletions
This file was deleted.

src/items/implementations.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,31 @@ impl Shape for Circle {
152152

153153
### Trait Implementation Coherence
154154

155-
A trait implementation must follow the [coherence] rules.
155+
A trait implementation is considered incoherent if either the orphan rules check fails
156+
or there are overlapping implementation instances.
157+
158+
Two trait implementations overlap when there is a non-empty intersection of the
159+
traits the implementation is for, the implementations can be instantiated with
160+
the same type. <!-- This is probably wrong? Source: No two implementations can
161+
be instantiable with the same set of types for the input type parameters. -->
162+
163+
#### Orphan rules
164+
165+
Given `impl<P1..=Pn> Trait<T1..=Tn> for T0`, an impl is valid only if at
166+
least one of the following is true:
167+
168+
- `Trait` is a [local trait]
169+
- All of
170+
- At least one of the types `T0..=Tn` must be a [local type]. Let `Ti` be the
171+
first such type.
172+
- No [uncovered type] parameters `P1..=Pn` may appear in `T0..Ti` (excluding
173+
`Ti`)
174+
175+
We only restrict the appearance of *uncovered* type parameters. Once again, it is
176+
important to note that for the purposes of coherence, [fundamental types] are
177+
special. The `T` in `Box<T>` is not considered covered, and `Box<LocalType>`
178+
is considered local.
179+
156180

157181
## Generic Implementations
158182

@@ -202,4 +226,7 @@ attributes].
202226
[path]: ../paths.md
203227
[the lint check attributes]: ../attributes/diagnostics.md#lint-check-attributes
204228
[Unsafe traits]: traits.md#unsafe-traits
205-
[coherence]: coherence.md
229+
[local trait]: ../glossary.md#local-trait
230+
[local type]: ../glossary.md#local-type
231+
[fundamental types]: ../glossary.md#fundamental-type
232+
[uncovered type]: ../glossary.md#uncovered-type

src/special-types-and-traits.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ compiler, not by [implementation items].
170170
[Methods]: items/associated-items.md#associated-functions-and-methods
171171
[method resolution]: expressions/method-call-expr.md
172172
[operators]: expressions/operator-expr.md
173-
[orphan rules]: items/coherence.md
173+
[orphan rules]: items/implementations.md#trait-implementation-coherence
174174
[Raw pointers]: types/pointer.md#raw-pointers-const-and-mut
175175
[`static` items]: items/static-items.md
176176
[Shared references]: types/pointer.md#shared-references-

0 commit comments

Comments
 (0)