Skip to content

Commit 569b18f

Browse files
committed
Add some tests for dynamic dropping
Also remove these drop-glue i8 things… They for some reason make these completely non-MIR tests fail after dyndrop commit which has literally 0 changes around the regular old trans. Wut?
1 parent eef0734 commit 569b18f

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
#![feature(rustc_attrs)]
11+
// error-pattern:drop 1
12+
// error-pattern:drop 2
13+
use std::io::{self, Write};
14+
15+
16+
/// Structure which will not allow to be dropped twice.
17+
struct Droppable(bool, u32);
18+
impl Drop for Droppable {
19+
fn drop(&mut self) {
20+
if self.0 {
21+
writeln!(io::stderr(), "{} dropped twice", self.1);
22+
::std::process::exit(1);
23+
}
24+
writeln!(io::stderr(), "drop {}", self.1);
25+
self.0 = true;
26+
}
27+
}
28+
29+
#[rustc_mir]
30+
fn mir(){
31+
let x = Droppable(false, 1);
32+
let y = Droppable(false, 2);
33+
let mut z = x;
34+
let k = y;
35+
z = k;
36+
}
37+
38+
fn main() {
39+
mir();
40+
panic!();
41+
}
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
#![feature(rustc_attrs)]
11+
// error-pattern:drop 1
12+
use std::io::{self, Write};
13+
14+
15+
/// Structure which will not allow to be dropped twice.
16+
struct Droppable(bool, u32);
17+
impl Drop for Droppable {
18+
fn drop(&mut self) {
19+
if self.0 {
20+
writeln!(io::stderr(), "{} dropped twice", self.1);
21+
::std::process::exit(1);
22+
}
23+
writeln!(io::stderr(), "drop {}", self.1);
24+
self.0 = true;
25+
}
26+
}
27+
28+
#[rustc_mir]
29+
fn mir(d: Droppable){
30+
loop {
31+
let x = d;
32+
break;
33+
}
34+
}
35+
36+
fn main() {
37+
mir(Droppable(false, 1));
38+
panic!();
39+
}
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
#![feature(rustc_attrs)]
11+
// error-pattern:unwind happens
12+
// error-pattern:drop 3
13+
// error-pattern:drop 2
14+
// error-pattern:drop 1
15+
use std::io::{self, Write};
16+
17+
18+
/// Structure which will not allow to be dropped twice.
19+
struct Droppable(bool, u32);
20+
impl Drop for Droppable {
21+
fn drop(&mut self) {
22+
if self.0 {
23+
writeln!(io::stderr(), "{} dropped twice", self.1);
24+
::std::process::exit(1);
25+
}
26+
writeln!(io::stderr(), "drop {}", self.1);
27+
self.0 = true;
28+
}
29+
}
30+
31+
fn may_panic() -> Droppable {
32+
panic!("unwind happens");
33+
}
34+
35+
#[rustc_mir]
36+
fn mir(d: Droppable){
37+
let y = Droppable(false, 2);
38+
let x = [Droppable(false, 1), y, d, may_panic()];
39+
}
40+
41+
fn main() {
42+
mir(Droppable(false, 3));
43+
}

0 commit comments

Comments
 (0)