Skip to content

Commit a6a993e

Browse files
committed
repr: add very basic support for functions
Closes #8917
1 parent 09ad0cd commit a6a993e

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/libstd/repr.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -566,14 +566,22 @@ impl<'self> TyVisitor for ReprVisitor<'self> {
566566
true
567567
}
568568

569-
fn visit_fn_input(&mut self, _i: uint, _mode: uint, _inner: *TyDesc) -> bool {
570-
// FIXME: #8917: should print out the parameter types here, separated by commas
569+
fn visit_fn_input(&mut self, i: uint, _mode: uint, inner: *TyDesc) -> bool {
570+
if i != 0 {
571+
self.writer.write(", ".as_bytes());
572+
}
573+
let name = unsafe { (*inner).name };
574+
self.writer.write(name.as_bytes());
571575
true
572576
}
573577

574-
fn visit_fn_output(&mut self, _retstyle: uint, _inner: *TyDesc) -> bool {
578+
fn visit_fn_output(&mut self, _retstyle: uint, inner: *TyDesc) -> bool {
575579
self.writer.write(")".as_bytes());
576-
// FIXME: #8917: should print out the output type here, as `-> T`
580+
let name = unsafe { (*inner).name };
581+
if name != "()" {
582+
self.writer.write(" -> ".as_bytes());
583+
self.writer.write(name.as_bytes());
584+
}
577585
true
578586
}
579587

@@ -620,6 +628,8 @@ fn test_repr() {
620628
use str;
621629
use str::Str;
622630
use rt::io::Decorator;
631+
use util::swap;
632+
use char::is_alphabetic;
623633

624634
fn exact_test<T>(t: &T, e:&str) {
625635
let mut m = io::mem::MemWriter::new();
@@ -674,7 +684,9 @@ fn test_repr() {
674684
exact_test(&(10u64, ~"hello"),
675685
"(10u64, ~\"hello\")");
676686

677-
exact_test(&(&println), "&fn()");
687+
exact_test(&println, "fn(&str)");
688+
exact_test(&swap::<int>, "fn(&mut int, &mut int)");
689+
exact_test(&is_alphabetic, "fn(char) -> bool");
678690
exact_test(&(~5 as ~ToStr), "~to_str::ToStr:Send");
679691

680692
struct Foo;

0 commit comments

Comments
 (0)