diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index 3e3587d87c4..14ff795b243 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -426,7 +426,6 @@ pub enum ExprKind<'tcx> { ConstParam { literal: ty::Const<'tcx>, def_id: DefId, - user_ty: Option>>, }, // FIXME improve docs for `StaticRef` by distinguishing it from `NamedConst` /// A literal containing the address of a `static`. diff --git a/compiler/rustc_middle/src/thir/visit.rs b/compiler/rustc_middle/src/thir/visit.rs index b4a7ce2c424..77e5b8f48d9 100644 --- a/compiler/rustc_middle/src/thir/visit.rs +++ b/compiler/rustc_middle/src/thir/visit.rs @@ -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 @@ pub trait Visitor<'a, 'tcx: 'a>: Sized { 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); diff --git a/compiler/rustc_mir_build/src/build/expr/as_constant.rs b/compiler/rustc_mir_build/src/build/expr/as_constant.rs index 7f0452d4dcd..c02eb40e2cf 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_constant.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_constant.rs @@ -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)); diff --git a/compiler/rustc_mir_build/src/build/expr/as_temp.rs b/compiler/rustc_mir_build/src/build/expr/as_temp.rs index 9b20805424f..f68143dc24f 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_temp.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_temp.rs @@ -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 })); } diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index 691c6ee6a48..a283c463808 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -876,7 +876,6 @@ impl<'tcx> Cx<'tcx> { val, ty: self.typeck_results().node_type(expr.hir_id), }), - user_ty: None, def_id, } } diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs index fdbf7672751..d26c10ed8f0 100644 --- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs +++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs @@ -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 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, '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,14 +356,18 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, '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(); - } } let mut is_poly_vis = IsThirPolymorphic { is_poly: false, thir: body };