External Publication
Visit Post

Add new reserved lifetime: 'owned

Rust Internals [Unofficial] April 4, 2026
Source

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.

Example:

use std::marker::PhantomData;

trait AsStr<'s> {
    fn to_str(self: &Self) -> &str;
    fn from_str(s: &'s str) -> Self;
}

impl<'s> AsStr<'s> for &'s str {
    fn to_str(self: &Self) -> &str {
        *self
    }

    fn from_str(s: &'s str) -> Self {
        s
    }
}

impl<'s> AsStr<'s> for String {
    fn to_str(self: &Self) -> &str {
        self.as_str()
    }

    fn from_str(s: &'s str) -> Self {
        s.to_string()
    }
}

struct Check<'s, S: AsStr<'s>> {
    s: S,
    _v: PhantomData<&'s ()>
}

impl<'s1, S: AsStr<'s1>> Check<'s1, S> {
    pub fn clone_to_owned(
        self: &'s1 Self,
    ) -> Check<'static, String>
    {
        Check {
            s: self.s.to_str().to_string(),
            _v: PhantomData::default()
        }
    }
}

fn example<'s, S: AsStr<'s>>(check: Check<'s, S>) -> Check<'static, String> {
    check.clone_to_owned()
}

Lsp diagnostic errors:

Diagnostics:
1. `check` does not live long enough
   borrowed value does not live long enough [E0597]
2. argument requires that `check` is borrowed for `'s` [E0597]
3. the parameter type `S` may not live long enough
   ...so that the type `S` will meet its required lifetime bounds [E0309]

Proposed 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.

Discussion in the ATmosphere

Loading comments...