Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ch10-03: Improve paragraph on error messages about 'static #4067

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/ch10-03-lifetime-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down