Skip to content

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