Skip to content

Commit 01af120

Browse files
committedJan 27, 2019
Auto merge of #57927 - Alexendoo:mem-drop-nll-docs, r=Centril
Remove lexical scope examples from std::mem::drop The example no longer produces an error in the 2018 edition
2 parents 1484d0d + 9c9144f commit 01af120

File tree

1 file changed

+1
-28
lines changed

1 file changed

+1
-28
lines changed
 

‎src/libcore/mem.rs

+1-28
Original file line numberDiff line numberDiff line change
@@ -713,8 +713,7 @@ pub fn replace<T>(dest: &mut T, mut src: T) -> T {
713713

714714
/// Disposes of a value.
715715
///
716-
/// While this does call the argument's implementation of [`Drop`][drop],
717-
/// it will not release any borrows, as borrows are based on lexical scope.
716+
/// This does call the argument's implementation of [`Drop`][drop].
718717
///
719718
/// This effectively does nothing for types which implement `Copy`, e.g.
720719
/// integers. Such values are copied and _then_ moved into the function, so the
@@ -741,32 +740,6 @@ pub fn replace<T>(dest: &mut T, mut src: T) -> T {
741740
/// drop(v); // explicitly drop the vector
742741
/// ```
743742
///
744-
/// Borrows are based on lexical scope, so this produces an error:
745-
///
746-
/// ```compile_fail,E0502
747-
/// let mut v = vec![1, 2, 3];
748-
/// let x = &v[0];
749-
///
750-
/// drop(x); // explicitly drop the reference, but the borrow still exists
751-
///
752-
/// v.push(4); // error: cannot borrow `v` as mutable because it is also
753-
/// // borrowed as immutable
754-
/// ```
755-
///
756-
/// An inner scope is needed to fix this:
757-
///
758-
/// ```
759-
/// let mut v = vec![1, 2, 3];
760-
///
761-
/// {
762-
/// let x = &v[0];
763-
///
764-
/// drop(x); // this is now redundant, as `x` is going out of scope anyway
765-
/// }
766-
///
767-
/// v.push(4); // no problems
768-
/// ```
769-
///
770743
/// Since [`RefCell`] enforces the borrow rules at runtime, `drop` can
771744
/// release a [`RefCell`] borrow:
772745
///

0 commit comments

Comments
 (0)
Please sign in to comment.