Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: 12015 - suggest const thread_local #12024

Closed
wants to merge 2 commits into from
Closed

Draft: 12015 - suggest const thread_local #12024

wants to merge 2 commits into from

Conversation

m-rph
Copy link
Contributor

@m-rph m-rph commented Dec 27, 2023

Currently Draft.

The lint aims to suggest using a const initializer in thread_local calls if possible:

thread_local! {
   static ... = const { RefCell::new(0) };
}

if possible.

After expanding the macro, I observed that if a const is given, there is no __init fn. Thus, we can check the init fn and it's actual body for the initializer value. This is currently in draft because I am not sure how to correctly check whether the expression can be evaluated as a const, and I hit an ICE with the two functions I tried to use.

Attempts to close: #12015

changelog: New Lint [suggest_const_thread_local]: suggest const { initializer } for threadlocal if possible.

  • Followed [lint naming conventions][lint_naming]
  • Added passing UI tests (including committed .stderr file)
  • cargo test passes locally
  • Executed cargo dev update_lints
  • Added lint documentation
  • Run cargo dev fmt

@rustbot
Copy link
Collaborator

rustbot commented Dec 27, 2023

r? @Jarcho

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Dec 27, 2023
@m-rph m-rph closed this Dec 27, 2023
@m-rph m-rph deleted the 12015 branch December 27, 2023 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add lint that suggest using const thread_local whenever possible
3 participants