about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Woerister <michaelwoerister@gmail>2013-07-15 15:48:57 +0200
committerMichael Woerister <michaelwoerister@gmail>2013-07-19 07:57:39 +0200
commiteed2d0e1f2f4c6743b33efa06d5028fcc33db3b1 (patch)
tree85a285872fb4fa63dc15b62f4f0af2ff6a1ad94d
parent7af2e6ee451ffa9baacfc3eb04d45f7b3cee295d (diff)
downloadrust-eed2d0e1f2f4c6743b33efa06d5028fcc33db3b1.tar.gz
rust-eed2d0e1f2f4c6743b33efa06d5028fcc33db3b1.zip
debuginfo: Added support for Option<T>-like enums.
-rw-r--r--src/librustc/middle/trans/debuginfo.rs4
-rw-r--r--src/test/debug-info/option-like-enum.rs69
2 files changed, 72 insertions, 1 deletions
diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs
index 1102428a538..2f9b9f19041 100644
--- a/src/librustc/middle/trans/debuginfo.rs
+++ b/src/librustc/middle/trans/debuginfo.rs
@@ -673,7 +673,9 @@ fn create_enum_metadata(cx: &mut CrateContext,
                 0) // RuntimeLang
             }};
         }
-        _ => { return ptr::null(); }
+        adt::NullablePointer { nonnull: ref struct_def, nndiscr, _ } => {
+            return create_adt_struct_metadata(cx, struct_def, variants[nndiscr], None, span);
+        }
     }
 
     fn create_adt_struct_metadata(cx: &mut CrateContext,
diff --git a/src/test/debug-info/option-like-enum.rs b/src/test/debug-info/option-like-enum.rs
new file mode 100644
index 00000000000..c909d6f54eb
--- /dev/null
+++ b/src/test/debug-info/option-like-enum.rs
@@ -0,0 +1,69 @@
+// 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.
+
+// compile-flags:-Z extra-debug-info
+// debugger:break zzz
+// debugger:run
+// debugger:finish
+
+// debugger:print some
+// check:$1 = {0x12345678}
+
+// debugger:print none
+// check:$2 = {0x0}
+
+// debugger:print full
+// check:$3 = {454545, 0x87654321, 9988}
+
+// debugger:print empty
+// check:$4 = {0, 0x0, 0}
+
+// debugger:print droid
+// check:$5 = {id = 675675, range = 10000001, internals = 0x43218765}
+
+// debugger:print void_droid
+// check:$6 = {id = 0, range = 0, internals = 0x0}
+
+
+// If a struct has exactly two variants, one of them is empty, and the other one
+// contains a non-nullable pointer, then this value is used as the discriminator.
+// The test cases in this file make sure that something readable is generated for
+// this kind of types.
+
+enum MoreFields<'self> {
+    Full(u32, &'self int, i16),
+    Empty
+}
+
+enum NamedFields<'self> {
+    Droid { id: i32, range: i64, internals: &'self int },
+    Void
+}
+
+fn main() {
+
+    let some : Option<&u32> = Some(unsafe { std::cast::transmute(0x12345678) });
+    let none : Option<&u32> = None;
+
+    let full = Full(454545, unsafe { std::cast::transmute(0x87654321) }, 9988);
+
+    let int_val = 0;
+    let mut empty = Full(0, &int_val, 0);
+    empty = Empty;
+
+    let droid = Droid { id: 675675, range: 10000001, internals: unsafe { std::cast::transmute(0x43218765) } };
+
+    let mut void_droid = Droid { id: 0, range: 0, internals: &int_val };
+    void_droid = Void;
+
+    zzz();
+}
+
+fn zzz() {()}
\ No newline at end of file