1
Fork 0

Support as casts in abstract consts

This commit is contained in:
Ellen 2021-06-08 08:02:12 +01:00
parent dda4a881e0
commit 8e7299dfcd
7 changed files with 66 additions and 14 deletions

View file

@ -97,9 +97,10 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
ControlFlow::CONTINUE
}
Node::Binop(_, _, _) | Node::UnaryOp(_, _) | Node::FunctionCall(_, _) => {
ControlFlow::CONTINUE
}
Node::Binop(_, _, _)
| Node::UnaryOp(_, _)
| Node::FunctionCall(_, _)
| Node::Cast(_, _, _) => ControlFlow::CONTINUE,
});
match failure_kind {
@ -304,6 +305,9 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
self.nodes[func].used = true;
nodes.iter().for_each(|&n| self.nodes[n].used = true);
}
Node::Cast(_, operand, _) => {
self.nodes[operand].used = true;
}
}
// Nodes start as unused.
@ -408,6 +412,12 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
self.locals[local] = self.add_node(Node::UnaryOp(op, operand), span);
Ok(())
}
Rvalue::Cast(cast_kind, ref operand, ty) => {
let operand = self.operand_to_node(span, operand)?;
self.locals[local] =
self.add_node(Node::Cast(cast_kind, operand, ty), span);
Ok(())
}
_ => self.error(Some(span), "unsupported rvalue")?,
}
}
@ -594,6 +604,7 @@ where
recurse(tcx, ct.subtree(func), f)?;
args.iter().try_for_each(|&arg| recurse(tcx, ct.subtree(arg), f))
}
Node::Cast(_, operand, _) => recurse(tcx, ct.subtree(operand), f),
}
}
@ -676,6 +687,11 @@ pub(super) fn try_unify<'tcx>(
&& iter::zip(a_args, b_args)
.all(|(&an, &bn)| try_unify(tcx, a.subtree(an), b.subtree(bn)))
}
(Node::Cast(a_cast_kind, a_operand, a_ty), Node::Cast(b_cast_kind, b_operand, b_ty))
if (a_ty == b_ty) && (a_cast_kind == b_cast_kind) =>
{
try_unify(tcx, a.subtree(a_operand), b.subtree(b_operand))
}
_ => false,
}
}

View file

@ -838,9 +838,10 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeFoldable<'tcx>>(
let leaf = leaf.subst(self.tcx, ct.substs);
self.visit_const(leaf)
}
Node::Binop(..) | Node::UnaryOp(..) | Node::FunctionCall(_, _) => {
ControlFlow::CONTINUE
}
Node::Binop(..)
| Node::UnaryOp(..)
| Node::FunctionCall(_, _)
| Node::Cast(_, _, _) => ControlFlow::CONTINUE,
})
} else {
ControlFlow::CONTINUE
@ -859,9 +860,10 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeFoldable<'tcx>>(
let leaf = leaf.subst(self.tcx, ct.substs);
self.visit_const(leaf)
}
Node::Binop(..) | Node::UnaryOp(..) | Node::FunctionCall(_, _) => {
ControlFlow::CONTINUE
}
Node::Binop(..)
| Node::UnaryOp(..)
| Node::FunctionCall(_, _)
| Node::Cast(_, _, _) => ControlFlow::CONTINUE,
})
} else {
ControlFlow::CONTINUE