1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-06-07 10:06:22 +02:00

Reformulate speaker notes regarding Box (#1819)

The first change is to reformulate the English in a way, that
emphasizes, that this is not a decision of the compiler, but the
impossibility of computing an infinite value (e.g. changed the language
from "not compute" to "would not be able to compute").

The second change is to fix the error message, of course the error
message from the compiler is "recursive withOUT indirection", as
"recursive with indirection" is actually what we want.
This commit is contained in:
Gergely Risko 2024-02-20 15:16:25 +01:00 committed by GitHub
parent 85d2987369
commit d5879d87b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -74,15 +74,16 @@ fn main() {
so only the pointer is moved. so only the pointer is moved.
- If `Box` was not used and we attempted to embed a `List` directly into the - If `Box` was not used and we attempted to embed a `List` directly into the
`List`, the compiler would not compute a fixed size of the struct in memory `List`, the compiler would not be able to compute a fixed size for the struct
(`List` would be of infinite size). in memory (the `List` would be of infinite size).
- `Box` solves this problem as it has the same size as a regular pointer and - `Box` solves this problem as it has the same size as a regular pointer and
just points at the next element of the `List` in the heap. just points at the next element of the `List` in the heap.
- Remove the `Box` in the List definition and show the compiler error. - Remove the `Box` in the List definition and show the compiler error. We get
"Recursive with indirection" is a hint you might want to use a Box or the message "recursive without indirection", because for data recursion, we
reference of some kind, instead of storing a value directly. have to use indirection, a Box or reference of some kind, instead of storing
the value directly.
# More to Explore # More to Explore