From fc2a2650e2e8d86a9eab06eb1a03ff1a0641cd58 Mon Sep 17 00:00:00 2001 From: lcnr Date: Wed, 1 Sep 2021 11:41:06 +0200 Subject: [PATCH] cleanup const generics FIXME --- .../src/traits/object_safety.rs | 35 +++---------------- 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index 041fd65e8fa4..57b8a84300ff 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -820,10 +820,10 @@ fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { } } - fn visit_const(&mut self, ct: &ty::Const<'tcx>) -> ControlFlow { - // First check if the type of this constant references `Self`. - self.visit_ty(ct.ty)?; - + fn visit_unevaluated_const( + &mut self, + uv: ty::Unevaluated<'tcx>, + ) -> ControlFlow { // Constants can only influence object safety if they reference `Self`. // This is only possible for unevaluated constants, so we walk these here. // @@ -837,7 +837,7 @@ fn visit_const(&mut self, ct: &ty::Const<'tcx>) -> ControlFlow { // This shouldn't really matter though as we can't really use any // constants which are not considered const evaluatable. use rustc_middle::mir::abstract_const::Node; - if let Ok(Some(ct)) = AbstractConst::from_const(self.tcx, ct) { + if let Ok(Some(ct)) = AbstractConst::new(self.tcx, uv.shrink()) { const_evaluatable::walk_abstract_const(self.tcx, ct, |node| match node.root() { Node::Leaf(leaf) => { let leaf = leaf.subst(self.tcx, ct.substs); @@ -852,31 +852,6 @@ fn visit_const(&mut self, ct: &ty::Const<'tcx>) -> ControlFlow { ControlFlow::CONTINUE } } - - fn visit_predicate(&mut self, pred: ty::Predicate<'tcx>) -> ControlFlow { - if let ty::PredicateKind::ConstEvaluatable(ct) = pred.kind().skip_binder() { - // FIXME(generic_const_exprs): We should probably deduplicate the logic for - // `AbstractConst`s here, it might make sense to change `ConstEvaluatable` to - // take a `ty::Const` instead. - use rustc_middle::mir::abstract_const::Node; - if let Ok(Some(ct)) = AbstractConst::new(self.tcx, ct) { - const_evaluatable::walk_abstract_const(self.tcx, ct, |node| match node.root() { - Node::Leaf(leaf) => { - let leaf = leaf.subst(self.tcx, ct.substs); - self.visit_const(leaf) - } - Node::Cast(_, _, ty) => self.visit_ty(ty), - Node::Binop(..) | Node::UnaryOp(..) | Node::FunctionCall(_, _) => { - ControlFlow::CONTINUE - } - }) - } else { - ControlFlow::CONTINUE - } - } else { - pred.super_visit_with(self) - } - } } value