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

Constants and interior mutability #5

Closed
RalfJung opened this issue Aug 23, 2018 · 3 comments
Closed

Constants and interior mutability #5

RalfJung opened this issue Aug 23, 2018 · 3 comments

Comments

@RalfJung
Copy link
Member

RalfJung commented Aug 23, 2018

According to @oli-obk, there are currently some checks somewhere to rule out interior mutability in constants. However, this is accepted:

use std::sync::atomic::AtomicUsize;
const FOO : AtomicUsize = AtomicUsize::new(3);

It would be great if the reasons for this check could be spelled out, ideally somewhere in this repo :D

@oli-obk
Copy link
Contributor

oli-obk commented Aug 23, 2018

Interior mutability is ruled out in statics, not in constants. Constants are annotated internally so statics using them know about it

@RalfJung
Copy link
Member Author

This works as well:

use std::sync::atomic::AtomicUsize;
static FOO : AtomicUsize = AtomicUsize::new(3);

And indeed why would it not...

@oli-obk
Copy link
Contributor

oli-obk commented Aug 30, 2018

discussion continued in rust-lang/rust#53819

@oli-obk oli-obk closed this as completed Aug 30, 2018
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