Skip to content

Commit 1597f91

Browse files
author
Keegan McAllister
committed
borrowck/README.md: Normalize types in examples
1 parent f051e13 commit 1597f91

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

src/librustc_borrowck/borrowck/README.md

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ and `*LV` is a pointer dereference. There is no auto-deref or other
5454
niceties. This means that if you have a type like:
5555

5656
```rust
57-
struct S { f: uint }
57+
struct S { f: i32 }
5858
```
5959

6060
and a variable `a: Box<S>`, then the rust expression `a.f` would correspond
@@ -63,7 +63,7 @@ to an `LV` of `(*a).f`.
6363
Here is the formal grammar for the types we'll consider:
6464

6565
```text
66-
TY = () | S<'LT...> | Box<TY> | & 'LT MQ TY
66+
TY = i32 | bool | S<'LT...> | Box<TY> | & 'LT MQ TY
6767
MQ = mut | imm
6868
```
6969

@@ -83,7 +83,7 @@ SD = struct S<'LT...> { (f: TY)... }
8383
Now, imagine we had a program like this:
8484

8585
```rust
86-
struct Foo { f: uint, g: uint }
86+
struct Foo { f: i32, g: i32 }
8787
...
8888
'a: {
8989
let mut x: Box<Foo> = ...;
@@ -508,7 +508,7 @@ of the `&Ty` pointer. In simple cases, this clause is redundant, since
508508
the `LIFETIME()` function will already enforce the required rule:
509509

510510
```rust
511-
fn foo(point: &'a Point) -> &'static f32 {
511+
fn foo(point: &'a Point) -> &'static i32 {
512512
&point.x // Error
513513
}
514514
```
@@ -518,7 +518,7 @@ but also by the basic `LIFETIME()` check. However, in more advanced
518518
examples involving multiple nested pointers, clause (1) is needed:
519519

520520
```rust
521-
fn foo(point: &'a &'b mut Point) -> &'b f32 {
521+
fn foo(point: &'a &'b mut Point) -> &'b i32 {
522522
&point.x // Error
523523
}
524524
```
@@ -537,7 +537,7 @@ As a final twist, consider the case of two nested *immutable*
537537
pointers, rather than a mutable pointer within an immutable one:
538538

539539
```rust
540-
fn foo(point: &'a &'b Point) -> &'b f32 {
540+
fn foo(point: &'a &'b Point) -> &'b i32 {
541541
&point.x // OK
542542
}
543543
```
@@ -559,7 +559,7 @@ create a borrowed pointer that outlives the memory it points at. So
559559
`LIFETIME` prevents a function like this:
560560

561561
```rust
562-
fn get_1<'a>() -> &'a int {
562+
fn get_1<'a>() -> &'a i32 {
563563
let x = 1;
564564
&x
565565
}
@@ -579,7 +579,7 @@ mutate it. This distinction is important for type checking functions
579579
like this one:
580580

581581
```rust
582-
fn inc_and_get<'a>(p: &'a mut Point) -> &'a int {
582+
fn inc_and_get<'a>(p: &'a mut Point) -> &'a i32 {
583583
p.x += 1;
584584
&p.x
585585
}
@@ -661,8 +661,8 @@ the old name. Here is an example:
661661

662662
```rust
663663
// src/test/compile-fail/borrowck-move-mut-base-ptr.rs
664-
fn foo(t0: &mut int) {
665-
let p: &int = &*t0; // Freezes `*t0`
664+
fn foo(t0: &mut i32) {
665+
let p: &i32 = &*t0; // Freezes `*t0`
666666
let t1 = t0; //~ ERROR cannot move out of `t0`
667667
*t1 = 22; // OK, not a write through `*t0`
668668
}
@@ -681,9 +681,9 @@ another path to access the same data, as shown here:
681681

682682
```rust
683683
// src/test/compile-fail/borrowck-mut-borrow-of-mut-base-ptr.rs
684-
fn foo<'a>(mut t0: &'a mut int,
685-
mut t1: &'a mut int) {
686-
let p: &int = &*t0; // Freezes `*t0`
684+
fn foo<'a>(mut t0: &'a mut i32,
685+
mut t1: &'a mut i32) {
686+
let p: &i32 = &*t0; // Freezes `*t0`
687687
let mut t2 = &mut t0; //~ ERROR cannot borrow `t0`
688688
**t2 += 1; // Mutates `*t0`
689689
}
@@ -702,9 +702,9 @@ value away to create a new path:
702702

703703
```rust
704704
// src/test/compile-fail/borrowck-swap-mut-base-ptr.rs
705-
fn foo<'a>(mut t0: &'a mut int,
706-
mut t1: &'a mut int) {
707-
let p: &int = &*t0; // Freezes `*t0`
705+
fn foo<'a>(mut t0: &'a mut i32,
706+
mut t1: &'a mut i32) {
707+
let p: &i32 = &*t0; // Freezes `*t0`
708708
swap(&mut t0, &mut t1); //~ ERROR cannot borrow `t0`
709709
*t1 = 22;
710710
}
@@ -720,21 +720,21 @@ as shown in the following example:
720720

721721
```rust
722722
// src/test/compile-fail/borrowck-borrow-of-mut-base-ptr.rs
723-
fn foo<'a>(mut t0: &'a mut int,
724-
mut t1: &'a mut int) {
725-
let p: &mut int = &mut *t0; // Claims `*t0`
723+
fn foo<'a>(mut t0: &'a mut i32,
724+
mut t1: &'a mut i32) {
725+
let p: &mut i32 = &mut *t0; // Claims `*t0`
726726
let mut t2 = &t0; //~ ERROR cannot borrow `t0`
727-
let q: &int = &*t2; // Freezes `*t0` but not through `*p`
727+
let q: &i32 = &*t2; // Freezes `*t0` but not through `*p`
728728
*p += 1; // violates type of `*q`
729729
}
730730
```
731731

732732
Here the problem is that `*t0` is claimed by `p`, and hence `p` wants
733733
to be the controlling pointer through which mutation or freezes occur.
734-
But `t2` would -- if it were legal -- have the type `& &mut int`, and
734+
But `t2` would -- if it were legal -- have the type `& &mut i32`, and
735735
hence would be a mutable pointer in an aliasable location, which is
736736
considered frozen (since no one can write to `**t2` as it is not a
737-
unique path). Therefore, we could reasonably create a frozen `&int`
737+
unique path). Therefore, we could reasonably create a frozen `&i32`
738738
pointer pointing at `*t0` that coexists with the mutable pointer `p`,
739739
which is clearly unsound.
740740

@@ -743,12 +743,12 @@ particular, if the referent is frozen, there is no harm in it:
743743

744744
```rust
745745
// src/test/run-pass/borrowck-borrow-of-mut-base-ptr-safe.rs
746-
fn foo<'a>(mut t0: &'a mut int,
747-
mut t1: &'a mut int) {
748-
let p: &int = &*t0; // Freezes `*t0`
746+
fn foo<'a>(mut t0: &'a mut i32,
747+
mut t1: &'a mut i32) {
748+
let p: &i32 = &*t0; // Freezes `*t0`
749749
let mut t2 = &t0;
750-
let q: &int = &*t2; // Freezes `*t0`, but that's ok...
751-
let r: &int = &*t0; // ...after all, could do same thing directly.
750+
let q: &i32 = &*t2; // Freezes `*t0`, but that's ok...
751+
let r: &i32 = &*t0; // ...after all, could do same thing directly.
752752
}
753753
```
754754

@@ -759,9 +759,9 @@ new alias `t2`, as demonstrated in this test case:
759759

760760
```rust
761761
// src/test/run-pass/borrowck-borrow-mut-base-ptr-in-aliasable-loc.rs
762-
fn foo(t0: & &mut int) {
762+
fn foo(t0: & &mut i32) {
763763
let t1 = t0;
764-
let p: &int = &**t0;
764+
let p: &i32 = &**t0;
765765
**t1 = 22; //~ ERROR cannot assign
766766
}
767767
```
@@ -831,8 +831,8 @@ moves/uninitializations of the variable that is being used.
831831
Let's look at a simple example:
832832

833833
```rust
834-
fn foo(a: Box<int>) {
835-
let b: Box<int>; // Gen bit 0.
834+
fn foo(a: Box<i32>) {
835+
let b: Box<i32>; // Gen bit 0.
836836

837837
if cond { // Bits: 0
838838
use(&*a);
@@ -846,7 +846,7 @@ fn foo(a: Box<int>) {
846846
use(&*b); // Error.
847847
}
848848

849-
fn use(a: &int) { }
849+
fn use(a: &i32) { }
850850
```
851851

852852
In this example, the variable `b` is created uninitialized. In one
@@ -977,8 +977,8 @@ not) the destructor invocation for that path.
977977
A simple example of this is the following:
978978

