Skip to content

Commit

Permalink
repr: add very basic support for functions
Browse files Browse the repository at this point in the history
Closes #8917
  • Loading branch information
thestinger committed Sep 3, 2013
1 parent 09ad0cd commit a6a993e
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/libstd/repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down

9 comments on commit a6a993e

@bors
Copy link
Contributor

@bors bors commented on a6a993e Sep 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on a6a993e Sep 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging thestinger/rust/name = a6a993e into auto

@bors
Copy link
Contributor

@bors bors commented on a6a993e Sep 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thestinger/rust/name = a6a993e merged ok, testing candidate = ccd68d43

@bors
Copy link
Contributor

@bors bors commented on a6a993e Sep 3, 2013

@bors
Copy link
Contributor

@bors bors commented on a6a993e Sep 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on a6a993e Sep 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging thestinger/rust/name = a6a993e into auto

@bors
Copy link
Contributor

@bors bors commented on a6a993e Sep 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thestinger/rust/name = a6a993e merged ok, testing candidate = c14daba

@bors
Copy link
Contributor

@bors bors commented on a6a993e Sep 3, 2013

@bors
Copy link
Contributor

@bors bors commented on a6a993e Sep 3, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = c14daba

Please sign in to comment.