Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
D7050E
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gustav Hansson
D7050E
Commits
8dfe43dd
Commit
8dfe43dd
authored
5 years ago
by
Gustav Hansson
Browse files
Options
Downloads
Patches
Plain Diff
added a bit about borrow checking
parent
d993f34e
Branches
master
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
HOME_EXAM.md
+31
-0
31 additions, 0 deletions
HOME_EXAM.md
with
31 additions
and
0 deletions
HOME_EXAM.md
+
31
−
0
View file @
8dfe43dd
...
...
@@ -116,6 +116,37 @@ The Type Checker works as intended and rejects ill-typed programs. It does not u
## Your borrrow checker
### Borrow Checker Rules
The first major thing the borrow checker should keep track of is the moving of variables using a Move Path.
```
Rust
let a: (Vec<u32>, Vec<u32>) = (vec![22], vec![44]);
let b = a.0; // <- Acceptable borrow is done here, move path: a.b
let c = b; // Another acceptable borrow, move path: a.b.c
let d = b; // Ill formed borrow, variable already moved,
// cant borrow from anything
// but the end of a move path
```
#### Illegal moves
-
Moving a element of an array. If you have an array A a move of element A[n] can't be made.
-
Move of static variables can't be made.
-
Move away from a borrowed refrenece can't be done.
Moving of variables as references can be done but it has some restrictions. When moving a nonmutable reference can be done multiple times:
```
Rust
let a: (Vec<u32>, Vec<u32>) = (vec![22], vec![44]);
let b = &a;
let c = &a; // This move is completely legal due to b and c being nonmutable.
```
Moving a mutable variable as a reference can also be done but only to one variable at a time:
```
Rust
let mut a: (Vec<u32>, Vec<u32>) = (vec![22], vec![44]);
let b = &mut a;
let c = &mut a; // Ill move, Can't move mutable references more then once.
```
This error is there to prevent race conditions that can happen when a value can be changed in different places at the same time.
### Comparision
Not implemented.
## Your LLVM backend
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment