diff options
| author | Caio <c410.f3r@gmail.com> | 2021-02-16 21:22:21 -0300 |
|---|---|---|
| committer | Caio <c410.f3r@gmail.com> | 2021-02-16 21:22:21 -0300 |
| commit | e7e93717ce8e6f5cec217ebfcda2d8c8b76f6b49 (patch) | |
| tree | 95e02203894ab5b08fd6c2d6088c56a65549310c /src/test/ui/for-loop-while | |
| parent | 097bc6a84f2280a889b9ab4b544f27851a978927 (diff) | |
| download | rust-e7e93717ce8e6f5cec217ebfcda2d8c8b76f6b49.tar.gz rust-e7e93717ce8e6f5cec217ebfcda2d8c8b76f6b49.zip | |
Move some tests to more reasonable directories
Diffstat (limited to 'src/test/ui/for-loop-while')
| -rw-r--r-- | src/test/ui/for-loop-while/cleanup-rvalue-during-if-and-while.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/test/ui/for-loop-while/cleanup-rvalue-during-if-and-while.rs b/src/test/ui/for-loop-while/cleanup-rvalue-during-if-and-while.rs new file mode 100644 index 00000000000..6fecb4e76da --- /dev/null +++ b/src/test/ui/for-loop-while/cleanup-rvalue-during-if-and-while.rs @@ -0,0 +1,43 @@ +// run-pass +// This test verifies that temporaries created for `while`'s and `if` +// conditions are dropped after the condition is evaluated. + +#![feature(box_syntax)] + +struct Temporary; + +static mut DROPPED: isize = 0; + +impl Drop for Temporary { + fn drop(&mut self) { + unsafe { DROPPED += 1; } + } +} + +impl Temporary { + fn do_stuff(&self) -> bool {true} +} + +fn borrow() -> Box<Temporary> { box Temporary } + + +pub fn main() { + let mut i = 0; + + // This loop's condition + // should call `Temporary`'s + // `drop` 6 times. + while borrow().do_stuff() { + i += 1; + unsafe { assert_eq!(DROPPED, i) } + if i > 5 { + break; + } + } + + // This if condition should + // call it 1 time + if borrow().do_stuff() { + unsafe { assert_eq!(DROPPED, i + 1) } + } +} |
