Skip to content

Commit

Permalink
ppaux -- add Repr implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Feb 11, 2014
1 parent 95c53c0 commit 42cd820
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion src/librustc/util/ppaux.rs
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
}
}

0 comments on commit 42cd820

Please sign in to comment.