From 63825d5800a8cc6da4565b30c605c42d81502e4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Sampaio?= Date: Sat, 12 Oct 2024 08:27:35 +0100 Subject: [PATCH] Ch10-03: Improve paragraph on error messages about `'static` --- src/ch10-03-lifetime-syntax.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ch10-03-lifetime-syntax.md b/src/ch10-03-lifetime-syntax.md index c87f38c4ce..7d56ffa110 100644 --- a/src/ch10-03-lifetime-syntax.md +++ b/src/ch10-03-lifetime-syntax.md @@ -570,13 +570,13 @@ let s: &'static str = "I have a static lifetime."; The text of this string is stored directly in the program’s binary, which is always available. Therefore, the lifetime of all string literals is `'static`. -You might see suggestions to use the `'static` lifetime in error messages. But -before specifying `'static` as the lifetime for a reference, think about -whether the reference you have actually lives the entire lifetime of your -program or not, and whether you want it to. Most of the time, an error message -suggesting the `'static` lifetime results from attempting to create a dangling -reference or a mismatch of the available lifetimes. In such cases, the solution -is to fix those problems, not to specify the `'static` lifetime. +The compiler may suggest specifying `'static` as the lifetime for a reference +in error messages. But before doing it, think about whether the reference you +have actually lives for the entire lifetime of your program or not. Most of the +time, an error message suggesting the `'static` lifetime results from +attempting to create a dangling reference or a mismatch of the available +lifetimes. In such cases, the solution is to fix those problems, not to specify +the `'static` lifetime. ## Generic Type Parameters, Trait Bounds, and Lifetimes Together