Cache with consistent env and bound

This commit is contained in:
Deadbeef
2021-12-01 23:22:42 +08:00
parent 87cd1ce6c1
commit 6b07cec05c
2 changed files with 36 additions and 8 deletions

View File

@@ -230,6 +230,19 @@ pub enum BoundConstness {
ConstIfConst,
}
impl BoundConstness {
/// Reduce `self` and `constness` to two possible combined states instead of four.
pub fn and(&mut self, constness: hir::Constness) -> hir::Constness {
match (constness, self) {
(hir::Constness::Const, BoundConstness::ConstIfConst) => hir::Constness::Const,
(_, this) => {
*this = BoundConstness::NotConst;
hir::Constness::NotConst
}
}
}
}
impl fmt::Display for BoundConstness {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
@@ -1326,6 +1339,11 @@ impl<'tcx> ParamEnv<'tcx> {
self
}
pub fn with_constness(mut self, constness: hir::Constness) -> Self {
self.packed.set_tag(ParamTag { constness, ..self.packed.tag() });
self
}
pub fn with_const(mut self) -> Self {
self.packed.set_tag(ParamTag { constness: hir::Constness::Const, ..self.packed.tag() });
self