1
Fork 0

remove thir::Visitor::visit_const

This commit is contained in:
b-naber 2022-03-15 16:20:46 +01:00
parent f713b5017c
commit e2496b3cf4
6 changed files with 25 additions and 34 deletions

View file

@ -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));

View file

@ -70,6 +70,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
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 }));
}

View file

@ -876,7 +876,6 @@ impl<'tcx> Cx<'tcx> {
val,
ty: self.typeck_results().node_type(expr.hir_id),
}),
user_ty: None,
def_id,
}
}