Skip to content

Commit e934f31

Browse files
committed
Ch. 20: correct text about how we got raw pointers
We no longer get the raw pointers from references, although we *could*, because we can now use the raw pointer operator rather than an `as` cast and thus can get them directly from a variable in scope.
1 parent 3fdb520 commit e934f31

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/ch20-01-unsafe-rust.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,9 @@ By opting out of having Rust enforce these guarantees, you can give up
8888
guaranteed safety in exchange for greater performance or the ability to
8989
interface with another language or hardware where Rust’s guarantees don’t apply.
9090

91-
Listing 20-1 shows how to create an immutable and a mutable raw pointer from
92-
references.
91+
Listing 20-1 shows how to create an immutable and a mutable raw pointer.
9392

94-
<Listing number="20-1" caption="Creating raw pointers from references">
93+
<Listing number="20-1" caption="Creating raw pointers with the raw borrow operators">
9594

9695
```rust
9796
{{#rustdoc_include ../listings/ch20-advanced-features/listing-20-01/src/main.rs:here}}
@@ -105,9 +104,9 @@ unsafe block, as you’ll see in a bit.
105104

106105
We’ve created raw pointers by using the raw borrow operators: `&raw const num`
107106
creates a `*const i32` immutable raw pointer, and `&raw mut num` creates a `&mut
108-
i32` mutable raw pointer. Because we created them directly from references
109-
guaranteed to be valid, we know these particular raw pointers are valid, but we
110-
can’t make that assumption about just any raw pointer.
107+
i32` mutable raw pointer. Because we created them directly from a local
108+
variable, we know these particular raw pointers are valid, but we can’t make
109+
that assumption about just any raw pointer.
111110

112111
To demonstrate this, next we’ll create a raw pointer whose validity we can’t be
113112
so certain of, using `as` to cast a value instead of using the raw reference

0 commit comments

Comments
 (0)