Skip to content

Commit 8aa26ad

Browse files
committed
Fix dereference of temporary immediate newtype structs
1 parent fd19289 commit 8aa26ad

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/librustc/middle/trans/datum.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,14 @@ impl Datum {
690690
}
691691
ByValue => {
692692
assert!(ty::type_is_immediate(bcx.tcx(), ty));
693-
(Some(Datum {ty: ty, ..*self}), bcx)
693+
(
694+
Some(Datum {
695+
val: ExtractValue(bcx, self.val, 0),
696+
ty: ty,
697+
mode: ByValue
698+
}),
699+
bcx
700+
)
694701
}
695702
}
696703
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 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+
struct Foo(uint);
12+
13+
fn foo() -> Foo {
14+
Foo(42)
15+
}
16+
17+
fn main() {
18+
assert_eq!(*foo(), 42);
19+
}

0 commit comments

Comments
 (0)