Skip to content

Commit 4a04b43

Browse files
committed
Add Display impl for ty::Const
1 parent 500f4b2 commit 4a04b43

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

src/librustc/ty/sty.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,9 +1919,8 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
19191919
/// Typed constant value.
19201920
#[derive(Copy, Clone, Debug, Hash, RustcEncodable, RustcDecodable, Eq, PartialEq, Ord, PartialOrd)]
19211921
pub struct Const<'tcx> {
1922-
pub ty: Ty<'tcx>,
1923-
19241922
pub val: ConstValue<'tcx>,
1923+
pub ty: Ty<'tcx>,
19251924
}
19261925

19271926
impl<'tcx> Const<'tcx> {

src/librustc/ty/subst.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use std::mem;
2727
use std::num::NonZeroUsize;
2828

2929
/// An entity in the Rust typesystem, which can be one of
30-
/// several kinds (only types, lifetimes, and const generics for now).
30+
/// several kinds (types, lifetimes, and consts).
3131
/// To reduce memory usage, a `Kind` is a interned pointer,
3232
/// with the lowest 2 bits being reserved for a tag to
3333
/// indicate the type (`Ty`, `Region`, or `Const`) it points to.
@@ -148,7 +148,7 @@ impl<'tcx> fmt::Display for Kind<'tcx> {
148148
match self.unpack() {
149149
UnpackedKind::Lifetime(lt) => write!(f, "{}", lt),
150150
UnpackedKind::Type(ty) => write!(f, "{}", ty),
151-
UnpackedKind::Const(ct) => write!(f, "{:?}", ct), // TODO(const_generics): impl display for Const
151+
UnpackedKind::Const(ct) => write!(f, "{}", ct),
152152
}
153153
}
154154
}

src/librustc/util/ppaux.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,26 @@ define_print! {
12831283
}
12841284
}
12851285

1286+
define_print! {
1287+
('tcx) ConstVal<'tcx>, (self, f, cx) {
1288+
display {
1289+
match self {
1290+
ConstVal::Value(value) => write!(f, "{:?}", value), // TODO(const_generics)
1291+
ConstVal::Unevaluated(..) => write!(f, "_"),
1292+
ConstVal::Param(ParamConst { name, .. }) => write!(f, "{}", name),
1293+
}
1294+
}
1295+
}
1296+
}
1297+
1298+
define_print! {
1299+
('tcx) ty::Const<'tcx>, (self, f, cx) {
1300+
display {
1301+
write!(f, "{} : {}", self.val, self.ty)
1302+
}
1303+
}
1304+
}
1305+
12861306
define_print! {
12871307
() ty::ParamTy, (self, f, cx) {
12881308
display {

src/librustc_resolve/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,7 @@ impl<'a, 'tcx, 'cl> Visitor<'tcx> for Resolver<'a, 'cl> {
810810
self.label_ribs.pop();
811811
self.ribs[ValueNS].pop();
812812
}
813+
813814
fn visit_generics(&mut self, generics: &'tcx Generics) {
814815
// For type parameter defaults, we have to ban access
815816
// to following type parameters, as the Substs can only

0 commit comments

Comments
 (0)