Make fields on AbstractConst
private
This commit is contained in:
parent
6e4061819f
commit
fc5633fed6
3 changed files with 13 additions and 13 deletions
|
@ -153,7 +153,7 @@ where
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
ct: AbstractConst<'tcx>,
|
ct: AbstractConst<'tcx>,
|
||||||
) -> ControlFlow<V::BreakTy> {
|
) -> ControlFlow<V::BreakTy> {
|
||||||
const_evaluatable::walk_abstract_const(tcx, ct, |node| match node.root(tcx, ct.substs) {
|
const_evaluatable::walk_abstract_const(tcx, ct, |node| match node.root(tcx) {
|
||||||
ACNode::Leaf(leaf) => self.visit_const(leaf),
|
ACNode::Leaf(leaf) => self.visit_const(leaf),
|
||||||
ACNode::Cast(_, _, ty) => self.visit_ty(ty),
|
ACNode::Cast(_, _, ty) => self.visit_ty(ty),
|
||||||
ACNode::Binop(..) | ACNode::UnaryOp(..) | ACNode::FunctionCall(_, _) => {
|
ACNode::Binop(..) | ACNode::UnaryOp(..) | ACNode::FunctionCall(_, _) => {
|
||||||
|
|
|
@ -16,7 +16,7 @@ use rustc_infer::infer::InferCtxt;
|
||||||
use rustc_middle::mir::abstract_const::{Node, NodeId, NotConstEvaluatable};
|
use rustc_middle::mir::abstract_const::{Node, NodeId, NotConstEvaluatable};
|
||||||
use rustc_middle::mir::interpret::ErrorHandled;
|
use rustc_middle::mir::interpret::ErrorHandled;
|
||||||
use rustc_middle::mir::{self, Rvalue, StatementKind, TerminatorKind};
|
use rustc_middle::mir::{self, Rvalue, StatementKind, TerminatorKind};
|
||||||
use rustc_middle::ty::subst::{GenericArg, Subst, SubstsRef};
|
use rustc_middle::ty::subst::{Subst, SubstsRef};
|
||||||
use rustc_middle::ty::{self, TyCtxt, TypeFoldable};
|
use rustc_middle::ty::{self, TyCtxt, TypeFoldable};
|
||||||
use rustc_session::lint;
|
use rustc_session::lint;
|
||||||
use rustc_span::def_id::LocalDefId;
|
use rustc_span::def_id::LocalDefId;
|
||||||
|
@ -80,7 +80,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
|
||||||
Concrete,
|
Concrete,
|
||||||
}
|
}
|
||||||
let mut failure_kind = FailureKind::Concrete;
|
let mut failure_kind = FailureKind::Concrete;
|
||||||
walk_abstract_const::<!, _>(tcx, ct, |node| match node.root(tcx, ct.substs) {
|
walk_abstract_const::<!, _>(tcx, ct, |node| match node.root(tcx) {
|
||||||
Node::Leaf(leaf) => {
|
Node::Leaf(leaf) => {
|
||||||
if leaf.has_infer_types_or_consts() {
|
if leaf.has_infer_types_or_consts() {
|
||||||
failure_kind = FailureKind::MentionsInfer;
|
failure_kind = FailureKind::MentionsInfer;
|
||||||
|
@ -185,8 +185,8 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
|
||||||
pub struct AbstractConst<'tcx> {
|
pub struct AbstractConst<'tcx> {
|
||||||
// FIXME: Consider adding something like `IndexSlice`
|
// FIXME: Consider adding something like `IndexSlice`
|
||||||
// and use this here.
|
// and use this here.
|
||||||
pub inner: &'tcx [Node<'tcx>],
|
inner: &'tcx [Node<'tcx>],
|
||||||
pub substs: SubstsRef<'tcx>,
|
substs: SubstsRef<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> AbstractConst<'tcx> {
|
impl<'tcx> AbstractConst<'tcx> {
|
||||||
|
@ -216,10 +216,10 @@ impl<'tcx> AbstractConst<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn root(self, tcx: TyCtxt<'tcx>, substs: &[GenericArg<'tcx>]) -> Node<'tcx> {
|
pub fn root(self, tcx: TyCtxt<'tcx>) -> Node<'tcx> {
|
||||||
let mut node = self.inner.last().copied().unwrap();
|
let node = self.inner.last().copied().unwrap();
|
||||||
if let Node::Leaf(leaf) = node {
|
if let Node::Leaf(leaf) = node {
|
||||||
node = Node::Leaf(leaf.subst(tcx, substs));
|
return Node::Leaf(leaf.subst(tcx, self.substs));
|
||||||
}
|
}
|
||||||
node
|
node
|
||||||
}
|
}
|
||||||
|
@ -589,7 +589,7 @@ where
|
||||||
f: &mut dyn FnMut(AbstractConst<'tcx>) -> ControlFlow<R>,
|
f: &mut dyn FnMut(AbstractConst<'tcx>) -> ControlFlow<R>,
|
||||||
) -> ControlFlow<R> {
|
) -> ControlFlow<R> {
|
||||||
f(ct)?;
|
f(ct)?;
|
||||||
let root = ct.root(tcx, ct.substs);
|
let root = ct.root(tcx);
|
||||||
match root {
|
match root {
|
||||||
Node::Leaf(_) => ControlFlow::CONTINUE,
|
Node::Leaf(_) => ControlFlow::CONTINUE,
|
||||||
Node::Binop(_, l, r) => {
|
Node::Binop(_, l, r) => {
|
||||||
|
@ -617,14 +617,14 @@ pub(super) fn try_unify<'tcx>(
|
||||||
// We substitute generics repeatedly to allow AbstractConsts to unify where a
|
// We substitute generics repeatedly to allow AbstractConsts to unify where a
|
||||||
// ConstKind::Unevalated could be turned into an AbstractConst that would unify e.g.
|
// ConstKind::Unevalated could be turned into an AbstractConst that would unify e.g.
|
||||||
// Param(N) should unify with Param(T), substs: [Unevaluated("T2", [Unevaluated("T3", [Param(N)])])]
|
// Param(N) should unify with Param(T), substs: [Unevaluated("T2", [Unevaluated("T3", [Param(N)])])]
|
||||||
while let Node::Leaf(a_ct) = a.root(tcx, a.substs) {
|
while let Node::Leaf(a_ct) = a.root(tcx) {
|
||||||
match AbstractConst::from_const(tcx, a_ct) {
|
match AbstractConst::from_const(tcx, a_ct) {
|
||||||
Ok(Some(a_act)) => a = a_act,
|
Ok(Some(a_act)) => a = a_act,
|
||||||
Ok(None) => break,
|
Ok(None) => break,
|
||||||
Err(_) => return true,
|
Err(_) => return true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while let Node::Leaf(b_ct) = b.root(tcx, b.substs) {
|
while let Node::Leaf(b_ct) = b.root(tcx) {
|
||||||
match AbstractConst::from_const(tcx, b_ct) {
|
match AbstractConst::from_const(tcx, b_ct) {
|
||||||
Ok(Some(b_act)) => b = b_act,
|
Ok(Some(b_act)) => b = b_act,
|
||||||
Ok(None) => break,
|
Ok(None) => break,
|
||||||
|
@ -632,7 +632,7 @@ pub(super) fn try_unify<'tcx>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match (a.root(tcx, a.substs), b.root(tcx, b.substs)) {
|
match (a.root(tcx), b.root(tcx)) {
|
||||||
(Node::Leaf(a_ct), Node::Leaf(b_ct)) => {
|
(Node::Leaf(a_ct), Node::Leaf(b_ct)) => {
|
||||||
if a_ct.ty != b_ct.ty {
|
if a_ct.ty != b_ct.ty {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -839,7 +839,7 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeFoldable<'tcx>>(
|
||||||
use rustc_middle::mir::abstract_const::Node;
|
use rustc_middle::mir::abstract_const::Node;
|
||||||
if let Ok(Some(ct)) = AbstractConst::new(self.tcx, uv.shrink()) {
|
if let Ok(Some(ct)) = AbstractConst::new(self.tcx, uv.shrink()) {
|
||||||
const_evaluatable::walk_abstract_const(self.tcx, ct, |node| {
|
const_evaluatable::walk_abstract_const(self.tcx, ct, |node| {
|
||||||
match node.root(self.tcx, ct.substs) {
|
match node.root(self.tcx) {
|
||||||
Node::Leaf(leaf) => self.visit_const(leaf),
|
Node::Leaf(leaf) => self.visit_const(leaf),
|
||||||
Node::Cast(_, _, ty) => self.visit_ty(ty),
|
Node::Cast(_, _, ty) => self.visit_ty(ty),
|
||||||
Node::Binop(..) | Node::UnaryOp(..) | Node::FunctionCall(_, _) => {
|
Node::Binop(..) | Node::UnaryOp(..) | Node::FunctionCall(_, _) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue