do use ty::Const in patterns and abstract consts
This commit is contained in:
parent
b38077ea0b
commit
ac60db231c
15 changed files with 105 additions and 127 deletions
|
@ -37,14 +37,9 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
|
|||
param_env: ty::ParamEnv<'tcx>,
|
||||
span: Span,
|
||||
) -> Result<(), NotConstEvaluatable> {
|
||||
<<<<<<< HEAD
|
||||
let tcx = infcx.tcx;
|
||||
|
||||
if tcx.features().generic_const_exprs {
|
||||
=======
|
||||
if infcx.tcx.features().generic_const_exprs {
|
||||
let tcx = infcx.tcx;
|
||||
>>>>>>> 6064f16d846 (change thir to use mir::ConstantKind instead of ty::Const)
|
||||
match AbstractConst::new(tcx, uv)? {
|
||||
// We are looking at a generic abstract constant.
|
||||
Some(ct) => {
|
||||
|
@ -249,7 +244,7 @@ impl<'tcx> AbstractConst<'tcx> {
|
|||
Ok(inner.map(|inner| AbstractConst { inner, substs: uv.substs }))
|
||||
}
|
||||
|
||||
pub fn from_constant(
|
||||
pub fn from_const(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
ct: ty::Const<'tcx>,
|
||||
) -> Result<Option<AbstractConst<'tcx>>, ErrorGuaranteed> {
|
||||
|
@ -382,6 +377,10 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn visit_const(&mut self, ct: ty::Const<'tcx>) {
|
||||
self.is_poly |= ct.has_param_types_or_consts();
|
||||
}
|
||||
|
||||
fn visit_constant(&mut self, ct: mir::ConstantKind<'tcx>) {
|
||||
self.is_poly |= ct.has_param_types_or_consts();
|
||||
}
|
||||
|
@ -423,10 +422,10 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
|
|||
self.recurse_build(self.body_id)?;
|
||||
|
||||
for n in self.nodes.iter() {
|
||||
if let Node::Leaf(mir::ConstantKind::Ty(ty::Const(Interned(
|
||||
if let Node::Leaf(ty::Const(Interned(
|
||||
ty::ConstS { val: ty::ConstKind::Unevaluated(ct), ty: _ },
|
||||
_,
|
||||
)))) = n
|
||||
))) = n
|
||||
{
|
||||
// `AbstractConst`s should not contain any promoteds as they require references which
|
||||
// are not allowed.
|
||||
|
@ -863,4 +862,4 @@ impl<'tcx> ConstUnifyCtxt<'tcx> {
|
|||
false
|
||||
>>>>>>> 6064f16d846 (change thir to use mir::ConstantKind instead of ty::Const)
|
||||
|
||||
*/
|
||||
*/
|
||||
|
|
|
@ -17,7 +17,6 @@ use crate::traits::{self, Obligation, ObligationCause};
|
|||
use rustc_errors::FatalError;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_middle::mir::ConstantKind;
|
||||
use rustc_middle::ty::subst::{GenericArg, InternalSubsts, Subst};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeVisitor};
|
||||
use rustc_middle::ty::{Predicate, ToPredicate};
|
||||
|
@ -837,10 +836,7 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeFoldable<'tcx>>(
|
|||
if let Ok(Some(ct)) = AbstractConst::new(self.tcx, uv.shrink()) {
|
||||
const_evaluatable::walk_abstract_const(self.tcx, ct, |node| {
|
||||
match node.root(self.tcx) {
|
||||
Node::Leaf(leaf) => match leaf {
|
||||
ConstantKind::Ty(c) => self.visit_const(c),
|
||||
ConstantKind::Val(_, ty) => self.visit_ty(ty),
|
||||
},
|
||||
Node::Leaf(leaf) => self.visit_const(leaf),
|
||||
Node::Cast(_, _, ty) => self.visit_ty(ty),
|
||||
Node::Binop(..) | Node::UnaryOp(..) | Node::FunctionCall(_, _) => {
|
||||
ControlFlow::CONTINUE
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue