remove thir::Visitor::visit_const
This commit is contained in:
parent
f713b5017c
commit
e2496b3cf4
@ -426,7 +426,6 @@ pub enum ExprKind<'tcx> {
|
||||
ConstParam {
|
||||
literal: ty::Const<'tcx>,
|
||||
def_id: DefId,
|
||||
user_ty: Option<Canonical<'tcx, UserType<'tcx>>>,
|
||||
},
|
||||
// FIXME improve docs for `StaticRef` by distinguishing it from `NamedConst`
|
||||
/// A literal containing the address of a `static`.
|
||||
|
@ -1,7 +1,6 @@
|
||||
use super::{
|
||||
Arm, Block, Expr, ExprKind, Guard, InlineAsmOperand, Pat, PatKind, Stmt, StmtKind, Thir,
|
||||
};
|
||||
use rustc_middle::ty::Const;
|
||||
|
||||
pub trait Visitor<'a, 'tcx: 'a>: Sized {
|
||||
fn thir(&self) -> &'a Thir<'tcx>;
|
||||
@ -25,8 +24,6 @@ fn visit_arm(&mut self, arm: &Arm<'tcx>) {
|
||||
fn visit_pat(&mut self, pat: &Pat<'tcx>) {
|
||||
walk_pat(self, pat);
|
||||
}
|
||||
|
||||
fn visit_const(&mut self, _cnst: Const<'tcx>) {}
|
||||
}
|
||||
|
||||
pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Expr<'tcx>) {
|
||||
@ -94,9 +91,8 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp
|
||||
}
|
||||
}
|
||||
ConstBlock { did: _, substs: _ } => {}
|
||||
Repeat { value, count } => {
|
||||
Repeat { value, count: _ } => {
|
||||
visitor.visit_expr(&visitor.thir()[value]);
|
||||
visitor.visit_const(count);
|
||||
}
|
||||
Array { ref fields } | Tuple { ref fields } => {
|
||||
for &field in &**fields {
|
||||
@ -125,7 +121,7 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp
|
||||
Literal { lit: _, neg: _ } => {}
|
||||
ScalarLiteral { lit: _, user_ty: _ } => {}
|
||||
NamedConst { def_id: _, substs: _, user_ty: _ } => {}
|
||||
ConstParam { literal: _, def_id: _, user_ty: _ } => {}
|
||||
ConstParam { literal: _, def_id: _ } => {}
|
||||
StaticRef { alloc_id: _, ty: _, def_id: _ } => {}
|
||||
InlineAsm { ref operands, template: _, options: _, line_spans: _ } => {
|
||||
for op in &**operands {
|
||||
@ -212,11 +208,8 @@ pub fn walk_pat<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, pat: &Pat<'
|
||||
visitor.visit_pat(&subpattern.pattern);
|
||||
}
|
||||
}
|
||||
Constant { value } => visitor.visit_const(*value),
|
||||
Range(range) => {
|
||||
visitor.visit_const(range.lo);
|
||||
visitor.visit_const(range.hi);
|
||||
}
|
||||
Constant { value: _ } => {}
|
||||
Range(_) => {}
|
||||
Slice { prefix, slice, suffix } | Array { prefix, slice, suffix } => {
|
||||
for subpattern in prefix {
|
||||
visitor.visit_pat(&subpattern);
|
||||
|
@ -17,10 +17,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
/// Compile `expr`, yielding a compile-time constant. Assumes that
|
||||
/// `expr` is a valid compile-time constant!
|
||||
crate fn as_constant(&mut self, expr: &Expr<'tcx>) -> Constant<'tcx> {
|
||||
debug!("expr: {:#?}", expr);
|
||||
// FIXME: Maybe we should try to evaluate here and only create an `Unevaluated`
|
||||
// constant in case the evaluation fails. Need some evaluation function that
|
||||
// allows normalization to fail.
|
||||
let create_uneval_from_def_id =
|
||||
|tcx: TyCtxt<'tcx>, def_id: DefId, ty: Ty<'tcx>, substs: SubstsRef<'tcx>| {
|
||||
let uneval = ty::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs);
|
||||
@ -74,17 +70,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
|
||||
Constant { user_ty, span, literal }
|
||||
}
|
||||
ExprKind::ConstParam { literal, def_id: _, user_ty } => {
|
||||
let user_ty = user_ty.map(|user_ty| {
|
||||
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
|
||||
span,
|
||||
user_ty,
|
||||
inferred_ty: ty,
|
||||
})
|
||||
});
|
||||
ExprKind::ConstParam { literal, def_id: _ } => {
|
||||
let literal = ConstantKind::Ty(literal);
|
||||
|
||||
Constant { user_ty: user_ty, span, literal }
|
||||
Constant { user_ty: None, span, literal }
|
||||
}
|
||||
ExprKind::ConstBlock { did: def_id, substs } => {
|
||||
let literal = ConstantKind::Ty(create_uneval_from_def_id(tcx, def_id, ty, substs));
|
||||
|
@ -70,6 +70,7 @@ fn as_temp_inner(
|
||||
local_decl.local_info =
|
||||
Some(Box::new(LocalInfo::StaticRef { def_id, is_thread_local: true }));
|
||||
}
|
||||
// FIXME Might have to include `ExprKind::ConstParam` here as well
|
||||
ExprKind::NamedConst { def_id, .. } => {
|
||||
local_decl.local_info = Some(Box::new(LocalInfo::ConstRef { def_id }));
|
||||
}
|
||||
|
@ -876,7 +876,6 @@ fn convert_path_expr(&mut self, expr: &'tcx hir::Expr<'tcx>, res: Res) -> ExprKi
|
||||
val,
|
||||
ty: self.typeck_results().node_type(expr.hir_id),
|
||||
}),
|
||||
user_ty: None,
|
||||
def_id,
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
|
||||
) -> Result<(), NotConstEvaluatable> {
|
||||
let tcx = infcx.tcx;
|
||||
|
||||
if infcx.tcx.features().generic_const_exprs {
|
||||
if tcx.features().generic_const_exprs {
|
||||
match AbstractConst::new(tcx, uv)? {
|
||||
// We are looking at a generic abstract constant.
|
||||
Some(ct) => {
|
||||
@ -342,7 +342,13 @@ fn thir(&self) -> &'a thir::Thir<'tcx> {
|
||||
fn visit_expr(&mut self, expr: &thir::Expr<'tcx>) {
|
||||
self.is_poly |= self.expr_is_poly(expr);
|
||||
if !self.is_poly {
|
||||
visit::walk_expr(self, expr)
|
||||
match expr.kind {
|
||||
thir::ExprKind::Repeat { value, count } => {
|
||||
self.visit_expr(&self.thir()[value]);
|
||||
self.is_poly |= count.has_param_types_or_consts();
|
||||
}
|
||||
_ => visit::walk_expr(self, expr),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -350,13 +356,17 @@ fn visit_expr(&mut self, expr: &thir::Expr<'tcx>) {
|
||||
fn visit_pat(&mut self, pat: &thir::Pat<'tcx>) {
|
||||
self.is_poly |= pat.ty.has_param_types_or_consts();
|
||||
if !self.is_poly {
|
||||
visit::walk_pat(self, pat);
|
||||
match pat.kind.as_ref() {
|
||||
thir::PatKind::Constant { value } => {
|
||||
self.is_poly |= value.has_param_types_or_consts();
|
||||
}
|
||||
thir::PatKind::Range(thir::PatRange { lo, hi, .. }) => {
|
||||
self.is_poly |=
|
||||
lo.has_param_types_or_consts() | hi.has_param_types_or_consts();
|
||||
}
|
||||
_ => visit::walk_pat(self, pat),
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
fn visit_const(&mut self, ct: ty::Const<'tcx>) {
|
||||
self.is_poly |= ct.has_param_types_or_consts();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user