diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index 95bf2a7f2753a..e47362e8d9ece 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -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 => { } } diff --git a/src/test/run-pass/empty-allocation-rvalue-non-null.rs b/src/test/run-pass/empty-allocation-rvalue-non-null.rs new file mode 100644 index 0000000000000..a5fc8425cf6b0 --- /dev/null +++ b/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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub fn main() { + let x = *~(); +}