diff options
| author | varkor <github@varkor.com> | 2019-02-20 01:15:49 +0000 |
|---|---|---|
| committer | varkor <github@varkor.com> | 2019-03-05 22:11:04 +0000 |
| commit | 0d1c9c08d7afd83644c825305804eb694bddb881 (patch) | |
| tree | fc85ee1f92ff03f5cf252581ef6e0c513e756076 | |
| parent | cbf5d22bcdd8674db1f3945326e4ff8d6b6986c8 (diff) | |
| download | rust-0d1c9c08d7afd83644c825305804eb694bddb881.tar.gz rust-0d1c9c08d7afd83644c825305804eb694bddb881.zip | |
Pretty printing for const generics
Co-Authored-By: Gabriel Smith <yodaldevoid@users.noreply.github.com>
| -rw-r--r-- | src/librustc/util/ppaux.rs | 70 |
1 files changed, 67 insertions, 3 deletions
diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index aecef3c5ec7..cdc0c3371eb 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -8,7 +8,8 @@ use crate::ty::{Error, Str, Array, Slice, Float, FnDef, FnPtr}; use crate::ty::{Param, Bound, RawPtr, Ref, Never, Tuple}; use crate::ty::{Closure, Generator, GeneratorWitness, Foreign, Projection, Opaque}; use crate::ty::{Placeholder, UnnormalizedProjection, Dynamic, Int, Uint, Infer}; -use crate::ty::{self, Ty, TyCtxt, TypeFoldable, GenericParamCount, GenericParamDefKind}; +use crate::ty::{self, Ty, TyCtxt, TypeFoldable, GenericParamCount, GenericParamDefKind, ParamConst}; +use crate::mir::interpret::ConstValue; use crate::util::nodemap::FxHashSet; use std::cell::Cell; @@ -478,6 +479,7 @@ impl PrintContext { GenericParamDefKind::Type { has_default, .. } => { Some((param.def_id, has_default)) } + GenericParamDefKind::Const => None, // FIXME(const_generics:defaults) }).peekable(); let has_default = { let has_default = type_params.peek().map(|(_, has_default)| has_default); @@ -571,6 +573,14 @@ impl PrintContext { )?; } + // FIXME(const_generics::defaults) + let consts = substs.consts(); + + for ct in consts { + start_or_continue(f, "<", ", ")?; + ct.print_display(f, self)?; + } + start_or_continue(f, "", ">")?; // For values, also print their name and type parameters. @@ -763,7 +773,8 @@ impl fmt::Debug for ty::GenericParamDef { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let type_name = match self.kind { ty::GenericParamDefKind::Lifetime => "Lifetime", - ty::GenericParamDefKind::Type {..} => "Type", + ty::GenericParamDefKind::Type { .. } => "Type", + ty::GenericParamDefKind::Const => "Const", }; write!(f, "{}({}, {:?}, {})", type_name, @@ -1088,6 +1099,12 @@ impl fmt::Debug for ty::TyVid { } } +impl<'tcx> fmt::Debug for ty::ConstVid<'tcx> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "_#{}f", self.index) + } +} + impl fmt::Debug for ty::IntVid { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "_#{}i", self.index) @@ -1448,7 +1465,12 @@ define_print! { write!(f, "_")?; } ty::LazyConst::Evaluated(c) => ty::tls::with(|tcx| { - write!(f, "{}", c.unwrap_usize(tcx)) + match c.val { + ConstValue::Infer(..) => write!(f, "_"), + ConstValue::Param(ParamConst { name, .. }) => + write!(f, "{}", name), + _ => write!(f, "{}", c.unwrap_usize(tcx)), + } })?, } write!(f, "]") @@ -1473,6 +1495,37 @@ define_print! { } define_print! { + ('tcx) ConstValue<'tcx>, (self, f, cx) { + display { + match self { + ConstValue::Infer(..) => write!(f, "_"), + ConstValue::Param(ParamConst { name, .. }) => write!(f, "{}", name), + _ => write!(f, "{:?}", self), + } + } + } +} + +define_print! { + ('tcx) ty::Const<'tcx>, (self, f, cx) { + display { + write!(f, "{} : {}", self.val, self.ty) + } + } +} + +define_print! { + ('tcx) ty::LazyConst<'tcx>, (self, f, cx) { + display { + match self { + ty::LazyConst::Unevaluated(..) => write!(f, "_ : _"), + ty::LazyConst::Evaluated(c) => write!(f, "{}", c), + } + } + } +} + +define_print! { () ty::ParamTy, (self, f, cx) { display { write!(f, "{}", self.name) @@ -1484,6 +1537,17 @@ define_print! { } define_print! { + () ty::ParamConst, (self, f, cx) { + display { + write!(f, "{}", self.name) + } + debug { + write!(f, "{}/#{}", self.name, self.index) + } + } +} + +define_print! { ('tcx, T: Print + fmt::Debug, U: Print + fmt::Debug) ty::OutlivesPredicate<T, U>, (self, f, cx) { display { |
