Skip to content

Commit 5ec1dea

Browse files
author
Nick Hamann
committed
Change int/uint => isize/usize in compiler docs.
1 parent e4e9319 commit 5ec1dea

File tree

3 files changed

+53
-53
lines changed

3 files changed

+53
-53
lines changed

src/librustc/middle/infer/higher_ranked/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The problem we are addressing is that there is a kind of subtyping
1717
between functions with bound region parameters. Consider, for
1818
example, whether the following relation holds:
1919

20-
for<'a> fn(&'a int) <: for<'b> fn(&'b int)? (Yes, a => b)
20+
for<'a> fn(&'a isize) <: for<'b> fn(&'b isize)? (Yes, a => b)
2121

2222
The answer is that of course it does. These two types are basically
2323
the same, except that in one we used the name `a` and one we used
@@ -27,14 +27,14 @@ In the examples that follow, it becomes very important to know whether
2727
a lifetime is bound in a function type (that is, is a lifetime
2828
parameter) or appears free (is defined in some outer scope).
2929
Therefore, from now on I will always write the bindings explicitly,
30-
using the Rust syntax `for<'a> fn(&'a int)` to indicate that `a` is a
30+
using the Rust syntax `for<'a> fn(&'a isize)` to indicate that `a` is a
3131
lifetime parameter.
3232

3333
Now let's consider two more function types. Here, we assume that the
3434
`'b` lifetime is defined somewhere outside and hence is not a lifetime
3535
parameter bound by the function type (it "appears free"):
3636

