From 125677e3f0e24fe753a8f24d2eead9057858b88e Mon Sep 17 00:00:00 2001
From: Richo Healey <richo@psych0tik.net>
Date: Thu, 20 Nov 2014 16:30:05 -0800
Subject: [PATCH 1/4] Add vim modeline to lldb formatter

The file doesn't adhere to the python standard, but this will let vi do
The Right Thing by default
---
 src/etc/lldb_rust_formatters.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/etc/lldb_rust_formatters.py b/src/etc/lldb_rust_formatters.py
index ca895414635..01a6f1c6328 100644
--- a/src/etc/lldb_rust_formatters.py
+++ b/src/etc/lldb_rust_formatters.py
@@ -243,3 +243,5 @@ def is_vec_slice(val):
 
   type_name = extract_type_name(ty.GetName()).replace("&'static", "&").replace(" ", "")
   return type_name.startswith("&[") and type_name.endswith("]")
+
+# vi: sw=2:ts=2

From 0ab01048d5c3bed1f3e8e1d00a33d8d597fc449e Mon Sep 17 00:00:00 2001
From: Richo Healey <richo@psych0tik.net>
Date: Thu, 20 Nov 2014 16:31:56 -0800
Subject: [PATCH 2/4] lldb: refactor print_vec_slice_val

Be more idiomatic and rely less on fiddly construction of output
---
 src/etc/lldb_rust_formatters.py | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/src/etc/lldb_rust_formatters.py b/src/etc/lldb_rust_formatters.py
index 01a6f1c6328..dba9ca6153f 100644
--- a/src/etc/lldb_rust_formatters.py
+++ b/src/etc/lldb_rust_formatters.py
@@ -43,8 +43,6 @@ def print_struct_val(val, internal_dict):
     return print_struct_val_starting_from(0, val, internal_dict)
 
 def print_vec_slice_val(val, internal_dict):
-  output = "&["
-
   length = val.GetChildAtIndex(1).GetValueAsUnsigned()
 
   data_ptr_val = val.GetChildAtIndex(0)
@@ -56,16 +54,12 @@ def print_vec_slice_val(val, internal_dict):
 
   start_address = data_ptr_val.GetValueAsUnsigned()
 
-  for i in range(length):
+  def render_element(i):
     address = start_address + i * element_type_size
-    element_val = val.CreateValueFromAddress( val.GetName() + ("[%s]" % i), address, element_type )
-    output += print_val(element_val, internal_dict)
+    element_val = val.CreateValueFromAddress( val.GetName() + ("[%s]" % i), address, element_type)
+    return print_val(element_val, internal_dict)
 
-    if i != length - 1:
-      output += ", "
-
-  output += "]"
-  return output
+  return "&[%s]" % (', '.join([render_element(i) for i in range(length)]))
 
 def print_struct_val_starting_from(field_start_index, val, internal_dict):
   '''

From 7191cd92c1f0ef3d1373e9b494575cb336b5e4c7 Mon Sep 17 00:00:00 2001
From: Richo Healey <richo@psych0tik.net>
Date: Thu, 20 Nov 2014 17:24:18 -0800
Subject: [PATCH 3/4] lldb: Clean up struct printing

---
 src/etc/lldb_rust_formatters.py | 36 ++++++++++++++-------------------
 1 file changed, 15 insertions(+), 21 deletions(-)

diff --git a/src/etc/lldb_rust_formatters.py b/src/etc/lldb_rust_formatters.py
index dba9ca6153f..642235ed4e3 100644
--- a/src/etc/lldb_rust_formatters.py
+++ b/src/etc/lldb_rust_formatters.py
@@ -71,39 +71,33 @@ def print_struct_val_starting_from(field_start_index, val, internal_dict):
   t = val.GetType()
   has_field_names = type_has_field_names(t)
   type_name = extract_type_name(t.GetName())
-  output = ""
-
-  if not type_name.startswith("("):
-    # this is a tuple, so don't print the type name
-    output += type_name
 
   if has_field_names:
-    output += " { \n"
+      template = "%(type_name)s {\n%(body)s\n}"
+      separator = ", \n"
   else:
-    output += "("
+      template = "%(type_name)s(%(body)s)"
+      separator = ", "
+
+  if type_name.startswith("("):
+    # this is a tuple, so don't print the type name
+    type_name = ""
 
   num_children = val.num_children
 
-  for child_index in range(field_start_index, num_children):
+  def render_child(child_index):
+    this = ""
     if has_field_names:
       field_name = t.GetFieldAtIndex(child_index).GetName()
-      output += field_name + ": "
+      this += field_name + ": "
 
     field_val = val.GetChildAtIndex(child_index)
-    output += print_val(field_val, internal_dict)
+    return this + print_val(field_val, internal_dict)
 
-    if child_index != num_children - 1:
-      output += ", "
+  body = separator.join([render_child(idx) for idx in range(field_start_index, num_children)])
 
-    if has_field_names:
-      output += "\n"
-
-  if has_field_names:
-    output += "}"
-  else:
-    output += ")"
-
-  return output
+  return template % {"type_name": type_name,
+                     "body": body}
 
 
 def print_enum_val(val, internal_dict):

From 68f90a2cad5d5230aa59ec95b87e5467cd554dac Mon Sep 17 00:00:00 2001
From: Richo Healey <richo@psych0tik.net>
Date: Fri, 21 Nov 2014 10:50:44 -0800
Subject: [PATCH 4/4] compiletest: namespaced enums fallout

---
 src/compiletest/runtest.rs | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs
index 75dc45d16eb..616e44f1800 100644
--- a/src/compiletest/runtest.rs
+++ b/src/compiletest/runtest.rs
@@ -1161,7 +1161,7 @@ fn compile_test_(config: &Config, props: &TestProps,
     let args = make_compile_args(config,
                                  props,
                                  link_args,
-                                 |a, b| ThisFile(make_exe_name(a, b)), testfile);
+                                 |a, b| TargetLocation::ThisFile(make_exe_name(a, b)), testfile);
     compose_and_run_compiler(config, props, testfile, args, None)
 }
 
@@ -1219,7 +1219,7 @@ fn compose_and_run_compiler(
                               crate_type,
                               |a,b| {
                                   let f = make_lib_name(a, b, testfile);
-                                  ThisDirectory(f.dir_path())
+                                  TargetLocation::ThisDirectory(f.dir_path())
                               },
                               &abs_ab);
         let auxres = compose_and_run(config,
@@ -1296,11 +1296,11 @@ fn make_compile_args(config: &Config,
         args.push("prefer-dynamic".to_string());
     }
     let path = match xform_file {
-        ThisFile(path) => {
+        TargetLocation::ThisFile(path) => {
             args.push("-o".to_string());
             path
         }
-        ThisDirectory(path) => {
+        TargetLocation::ThisDirectory(path) => {
             args.push("--out-dir".to_string());
             path
         }
@@ -1672,7 +1672,8 @@ fn compile_test_and_save_bitcode(config: &Config, props: &TestProps,
     let args = make_compile_args(config,
                                  props,
                                  link_args,
-                                 |a, b| ThisDirectory(output_base_name(a, b).dir_path()),
+                                 |a, b| TargetLocation::ThisDirectory(
+                                     output_base_name(a, b).dir_path()),
                                  testfile);
     compose_and_run_compiler(config, props, testfile, args, None)
 }