-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Explain drop a bit more #30696
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
Explain drop a bit more #30696
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,6 +95,16 @@ use fmt; | |
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub trait Drop { | ||
/// A method called when the value goes out of scope. | ||
/// | ||
/// When this method has been called, `self` has not yet been deallocated. | ||
/// If it were, `self` would be a dangling reference. | ||
/// | ||
/// After this function is over, the memory of `self` will be deallocated. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe instead of 'deallocated', 'deinitialized' would be more accurate? It could even say, 'deinitialized, and if |
||
/// | ||
/// # Panics | ||
/// | ||
/// Given that a `panic!` will call `drop()` as it unwinds, any `panic!` in | ||
/// a `drop()` implementation will likely abort. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I kind of want this to say more. It's still not obvious why panicking during drop results in abort. Is there additional material we can link to that explains exception safety and double-panic? This could be more emphatic, like
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's the double panic detector; the comment implies that something besides an abort could be done but it would be tricky. Scary-sounding alternatives like calling |
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
fn drop(&mut 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.
I think the tense in the first clause makes things a bit ambiguous. How about something like "Before this method is called,
self
has not yet been deallocated."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.
Actually, I'm not sure it even makes sense to use the word "deallocated," since a number of
Drop
impls don't have anything to do with allocation. I think this description should probably just talk about it being invalid (or some other word) to accessself
afterdrop
has been called.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.
Yeah I mean, I felt like it was a little weird because
&mut
is always valid, but @durka felt differently.