diff options
| author | Havvy <ryan.havvy@gmail.com> | 2017-05-22 15:15:04 -0700 |
|---|---|---|
| committer | Havvy <ryan.havvy@gmail.com> | 2017-05-22 15:15:04 -0700 |
| commit | ca909c836fb509bcda5471cdeef0dd9ccd00c54d (patch) | |
| tree | c990150a12c6b76f774be44ee57aa60457d2cfe3 /src/libcore | |
| parent | 14b767d07e15e66203429f674315727a47e01ed5 (diff) | |
| download | rust-ca909c836fb509bcda5471cdeef0dd9ccd00c54d.tar.gz rust-ca909c836fb509bcda5471cdeef0dd9ccd00c54d.zip | |
Add example of variable declaration drop order to Drop trait.
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/ops.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 4c2d05accf3..a2cdd646bd4 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -199,6 +199,18 @@ use marker::Unsize; /// let _x = Outer(Inner); /// } /// ``` +/// +/// Because variables are dropped in the reverse order they are declared, +/// `main` will print `Declared second!` and then `Declared first!`. +/// +/// ``` +/// struct PrintOnDrop(&'static str); +/// +/// fn main() { +/// let _first = PrintOnDrop("Declared first!"); +/// let _second = PrintOnDrop("Declared second!"); +/// } +/// ``` #[lang = "drop"] #[stable(feature = "rust1", since = "1.0.0")] pub trait Drop { |
