rust-lang / nomicon

The Dark Arts of Advanced and Unsafe Rust Programming
https://doc.rust-lang.org/nomicon/
Apache License 2.0
1.75k stars 256 forks source link

Update lifetimes.md #372

Closed zhenya-1007 closed 1 year ago

zhenya-1007 commented 2 years ago

Get rid of the obviously wrong (and potentially confusing) double lifetime annotation. My guess as to the etiology is an errant copy-and-paste.

ehuss commented 2 years ago

Hi, thanks for the PR!

This doesn't look obviously wrong to me, so can you say more about what you think is wrong about it? This is intentionally not Rust syntax, and is intended as an illustration of desugaring. z is a double reference to x. The inner reference has a lifetime of 'b and the outer reference has a lifetime of 'c. The example seems to be trying to illustrate this.

zhenya-1007 commented 2 years ago

Thank you for taking a look.

z is a double reference to x. The inner reference has a lifetime of 'b and the outer reference has a lifetime of 'c.

With this explanation, it makes sense. Without it, it looked like a copy-and-paste slip-up to me. I think that's because there are no other examples (that I could find) where lifetime annotations appear twice in a de-sugaring.

I have updated the PR to add a comment instead of deleting what I thought was an extraneous lifetime annotation.
Please take another look.