From 356bf529eedaea523b4266057b2ce8a13435b737 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Wed, 24 Feb 2016 20:36:20 +0200 Subject: [PATCH] Fix tests --- src/test/run-fail/mir_dynamic_drops_1.rs | 13 +++++++------ src/test/run-fail/mir_dynamic_drops_2.rs | 13 +++++++------ src/test/run-fail/mir_dynamic_drops_3.rs | 20 +++++++++++--------- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/test/run-fail/mir_dynamic_drops_1.rs b/src/test/run-fail/mir_dynamic_drops_1.rs index f3c2eafde245..590b9fbe43cf 100644 --- a/src/test/run-fail/mir_dynamic_drops_1.rs +++ b/src/test/run-fail/mir_dynamic_drops_1.rs @@ -14,22 +14,23 @@ use std::io::{self, Write}; /// Structure which will not allow to be dropped twice. -struct Droppable(bool, u32); -impl Drop for Droppable { +struct Droppable<'a>(&'a mut bool, u32); +impl<'a> Drop for Droppable<'a> { fn drop(&mut self) { - if self.0 { + if *self.0 { writeln!(io::stderr(), "{} dropped twice", self.1); ::std::process::exit(1); } writeln!(io::stderr(), "drop {}", self.1); - self.0 = true; + *self.0 = true; } } #[rustc_mir] fn mir(){ - let x = Droppable(false, 1); - let y = Droppable(false, 2); + let (mut xv, mut yv) = (false, false); + let x = Droppable(&mut xv, 1); + let y = Droppable(&mut yv, 2); let mut z = x; let k = y; z = k; diff --git a/src/test/run-fail/mir_dynamic_drops_2.rs b/src/test/run-fail/mir_dynamic_drops_2.rs index ada04dfce647..eafd3d351fb9 100644 --- a/src/test/run-fail/mir_dynamic_drops_2.rs +++ b/src/test/run-fail/mir_dynamic_drops_2.rs @@ -13,20 +13,20 @@ use std::io::{self, Write}; /// Structure which will not allow to be dropped twice. -struct Droppable(bool, u32); -impl Drop for Droppable { +struct Droppable<'a>(&'a mut bool, u32); +impl<'a> Drop for Droppable<'a> { fn drop(&mut self) { - if self.0 { + if *self.0 { writeln!(io::stderr(), "{} dropped twice", self.1); ::std::process::exit(1); } writeln!(io::stderr(), "drop {}", self.1); - self.0 = true; + *self.0 = true; } } #[rustc_mir] -fn mir(d: Droppable){ +fn mir<'a>(d: Droppable<'a>){ loop { let x = d; break; @@ -34,6 +34,7 @@ fn mir(d: Droppable){ } fn main() { - mir(Droppable(false, 1)); + let mut xv = false; + mir(Droppable(&mut xv, 1)); panic!(); } diff --git a/src/test/run-fail/mir_dynamic_drops_3.rs b/src/test/run-fail/mir_dynamic_drops_3.rs index cfbfb0759546..730d9c8f2268 100644 --- a/src/test/run-fail/mir_dynamic_drops_3.rs +++ b/src/test/run-fail/mir_dynamic_drops_3.rs @@ -16,28 +16,30 @@ use std::io::{self, Write}; /// Structure which will not allow to be dropped twice. -struct Droppable(bool, u32); -impl Drop for Droppable { +struct Droppable<'a>(&'a mut bool, u32); +impl<'a> Drop for Droppable<'a> { fn drop(&mut self) { - if self.0 { + if *self.0 { writeln!(io::stderr(), "{} dropped twice", self.1); ::std::process::exit(1); } writeln!(io::stderr(), "drop {}", self.1); - self.0 = true; + *self.0 = true; } } -fn may_panic() -> Droppable { +fn may_panic<'a>() -> Droppable<'a> { panic!("unwind happens"); } #[rustc_mir] -fn mir(d: Droppable){ - let y = Droppable(false, 2); - let x = [Droppable(false, 1), y, d, may_panic()]; +fn mir<'a>(d: Droppable<'a>){ + let (mut a, mut b) = (false, false); + let y = Droppable(&mut a, 2); + let x = [Droppable(&mut b, 1), y, d, may_panic()]; } fn main() { - mir(Droppable(false, 3)); + let mut c = false; + mir(Droppable(&mut c, 3)); }