-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Footgun with const declarations of type Atomic* #65822
Comments
Clippy has a lint for this. |
@sfackler I assume this refers to https://rust-lang.github.io/rust-clippy/master/index.html#borrow_interior_mutable_const ? @asajeffrey Are you happy with that or would you like the language team to consider upstreaming the lint? |
The thing about that line is that you have to know to enable it, and pretty much the only way to learn that is the hard way. It would be nice if this was enabled by default, but that's probably a breaking change. |
cc @oli-obk (who is on vacation, but they'll be back one day) |
This lint is enabled by default (even more, it will stop compilation with the error), candidate for #53224 |
I just got beaten by this too, I think relying on clippy for it is not great. |
What checks are those? Why do they not apply? |
This does seem like the kind of thing the compiler should catch, which is the subject of #40543. @asajeffrey The clippy lints do apply to atomics. You may have gotten bitten by rust-lang/rust-clippy#4612 or similar.
Clippy produces:
|
This is still an issue. #53224 has been closed. 1-48-0-nightly still produces no warnings or errors. |
|
I just got caught by a footgun where I'd declared a global counter as:
and incremented it using
COUNTER.fetch_add(1, Ordering::SeqCst)
. It took me a while to realize why I was always getting0
! There are checks forconst
declarations not having interior mutability to catch these footguns, but they don't apply to atomics.The text was updated successfully, but these errors were encountered: