diff options
| author | Seo Sanghyeon <sanxiyn@gmail.com> | 2013-07-02 01:08:51 +0900 |
|---|---|---|
| committer | Seo Sanghyeon <sanxiyn@gmail.com> | 2013-07-02 01:08:51 +0900 |
| commit | 8aa26ad4547007996e1c3c0f1aa941ea8689b5a6 (patch) | |
| tree | 0719a772b138bd2b3cbfb17ffa5672341296ea92 | |
| parent | fd192891085ecb3c4fee458b2dc374aa5d1ed18d (diff) | |
| download | rust-8aa26ad4547007996e1c3c0f1aa941ea8689b5a6.tar.gz rust-8aa26ad4547007996e1c3c0f1aa941ea8689b5a6.zip | |
Fix dereference of temporary immediate newtype structs
| -rw-r--r-- | src/librustc/middle/trans/datum.rs | 9 | ||||
| -rw-r--r-- | src/test/run-pass/newtype-temporary.rs | 19 |
2 files changed, 27 insertions, 1 deletions
diff --git a/src/librustc/middle/trans/datum.rs b/src/librustc/middle/trans/datum.rs index b9829fd47c1..8ee4b6644cb 100644 --- a/src/librustc/middle/trans/datum.rs +++ b/src/librustc/middle/trans/datum.rs @@ -690,7 +690,14 @@ impl Datum { } ByValue => { assert!(ty::type_is_immediate(bcx.tcx(), ty)); - (Some(Datum {ty: ty, ..*self}), bcx) + ( + Some(Datum { + val: ExtractValue(bcx, self.val, 0), + ty: ty, + mode: ByValue + }), + bcx + ) } } } diff --git a/src/test/run-pass/newtype-temporary.rs b/src/test/run-pass/newtype-temporary.rs new file mode 100644 index 00000000000..d2407f3d605 --- /dev/null +++ b/src/test/run-pass/newtype-temporary.rs @@ -0,0 +1,19 @@ +// Copyright 2013 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. + +struct Foo(uint); + +fn foo() -> Foo { + Foo(42) +} + +fn main() { + assert_eq!(*foo(), 42); +} |
