Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typo: normalize usage of 0th and 1st #272

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/fifth-testing-stacked-borrows.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ Even though `data` is one "allocation" (local variable), `ref1_at_0` is only bor
unsafe {
let mut data = [0; 10];
let ref1_at_0 = &mut data[0]; // Reference to 0th element
let ref2_at_1 = &mut data[1]; // Reference to 1th element
let ref2_at_1 = &mut data[1]; // Reference to 1st element
let ptr3_at_0 = ref1_at_0 as *mut i32; // Ptr to 0th element
let ptr4_at_1 = ref2_at_1 as *mut i32; // Ptr to 1th element
let ptr4_at_1 = ref2_at_1 as *mut i32; // Ptr to 1st element

*ptr4_at_1 += 4;
*ptr3_at_0 += 3;
Expand All @@ -296,7 +296,7 @@ error[E0499]: cannot borrow `data[_]` as mutable more than once at a time
|
4 | let ref1_at_0 = &mut data[0]; // Reference to 0th element
| ------------ first mutable borrow occurs here
5 | let ref2_at_1 = &mut data[1]; // Reference to 1th element
5 | let ref2_at_1 = &mut data[1]; // Reference to 1st element
| ^^^^^^^^^^^^ second mutable borrow occurs here
6 | let ptr3_at_0 = ref1_at_0 as *mut i32; // Ptr to 0th element
| --------- first borrow later used here
Expand All @@ -315,9 +315,9 @@ unsafe {
let (slice2_at_0, slice3_at_1) = slice1.split_at_mut(1);

let ref4_at_0 = &mut slice2_at_0[0]; // Reference to 0th element
let ref5_at_1 = &mut slice3_at_1[0]; // Reference to 1th element
let ref5_at_1 = &mut slice3_at_1[0]; // Reference to 1st element
let ptr6_at_0 = ref4_at_0 as *mut i32; // Ptr to 0th element
let ptr7_at_1 = ref5_at_1 as *mut i32; // Ptr to 1th element
let ptr7_at_1 = ref5_at_1 as *mut i32; // Ptr to 1st element

*ptr7_at_1 += 7;
*ptr6_at_0 += 6;
Expand Down Expand Up @@ -353,9 +353,9 @@ unsafe {
let ptr2_all = slice1_all.as_mut_ptr(); // Pointer for the entire array

let ptr3_at_0 = ptr2_all; // Pointer to 0th elem (the same)
let ptr4_at_1 = ptr2_all.add(1); // Pointer to 1th elem
let ptr4_at_1 = ptr2_all.add(1); // Pointer to 1st elem
let ref5_at_0 = &mut *ptr3_at_0; // Reference to 0th elem
let ref6_at_1 = &mut *ptr4_at_1; // Reference to 1th elem
let ref6_at_1 = &mut *ptr4_at_1; // Reference to 1st elem

*ref6_at_1 += 6;
*ref5_at_0 += 5;
Expand Down Expand Up @@ -894,4 +894,4 @@ Whelp that's all folks, we're finally done talking and thinking about stacked bo

Great question! To answer that we'll finally be returning to our true calling: writing some god damn linked lists.

Wait, I need to write linked lists again? Let's not be hasty folks. Be reasonable. Just hold on I'm sure there's some other interesting issues for me to discu—
Wait, I need to write linked lists again? Let's not be hasty folks. Be reasonable. Just hold on I'm sure there's some other interesting issues for me to discu—