Skip to content

Commit eaeede2

Browse files
committed
Fix ICE caused by Drop implementations for unsized types
Fixes rust-lang#26709
1 parent 4c246ec commit eaeede2

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/librustc_trans/trans/glue.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ fn trans_struct_drop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
355355
let ty = Type::from_ref(llvm::LLVMTypeOf(dtor_addr));
356356
ty.element_type().func_params()
357357
};
358-
assert_eq!(params.len(), 1);
358+
assert_eq!(params.len(), if type_is_sized(bcx.tcx(), t) { 1 } else { 2 });
359359

360360
// Be sure to put the contents into a scope so we can use an invoke
361361
// instruction to call the user destructor but still call the field
@@ -371,7 +371,12 @@ fn trans_struct_drop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
371371

372372
let glue_type = get_drop_glue_type(bcx.ccx(), t);
373373
let dtor_ty = bcx.tcx().mk_ctor_fn(class_did, &[glue_type], bcx.tcx().mk_nil());
374-
let (_, bcx) = invoke(bcx, dtor_addr, &[v0], dtor_ty, DebugLoc::None);
374+
let (_, bcx) = if type_is_sized(bcx.tcx(), t) {
375+
invoke(bcx, dtor_addr, &[v0], dtor_ty, DebugLoc::None)
376+
} else {
377+
let args = [Load(bcx, expr::get_dataptr(bcx, v0)), Load(bcx, expr::get_len(bcx, v0))];
378+
invoke(bcx, dtor_addr, &args, dtor_ty, DebugLoc::None)
379+
};
375380

376381
bcx.fcx.pop_and_trans_custom_cleanup_scope(bcx, contents_scope)
377382
}

src/test/run-pass/issue-26709.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
struct Wrapper<'a, T: ?Sized>(&'a mut i32, T);
12+
13+
impl<'a, T: ?Sized> Drop for Wrapper<'a, T> {
14+
fn drop(&mut self) {
15+
*self.0 = 432;
16+
}
17+
}
18+
19+
fn main() {
20+
let mut x = 0;
21+
{
22+
let wrapper = Box::new(Wrapper(&mut x, 123));
23+
let _: Box<Wrapper<Send>> = wrapper;
24+
}
25+
assert_eq!(432, x)
26+
}

0 commit comments

Comments
 (0)