Skip to content

Commit 1028da3

Browse files
committed
---
yaml --- r: 194803 b: refs/heads/auto c: 7c671e5 h: refs/heads/master i: 194801: bfd9e0d 194799: e05eaa1 v: v3
1 parent b18c5b4 commit 1028da3

File tree

6 files changed

+204
-1
lines changed

6 files changed

+204
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: 3902190ac4d64962b2c1ac9a6ae88777b7112f82
13+
refs/heads/auto: 7c671e51770e1e818a57b07bb831f50840049660
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2015 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+
11+
// Test that we cleanup a fixed size Box<[D; k]> properly when D has a
12+
// destructor.
13+
14+
use std::thread;
15+
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
16+
17+
static LOG: AtomicUsize = ATOMIC_USIZE_INIT;
18+
19+
struct D(u8);
20+
21+
impl Drop for D {
22+
fn drop(&mut self) {
23+
println!("Dropping {}", self.0);
24+
let old = LOG.load(Ordering::SeqCst);
25+
LOG.compare_and_swap(old, old << 4 | self.0 as usize, Ordering::SeqCst);
26+
}
27+
}
28+
29+
fn main() {
30+
fn die() -> D { panic!("Oh no"); }
31+
let g = thread::spawn(|| {
32+
let _b1: Box<[D; 4]> = Box::new([D( 1), D( 2), D( 3), D( 4)]);
33+
let _b2: Box<[D; 4]> = Box::new([D( 5), D( 6), D( 7), D( 8)]);
34+
let _b3: Box<[D; 4]> = Box::new([D( 9), D(10), die(), D(12)]);
35+
let _b4: Box<[D; 4]> = Box::new([D(13), D(14), D(15), D(16)]);
36+
});
37+
assert!(g.join().is_err());
38+
39+
// When the panic occurs, we will be in the midst of constructing
40+
// the input to `_b3`. Therefore, we drop the elements of the
41+
// partially filled array first, before we get around to dropping
42+
// the elements of `_b1` and _b2`.
43+
44+
// Issue 23222: The order in which the elements actually get
45+
// dropped is a little funky. See similar notes in nested-vec-3;
46+
// in essence, I would not be surprised if we change the ordering
47+
// given in `expect` in the future.
48+
49+
let expect = 0x__A_9__5_6_7_8__1_2_3_4;
50+
let actual = LOG.load(Ordering::SeqCst);
51+
assert!(actual == expect, "expect: 0x{:x} actual: 0x{:x}", expect, actual);
52+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2015 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+
11+
// Test that we cleanup dynamic sized Box<[D]> properly when D has a
12+
// destructor.
13+
14+
use std::thread;
15+
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
16+
17+
static LOG: AtomicUsize = ATOMIC_USIZE_INIT;
18+
19+
struct D(u8);
20+
21+
impl Drop for D {
22+
fn drop(&mut self) {
23+
println!("Dropping {}", self.0);
24+
let old = LOG.load(Ordering::SeqCst);
25+
LOG.compare_and_swap(old, old << 4 | self.0 as usize, Ordering::SeqCst);
26+
}
27+
}
28+
29+
fn main() {
30+
fn die() -> D { panic!("Oh no"); }
31+
let g = thread::spawn(|| {
32+
let _b1: Box<[D; 4]> = Box::new([D( 1), D( 2), D( 3), D( 4)]);
33+
let _b2: Box<[D; 4]> = Box::new([D( 5), D( 6), D( 7), D( 8)]);
34+
let _b3: Box<[D; 4]> = Box::new([D( 9), D(10), die(), D(12)]);
35+
let _b4: Box<[D; 4]> = Box::new([D(13), D(14), D(15), D(16)]);
36+
});
37+
assert!(g.join().is_err());
38+
39+
// When the panic occurs, we will be in the midst of constructing
40+
// the input to `_b3`. Therefore, we drop the elements of the
41+
// partially filled array first, before we get around to dropping
42+
// the elements of `_b1` and _b2`.
43+
44+
// Issue 23222: The order in which the elements actually get
45+
// dropped is a little funky. See similar notes in nested-vec-3;
46+
// in essence, I would not be surprised if we change the ordering
47+
// given in `expect` in the future.
48+
49+
let expect = 0x__A_9__5_6_7_8__1_2_3_4;
50+
let actual = LOG.load(Ordering::SeqCst);
51+
assert!(actual == expect, "expect: 0x{:x} actual: 0x{:x}", expect, actual);
52+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2015 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+
11+
// Test that using the `vec!` macro nested within itself works
12+
13+
fn main() {
14+
let nested = vec![vec![1u32, 2u32, 3u32]];
15+
assert_eq!(nested[0][1], 2);
16+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2015 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+
11+
// Test that using the `vec!` macro nested within itself works
12+
// when the contents implement Drop
13+
14+
struct D(u32);
15+
16+
impl Drop for D {
17+
fn drop(&mut self) { println!("Dropping {}", self.0); }
18+
}
19+
20+
fn main() {
21+
let nested = vec![vec![D(1u32), D(2u32), D(3u32)]];
22+
assert_eq!(nested[0][1].0, 2);
23+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright 2015 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+
11+
// Test that using the `vec!` macro nested within itself works when
12+
// the contents implement Drop and we hit a panic in the middle of
13+
// construction.
14+
15+
16+
use std::thread;
17+
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
18+
19+
static LOG: AtomicUsize = ATOMIC_USIZE_INIT;
20+
21+
struct D(u8);
22+
23+
impl Drop for D {
24+
fn drop(&mut self) {
25+
println!("Dropping {}", self.0);
26+
let old = LOG.load(Ordering::SeqCst);
27+
LOG.compare_and_swap(old, old << 4 | self.0 as usize, Ordering::SeqCst);
28+
}
29+
}
30+
31+
fn main() {
32+
fn die() -> D { panic!("Oh no"); }
33+
let g = thread::spawn(|| {
34+
let _nested = vec![vec![D( 1), D( 2), D( 3), D( 4)],
35+
vec![D( 5), D( 6), D( 7), D( 8)],
36+
vec![D( 9), D(10), die(), D(12)],
37+
vec![D(13), D(14), D(15), D(16)]];
38+
});
39+
assert!(g.join().is_err());
40+
41+
// When the panic occurs, we will be in the midst of constructing the
42+
// second inner vector. Therefore, we drop the elements of the
43+
// partially filled vector first, before we get around to dropping
44+
// the elements of the filled vector.
45+
46+
// Issue 23222: The order in which the elements actually get
47+
// dropped is a little funky: as noted above, we'll drop the 9+10
48+
// first, but due to #23222, they get dropped in reverse
49+
// order. Likewise, again due to #23222, we will drop the second
50+
// filled vec before the first filled vec.
51+
//
52+
// If Issue 23222 is "fixed", then presumably the corrected
53+
// expected order of events will be 0x__9_A__1_2_3_4__5_6_7_8;
54+
// that is, we would still drop 9+10 first, since they belong to
55+
// the more deeply nested expression when the panic occurs.
56+
57+
let expect = 0x__A_9__5_6_7_8__1_2_3_4;
58+
let actual = LOG.load(Ordering::SeqCst);
59+
assert!(actual == expect, "expect: 0x{:x} actual: 0x{:x}", expect, actual);
60+
}

0 commit comments

Comments
 (0)