Skip to content

Commit e2496b3

Browse files
committed
remove thir::Visitor::visit_const
1 parent f713b50 commit e2496b3

File tree

6 files changed

+25
-34
lines changed

6 files changed

+25
-34
lines changed

compiler/rustc_middle/src/thir.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,6 @@ pub enum ExprKind<'tcx> {
426426
ConstParam {
427427
literal: ty::Const<'tcx>,
428428
def_id: DefId,
429-
user_ty: Option<Canonical<'tcx, UserType<'tcx>>>,
430429
},
431430
// FIXME improve docs for `StaticRef` by distinguishing it from `NamedConst`
432431
/// A literal containing the address of a `static`.

compiler/rustc_middle/src/thir/visit.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use super::{
22
Arm, Block, Expr, ExprKind, Guard, InlineAsmOperand, Pat, PatKind, Stmt, StmtKind, Thir,
33
};
4-
use rustc_middle::ty::Const;
54

65
pub trait Visitor<'a, 'tcx: 'a>: Sized {
76
fn thir(&self) -> &'a Thir<'tcx>;
@@ -25,8 +24,6 @@ pub trait Visitor<'a, 'tcx: 'a>: Sized {
2524
fn visit_pat(&mut self, pat: &Pat<'tcx>) {
2625
walk_pat(self, pat);
2726
}
28-
29-
fn visit_const(&mut self, _cnst: Const<'tcx>) {}
3027
}
3128

3229
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
9491
}
9592
}
9693
ConstBlock { did: _, substs: _ } => {}
97-
Repeat { value, count } => {
94+
Repeat { value, count: _ } => {
9895
visitor.visit_expr(&visitor.thir()[value]);
99-
visitor.visit_const(count);
10096
}
10197
Array { ref fields } | Tuple { ref fields } => {
10298
for &field in &**fields {
@@ -125,7 +121,7 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp
125121
Literal { lit: _, neg: _ } => {}
126122
ScalarLiteral { lit: _, user_ty: _ } => {}
127123
NamedConst { def_id: _, substs: _, user_ty: _ } => {}
128-
ConstParam { literal: _, def_id: _, user_ty: _ } => {}
124+
ConstParam { literal: _, def_id: _ } => {}
129125
StaticRef { alloc_id: _, ty: _, def_id: _ } => {}
130126
InlineAsm { ref operands, template: _, options: _, line_spans: _ } => {
131127
for op in &**operands {
@@ -212,11 +208,8 @@ pub fn walk_pat<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, pat: &Pat<'
212208
visitor.visit_pat(&subpattern.pattern);
213209
}
214210
}
215-
Constant { value } => visitor.visit_const(*value),
216-
Range(range) => {
217-
visitor.visit_const(range.lo);
218-
visitor.visit_const(range.hi);
219-
}
211+
Constant { value: _ } => {}
212+
Range(_) => {}
220213
Slice { prefix, slice, suffix } | Array { prefix, slice, suffix } => {
221214
for subpattern in prefix {
222215
visitor.visit_pat(&subpattern);

compiler/rustc_mir_build/src/build/expr/as_constant.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1717
/// Compile `expr`, yielding a compile-time constant. Assumes that
1818
/// `expr` is a valid compile-time constant!
1919
crate fn as_constant(&mut self, expr: &Expr<'tcx>) -> Constant<'tcx> {
20-
debug!("expr: {:#?}", expr);
21-
// FIXME: Maybe we should try to evaluate here and only create an `Unevaluated`
22-
// constant in case the evaluation fails. Need some evaluation function that
23-
// allows normalization to fail.
2420
let create_uneval_from_def_id =
2521
|tcx: TyCtxt<'tcx>, def_id: DefId, ty: Ty<'tcx>, substs: SubstsRef<'tcx>| {
2622
let uneval = ty::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs);
@@ -74,17 +70,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
7470

7571
Constant { user_ty, span, literal }
7672
}
77-
ExprKind::ConstParam { literal, def_id: _, user_ty } => {
78-
let user_ty = user_ty.map(|user_ty| {
79-
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
80-
span,
81-
user_ty,
82-
inferred_ty: ty,
83-
})
84-
});
73+
ExprKind::ConstParam { literal, def_id: _ } => {
8574
let literal = ConstantKind::Ty(literal);
8675

87-
Constant { user_ty: user_ty, span, literal }
76+
Constant { user_ty: None, span, literal }
8877
}
8978
ExprKind::ConstBlock { did: def_id, substs } => {
9079
let literal = ConstantKind::Ty(create_uneval_from_def_id(tcx, def_id, ty, substs));

compiler/rustc_mir_build/src/build/expr/as_temp.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
7070
local_decl.local_info =
7171
Some(Box::new(LocalInfo::StaticRef { def_id, is_thread_local: true }));
7272
}
73+
// FIXME Might have to include `ExprKind::ConstParam` here as well
7374
ExprKind::NamedConst { def_id, .. } => {
7475
local_decl.local_info = Some(Box::new(LocalInfo::ConstRef { def_id }));
7576
}

compiler/rustc_mir_build/src/thir/cx/expr.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,6 @@ impl<'tcx> Cx<'tcx> {
876876
val,
877877
ty: self.typeck_results().node_type(expr.hir_id),
878878
}),
879-
user_ty: None,
880879
def_id,
881880
}
882881
}

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
3939
) -> Result<(), NotConstEvaluatable> {
4040
let tcx = infcx.tcx;
4141

42-
if infcx.tcx.features().generic_const_exprs {
42+
if tcx.features().generic_const_exprs {
4343
match AbstractConst::new(tcx, uv)? {
4444
// We are looking at a generic abstract constant.
4545
Some(ct) => {
@@ -342,22 +342,32 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
342342
fn visit_expr(&mut self, expr: &thir::Expr<'tcx>) {
343343
self.is_poly |= self.expr_is_poly(expr);
344344
if !self.is_poly {
345-
visit::walk_expr(self, expr)
345+
match expr.kind {
346+
thir::ExprKind::Repeat { value, count } => {
347+
self.visit_expr(&self.thir()[value]);
348+
self.is_poly |= count.has_param_types_or_consts();
349+
}
350+
_ => visit::walk_expr(self, expr),
351+
}
346352
}
347353
}
348354

349355
#[instrument(skip(self), level = "debug")]
350356
fn visit_pat(&mut self, pat: &thir::Pat<'tcx>) {
351357
self.is_poly |= pat.ty.has_param_types_or_consts();
352358
if !self.is_poly {
353-
visit::walk_pat(self, pat);
359+
match pat.kind.as_ref() {
360+
thir::PatKind::Constant { value } => {
361+
self.is_poly |= value.has_param_types_or_consts();
362+
}
363+
thir::PatKind::Range(thir::PatRange { lo, hi, .. }) => {
364+
self.is_poly |=
365+
lo.has_param_types_or_consts() | hi.has_param_types_or_consts();
366+
}
367+
_ => visit::walk_pat(self, pat),
368+
}
354369
}
355370
}
356-
357-
#[instrument(skip(self), level = "debug")]
358-
fn visit_const(&mut self, ct: ty::Const<'tcx>) {
359-
self.is_poly |= ct.has_param_types_or_consts();
360-
}
361371
}
362372

363373
let mut is_poly_vis = IsThirPolymorphic { is_poly: false, thir: body };

0 commit comments

Comments
 (0)