1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-01-27 23:35:05 +02:00

Update lifetime-elision.md (#1795)

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> {
This commit is contained in:
IP1llar 2024-02-08 19:48:21 +00:00 committed by GitHub
parent 6fcb591585
commit d15314527b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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