about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-09-03 08:06:04 -0700
committerbors <bors@rust-lang.org>2013-09-03 08:06:04 -0700
commitc14daba3b2f3218438a6928ed0676986c6339d48 (patch)
tree62c821dd7caa500db2da6dea3ab3190d218a3953 /src/libstd
parent1ac8e8885bb1917f71ce432dcf181253b47f0bca (diff)
parenta6a993ee7137cf1640a7b16ddcd516a6d78f91be (diff)
downloadrust-c14daba3b2f3218438a6928ed0676986c6339d48.tar.gz
rust-c14daba3b2f3218438a6928ed0676986c6339d48.zip
auto merge of #8947 : thestinger/rust/name, r=huonw
Storing the type name in the `tydesc` aims to avoid the need to pass a type name in almost every single visitor method.

It would likely be much saner for `repr` to simply be passed the `TyDesc` corresponding to the function or just the type name, but this is good enough for now.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/repr.rs22
-rw-r--r--src/libstd/unstable/intrinsics.rs3
2 files changed, 20 insertions, 5 deletions
diff --git a/src/libstd/repr.rs b/src/libstd/repr.rs
index 31f5b6f5208..7141a17d133 100644
--- a/src/libstd/repr.rs
+++ b/src/libstd/repr.rs
@@ -566,14 +566,22 @@ impl<'self> TyVisitor for ReprVisitor<'self> {
         true
     }
 
-    fn visit_fn_input(&mut self, _i: uint, _mode: uint, _inner: *TyDesc) -> bool {
-        // FIXME: #8917: should print out the parameter types here, separated by commas
+    fn visit_fn_input(&mut self, i: uint, _mode: uint, inner: *TyDesc) -> bool {
+        if i != 0 {
+            self.writer.write(", ".as_bytes());
+        }
+        let name = unsafe { (*inner).name };
+        self.writer.write(name.as_bytes());
         true
     }
 
-    fn visit_fn_output(&mut self, _retstyle: uint, _inner: *TyDesc) -> bool {
+    fn visit_fn_output(&mut self, _retstyle: uint, inner: *TyDesc) -> bool {
         self.writer.write(")".as_bytes());
-        // FIXME: #8917: should print out the output type here, as `-> T`
+        let name = unsafe { (*inner).name };
+        if name != "()" {
+            self.writer.write(" -> ".as_bytes());
+            self.writer.write(name.as_bytes());
+        }
         true
     }
 
@@ -620,6 +628,8 @@ fn test_repr() {
     use str;
     use str::Str;
     use rt::io::Decorator;
+    use util::swap;
+    use char::is_alphabetic;
 
     fn exact_test<T>(t: &T, e:&str) {
         let mut m = io::mem::MemWriter::new();
@@ -674,7 +684,9 @@ fn test_repr() {
     exact_test(&(10u64, ~"hello"),
                "(10u64, ~\"hello\")");
 
-    exact_test(&(&println), "&fn()");
+    exact_test(&println, "fn(&str)");
+    exact_test(&swap::<int>, "fn(&mut int, &mut int)");
+    exact_test(&is_alphabetic, "fn(char) -> bool");
     exact_test(&(~5 as ~ToStr), "~to_str::ToStr:Send");
 
     struct Foo;
diff --git a/src/libstd/unstable/intrinsics.rs b/src/libstd/unstable/intrinsics.rs
index fbd5bdaf587..c3791d18b38 100644
--- a/src/libstd/unstable/intrinsics.rs
+++ b/src/libstd/unstable/intrinsics.rs
@@ -66,6 +66,9 @@ pub struct TyDesc {
     // `U`, but in the case of `@Trait` or `~Trait` objects, the type
     // `U` is unknown.
     borrow_offset: uint,
+
+    // Name corresponding to the type
+    name: &'static str
 }
 
 #[lang="opaque"]