Skip to content

Commit 386e9fb

Browse files
varkoryodaldevoid
andcommitted
Add type_flags helper methods to consts
Co-Authored-By: Gabriel Smith <[email protected]>
1 parent 8cbbbaa commit 386e9fb

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/librustc/ty/sty.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,6 +2110,22 @@ impl<'tcx> LazyConst<'tcx> {
21102110
pub fn unwrap_usize(&self, tcx: TyCtxt<'_, '_, '_>) -> u64 {
21112111
self.assert_usize(tcx).expect("expected `LazyConst` to contain a usize")
21122112
}
2113+
2114+
pub fn type_flags(&self) -> TypeFlags {
2115+
// FIXME(const_generics): incorporate substs flags.
2116+
let flags = match self {
2117+
LazyConst::Unevaluated(..) => {
2118+
TypeFlags::HAS_NORMALIZABLE_PROJECTION | TypeFlags::HAS_PROJECTION
2119+
}
2120+
LazyConst::Evaluated(c) => {
2121+
c.type_flags()
2122+
}
2123+
};
2124+
2125+
debug!("type_flags({:?}) = {:?}", self, flags);
2126+
2127+
flags
2128+
}
21132129
}
21142130

21152131
/// Typed constant value.
@@ -2225,6 +2241,33 @@ impl<'tcx> Const<'tcx> {
22252241
self.assert_usize(tcx).unwrap_or_else(||
22262242
bug!("expected constant usize, got {:#?}", self))
22272243
}
2244+
2245+
pub fn type_flags(&self) -> TypeFlags {
2246+
let mut flags = self.ty.flags;
2247+
2248+
match self.val {
2249+
ConstValue::Param(_) => {
2250+
flags |= TypeFlags::HAS_FREE_LOCAL_NAMES;
2251+
flags |= TypeFlags::HAS_PARAMS;
2252+
}
2253+
ConstValue::Infer(infer) => {
2254+
flags |= TypeFlags::HAS_FREE_LOCAL_NAMES;
2255+
flags |= TypeFlags::HAS_CT_INFER;
2256+
match infer {
2257+
InferConst::Fresh(_) |
2258+
InferConst::Canonical(_, _) => {}
2259+
InferConst::Var(_) => {
2260+
flags |= TypeFlags::KEEP_IN_LOCAL_TCX;
2261+
}
2262+
}
2263+
}
2264+
_ => {}
2265+
}
2266+
2267+
debug!("type_flags({:?}) = {:?}", self, flags);
2268+
2269+
flags
2270+
}
22282271
}
22292272

22302273
impl<'tcx> serialize::UseSpecializedDecodable for &'tcx LazyConst<'tcx> {}

0 commit comments

Comments
 (0)