-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f2552c
commit 62d2a4f
Showing
3 changed files
with
51 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#feature on safety | ||
#include <std2.h> | ||
|
||
int main() safe { | ||
std2::vector<size_t> A { }, B { }; | ||
|
||
// Get a shared borrow to an element in B. | ||
// The borrow is live until it is loaded from below. | ||
const size_t^ b = B[0]; | ||
|
||
// A[0] is in the mutable context, so A[0] is the mutable operator[]. | ||
// B[0] is outside the mutable context, so B[0] is the const operator[]. | ||
// No borrow checking error. | ||
mut A[0] += B[0]; | ||
|
||
// Keep b live. | ||
size_t x = *b; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#feature on safety | ||
#include <std2.h> | ||
|
||
int main() safe { | ||
std2::vector<size_t> A { }, B { }; | ||
|
||
// Get a shared borrow to an element in B. | ||
// The borrow is live until it is loaded from below. | ||
const size_t^ b = B[0]; | ||
|
||
// A is in the mutable context for its operator[] call. | ||
// B is not in the mutable conetxt for its operator[] call. | ||
// No borrow checker error. | ||
mut A[B[0]] += 1; | ||
|
||
// Keep b live. | ||
size_t x = *b; | ||
} |