Skip to content

Commit dc6af49

Browse files
committed
use the derived Debug rather than our custom written ones
That encoding that the custom Debugs was using is rather inscrutable, and incomplete.
1 parent a17e724 commit dc6af49

File tree

1 file changed

+5
-60
lines changed

1 file changed

+5
-60
lines changed

src/librustc/middle/mem_categorization.rs

Lines changed: 5 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ use std::fmt;
8888
use std::rc::Rc;
8989
use util::nodemap::ItemLocalMap;
9090

91-
#[derive(Clone, PartialEq)]
91+
#[derive(Clone, Debug, PartialEq)]
9292
pub enum Categorization<'tcx> {
9393
Rvalue(ty::Region<'tcx>), // temporary val, argument is its scope
9494
StaticItem,
@@ -109,7 +109,7 @@ pub struct Upvar {
109109
}
110110

111111
// different kinds of pointers:
112-
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
112+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
113113
pub enum PointerKind<'tcx> {
114114
/// `Box<T>`
115115
Unique,
@@ -177,7 +177,7 @@ pub enum Note {
177177
// dereference, but its type is the type *before* the dereference
178178
// (`@T`). So use `cmt.ty` to find the type of the value in a consistent
179179
// fashion. For more details, see the method `cat_pattern`
180-
#[derive(Clone, PartialEq)]
180+
#[derive(Clone, Debug, PartialEq)]
181181
pub struct cmt_<'tcx> {
182182
pub id: ast::NodeId, // id of expr/pat producing this value
183183
pub span: Span, // span of same expr/pat
@@ -750,12 +750,13 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
750750

751751
let kind = match self.node_ty(fn_hir_id)?.sty {
752752
ty::TyGenerator(..) => ty::ClosureKind::FnOnce,
753-
_ => {
753+
ty::TyClosure(..) => {
754754
match self.tables.closure_kinds().get(fn_hir_id) {
755755
Some(&(kind, _)) => kind,
756756
None => span_bug!(span, "missing closure kind"),
757757
}
758758
}
759+
ref t => span_bug!(span, "unexpected type for fn in mem_categorization: {:?}", t),
759760
};
760761

761762
let closure_expr_def_index = self.tcx.hir.local_def_id(fn_node_id).index;
@@ -1499,41 +1500,6 @@ impl<'tcx> cmt_<'tcx> {
14991500
}
15001501
}
15011502

1502-
impl<'tcx> fmt::Debug for cmt_<'tcx> {
1503-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1504-
write!(f, "{{{:?} id:{} m:{:?} ty:{:?}}}",
1505-
self.cat,
1506-
self.id,
1507-
self.mutbl,
1508-
self.ty)
1509-
}
1510-
}
1511-
1512-
impl<'tcx> fmt::Debug for Categorization<'tcx> {
1513-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1514-
match *self {
1515-
Categorization::StaticItem => write!(f, "static"),
1516-
Categorization::Rvalue(r) => { write!(f, "rvalue({:?})", r) }
1517-
Categorization::Local(id) => {
1518-
let name = ty::tls::with(|tcx| tcx.hir.name(id));
1519-
write!(f, "local({})", name)
1520-
}
1521-
Categorization::Upvar(upvar) => {
1522-
write!(f, "upvar({:?})", upvar)
1523-
}
1524-
Categorization::Deref(ref cmt, ptr) => {
1525-
write!(f, "{:?}-{:?}->", cmt.cat, ptr)
1526-
}
1527-
Categorization::Interior(ref cmt, interior) => {
1528-
write!(f, "{:?}.{:?}", cmt.cat, interior)
1529-
}
1530-
Categorization::Downcast(ref cmt, _) => {
1531-
write!(f, "{:?}->(enum)", cmt.cat)
1532-
}
1533-
}
1534-
}
1535-
}
1536-
15371503
pub fn ptr_sigil(ptr: PointerKind) -> &'static str {
15381504
match ptr {
15391505
Unique => "Box",
@@ -1547,27 +1513,6 @@ pub fn ptr_sigil(ptr: PointerKind) -> &'static str {
15471513
}
15481514
}
15491515

1550-
impl<'tcx> fmt::Debug for PointerKind<'tcx> {
1551-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1552-
match *self {
1553-
Unique => write!(f, "Box"),
1554-
BorrowedPtr(ty::ImmBorrow, ref r) |
1555-
Implicit(ty::ImmBorrow, ref r) => {
1556-
write!(f, "&{:?}", r)
1557-
}
1558-
BorrowedPtr(ty::MutBorrow, ref r) |
1559-
Implicit(ty::MutBorrow, ref r) => {
1560-
write!(f, "&{:?} mut", r)
1561-
}
1562-
BorrowedPtr(ty::UniqueImmBorrow, ref r) |
1563-
Implicit(ty::UniqueImmBorrow, ref r) => {
1564-
write!(f, "&{:?} uniq", r)
1565-
}
1566-
UnsafePtr(_) => write!(f, "*")
1567-
}
1568-
}
1569-
}
1570-
15711516
impl fmt::Debug for InteriorKind {
15721517
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
15731518
match *self {

0 commit comments

Comments
 (0)