From 293699e9755ca56c484d640154b688c586925b13 Mon Sep 17 00:00:00 2001 From: seven7763 Date: Fri, 4 Sep 2026 07:45:09 +0800 Subject: [PATCH] Clarify that static variables are not synonymous with global variables "In Rust, global variables are called _static_ variables" implies global == static, but a static item is about the 'static lifetime of the binding, not its scope: static items may be declared at module scope or inside a function. Fixes #4819 --- src/ch20-01-unsafe-rust.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ch20-01-unsafe-rust.md b/src/ch20-01-unsafe-rust.md index 12f9fb6f27..4e1a34e1b4 100644 --- a/src/ch20-01-unsafe-rust.md +++ b/src/ch20-01-unsafe-rust.md @@ -392,7 +392,9 @@ support but which can be problematic with Rust’s ownership rules. If two threads are accessing the same mutable global variable, it can cause a data race. -In Rust, global variables are called _static_ variables. Listing 20-10 shows an +Rust doesn’t have a dedicated “global variable” keyword; instead, it has +_static_ variables, which live for the entire program and can be declared at +module scope (globally) or inside a function (locally). Listing 20-10 shows an example declaration and use of a static variable with a string slice as a value.