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 1/2] 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 From 01f0b1bbb42df4b36b3690929dbc68ce4c28343c Mon Sep 17 00:00:00 2001 From: "Brian G. Merrell" Date: Sat, 14 Dec 2024 03:05:15 -0700 Subject: [PATCH 2/2] Help with ambiguity about 'static lifetimes --- src/ch10-03-lifetime-syntax.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/ch10-03-lifetime-syntax.md b/src/ch10-03-lifetime-syntax.md index 0a356ec641..2f82287e0e 100644 --- a/src/ch10-03-lifetime-syntax.md +++ b/src/ch10-03-lifetime-syntax.md @@ -567,13 +567,14 @@ 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. +You might see some error messages from the compiler suggesting that you use the +`'static'` lifetime to fix a problem. However, 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. ## Generic Type Parameters, Trait Bounds, and Lifetimes Together