ppaux -- add Repr implementations

This commit is contained in:
Niko Matsakis 2014-02-07 14:51:18 -05:00
parent 95c53c049c
commit 42cd820c62

View File

@ -565,11 +565,26 @@ impl<T:Repr> Repr for Option<T> {
fn repr(&self, tcx: ctxt) -> ~str {
match self {
&None => ~"None",
&Some(ref t) => format!("Some({})", t.repr(tcx))
&Some(ref t) => t.repr(tcx),
}
}
}
impl<T:Repr,U:Repr> Repr for Result<T,U> {
fn repr(&self, tcx: ctxt) -> ~str {
match self {
&Ok(ref t) => t.repr(tcx),
&Err(ref u) => format!("Err({})", u.repr(tcx))
}
}
}
impl Repr for () {
fn repr(&self, _tcx: ctxt) -> ~str {
~"()"
}
}
impl<T:Repr> Repr for @T {
fn repr(&self, tcx: ctxt) -> ~str {
(&**self).repr(tcx)
@ -1021,3 +1036,32 @@ impl UserString for AbiSet {
self.to_str()
}
}
impl Repr for ty::UpvarId {
fn repr(&self, tcx: ctxt) -> ~str {
format!("UpvarId({};`{}`;{})",
self.var_id,
ty::local_var_name_str(tcx, self.var_id),
self.closure_expr_id)
}
}
impl Repr for ast::Mutability {
fn repr(&self, _tcx: ctxt) -> ~str {
format!("{:?}", *self)
}
}
impl Repr for ty::BorrowKind {
fn repr(&self, _tcx: ctxt) -> ~str {
format!("{:?}", *self)
}
}
impl Repr for ty::UpvarBorrow {
fn repr(&self, tcx: ctxt) -> ~str {
format!("UpvarBorrow({}, {})",
self.kind.repr(tcx),
self.region.repr(tcx))
}
}