Skip to content

Commit

Permalink
fix ~ZeroSizeType rvalues
Browse files Browse the repository at this point in the history
Closes #13360
  • Loading branch information
thestinger authored and alexcrichton committed Apr 8, 2014
1 parent cced02f commit de2567d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/librustc/middle/trans/expr.rs
Expand Up @@ -1802,11 +1802,15 @@ fn deref_once<'a>(bcx: &'a Block<'a>,
RvalueExpr(Rvalue { mode: ByRef }) => {
let scope = cleanup::temporary_scope(bcx.tcx(), expr.id);
let ptr = Load(bcx, datum.val);
bcx.fcx.schedule_free_value(scope, ptr, cleanup::HeapExchange);
if !type_is_zero_size(bcx.ccx(), content_ty) {
bcx.fcx.schedule_free_value(scope, ptr, cleanup::HeapExchange);
}
}
RvalueExpr(Rvalue { mode: ByValue }) => {
let scope = cleanup::temporary_scope(bcx.tcx(), expr.id);
bcx.fcx.schedule_free_value(scope, datum.val, cleanup::HeapExchange);
if !type_is_zero_size(bcx.ccx(), content_ty) {
bcx.fcx.schedule_free_value(scope, datum.val, cleanup::HeapExchange);
}
}
LvalueExpr => { }
}
Expand Down
13 changes: 13 additions & 0 deletions src/test/run-pass/empty-allocation-rvalue-non-null.rs
@@ -0,0 +1,13 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

pub fn main() {
let x = *~();
}

0 comments on commit de2567d

Please sign in to comment.