1
Fork 0

Rollup merge of #88557 - lcnr:const-generics-cleanup, r=BoxyUwU

small const generics cleanup
This commit is contained in:
Mara Bos 2021-09-03 13:30:48 +02:00 committed by GitHub
commit 4b5da4aefe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 31 deletions

View file

@ -820,10 +820,10 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeFoldable<'tcx>>(
} }
} }
fn visit_const(&mut self, ct: &ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> { fn visit_unevaluated_const(
// First check if the type of this constant references `Self`. &mut self,
self.visit_ty(ct.ty)?; uv: ty::Unevaluated<'tcx>,
) -> ControlFlow<Self::BreakTy> {
// Constants can only influence object safety if they reference `Self`. // Constants can only influence object safety if they reference `Self`.
// This is only possible for unevaluated constants, so we walk these here. // This is only possible for unevaluated constants, so we walk these here.
// //
@ -837,7 +837,7 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeFoldable<'tcx>>(
// This shouldn't really matter though as we can't really use any // This shouldn't really matter though as we can't really use any
// constants which are not considered const evaluatable. // constants which are not considered const evaluatable.
use rustc_middle::mir::abstract_const::Node; 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() { const_evaluatable::walk_abstract_const(self.tcx, ct, |node| match node.root() {
Node::Leaf(leaf) => { Node::Leaf(leaf) => {
let leaf = leaf.subst(self.tcx, ct.substs); let leaf = leaf.subst(self.tcx, ct.substs);
@ -852,31 +852,6 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeFoldable<'tcx>>(
ControlFlow::CONTINUE ControlFlow::CONTINUE
} }
} }
fn visit_predicate(&mut self, pred: ty::Predicate<'tcx>) -> ControlFlow<Self::BreakTy> {
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 value

View file

@ -120,7 +120,7 @@ fn insert_required_predicates_to_be_wf<'tcx>(
// Luckily the only types contained in default substs are type // Luckily the only types contained in default substs are type
// parameters which don't matter here. // parameters which don't matter here.
// //
// FIXME(const_generics): Once more complex const parameter types // FIXME(adt_const_params): Once complex const parameter types
// are allowed, this might be incorrect. I think that we will still be // are allowed, this might be incorrect. I think that we will still be
// fine, as all outlives relations of the const param types should also // fine, as all outlives relations of the const param types should also
// be part of the adt containing it, but we should still both update the // be part of the adt containing it, but we should still both update the