]> git.lizzy.rs Git - rust.git/commitdiff
rustc: use define_print! to implement fmt::{Display,Debug} for Kind.
authorEduard-Mihai Burtescu <edy.burt@gmail.com>
Fri, 7 Dec 2018 23:13:23 +0000 (01:13 +0200)
committerEduard-Mihai Burtescu <edy.burt@gmail.com>
Fri, 15 Mar 2019 07:26:13 +0000 (09:26 +0200)
src/librustc/ty/subst.rs
src/librustc/util/ppaux.rs

index 85a05bb9f558586d746d9012d43ade2cc7a63428..973f7f15f84ca4e7ff0e9a2852816dc74f3238e1 100644 (file)
@@ -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>;
 
index b56ce0665e9e94df84de56c6936264ac235887f4..c2b2cf4e62f9a2d26d5e2357126a8f58b67d39fa 100644 (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 @@ 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)),
+            }
+        }
+    }
+}