Skip to content

Add comment on why RefCell::unwrap is safe. #19137

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

Merged
merged 1 commit into from
Nov 23, 2014

Conversation

tbu-
Copy link
Contributor

@tbu- tbu- commented Nov 20, 2014

No description provided.

@huonw
Copy link
Member

huonw commented Nov 20, 2014

I think it's actually safe: moving the RefCell (i.e taking self by-value) requires that there are no existing borrows, and both .borrow() and .borrow_mut() store borrows, so it's impossible to call unwrap while either of those exist. The debug_assert! is just a final check to ensure that RefCell is maintaining its own invariants.

If you adjust this patch to leave the debug_assert! as is, but add a comment describing the above for future readers, I'll r+ in a flash since it's definitely subtle.

@nikomatsakis
Copy link
Contributor

Actually, I think we intentionally used debug_assert there to avoid undue performance impact for something we believe to be statically verified.

@tbu- tbu- force-pushed the pr_refcell_unsafety branch from 6a44e67 to f9f5c03 Compare November 20, 2014 11:29
@tbu- tbu- changed the title Make RefCell::unwrap safe Add comment on why RefCell::unwrap is safe. Nov 20, 2014
alexcrichton added a commit to alexcrichton/rust that referenced this pull request Nov 22, 2014
@bors bors closed this Nov 23, 2014
@bors bors merged commit f9f5c03 into rust-lang:master Nov 23, 2014
lnicola pushed a commit to lnicola/rust that referenced this pull request Feb 17, 2025
fix: highlight `extern crate` in doc comments
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.

4 participants