From a6a993ee7137cf1640a7b16ddcd516a6d78f91be Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Tue, 3 Sep 2013 04:45:00 -0400 Subject: [PATCH] repr: add very basic support for functions Closes #8917 --- src/libstd/repr.rs | 22 +++++++++++++++++----- 1 file changed, 17 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, 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::, "fn(&mut int, &mut int)"); + exact_test(&is_alphabetic, "fn(char) -> bool"); exact_test(&(~5 as ~ToStr), "~to_str::ToStr:Send"); struct Foo;