External Publication
Visit Post

Could borrow checking with origins unblock sound specialization

Rust Internals [Unofficial] March 14, 2026
Source

No, 'static bounds are also computed by the borrow checker, just like other T: 'a lifetime bounds. I could modify my above example to make n_ref a 'static reference, meaning that better control flow analysis in the borrow checker could result in another_ref later being recognized as a 'static reference when it’s used in result.

Specializing on some compiler-implemented HasNoLifetimeParameters trait could be reasonable, though. I believe that

struct Foo(&'static str);

could implement HasNoLifetimeParameters, while &'static str would not, in order to avoid relying on context to determine whether a given string is “really genuinely guaranteed to always be 'static”, “always 'static in the current rustc version, but not explicitly annotated as 'static so this might surprise the user”, or “only sometimes 'static”.

Discussion in the ATmosphere

Loading comments...