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 atomic_int!'s new function const #170

Open
cmnord opened this issue Sep 6, 2020 · 3 comments
Open

Make atomic_int!'s new function const #170

cmnord opened this issue Sep 6, 2020 · 3 comments

Comments

@cmnord
Copy link

cmnord commented Sep 6, 2020

I'm trying to test a spinlock that uses parking_lot's lock_api with Loom.

To implement lock_api's RawRwLock I need to supply a const initial value, as specified on this line. This works with the standard library's std::sync::atomic::AtomicUsize const fn new, but not with Loom's atomic_int! macro which generates a non-const fn new.

I get the following error when running RUSTFLAGS="--cfg loom" cargo test, where rin is one of the fields of the struct I initialize. It does not throw an error with regular cargo test (using std::sync::atomic).

error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
  --> src/lib.rs:50:14
   |
50 |         rin: AtomicUsize::new(0),
   |              ^^^^^^^^^^^^^^^^^^^

Is it possible to make loom::sync::atomic::AtomicUsize::new const, or can you recommend another workaround?

@LucioFranco
Copy link
Member

This won't work because location! from track_caller requires some more const fn things to be stabilized.

@cmnord
Copy link
Author

cmnord commented Sep 28, 2020

I see, I guess my project will have to wait then. Can you recommend any workaround?

@LucioFranco
Copy link
Member

Not really aware of a work around, except for feature flagging the const aspects but that may be hard.

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

No branches or pull requests

2 participants