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

Make new a const fn #67

Merged
merged 1 commit into from
Feb 20, 2024
Merged

Make new a const fn #67

merged 1 commit into from
Feb 20, 2024

Conversation

Swatinem
Copy link
Contributor

@Swatinem Swatinem commented Feb 7, 2024

This removes the initial capacity of 2 and rather makes new a const fn.

Fixes #49

@Amanieu
Copy link
Owner

Amanieu commented Feb 20, 2024

LGTM once CI is fixed by #69.

@Swatinem
Copy link
Contributor Author

The CI failure here looks like exactly what I had locally, and which is fixed by #68

@Swatinem
Copy link
Contributor Author

and now that I think about it, I believe removing the default capacity of 2 is what exposed this problem, as likely the very first bucket is never created, and thus the broken code would early-return in that case.

This removes the initial capacity of `2` and rather makes `new` a `const fn`.
@Amanieu Amanieu merged commit b541fc6 into Amanieu:master Feb 20, 2024
2 checks passed
@james7132
Copy link
Contributor

This bumped the MSRV to 1.61, which should probably be reflected in the Cargo.toml.

  error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
     --> /home/runner/.cargo/registry/src/suiyiyu.us.kg-1ecc6299db9ec823/thread_local-1.1.8/src/lib.rs:154:6
      |
  154 | impl<T: Send> ThreadLocal<T> {
      |      ^
  155 |     /// Creates a new empty `ThreadLocal`.
  156 |     pub const fn new() -> ThreadLocal<T> {
      |     ------------------------------------ function declared as const here
      |
      = note: see issue #93706 <https://github.com/rust-lang/rust/issues/93706> for more information

@Amanieu
Copy link
Owner

Amanieu commented Feb 21, 2024

Done

@Swatinem Swatinem deleted the const-new branch February 21, 2024 08:37
@Swatinem Swatinem mentioned this pull request Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: const constructor for ThreadLocal
3 participants