Skip to content

Commit 42a5a06

Browse files
authored
Touch up formatting for variance README.md
There were a few places that need extra indentation to register as a code block.
1 parent 49dd95b commit 42a5a06

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/librustc_typeck/variance/README.md

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
## Variance of type and lifetime parameters
2+
13
This file infers the variance of type and lifetime parameters. The
24
algorithm is taken from Section 4 of the paper "Taming the Wildcards:
35
Combining Definition- and Use-Site Variance" published in PLDI'11 and
@@ -52,11 +54,11 @@ These indicate that (1) the variance of A must be at most covariant;
5254
variance of C must be at most covariant *and* contravariant. All of these
5355
results are based on a variance lattice defined as follows:
5456

55-
* Top (bivariant)
56-
- +
57-
o Bottom (invariant)
57+
* Top (bivariant)
58+
- +
59+
o Bottom (invariant)
5860

59-
Based on this lattice, the solution V(A)=+, V(B)=-, V(C)=o is the
61+
Based on this lattice, the solution `V(A)=+`, `V(B)=-`, `V(C)=o` is the
6062
optimal solution. Note that there is always a naive solution which
6163
just declares all variables to be invariant.
6264

@@ -68,11 +70,11 @@ take the form:
6870
V(X) <= Term
6971
Term := + | - | * | o | V(X) | Term x Term
7072

71-
Here the notation V(X) indicates the variance of a type/region
73+
Here the notation `V(X)` indicates the variance of a type/region
7274
parameter `X` with respect to its defining class. `Term x Term`
7375
represents the "variance transform" as defined in the paper:
7476

75-
If the variance of a type variable `X` in type expression `E` is `V2`
77+
> If the variance of a type variable `X` in type expression `E` is `V2`
7678
and the definition-site variance of the [corresponding] type parameter
7779
of a class `C` is `V1`, then the variance of `X` in the type expression
7880
`C<E>` is `V3 = V1.xform(V2)`.
@@ -267,7 +269,7 @@ expressions -- must be invariant with respect to all of their
267269
inputs. To see why this makes sense, consider what subtyping for a
268270
trait reference means:
269271

270-
<T as Trait> <: <U as Trait>
272+
<T as Trait> <: <U as Trait>
271273

272274
means that if I know that `T as Trait`, I also know that `U as
273275
Trait`. Moreover, if you think of it as dictionary passing style,
@@ -291,9 +293,9 @@ impl<T> Identity for T { type Out = T; ... }
291293
Now if I have `<&'static () as Identity>::Out`, this can be
292294
validly derived as `&'a ()` for any `'a`:
293295

294-
<&'a () as Identity> <: <&'static () as Identity>
295-
if &'static () < : &'a () -- Identity is contravariant in Self
296-
if 'static : 'a -- Subtyping rules for relations
296+
<&'a () as Identity> <: <&'static () as Identity>
297+
if &'static () < : &'a () -- Identity is contravariant in Self
298+
if 'static : 'a -- Subtyping rules for relations
297299

298300
This change otoh means that `<'static () as Identity>::Out` is
299301
always `&'static ()` (which might then be upcast to `'a ()`,

0 commit comments

Comments
 (0)