1
Fork 0

rustc: use define_print! to implement fmt::{Display,Debug} for Kind.

This commit is contained in:
Eduard-Mihai Burtescu 2018-12-08 01:13:23 +02:00
parent eb525b0916
commit 939c69c71f
2 changed files with 18 additions and 20 deletions

View file

@ -13,7 +13,6 @@ use rustc_macros::HashStable;
use core::intrinsics;
use std::cmp::Ordering;
use std::fmt;
use std::marker::PhantomData;
use std::mem;
use std::num::NonZeroUsize;
@ -115,26 +114,8 @@ impl<'tcx> Kind<'tcx> {
}
}
impl<'tcx> fmt::Debug for Kind<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.unpack() {
UnpackedKind::Lifetime(lt) => write!(f, "{:?}", lt),
UnpackedKind::Type(ty) => write!(f, "{:?}", ty),
UnpackedKind::Const(ct) => write!(f, "{:?}", ct),
}
}
}
impl<'tcx> fmt::Display for Kind<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.unpack() {
UnpackedKind::Lifetime(lt) => write!(f, "{}", lt),
UnpackedKind::Type(ty) => write!(f, "{}", ty),
UnpackedKind::Const(ct) => write!(f, "{}", ct),
}
}
}
impl<'a, 'tcx> Lift<'tcx> for Kind<'a> {
type Lifted = Kind<'tcx>;

View file

@ -1,7 +1,7 @@
use crate::hir::def_id::DefId;
use crate::hir::map::definitions::DefPathData;
use crate::middle::region;
use crate::ty::subst::{self, Subst, SubstsRef};
use crate::ty::subst::{self, Kind, Subst, SubstsRef, UnpackedKind};
use crate::ty::{BrAnon, BrEnv, BrFresh, BrNamed};
use crate::ty::{Bool, Char, Adt};
use crate::ty::{Error, Str, Array, Slice, Float, FnDef, FnPtr};
@ -1535,3 +1535,20 @@ define_print! {
}
}
}
define_print! {
('tcx) Kind<'tcx>, (self, f, cx) {
display {
match self.unpack() {
UnpackedKind::Lifetime(lt) => print!(f, cx, print(lt)),
UnpackedKind::Type(ty) => print!(f, cx, print(ty)),
}
}
debug {
match self.unpack() {
UnpackedKind::Lifetime(lt) => print!(f, cx, print(lt)),
UnpackedKind::Type(ty) => print!(f, cx, print(ty)),
}
}
}
}