-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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 RefCell unstably const #137843
base: master
Are you sure you want to change the base?
make RefCell unstably const #137843
Conversation
ef5a67e
to
ddc8777
Compare
@rustbot label -T-libs +T-libs-api |
RefCell
unstably const
RefCell
unstably const
Cc @rust-lang/wg-const-eval |
The main problem is dropping. Please make sure to also add a test actually using a |
library/core/src/cell.rs
Outdated
debug_assert!(is_writing(borrow)); | ||
self.borrow.replace(borrow + 1); | ||
mem::forget(self) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is even going on here? Seems like you added some hacks related to dropping, but there are no comments at all explaining them. Please add extensive comments any time you do anything unusual.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies. I've reverted this now in favor of const Drop
and added a comment to my clone
helper (since there's no const Clone
trait)
@compiler-errors what is the state of |
Since we probably all want to hear the answer to that question... cc @rust-lang/lang |
No. Until we know what const traits syntax to implement, adding more const trait impls is not something we want. The libstd churn is not worth it |
Yes |
@Daniel-Aaron-Bloom okay so please remove the |
Should I also remove try to remove my added private function |
Oh that's what those functions are for? Sure, seems fine to me as long no incomplete nightly features have to be enabled for this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically we prefer library tests over ui tests for things like this. Somewhere in library/coretests
there should be a good place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Will do.
|
||
fn main() { | ||
let dummy = REF_CELL_TEST; | ||
assert_eq!(DROP_COUNT.load(Ordering::Relaxed), 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the point of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly it was just a dumb way to ensure the destructor is never called. But now I realize I could have just thrown a panic
in the drop
impl.
tests/ui/consts/const-refcell.rs
Outdated
} | ||
} | ||
|
||
const REF_CELL_TEST: RefCell<Dummy> = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also try to actually change the value in the RefCell, and then observe the change in a following borrow()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -154,6 +154,7 @@ | |||
#![feature(cfg_target_has_atomic)] | |||
#![feature(cfg_target_has_atomic_equal_alignment)] | |||
#![feature(cfg_ub_checks)] | |||
#![feature(const_destruct)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@compiler-errors @lcnr @fee1-dead is this feature okay to use in libcore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not until the syntax is finalized by T-lang. I've marked this PR as blocked
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which syntax? There is no ~const
in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All this feature gate does is
- allow
impl const Drop
-- but we already have a fewimpl const
in the standard library so that syntax can't be the concern (I'm not even sure if the feature gate is truly required for this) - adjust the const_check logic to allow
drop
in const if the type in question is const-destructible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
impl const Trait for Type
syntax is also not clear anymore that it will get accepted. So we're putting everything on hold and not adding more things we may have to revert
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I go back to the private const_drop
and as_mut
helpers then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we'll just hold off on merging. I'm optimistic we'll get a decision soon
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Ralf Jung <post@ralfj.de>
Co-authored-by: Ralf Jung <post@ralfj.de>
06262da
to
484a39a
Compare
Now that we can do interior mutability in
const
, most of theRefCell
API can beconst fn
. The main exceptions are APIs which useFnOnce
(RefCell::replace_with
andRef[Mut]::[filter_]map[_split]
) andRefCell::take
which callsDefault::default
.Tracking issue: #137844