提交 939c69c7 编写于 作者: E Eduard-Mihai Burtescu

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

上级 eb525b09
......@@ -13,7 +13,6 @@
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 @@ pub fn unpack(self) -> UnpackedKind<'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>;
......
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 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
}
}
}
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)),
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册