Skip to content

Commit

Permalink
Update lifetime-elision.md (google#1795)
Browse files Browse the repository at this point in the history
In the details section, it is suggested to adjust the signature of the
nearest function to "lie" about the lifetimes returned to:

fn nearest<'a, 'q'>(points: &'a [Point], query: &'q Point) -> Option<&'q
Point> {

to demonstrate the compiler checks lifetimes for validity. However, the
syntax for 'q is incorrect and it should instead be

fn nearest<'a, 'q>(points: &'a [Point], query: &'q Point) -> Option<&'q
Point> {
  • Loading branch information
IP1llar authored Feb 8, 2024
1 parent 6fcb591 commit d153145
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/slices-and-lifetimes/lifetime-elision.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ references in its arguments that requires explicit annotation.
Try adjusting the signature to "lie" about the lifetimes returned:

```rust,ignore
fn nearest<'a, 'q'>(points: &'a [Point], query: &'q Point) -> Option<&'q Point> {
fn nearest<'a, 'q>(points: &'a [Point], query: &'q Point) -> Option<&'q Point> {
```

This won't compile, demonstrating that the annotations are checked for validity
Expand Down

0 comments on commit d153145

Please sign in to comment.