{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreifiwb4qgjoank6kybfluqtt753axouooryd3bgqjf4e24w52v475a",
"uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3miprpl7stgw2"
},
"path": "/t/add-new-reserved-lifetime-owned/24129#post_1",
"publishedAt": "2026-04-04T05:38:15.000Z",
"site": "https://internals.rust-lang.org",
"textContent": "Problem statement: Right now rust treats all owned types like String as having 'static lifetime, meaning rust in terms of borrow checking sees &'static str and String as same. This creates issues when we try to make a structure that is polymorphic over some type parameter S that could be a string slice reference or owned String.\n\nExample:\n\n\n use std::marker::PhantomData;\n\n trait AsStr<'s> {\n fn to_str(self: &Self) -> &str;\n fn from_str(s: &'s str) -> Self;\n }\n\n impl<'s> AsStr<'s> for &'s str {\n fn to_str(self: &Self) -> &str {\n *self\n }\n\n fn from_str(s: &'s str) -> Self {\n s\n }\n }\n\n impl<'s> AsStr<'s> for String {\n fn to_str(self: &Self) -> &str {\n self.as_str()\n }\n\n fn from_str(s: &'s str) -> Self {\n s.to_string()\n }\n }\n\n struct Check<'s, S: AsStr<'s>> {\n s: S,\n _v: PhantomData<&'s ()>\n }\n\n impl<'s1, S: AsStr<'s1>> Check<'s1, S> {\n pub fn clone_to_owned(\n self: &'s1 Self,\n ) -> Check<'static, String>\n {\n Check {\n s: self.s.to_str().to_string(),\n _v: PhantomData::default()\n }\n }\n }\n\n fn example<'s, S: AsStr<'s>>(check: Check<'s, S>) -> Check<'static, String> {\n check.clone_to_owned()\n }\n\n\nLsp diagnostic errors:\n\n\n Diagnostics:\n 1. `check` does not live long enough\n borrowed value does not live long enough [E0597]\n 2. argument requires that `check` is borrowed for `'s` [E0597]\n 3. the parameter type `S` may not live long enough\n ...so that the type `S` will meet its required lifetime bounds [E0309]\n\n\nProposed solution is owned lifetime that is allowed only for non-reference types, therefore any reference outlives 'owned, because we know that structure with 'owned type does not hold any references to initial data, making a copy.",
"title": "Add new reserved lifetime: 'owned"
}