37-
for<'a> fn(&'a int) <: fn(&'b int)? (Yes, a => b)
37+
for<'a> fn(&'a isize) <: fn(&'b isize)? (Yes, a => b)
3838

3939
This subtyping relation does in fact hold. To see why, you have to
4040
consider what subtyping means. One way to look at `T1 <: T2` is to
@@ -51,7 +51,7 @@ to the same thing: a function that accepts pointers with any lifetime
5151

5252
So, what if we reverse the order of the two function types, like this:
5353

54-
fn(&'b int) <: for<'a> fn(&'a int)? (No)
54+
fn(&'b isize) <: for<'a> fn(&'a isize)? (No)
5555

5656
Does the subtyping relationship still hold? The answer of course is
5757
no. In this case, the function accepts *only the lifetime `'b`*,
@@ -60,8 +60,8 @@ accepted any lifetime.
6060

6161
What about these two examples:
6262

63-
for<'a,'b> fn(&'a int, &'b int) <: for<'a> fn(&'a int, &'a int)? (Yes)
64-
for<'a> fn(&'a int, &'a int) <: for<'a,'b> fn(&'a int, &'b int)? (No)
63+
for<'a,'b> fn(&'a isize, &'b isize) <: for<'a> fn(&'a isize, &'a isize)? (Yes)
64+
for<'a> fn(&'a isize, &'a isize) <: for<'a,'b> fn(&'a isize, &'b isize)? (No)
6565

6666
Here, it is true that functions which take two pointers with any two
6767
lifetimes can be treated as if they only accepted two pointers with

src/librustc/middle/infer/region_inference/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ every expression, block, and pattern (patterns are considered to
121121
"execute" by testing the value they are applied to and creating any
122122
relevant bindings). So, for example:
123123

124-
fn foo(x: int, y: int) { // -+
124+
fn foo(x: isize, y: isize) { // -+
125125
// +------------+ // |
126126
// | +-----+ // |
127127
// | +-+ +-+ +-+ // |
@@ -168,13 +168,13 @@ an error.
168168
Here is a more involved example (which is safe) so we can see what's
169169
going on:
170170

171-
struct Foo { f: uint, g: uint }
171+
struct Foo { f: usize, g: usize }
172172
...
173-
fn add(p: &mut uint, v: uint) {
173+
fn add(p: &mut usize, v: usize) {
174174
*p += v;
175175
}
176176
...
177-
fn inc(p: &mut uint) -> uint {
177+
fn inc(p: &mut usize) -> usize {
178178
*p += 1; *p
179179
}
180180
fn weird() {
@@ -199,8 +199,8 @@ in a call expression:
199199

200200
'a: {
201201
'a_arg1: let a_temp1: ... = add;
202-
'a_arg2: let a_temp2: &'a mut uint = &'a mut (*x).f;
203-
'a_arg3: let a_temp3: uint = {
202+
'a_arg2: let a_temp2: &'a mut usize = &'a mut (*x).f;
203+
'a_arg3: let a_temp3: usize = {
204204
let b_temp1: ... = inc;
205205
let b_temp2: &'b = &'b mut (*x).f;
206206
'b_call: b_temp1(b_temp2)
@@ -225,13 +225,13 @@ it will not be *dereferenced* during the evaluation of the second
225225
argument, it can still be *invalidated* by that evaluation. Consider
226226
this similar but unsound example:
227227

228-
struct Foo { f: uint, g: uint }
228+
struct Foo { f: usize, g: usize }
229229
...
230-
fn add(p: &mut uint, v: uint) {
230+
fn add(p: &mut usize, v: usize) {
231231
*p += v;
232232
}
233233
...
234-
fn consume(x: Box<Foo>) -> uint {
234+
fn consume(x: Box<Foo>) -> usize {
235235
x.f + x.g
236236
}
237237
fn weird() {

src/librustc/middle/traits/README.md

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ reference to a trait. So, for example, if there is a generic function like:
1212

1313
and then a call to that function:
1414

15-
let v: Vec<int> = clone_slice([1, 2, 3])
15+
let v: Vec<isize> = clone_slice([1, 2, 3])
1616

1717
it is the job of trait resolution to figure out (in which case)
18-
whether there exists an impl of `int : Clone`
18+
whether there exists an impl of `isize : Clone`
1919

2020
Note that in some cases, like generic functions, we may not be able to
2121
find a specific impl, but we can figure out that the caller must
@@ -115,27 +115,27 @@ trait Convert<Target> {
115115

116116
This trait just has one method. It's about as simple as it gets. It
117117
converts from the (implicit) `Self` type to the `Target` type. If we
118-
wanted to permit conversion between `int` and `uint`, we might
118+
wanted to permit conversion between `isize` and `usize`, we might
119119
implement `Convert` like so:
120120

121121
```rust
122-
impl Convert<uint> for int { ... } // int -> uint
123-
impl Convert<int> for uint { ... } // uint -> int
122+
impl Convert<usize> for isize { ... } // isize -> usize
123+
impl Convert<isize> for usize { ... } // usize -> isize
124124
```
125125

126126
Now imagine there is some code like the following:
127127

128128
```rust
129-
let x: int = ...;
129+
let x: isize = ...;
130130
let y = x.convert();
131131
```
132132

133133
The call to convert will generate a trait reference `Convert<$Y> for
134-
int`, where `$Y` is the type variable representing the type of
134+
isize`, where `$Y` is the type variable representing the type of
135135
`y`. When we match this against the two impls we can see, we will find
136-
that only one remains: `Convert<uint> for int`. Therefore, we can
136+
that only one remains: `Convert<usize> for isize`. Therefore, we can
137137
select this impl, which will cause the type of `$Y` to be unified to
138-
`uint`. (Note that while assembling candidates, we do the initial
138+
`usize`. (Note that while assembling candidates, we do the initial
139139
unifications in a transaction, so that they don't affect one another.)
140140

141141
There are tests to this effect in src/test/run-pass:
@@ -225,7 +225,7 @@ Confirmation unifies the output type parameters of the trait with the
225225
values found in the obligation, possibly yielding a type error. If we
226226
return to our example of the `Convert` trait from the previous
227227
section, confirmation is where an error would be reported, because the
228-
impl specified that `T` would be `uint`, but the obligation reported
228+
impl specified that `T` would be `usize`, but the obligation reported
229229
`char`. Hence the result of selection would be an error.
230230

231231
### Selection during translation
@@ -250,20 +250,20 @@ Here is an example:
250250
trait Foo { ... }
251251
impl<U,T:Bar<U>> Foo for Vec<T> { ... }
252252

253-
impl Bar<uint> for int { ... }
253+
impl Bar<usize> for isize { ... }
254254

255-
After one shallow round of selection for an obligation like `Vec<int>
255+
After one shallow round of selection for an obligation like `Vec<isize>
256256
: Foo`, we would know which impl we want, and we would know that
257-
`T=int`, but we do not know the type of `U`. We must select the
258-
nested obligation `int : Bar<U>` to find out that `U=uint`.
257+
`T=isize`, but we do not know the type of `U`. We must select the
258+
nested obligation `isize : Bar<U>` to find out that `U=usize`.
259259

260260
It would be good to only do *just as much* nested resolution as
261261
necessary. Currently, though, we just do a full resolution.
262262

263263
# Higher-ranked trait bounds
264264

265265
One of the more subtle concepts at work are *higher-ranked trait
266-
bounds*. An example of such a bound is `for<'a> MyTrait<&'a int>`.
266+
bounds*. An example of such a bound is `for<'a> MyTrait<&'a isize>`.
267267
Let's walk through how selection on higher-ranked trait references
268268
works.
269269

@@ -279,21 +279,21 @@ trait Foo<X> {
279279
```
280280

281281
Let's say we have a function `want_hrtb` that wants a type which
282-
implements `Foo<&'a int>` for any `'a`:
282+
implements `Foo<&'a isize>` for any `'a`:
283283

284284
```rust
285-
fn want_hrtb<T>() where T : for<'a> Foo<&'a int> { ... }
285+
fn want_hrtb<T>() where T : for<'a> Foo<&'a isize> { ... }
286286
```
287287

288-
Now we have a struct `AnyInt` that implements `Foo<&'a int>` for any
288+
Now we have a struct `AnyInt` that implements `Foo<&'a isize>` for any
289289
`'a`:
290290

291291
```rust
292292
struct AnyInt;
293-
impl<'a> Foo<&'a int> for AnyInt { }
293+
impl<'a> Foo<&'a isize> for AnyInt { }
294294
```
295295

296-
And the question is, does `AnyInt : for<'a> Foo<&'a int>`? We want the
296+
And the question is, does `AnyInt : for<'a> Foo<&'a isize>`? We want the
297297
answer to be yes. The algorithm for figuring it out is closely related
298298
to the subtyping for higher-ranked types (which is described in
299299
`middle::infer::higher_ranked::doc`, but also in a [paper by SPJ] that
@@ -306,12 +306,12 @@ I recommend you read).
306306
[paper by SPJ]: http://research.microsoft.com/en-us/um/people/simonpj/papers/higher-rank/
307307

308308
So let's work through our example. The first thing we would do is to
309-
skolemize the obligation, yielding `AnyInt : Foo<&'0 int>` (here `'0`
309+
skolemize the obligation, yielding `AnyInt : Foo<&'0 isize>` (here `'0`
310310
represents skolemized region #0). Note that now have no quantifiers;
311311
in terms of the compiler type, this changes from a `ty::PolyTraitRef`
312312
to a `TraitRef`. We would then create the `TraitRef` from the impl,
313313
using fresh variables for it's bound regions (and thus getting
314-
`Foo<&'$a int>`, where `'$a` is the inference variable for `'a`). Next
314+
`Foo<&'$a isize>`, where `'$a` is the inference variable for `'a`). Next
315315
we relate the two trait refs, yielding a graph with the constraint
316316
that `'0 == '$a`. Finally, we check for skolemization "leaks" -- a
317317
leak is basically any attempt to relate a skolemized region to another
@@ -327,13 +327,13 @@ Let's consider a failure case. Imagine we also have a struct
327327

328328
```rust
329329
struct StaticInt;
330-
impl Foo<&'static int> for StaticInt;
330+
impl Foo<&'static isize> for StaticInt;
331331
```
332332

333-
We want the obligation `StaticInt : for<'a> Foo<&'a int>` to be
333+
We want the obligation `StaticInt : for<'a> Foo<&'a isize>` to be
334334
considered unsatisfied. The check begins just as before. `'a` is
335335
skolemized to `'0` and the impl trait reference is instantiated to
336-
`Foo<&'static int>`. When we relate those two, we get a constraint
336+
`Foo<&'static isize>`. When we relate those two, we get a constraint
337337
like `'static == '0`. This means that the taint set for `'0` is `{'0,
338338
'static}`, which fails the leak check.
339339

@@ -358,13 +358,13 @@ impl<X,F> Foo<X> for F
358358
}
359359
```
360360

361-
Now let's say we have a obligation `for<'a> Foo<&'a int>` and we match
361+
Now let's say we have a obligation `for<'a> Foo<&'a isize>` and we match
362362
this impl. What obligation is generated as a result? We want to get
363-
`for<'a> Bar<&'a int>`, but how does that happen?
363+
`for<'a> Bar<&'a isize>`, but how does that happen?
364364

365365
After the matching, we are in a position where we have a skolemized
366-
substitution like `X => &'0 int`. If we apply this substitution to the
367-
impl obligations, we get `F : Bar<&'0 int>`. Obviously this is not
366+
substitution like `X => &'0 isize`. If we apply this substitution to the
367+
impl obligations, we get `F : Bar<&'0 isize>`. Obviously this is not
368368
directly usable because the skolemized region `'0` cannot leak out of
369369
our computation.
370370

@@ -375,7 +375,7 @@ leak check passed, so this taint set consists solely of the skolemized
375375
region itself plus various intermediate region variables. We then walk
376376
the trait-reference and convert every region in that taint set back to
377377
a late-bound region, so in this case we'd wind up with `for<'a> F :
378-
Bar<&'a int>`.
378+
Bar<&'a isize>`.
379379

380380
# Caching and subtle considerations therewith
381381

@@ -391,8 +391,8 @@ but *replay* its effects on the type variables.
391391

392392
The high-level idea of how the cache works is that we first replace
393393
all unbound inference variables with skolemized versions. Therefore,
394-
if we had a trait reference `uint : Foo<$1>`, where `$n` is an unbound
395-
inference variable, we might replace it with `uint : Foo<%0>`, where
394+
if we had a trait reference `usize : Foo<$1>`, where `$n` is an unbound
395+
inference variable, we might replace it with `usize : Foo<%0>`, where
396396
`%n` is a skolemized type. We would then look this up in the cache.
397397
If we found a hit, the hit would tell us the immediate next step to
398398
take in the selection process: i.e., apply impl #22, or apply where
@@ -401,17 +401,17 @@ Therefore, we search through impls and where clauses and so forth, and
401401
we come to the conclusion that the only possible impl is this one,
402402
with def-id 22:
403403

404-
impl Foo<int> for uint { ... } // Impl #22
404+
impl Foo<isize> for usize { ... } // Impl #22
405405

406-
We would then record in the cache `uint : Foo<%0> ==>
406+
We would then record in the cache `usize : Foo<%0> ==>
407407
ImplCandidate(22)`. Next we would confirm `ImplCandidate(22)`, which
408-
would (as a side-effect) unify `$1` with `int`.
408+
would (as a side-effect) unify `$1` with `isize`.
409409

410-
Now, at some later time, we might come along and see a `uint :
411-
Foo<$3>`. When skolemized, this would yield `uint : Foo<%0>`, just as
410+
Now, at some later time, we might come along and see a `usize :
411+
Foo<$3>`. When skolemized, this would yield `usize : Foo<%0>`, just as
412412
before, and hence the cache lookup would succeed, yielding
413413
`ImplCandidate(22)`. We would confirm `ImplCandidate(22)` which would
414-
(as a side-effect) unify `$3` with `int`.
414+
(as a side-effect) unify `$3` with `isize`.
415415

416416
## Where clauses and the local vs global cache
417417

0 commit comments

Comments
 (0)