Skip to content

Commit a5e719f

Browse files
committed
rustc: use define_print! to implement fmt::{Display,Debug} for Kind.
1 parent 6dc5fbc commit a5e719f

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

src/librustc/ty/subst.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use smallvec::SmallVec;
1111

1212
use core::intrinsics;
1313
use std::cmp::Ordering;
14-
use std::fmt;
1514
use std::marker::PhantomData;
1615
use std::mem;
1716
use std::num::NonZeroUsize;
@@ -99,24 +98,6 @@ impl<'tcx> Kind<'tcx> {
9998
}
10099
}
101100

102-
impl<'tcx> fmt::Debug for Kind<'tcx> {
103-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
104-
match self.unpack() {
105-
UnpackedKind::Lifetime(lt) => write!(f, "{:?}", lt),
106-
UnpackedKind::Type(ty) => write!(f, "{:?}", ty),
107-
}
108-
}
109-
}
110-
111-
impl<'tcx> fmt::Display for Kind<'tcx> {
112-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
113-
match self.unpack() {
114-
UnpackedKind::Lifetime(lt) => write!(f, "{}", lt),
115-
UnpackedKind::Type(ty) => write!(f, "{}", ty),
116-
}
117-
}
118-
}
119-
120101
impl<'a, 'tcx> Lift<'tcx> for Kind<'a> {
121102
type Lifted = Kind<'tcx>;
122103

src/librustc/util/ppaux.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use hir::def_id::DefId;
22
use hir::map::definitions::DefPathData;
33
use middle::region;
4-
use ty::subst::{Subst, Substs};
4+
use ty::subst::{Kind, Subst, Substs, UnpackedKind};
55
use ty::{BrAnon, BrEnv, BrFresh, BrNamed};
66
use ty::{Bool, Char, Adt};
77
use ty::{Error, Str, Array, Slice, Float, FnDef, FnPtr};
@@ -1460,3 +1460,20 @@ define_print! {
14601460
}
14611461
}
14621462
}
1463+
1464+
define_print! {
1465+
('tcx) Kind<'tcx>, (self, f, cx) {
1466+
display {
1467+
match self.unpack() {
1468+
UnpackedKind::Lifetime(lt) => print!(f, cx, print(lt)),
1469+
UnpackedKind::Type(ty) => print!(f, cx, print(ty)),
1470+
}
1471+
}
1472+
debug {
1473+
match self.unpack() {
1474+
UnpackedKind::Lifetime(lt) => print!(f, cx, print(lt)),
1475+
UnpackedKind::Type(ty) => print!(f, cx, print(ty)),
1476+
}
1477+
}
1478+
}
1479+
}

0 commit comments

Comments
 (0)