From cfbe0960a917b45ac2e27ee8d5251636e09d3735 Mon Sep 17 00:00:00 2001 From: Pavel Filatov Date: Wed, 12 Nov 2025 10:23:15 +0700 Subject: [PATCH 1/3] Update ch10-04-inventory.toml Added a similar note to the one in ch08-04-inventory.toml https://github.com/cognitive-engineering-lab/rust-book/blob/54149f8a37a24556e7d52d68c6fd06265f319b33/quizzes/ch08-04-inventory.toml#L275 --- quizzes/ch10-04-inventory.toml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/quizzes/ch10-04-inventory.toml b/quizzes/ch10-04-inventory.toml index 13eb57243e..92651f57b3 100644 --- a/quizzes/ch10-04-inventory.toml +++ b/quizzes/ch10-04-inventory.toml @@ -292,7 +292,9 @@ println!("{:?}", result.scores); context = """ This program is actually safe as written. It is a limitation of the borrow checker to not understand that `get_curve` only borrows `curve`, and doesn't affect `scores`. However, in theory if `get_curve` were changed to return a reference -to something with `self.scores`, then memory safety could potentially be violated. +to something with `self.scores`, then memory safety could potentially be violated. Note that +the `let x = &result.scores[0];` program would not compile, as Rust's borrow checker would not +allow to borrow `result` as mmutable while immutable borrow of `result` exists. """ [[questions]] @@ -383,4 +385,4 @@ so it allows the function to compile. This is a common workaround for this type Another option is to leverage the fact that `self.curve` is cheap to copy and use [`Option::copied`](https://doc.rust-lang.org/std/option/enum.Option.html#method.copied), which would release the borrow on `self` as soon as `.copied()` is called. -""" \ No newline at end of file +""" From 2dc64db8c99049884ed40ae1116a881369428ec2 Mon Sep 17 00:00:00 2001 From: Pavel Filatov Date: Wed, 12 Nov 2025 10:27:22 +0700 Subject: [PATCH 2/3] Update ch10-04-inventory.toml fix typo --- quizzes/ch10-04-inventory.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/quizzes/ch10-04-inventory.toml b/quizzes/ch10-04-inventory.toml index 92651f57b3..3cb08720aa 100644 --- a/quizzes/ch10-04-inventory.toml +++ b/quizzes/ch10-04-inventory.toml @@ -294,7 +294,7 @@ This program is actually safe as written. It is a limitation of the borrow check only borrows `curve`, and doesn't affect `scores`. However, in theory if `get_curve` were changed to return a reference to something with `self.scores`, then memory safety could potentially be violated. Note that the `let x = &result.scores[0];` program would not compile, as Rust's borrow checker would not -allow to borrow `result` as mmutable while immutable borrow of `result` exists. +allow to borrow `result` as mutable while immutable borrow of `result` exists. """ [[questions]] @@ -386,3 +386,4 @@ so it allows the function to compile. This is a common workaround for this type Another option is to leverage the fact that `self.curve` is cheap to copy and use [`Option::copied`](https://doc.rust-lang.org/std/option/enum.Option.html#method.copied), which would release the borrow on `self` as soon as `.copied()` is called. """ + From 198e71ec746dcb69784e2221046a5a614de35d78 Mon Sep 17 00:00:00 2001 From: Pavel Filatov Date: Wed, 12 Nov 2025 10:27:59 +0700 Subject: [PATCH 3/3] Update ch10-04-inventory.toml remove additional \n --- quizzes/ch10-04-inventory.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/quizzes/ch10-04-inventory.toml b/quizzes/ch10-04-inventory.toml index 3cb08720aa..5ad8a1d62c 100644 --- a/quizzes/ch10-04-inventory.toml +++ b/quizzes/ch10-04-inventory.toml @@ -386,4 +386,3 @@ so it allows the function to compile. This is a common workaround for this type Another option is to leverage the fact that `self.curve` is cheap to copy and use [`Option::copied`](https://doc.rust-lang.org/std/option/enum.Option.html#method.copied), which would release the borrow on `self` as soon as `.copied()` is called. """ -