@@ -23,22 +23,21 @@ the following:
23
23
24
24
``` rust
25
25
tcx . infer_ctxt (). enter (| infcx | {
26
- // use the inference context `infcx` in here
26
+ // Use the inference context `infcx` here.
27
27
})
28
28
```
29
29
30
30
Each inference context creates a short-lived type arena to store the
31
- fresh types and things that it will create, as described in
32
- [ the README in the ty module] [ ty-readme ] . This arena is created by the ` enter `
33
- function and disposed after it returns.
31
+ fresh types and things that it will create, as described in the
32
+ [ README in the ` ty ` module] [ ty-readme ] . This arena is created by the ` enter `
33
+ function and disposed of after it returns.
34
34
35
35
[ ty-readme ] : ty.html
36
36
37
- Within the closure, the infcx will have the type `InferCtxt<'cx, 'gcx,
38
- 'tcx>` for some fresh ` 'cx` and ` 'tcx` – the latter corresponds to
39
- the lifetime of this temporary arena, and the ` 'cx ` is the lifetime of
40
- the ` InferCtxt ` itself. (Again, see [ that ty README] [ ty-readme ] for
41
- more details on this setup.)
37
+ Within the closure, ` infcx ` has the type ` InferCtxt<'cx, 'gcx, 'tcx> `
38
+ for some fresh ` 'cx ` and ` 'tcx ` – the latter corresponds to the lifetime of
39
+ this temporary arena, and the ` 'cx ` is the lifetime of the ` InferCtxt ` itself.
40
+ (Again, see the [ ` ty ` README] [ ty-readme ] for more details on this setup.)
42
41
43
42
The ` tcx.infer_ctxt ` method actually returns a build, which means
44
43
there are some kinds of configuration you can do before the ` infcx ` is
@@ -58,7 +57,7 @@ inference works, or perhaps this blog post on
58
57
59
58
[ Unification in the Chalk project ] : http://smallcultfollowing.com/babysteps/blog/2017/03/25/unification-in-chalk-part-1/
60
59
61
- All told , the inference context stores four kinds of inference variables as of this
60
+ All said , the inference context stores four kinds of inference variables as of
62
61
writing:
63
62
64
63
- Type variables, which come in three varieties:
@@ -67,7 +66,7 @@ writing:
67
66
arise from an integer literal expression like ` 22 ` .
68
67
- Float type variables, which can only be unified with a float type, and
69
68
arise from a float literal expression like ` 22.0 ` .
70
- - Region variables, which represent lifetimes, and arise all over the dang place.
69
+ - Region variables, which represent lifetimes, and arise all over the place.
71
70
72
71
All the type variables work in much the same way: you can create a new
73
72
type variable, and what you get is ` Ty<'tcx> ` representing an
@@ -86,7 +85,7 @@ The most basic operations you can perform in the type inferencer is
86
85
recommended way to add an equality constraint is using the ` at `
87
86
method, roughly like so:
88
87
89
- ```
88
+ ``` rust
90
89
infcx . at (... ). eq (t , u );
91
90
```
92
91
@@ -95,7 +94,7 @@ doing this unification, and in what environment, and the `eq` method
95
94
performs the actual equality constraint.
96
95
97
96
When you equate things, you force them to be precisely equal. Equating
98
- returns a ` InferResult ` – if it returns ` Err(err) ` , then equating
97
+ returns an ` InferResult ` – if it returns ` Err(err) ` , then equating
99
98
failed, and the enclosing ` TypeError ` will tell you what went wrong.
100
99
101
100
The success case is perhaps more interesting. The "primary" return
@@ -105,12 +104,12 @@ side-effects of constraining type variables and so forth. However, the
105
104
actual return type is not ` () ` , but rather ` InferOk<()> ` . The
106
105
` InferOk ` type is used to carry extra trait obligations – your job is
107
106
to ensure that these are fulfilled (typically by enrolling them in a
108
- fulfillment context). See the [ trait README] for more background here .
107
+ fulfillment context). See the [ trait README] for more background on that .
109
108
110
109
[ trait README ] : trait-resolution.html
111
110
112
- You can also enforce subtyping through ` infcx.at(..).sub(..) ` . The same
113
- basic concepts apply as above.
111
+ You can similarly enforce subtyping through ` infcx.at(..).sub(..) ` . The same
112
+ basic concepts as above apply .
114
113
115
114
## "Trying" equality
116
115
@@ -119,7 +118,7 @@ types without error. You can test that with `infcx.can_eq` (or
119
118
` infcx.can_sub ` for subtyping). If this returns ` Ok ` , then equality
120
119
is possible – but in all cases, any side-effects are reversed.
121
120
122
- Be aware though that the success or failure of these methods is always
121
+ Be aware, though, that the success or failure of these methods is always
123
122
** modulo regions** . That is, two types ` &'a u32 ` and ` &'b u32 ` will
124
123
return ` Ok ` for ` can_eq ` , even if ` 'a != 'b ` . This falls out from the
125
124
"two-phase" nature of how we solve region constraints.
@@ -146,7 +145,7 @@ patterns.
146
145
147
146
## Subtyping obligations
148
147
149
- One thing worth discussing are subtyping obligations. When you force
148
+ One thing worth discussing is subtyping obligations. When you force
150
149
two types to be a subtype, like ` ?T <: i32 ` , we can often convert those
151
150
into equality constraints. This follows from Rust's rather limited notion
152
151
of subtyping: so, in the above case, ` ?T <: i32 ` is equivalent to ` ?T = i32 ` .
@@ -172,11 +171,11 @@ mechanism. You'll have to try again when more details about `?T` or
172
171
Regions are inferred somewhat differently from types. Rather than
173
172
eagerly unifying things, we simply collect constraints as we go, but
174
173
make (almost) no attempt to solve regions. These constraints have the
175
- form of an outlives constraint:
174
+ form of an " outlives" constraint:
176
175
177
176
'a: 'b
178
177
179
- Actually the code tends to view them as a subregion relation, but it's the same
178
+ Actually, the code tends to view them as a subregion relation, but it's the same
180
179
idea:
181
180
182
181
'b <= 'a
@@ -202,7 +201,7 @@ ways to solve region constraints right now: lexical and
202
201
non-lexical. Eventually there will only be one.
203
202
204
203
To solve ** lexical** region constraints, you invoke
205
- ` resolve_regions_and_report_errors ` . This will "close " the region
204
+ ` resolve_regions_and_report_errors ` . This "closes " the region
206
205
constraint process and invoke the ` lexical_region_resolve ` code. Once
207
206
this is done, any further attempt to equate or create a subtyping
208
207
relationship will yield an ICE.
@@ -224,4 +223,4 @@ Lexical region resolution is done by initially assigning each region
224
223
variable to an empty value. We then process each outlives constraint
225
224
repeatedly, growing region variables until a fixed-point is reached.
226
225
Region variables can be grown using a least-upper-bound relation on
227
- the region lattice in a fairly straight-forward fashion.
226
+ the region lattice in a fairly straightforward fashion.
0 commit comments