Skip to content

Commit 76c9028

Browse files
committed
Fix uninit() intrinsic when used with empty types
1 parent fd31830 commit 76c9028

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/librustc/middle/trans/intrinsic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ pub fn trans_intrinsic(ccx: @CrateContext,
317317
"uninit" => {
318318
// Do nothing, this is effectively a no-op
319319
let retty = substs.tys[0];
320-
if type_is_immediate(ccx, retty) && !ty::type_is_nil(retty) {
320+
if type_is_immediate(ccx, retty) && !type_is_voidish(ccx, retty) {
321321
unsafe {
322322
Ret(bcx, lib::llvm::llvm::LLVMGetUndef(type_of(ccx, retty).to_ref()));
323323
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2012-2013 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 the uninit() construct returning various empty types.
12+
13+
use std::vec;
14+
use std::unstable::intrinsics;
15+
16+
#[deriving(Clone)]
17+
struct Foo;
18+
19+
fn main() {
20+
unsafe {
21+
let _x: Foo = intrinsics::uninit();
22+
let _x: [Foo, ..2] = intrinsics::uninit();
23+
}
24+
}

0 commit comments

Comments
 (0)