/// 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;
/// 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;
}
fn main() {
- mir(Droppable(false, 1));
+ let mut xv = false;
+ mir(Droppable(&mut xv, 1));
panic!();
}
/// 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));
}