@@ -597,20 +597,19 @@ Borrow is used at multiple locations, therefor it is mutable from different refe
Below follows the rewritten examples that are accepted by the borrow checker.
```rust
fna(x:&muti32)->(){
*x+=1;
*x=*x+1;
}
fnmain()->(){
letmuty:i32=5;
a(&muty);
}
```
```rust
fnb(x:&muti32,y:&muti32)->(){
*x+=1;
*y+=1;
*x=*x+1;
*y=*y+1;
}
fnmain()->(){
letmutx:i32=5;
...
...
@@ -621,16 +620,17 @@ fn main() -> () {
```rust
fnmain()->(){
letmutx=0;
lety=&mutx;
*y+=1;
x+=1;
letmutx:i32=0;
lety:i32=&mutx;
*y=*y+1;
x=x+1;
}
```
The borrowchecker should make sure that:
- One reference can only be mutable at a time.
- Multiple immutable references can be used.
- One mutable reference and multiple immutable references can not exist at the same time
This ensures that a variable can not be changed at the same time that another reference tries to read it.
...
...
@@ -648,5 +648,4 @@ The process of implementing the type checker and the interpreter was similar. Th
- Code optimization and register allocation. Machine code generation for common architectures. [Both LLVM/Crane-Lift does the "dirty work" of backend optimization/register allocation leveraging the SSA form of the LLVM-IR]
Comment on additional things that you have experienced and learned throughout the course.
It has been difficult to write good structured code because this is the first time I worked with Rust. Therefor the rules and structure was new to me which ended up in very messy code. I focused on getting as much as possible to work to get a broad understanding instead. It would be really fun to rewrite everything from the beginning now with the knowledge and insight the course have given!