{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreifrljldu3tsdotbf3texgts7h4doswwkqtn53zuca2wnxu6nbui3m",
    "uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mhatbvq2v6g2"
  },
  "path": "/t/private-lifetime-inference/24088#post_12",
  "publishedAt": "2026-03-17T09:16:15.000Z",
  "site": "https://internals.rust-lang.org",
  "tags": [
    "rust-blog/posts/common-rust-lifetime-misconceptions.md at master · pretzelhammer/rust-blog · GitHub"
  ],
  "textContent": "redradist:\n\n> The compiler knows the right answer. Why am I doing this by hand?\n\nthis is very incorrect. the compiler does not know, nor can it know. what the \"right\" lifetimes should be, as they depend on many factors the compiler cannot consider.\n\nmany newer users already suffer from the current inference rules(in particular looking at elided_lifetimes_in_paths) when trying to debug lifetimes, they do not need more confusion.\n\nredradist:\n\n>\n>     // Today: must annotate manually, even though it's private\n>     fn find_best<'a>(primary: &'a Data, fallback: &'a Data) -> &'a Summary {\n>         if primary.is_valid() { &primary.summary } else { &fallback.summary }\n>     }\n>\n\nthis is a great simple example of somewhere where the compiler **cannot** infer what the right lifetimes should be. it could very well be, and often is, `find_best<'a>(primary: &'a Data, fallback: &Data) -> &'a Summary `, or `find_best<'a>(primary: &Data, fallback: &'a Data) -> &'a Summary `.\n\ni encourage you to read this rust-blog/posts/common-rust-lifetime-misconceptions.md at master · pretzelhammer/rust-blog · GitHub .",
  "title": "Private lifetime inference"
}