Skip to content

Commit de2567d

Browse files
thestingeralexcrichton
authored andcommitted
fix ~ZeroSizeType rvalues
Closes #13360
1 parent cced02f commit de2567d

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/librustc/middle/trans/expr.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1802,11 +1802,15 @@ fn deref_once<'a>(bcx: &'a Block<'a>,
18021802
RvalueExpr(Rvalue { mode: ByRef }) => {
18031803
let scope = cleanup::temporary_scope(bcx.tcx(), expr.id);
18041804
let ptr = Load(bcx, datum.val);
1805-
bcx.fcx.schedule_free_value(scope, ptr, cleanup::HeapExchange);
1805+
if !type_is_zero_size(bcx.ccx(), content_ty) {
1806+
bcx.fcx.schedule_free_value(scope, ptr, cleanup::HeapExchange);
1807+
}
18061808
}
18071809
RvalueExpr(Rvalue { mode: ByValue }) => {
18081810
let scope = cleanup::temporary_scope(bcx.tcx(), expr.id);
1809-
bcx.fcx.schedule_free_value(scope, datum.val, cleanup::HeapExchange);
1811+
if !type_is_zero_size(bcx.ccx(), content_ty) {
1812+
bcx.fcx.schedule_free_value(scope, datum.val, cleanup::HeapExchange);
1813+
}
18101814
}
18111815
LvalueExpr => { }
18121816
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2014 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+
pub fn main() {
12+
let x = *~();
13+
}

0 commit comments

Comments
 (0)