Skip to content

Commit 97e9eac

Browse files
Rollup merge of #36997 - KillTheMule:patch-1, r=steveklabnik
Book: Be very explicit of lifetimes being descriptive ... not prescriptive. Pointed out in https://users.rust-lang.org/t/what-if-i-get-lifetimes-wrong/7535/4, which was a revelation to me and made me think this should be more clear in the book. I'm not sure if I got this entirely right or if the wording is good, but I figured a PR is more helpful than a simple issue. r? @steveklabnik Small Note: There's also https://github.com/rust-lang/book, should I have sent the PR there? It doesn't coincide with the online book though, so I figured it's better of here.
2 parents 0b7fe4d + 0d0cdb7 commit 97e9eac

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/doc/book/lifetimes.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,12 @@ To fix this, we have to make sure that step four never happens after step
5656
three. The ownership system in Rust does this through a concept called
5757
lifetimes, which describe the scope that a reference is valid for.
5858

59-
When we have a function that takes an argument by reference, we can be
60-
implicit or explicit about the lifetime of the reference:
59+
**Note** It's important to understand that lifetime annotations are
60+
_descriptive_, not _prescriptive_. This means that how long a reference is valid
61+
is determined by the code, not by the annotations. The annotations, however,
62+
give information about lifetimes to the compiler that uses them to check the
63+
validity of references. The compiler can do so without annotations in simple
64+
cases, but needs the programmers support in complex scenarios.
6165

6266
```rust
6367
// implicit

0 commit comments

Comments
 (0)