You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tracking issue for release notes of #159564: Allow elided ('static) lifetimes in thread_local! #163353
This issue tracks the release notes text for #159564.
cc @zachs18, @clarfonthey -- original issue/PR authors and assignees for drafting text
See the forge.rust-lang.org chapter about release notes for an overview of how the release team makes use of these tracking issues.
Release notes text
This section should be edited to specify the correct category(s) for the change, with succinct description(s) of what changed. Some things worth considering:
Does this need an additional compat notes section?
Was this a libs stabilization that should have additional headers to list new APIs under Stabilized APIs and Const Stabilized APIs?
# Other-[`'static` lifetimes in `thread_local!` are now elided like in ordinary `static` variables](https://github.com/rust-lang/rust/pull/159564)
Tip
Use the previous releases for inspiration on how to write the release notes text and which categories to pick.
Release blog section
If this change is notable enough for inclusion in the blog post then this section should be edited to contain a draft for the blog post. Otherwise leave it empty.
# `'static` lifetimes in `thread_local!`
While the `thread_local!` macro is designed to mimic ordinary Rust syntax, it has one case that hasn't been updated until now! For example, consider the below `'static` variable:
```ruststaticIMPORTANT_STRING:RefCell<Cow<'_, str>> =RefCell::new(Cow::Borrowed("hello world!"));
```
Because this is a `static` variable, it automatically elides `'static` lifetimes, meaning that the `'_` lifetime is automatically assumed to be `'static`. But for a thread-local:
```rustthread_local! {
staticIMPORTANT_STRING:RefCell<Cow<'static, str>> =RefCell::new(Cow::Borrowed("hello world!"));
}
```
Until Rust 1.100, you had to explicitly specify the lifetime due to a limitation of the macro. Now, you can finally write:
```rustthread_local! {
staticIMPORTANT_STRING:RefCell<Cow<'_, str>> =RefCell::new(Cow::Borrowed("hello world!"));
}
```
While code may want to always specify these lifetimes to ensure compatibility on old Rust versions, at least on the latest version of Rust, we've closed this gap between `thread_local!` variables and normal `static` variables.
Note
If a blog post section is required the release-blog-post label should be added (@rustbot label +release-blog-post) to this issue as otherwise it may be missed by the release team.
This issue tracks the release notes text for #159564.
cc @zachs18, @clarfonthey -- original issue/PR authors and assignees for drafting text
See the forge.rust-lang.org chapter about release notes for an overview of how the release team makes use of these tracking issues.
Release notes text
This section should be edited to specify the correct category(s) for the change, with succinct description(s) of what changed. Some things worth considering:
Stabilized APIsandConst Stabilized APIs?Tip
Use the previous releases for inspiration on how to write the release notes text and which categories to pick.
Release blog section
If this change is notable enough for inclusion in the blog post then this section should be edited to contain a draft for the blog post. Otherwise leave it empty.
Note
If a blog post section is required the
release-blog-postlabel should be added (@rustbot label +release-blog-post) to this issue as otherwise it may be missed by the release team.