Skip to content

Commit 42cd820

Browse files
committed
ppaux -- add Repr implementations
1 parent 95c53c0 commit 42cd820

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

src/librustc/util/ppaux.rs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,11 +565,26 @@ impl<T:Repr> Repr for Option<T> {
565565
fn repr(&self, tcx: ctxt) -> ~str {
566566
match self {
567567
&None => ~"None",
568-
&Some(ref t) => format!("Some({})", t.repr(tcx))
568+
&Some(ref t) => t.repr(tcx),
569569
}
570570
}
571571
}
572572

573+
impl<T:Repr,U:Repr> Repr for Result<T,U> {
574+
fn repr(&self, tcx: ctxt) -> ~str {
575+
match self {
576+
&Ok(ref t) => t.repr(tcx),
577+
&Err(ref u) => format!("Err({})", u.repr(tcx))
578+
}
579+
}
580+
}
581+
582+
impl Repr for () {
583+
fn repr(&self, _tcx: ctxt) -> ~str {
584+
~"()"
585+
}
586+
}
587+
573588
impl<T:Repr> Repr for @T {
574589
fn repr(&self, tcx: ctxt) -> ~str {
575590
(&**self).repr(tcx)
@@ -1021,3 +1036,32 @@ impl UserString for AbiSet {
10211036
self.to_str()
10221037
}
10231038
}
1039+
1040+
impl Repr for ty::UpvarId {
1041+
fn repr(&self, tcx: ctxt) -> ~str {
1042+
format!("UpvarId({};`{}`;{})",
1043+
self.var_id,
1044+
ty::local_var_name_str(tcx, self.var_id),
1045+
self.closure_expr_id)
1046+
}
1047+
}
1048+
1049+
impl Repr for ast::Mutability {
1050+
fn repr(&self, _tcx: ctxt) -> ~str {
1051+
format!("{:?}", *self)
1052+
}
1053+
}
1054+
1055+
impl Repr for ty::BorrowKind {
1056+
fn repr(&self, _tcx: ctxt) -> ~str {
1057+
format!("{:?}", *self)
1058+
}
1059+
}
1060+
1061+
impl Repr for ty::UpvarBorrow {
1062+
fn repr(&self, tcx: ctxt) -> ~str {
1063+
format!("UpvarBorrow({}, {})",
1064+
self.kind.repr(tcx),
1065+
self.region.repr(tcx))
1066+
}
1067+
}

0 commit comments

Comments
 (0)