File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -434,6 +434,11 @@ pub fn replace<T>(dest: &mut T, mut src: T) -> T {
434
434
/// While this does call the argument's implementation of `Drop`, it will not
435
435
/// release any borrows, as borrows are based on lexical scope.
436
436
///
437
+ /// This effectively does nothing for
438
+ /// [types which implement `Copy`](../../book/ownership.html#copy-types),
439
+ /// e.g. integers. Such values are copied and _then_ moved into the function,
440
+ /// so the value persists after this function call.
441
+ ///
437
442
/// # Examples
438
443
///
439
444
/// Basic usage:
@@ -486,6 +491,21 @@ pub fn replace<T>(dest: &mut T, mut src: T) -> T {
486
491
/// let borrow = x.borrow();
487
492
/// println!("{}", *borrow);
488
493
/// ```
494
+ ///
495
+ /// Integers and other types implementing `Copy` are unaffected by `drop()`
496
+ ///
497
+ /// ```
498
+ /// #[derive(Copy, Clone)]
499
+ /// struct Foo(u8);
500
+ ///
501
+ /// let x = 1;
502
+ /// let y = Foo(2);
503
+ /// drop(x); // a copy of `x` is moved and dropped
504
+ /// drop(y); // a copy of `y` is moved and dropped
505
+ ///
506
+ /// println!("x: {}, y: {}", x, y.0); // still available
507
+ /// ```
508
+ ///
489
509
#[ inline]
490
510
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
491
511
pub fn drop < T > ( _x : T ) { }
You can’t perform that action at this time.
0 commit comments