{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreifqjbcbefnj7ulw6pxoaxkaq4v6e4hvrhdj2vkjbqnif53hf3qnby",
    "uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mgzalahjxtq2"
  },
  "path": "/t/could-borrow-checking-with-origins-unblock-sound-specialization/24079#post_4",
  "publishedAt": "2026-03-14T01:22:18.000Z",
  "site": "https://internals.rust-lang.org",
  "textContent": "We just _don't want codegen to depend on lifetimes_ , though; we don't merely want specialization on lifetimes to not be unsound, we further don't want to allow specialization on lifetimes at all. Whether or not a given reference is `'static` can be somewhat unpredictable due to const promotion (e.g., `let x = &1_u8`) or reborrowing. Further, specialization on lifetimes can try to specialize on two references having the _same_ lifetime, which seems even more unpredictable.\n\nAlso, consider the following:\n\n\n    let n: u8 = 0;\n    let n_ref = &n;\n    {\n        let other: u8 = 1;\n        let another_ref = n_ref;\n        // Fairly sure that `if false { .. }` would have the same effect.\n        if random_u32().is_multiple_of(2) {\n            another_ref = &other;\n            // Conditional early return of a borrow.\n            return another_ref;\n        }\n\n        // Under the current borrow checker, I'm fairly sure the origins are:\n        // {shared(n)} and {shared(n), shared(other)}, not the same.\n        // Under Polonius, I'm fairly sure the origins are:\n        // {shared(n)} and {shared(n)}, the same.\n        let result = (n_ref, another_ref).merge();\n    }\n\n\nIn other words, your proposal would make the _exact behavior of the borrow checker_ load-bearing, and _improving_ the borrow checker would be a breaking change.",
  "title": "Could borrow checking with origins unblock sound specialization"
}