979979
```rust
980-
struct D { p: int }
981-
impl D { fn new(x: int) -> D { ... }
980+
struct D { p: i32 }
981+
impl D { fn new(x: i32) -> D { ... }
982982
impl Drop for D { ... }
983983

984984
fn foo(a: D, b: D, t: || -> bool) {
@@ -1091,7 +1091,7 @@ the elements of an array that has been passed by value, such as
10911091
the following:
10921092

10931093
```rust
1094-
fn foo(a: [D; 10], i: uint) -> D {
1094+
fn foo(a: [D; 10], i: i32) -> D {
10951095
a[i]
10961096
}
10971097
```
@@ -1107,7 +1107,7 @@ all-but-one element of the array. A place where that distinction
11071107
would arise is the following:
11081108

11091109
```rust
1110-
fn foo(a: [D; 10], b: [D; 10], i: uint, t: bool) -> D {
1110+
fn foo(a: [D; 10], b: [D; 10], i: i32, t: bool) -> D {
11111111
if t {
11121112
a[i]
11131113
} else {
@@ -1122,7 +1122,7 @@ fn foo(a: [D; 10], b: [D; 10], i: uint, t: bool) -> D {
11221122

11231123
There are a number of ways that the trans backend could choose to
11241124
compile this (e.g. a `[bool; 10]` array for each such moved array;
1125-
or an `Option<uint>` for each moved array). From the viewpoint of the
1125+
or an `Option<usize>` for each moved array). From the viewpoint of the
11261126
borrow-checker, the important thing is to record what kind of fragment
11271127
is implied by the relevant moves.
11281128

0 commit comments

Comments
 (0)