From 5a9498e9e9173a911f481f8024632bf7ede887ac Mon Sep 17 00:00:00 2001 From: Dodothereal <129273127+Dodothereal@users.noreply.github.com> Date: Tue, 23 Jun 2026 19:00:57 +0200 Subject: [PATCH] docs(ch04-02): clarify reference scope is distinct from variable scope Fixes #4706: the phrase 'a reference's scope starts from where it is introduced' implicitly shifts the meaning of the word 'scope' from the lexical (curly-bracket) scope used for variables to the non-lexical lifetime-style scope used for references. Without acknowledging the shift, beginners may conflate the two. Prepend one sentence to the existing paragraph to make the distinguishing factor explicit. --- src/ch04-02-references-and-borrowing.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ch04-02-references-and-borrowing.md b/src/ch04-02-references-and-borrowing.md index 8c37601d57..99e806eb5b 100644 --- a/src/ch04-02-references-and-borrowing.md +++ b/src/ch04-02-references-and-borrowing.md @@ -171,10 +171,12 @@ from under them! However, multiple immutable references are allowed because no one who is just reading the data has the ability to affect anyone else’s reading of the data. -Note that a reference’s scope starts from where it is introduced and continues -through the last time that reference is used. For instance, this code will -compile because the last usage of the immutable references is in the `println!`, -before the mutable reference is introduced: +Note that a reference’s scope is distinct from a variable’s scope: a +variable’s scope extends to the end of the block where it was declared, +whereas a reference’s scope starts from where the reference is introduced +and continues through the last time that reference is used. For instance, +this code will compile because the last usage of the immutable references +is in the `println!`, before the mutable reference is introduced: ```rust {{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-13-reference-scope-ends/src/main.rs:here}}