Fix handling of discriminantless univariant enums in Rust

Message ID CAFOnWkkJJwoPXEYZ3QrYOwbHS-CuQi2YLJSJHvBt6YM3H9Zq7g@mail.gmail.com
State New, archived
Headers

Commit Message

Manish Goregaokar Oct. 28, 2016, 7:56 p.m. UTC
  Fixed another enum issue, reported in the same PR:

(I'm not sure if this is the correct fix)

From: Manish Goregaokar <manish@mozilla.com>
Date: Thu, 27 Oct 2016 16:46:34 -0700
Subject: Handle field access on encoded struct-like enums

2016-10-28  Manish Goregaokar  <manish@mozilla.com>

gdb/ChangeLog:
    * rust-lang.c (rust_evaluate_subexp): Handle field access
    on encoded struct-like enums

gdb/testsuite/ChangeLog:
    * simple.rs: Add test for encoded struct-like enums
    * simple.exp: Add test expectations
---
 gdb/rust-lang.c                   |  4 +++-
 gdb/testsuite/gdb.rust/simple.exp |  6 ++++++
 gdb/testsuite/gdb.rust/simple.rs  | 20 ++++++++++++++++++++
 3 files changed, 29 insertions(+), 1 deletion(-)
  

Patch

diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 9d13353..9569584 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1736,7 +1736,9 @@  tuple structs, and tuple-like enum variants"));
         variant_type = TYPE_FIELD_TYPE (type, disr.field_no);

         if (variant_type == NULL
-        || rust_tuple_variant_type_p (variant_type))
+            || (disr.is_encoded
+                ? rust_tuple_struct_type_p (variant_type)
+                : rust_tuple_variant_type_p (variant_type)))
           error(_("Attempting to access named field %s of tuple variant %s, \
 which has only anonymous fields"),
             field_name, disr.name);
diff --git a/gdb/testsuite/gdb.rust/simple.exp
b/gdb/testsuite/gdb.rust/simple.exp
index dbfc88a..075bff7 100644
--- a/gdb/testsuite/gdb.rust/simple.exp
+++ b/gdb/testsuite/gdb.rust/simple.exp
@@ -222,3 +222,9 @@  gdb_test "print (1,)" "Tuple expressions not supported yet"
 gdb_test "print (1)" " = 1"

 gdb_test "print 23..97.0" "Range expression with different types"
+
+gdb_test "print (*parametrized.next.val)" \
+    " = simple::ParametrizedStruct<i32> {next:
simple::ParametrizedEnum<Box<simple::ParametrizedStruct<i32>>>::Empty,
value: 1}"
+gdb_test "print parametrized.next.val" " =
\\(simple::ParametrizedStruct<i32> \\*\\) $hex"
+gdb_test "print parametrized" \
+    " = simple::ParametrizedStruct<i32> \\{next:
simple::ParametrizedEnum<Box<simple::ParametrizedStruct<i32>>>::Val\\{val:
$hex\\}, value: 0\\}"
\ No newline at end of file
diff --git a/gdb/testsuite/gdb.rust/simple.rs b/gdb/testsuite/gdb.rust/simple.rs
index b2e29ae..e756296 100644
--- a/gdb/testsuite/gdb.rust/simple.rs
+++ b/gdb/testsuite/gdb.rust/simple.rs
@@ -67,6 +67,16 @@  enum Univariant {
     Foo {a: u8}
 }

+enum ParametrizedEnum<T> {
+    Val { val: T },
+    Empty,
+}
+
+struct ParametrizedStruct<T> {
+    next: ParametrizedEnum<Box<ParametrizedStruct<T>>>,
+    value: T
+}
+
 fn main () {
     let a = ();
     let b : [i32; 0] = [];
@@ -123,6 +133,16 @@  fn main () {
     let custom_some = NonZeroOptimized::Value("hi".into());
     let custom_none = NonZeroOptimized::Empty;

+    let parametrized = ParametrizedStruct {
+        next: ParametrizedEnum::Val {
+            val: Box::new(ParametrizedStruct {
+                next: ParametrizedEnum::Empty,
+                value: 1,
+            })
+        },
+        value: 0,
+    };
+
     println!("{}, {}", x.0, x.1);        // set breakpoint here
     println!("{}", diff2(92, 45));
     empty();