File tree 1 file changed +8
-2
lines changed
1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -217,8 +217,13 @@ pub trait Drop {
217
217
///
218
218
/// # Panics
219
219
///
220
- /// Given that a [`panic!`] will call `drop` as it unwinds, any [`panic!`]
221
- /// in a `drop` implementation will likely abort.
220
+ /// Implementations should generally avoid [`panic!`]ing, because `drop()` may itself be called
221
+ /// during unwinding due to a panic, and if the `drop()` panics in that situation (a “double
222
+ /// panic”), this will likely abort the program. It is possible to check [`panicking()`] first,
223
+ /// which may be desirable for a `Drop` implementation that is reporting a bug of the kind
224
+ /// “you didn't finish using this before it was dropped”; but most types should simply clean up
225
+ /// their owned allocations or other resources and return normally from `drop()`, regardless of
226
+ /// what state they are in.
222
227
///
223
228
/// Note that even if this panics, the value is considered to be dropped;
224
229
/// you must not cause `drop` to be called again. This is normally automatically
@@ -227,6 +232,7 @@ pub trait Drop {
227
232
///
228
233
/// [E0040]: ../../error_codes/E0040.html
229
234
/// [`panic!`]: crate::panic!
235
+ /// [`panicking()`]: ../../std/thread/fn.panicking.html
230
236
/// [`mem::drop`]: drop
231
237
/// [`ptr::drop_in_place`]: crate::ptr::drop_in_place
232
238
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
You can’t perform that action at this time.
0 commit comments