@@ -54,7 +54,7 @@ and `*LV` is a pointer dereference. There is no auto-deref or other
54
54
niceties. This means that if you have a type like:
55
55
56
56
``` rust
57
- struct S { f : uint }
57
+ struct S { f : i32 }
58
58
```
59
59
60
60
and a variable ` a: Box<S> ` , then the rust expression ` a.f ` would correspond
@@ -63,7 +63,7 @@ to an `LV` of `(*a).f`.
63
63
Here is the formal grammar for the types we'll consider:
64
64
65
65
``` text
66
- TY = () | S<'LT...> | Box<TY> | & 'LT MQ TY
66
+ TY = i32 | bool | S<'LT...> | Box<TY> | & 'LT MQ TY
67
67
MQ = mut | imm
68
68
```
69
69
@@ -83,7 +83,7 @@ SD = struct S<'LT...> { (f: TY)... }
83
83
Now, imagine we had a program like this:
84
84
85
85
``` rust
86
- struct Foo { f : uint , g : uint }
86
+ struct Foo { f : i32 , g : i32 }
87
87
...
88
88
'a : {
89
89
let mut x : Box <Foo > = ... ;
@@ -508,7 +508,7 @@ of the `&Ty` pointer. In simple cases, this clause is redundant, since
508
508
the ` LIFETIME() ` function will already enforce the required rule:
509
509
510
510
``` rust
511
- fn foo (point : & 'a Point ) -> & 'static f32 {
511
+ fn foo (point : & 'a Point ) -> & 'static i32 {
512
512
& point . x // Error
513
513
}
514
514
```
@@ -518,7 +518,7 @@ but also by the basic `LIFETIME()` check. However, in more advanced
518
518
examples involving multiple nested pointers, clause (1) is needed:
519
519
520
520
``` rust
521
- fn foo (point : & 'a & 'b mut Point ) -> & 'b f32 {
521
+ fn foo (point : & 'a & 'b mut Point ) -> & 'b i32 {
522
522
& point . x // Error
523
523
}
524
524
```
@@ -537,7 +537,7 @@ As a final twist, consider the case of two nested *immutable*
537
537
pointers, rather than a mutable pointer within an immutable one:
538
538
539
539
``` rust
540
- fn foo (point : & 'a & 'b Point ) -> & 'b f32 {
540
+ fn foo (point : & 'a & 'b Point ) -> & 'b i32 {
541
541
& point . x // OK
542
542
}
543
543
```
@@ -559,7 +559,7 @@ create a borrowed pointer that outlives the memory it points at. So
559
559
` LIFETIME ` prevents a function like this:
560
560
561
561
``` rust
562
- fn get_1 <'a >() -> & 'a int {
562
+ fn get_1 <'a >() -> & 'a i32 {
563
563
let x = 1 ;
564
564
& x
565
565
}
@@ -579,7 +579,7 @@ mutate it. This distinction is important for type checking functions
579
579
like this one:
580
580
581
581
``` 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 {
583
583
p . x += 1 ;
584
584
& p . x
585
585
}
@@ -661,8 +661,8 @@ the old name. Here is an example:
661
661
662
662
``` rust
663
663
// 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`
666
666
let t1 = t0 ; // ~ ERROR cannot move out of `t0`
667
667
* t1 = 22 ; // OK, not a write through `*t0`
668
668
}
@@ -681,9 +681,9 @@ another path to access the same data, as shown here:
681
681
682
682
``` rust
683
683
// 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`
687
687
let mut t2 = & mut t0 ; // ~ ERROR cannot borrow `t0`
688
688
* * t2 += 1 ; // Mutates `*t0`
689
689
}
@@ -702,9 +702,9 @@ value away to create a new path:
702
702
703
703
``` rust
704
704
// 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`
708
708
swap (& mut t0 , & mut t1 ); // ~ ERROR cannot borrow `t0`
709
709
* t1 = 22 ;
710
710
}
@@ -720,21 +720,21 @@ as shown in the following example:
720
720
721
721
``` rust
722
722
// 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`
726
726
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`
728
728
* p += 1 ; // violates type of `*q`
729
729
}
730
730
```
731
731
732
732
Here the problem is that ` *t0 ` is claimed by ` p ` , and hence ` p ` wants
733
733
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
735
735
hence would be a mutable pointer in an aliasable location, which is
736
736
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 `
738
738
pointer pointing at ` *t0 ` that coexists with the mutable pointer ` p ` ,
739
739
which is clearly unsound.
740
740
@@ -743,12 +743,12 @@ particular, if the referent is frozen, there is no harm in it:
743
743
744
744
``` rust
745
745
// 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`
749
749
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.
752
752
}
753
753
```
754
754
@@ -759,9 +759,9 @@ new alias `t2`, as demonstrated in this test case:
759
759
760
760
``` rust
761
761
// 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 ) {
763
763
let t1 = t0 ;
764
- let p : & int = & * * t0 ;
764
+ let p : & i32 = & * * t0 ;
765
765
* * t1 = 22 ; // ~ ERROR cannot assign
766
766
}
767
767
```
@@ -831,8 +831,8 @@ moves/uninitializations of the variable that is being used.
831
831
Let's look at a simple example:
832
832
833
833
``` 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.
836
836
837
837
if cond { // Bits: 0
838
838
use (& * a );
@@ -846,7 +846,7 @@ fn foo(a: Box<int>) {
846
846
use (& * b ); // Error.
847
847
}
848
848
849
- fn use (a : & int ) { }
849
+ fn use (a : & i32 ) { }
850
850
```
851
851
852
852
In this example, the variable ` b ` is created uninitialized. In one
@@ -977,8 +977,8 @@ not) the destructor invocation for that path.
977
977
A simple example of this is the following:
978
978
979
979
``` 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 { ... }
982
982
impl Drop for D { ... }
983
983
984
984
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
1091
1091
the following:
1092
1092
1093
1093
``` rust
1094
- fn foo (a : [D ; 10 ], i : uint ) -> D {
1094
+ fn foo (a : [D ; 10 ], i : i32 ) -> D {
1095
1095
a [i ]
1096
1096
}
1097
1097
```
@@ -1107,7 +1107,7 @@ all-but-one element of the array. A place where that distinction
1107
1107
would arise is the following:
1108
1108
1109
1109
``` 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 {
1111
1111
if t {
1112
1112
a [i ]
1113
1113
} else {
@@ -1122,7 +1122,7 @@ fn foo(a: [D; 10], b: [D; 10], i: uint, t: bool) -> D {
1122
1122
1123
1123
There are a number of ways that the trans backend could choose to
1124
1124
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
1126
1126
borrow-checker, the important thing is to record what kind of fragment
1127
1127
is implied by the relevant moves.
1128
1128
0 commit comments