From ac388381f65ba90b7cf4ccd239b3aa46d2ae21bc Mon Sep 17 00:00:00 2001 From: cheater <195390+cheater@users.noreply.github.com> Date: Sun, 21 Sep 2025 04:20:50 +0200 Subject: [PATCH] Update ch04-02-references-and-borrowing.md Explain dangling reference prevention better. The original wording might lead someone learning Rust to think that data will be kept around for as long as a reference exists. Instead, as soon as data is dropped, the reference is barred from being used. Those are two different mechanisms, and this disambiguates which one is in place. --- src/ch04-02-references-and-borrowing.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ch04-02-references-and-borrowing.md b/src/ch04-02-references-and-borrowing.md index 6b92e53a8a..64cac080cd 100644 --- a/src/ch04-02-references-and-borrowing.md +++ b/src/ch04-02-references-and-borrowing.md @@ -198,8 +198,8 @@ pointer_—a pointer that references a location in memory that may have been given to someone else—by freeing some memory while preserving a pointer to that memory. In Rust, by contrast, the compiler guarantees that references will never be dangling references: if you have a reference to some data, the -compiler will ensure that the data will not go out of scope before the -reference to the data does. +compiler will not let you use that reference after the data has gone +out of scope. Let’s try to create a dangling reference to see how Rust prevents them with a compile-time error: