]> git.lizzy.rs Git - rust.git/commitdiff
Fix dereference of temporary immediate newtype structs
authorSeo Sanghyeon <sanxiyn@gmail.com>
Mon, 1 Jul 2013 16:08:51 +0000 (01:08 +0900)
committerSeo Sanghyeon <sanxiyn@gmail.com>
Mon, 1 Jul 2013 16:08:51 +0000 (01:08 +0900)
src/librustc/middle/trans/datum.rs
src/test/run-pass/newtype-temporary.rs [new file with mode: 0644]

index b9829fd47c1a6ec49ee83824c808e7d19eb2f7f7..8ee4b6644cbe97d1a5d3152440029fc99ceb9103 100644 (file)
@@ -690,7 +690,14 @@ pub fn try_deref(&self,
                     }
                     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 (file)
index 0000000..d2407f3
--- /dev/null
@@ -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);
+}