From 386e9fbda225bd04039a47caad9138983faff18c Mon Sep 17 00:00:00 2001 From: varkor Date: Wed, 20 Feb 2019 01:10:22 +0000 Subject: [PATCH] Add type_flags helper methods to consts Co-Authored-By: Gabriel Smith --- src/librustc/ty/sty.rs | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 3b58cca38dd..1aa4ca7ff97 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -2110,6 +2110,22 @@ impl<'tcx> LazyConst<'tcx> { pub fn unwrap_usize(&self, tcx: TyCtxt<'_, '_, '_>) -> u64 { self.assert_usize(tcx).expect("expected `LazyConst` to contain a usize") } + + pub fn type_flags(&self) -> TypeFlags { + // FIXME(const_generics): incorporate substs flags. + let flags = match self { + LazyConst::Unevaluated(..) => { + TypeFlags::HAS_NORMALIZABLE_PROJECTION | TypeFlags::HAS_PROJECTION + } + LazyConst::Evaluated(c) => { + c.type_flags() + } + }; + + debug!("type_flags({:?}) = {:?}", self, flags); + + flags + } } /// Typed constant value. @@ -2225,6 +2241,33 @@ impl<'tcx> Const<'tcx> { self.assert_usize(tcx).unwrap_or_else(|| bug!("expected constant usize, got {:#?}", self)) } + + pub fn type_flags(&self) -> TypeFlags { + let mut flags = self.ty.flags; + + match self.val { + ConstValue::Param(_) => { + flags |= TypeFlags::HAS_FREE_LOCAL_NAMES; + flags |= TypeFlags::HAS_PARAMS; + } + ConstValue::Infer(infer) => { + flags |= TypeFlags::HAS_FREE_LOCAL_NAMES; + flags |= TypeFlags::HAS_CT_INFER; + match infer { + InferConst::Fresh(_) | + InferConst::Canonical(_, _) => {} + InferConst::Var(_) => { + flags |= TypeFlags::KEEP_IN_LOCAL_TCX; + } + } + } + _ => {} + } + + debug!("type_flags({:?}) = {:?}", self, flags); + + flags + } } impl<'tcx> serialize::UseSpecializedDecodable for &'tcx LazyConst<'tcx> {}