Skip to content

Commit b7f53b8

Browse files
committed
fix drop of fat ptrs
1 parent 356bf52 commit b7f53b8

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/librustc_trans/trans/mir/operand.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
245245
}
246246
let lvalue = self.trans_lvalue(bcx, lvalue);
247247
let ty = lvalue.ty.to_ty(bcx.tcx());
248-
if !glue::type_needs_drop(bcx.tcx(), ty) ||
249-
common::type_is_fat_ptr(bcx.tcx(), ty) {
248+
if !glue::type_needs_drop(bcx.tcx(), ty) {
250249
return
251250
} else {
252251
drop::drop_fill(bcx, lvalue.llval, ty);

src/test/run-pass/mir_fat_ptr_drop.rs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 ordinary fat pointer operations work.
12+
13+
#![feature(braced_empty_structs)]
14+
#![feature(rustc_attrs)]
15+
16+
use std::sync::atomic;
17+
use std::sync::atomic::Ordering::SeqCst;
18+
19+
static COUNTER: atomic::AtomicUsize = atomic::ATOMIC_USIZE_INIT;
20+
21+
struct DropMe {
22+
}
23+
24+
impl Drop for DropMe {
25+
fn drop(&mut self) {
26+
COUNTER.fetch_add(1, SeqCst);
27+
}
28+
}
29+
30+
#[rustc_mir]
31+
fn fat_ptr_move_then_drop(a: Box<[DropMe]>) {
32+
let b = a;
33+
}
34+
35+
fn main() {
36+
let a: Box<[DropMe]> = Box::new([DropMe { }]);
37+
fat_ptr_move_then_drop(a);
38+
assert_eq!(COUNTER.load(SeqCst), 1);
39+
}

0 commit comments

Comments
 (0)