remove search_for_adt_const_param_violation

This commit is contained in:
Michael Goulet 2023-05-17 18:51:45 +00:00
parent bbf41279fa
commit 8ab10bacdf
2 changed files with 19 additions and 55 deletions

View file

@ -62,9 +62,7 @@ pub use self::specialize::specialization_graph::FutureCompatOverlapErrorKind;
pub use self::specialize::{
specialization_graph, translate_substs, translate_substs_with_cause, OverlapError,
};
pub use self::structural_match::{
search_for_adt_const_param_violation, search_for_structural_match_violation,
};
pub use self::structural_match::search_for_structural_match_violation;
pub use self::structural_normalize::StructurallyNormalizeExt;
pub use self::util::elaborate;
pub use self::util::{expand_trait_aliases, TraitAliasExpander};

View file

@ -34,24 +34,7 @@ pub fn search_for_structural_match_violation<'tcx>(
tcx: TyCtxt<'tcx>,
ty: Ty<'tcx>,
) -> Option<Ty<'tcx>> {
ty.visit_with(&mut Search { tcx, span, seen: FxHashSet::default(), adt_const_param: false })
.break_value()
}
/// This method traverses the structure of `ty`, trying to find any
/// types that are not allowed to be used in a const generic.
///
/// This is either because the type does not implement `StructuralEq`
/// and `StructuralPartialEq`, or because the type is intentionally
/// not supported in const generics (such as floats and raw pointers,
/// which are allowed in match blocks).
pub fn search_for_adt_const_param_violation<'tcx>(
span: Span,
tcx: TyCtxt<'tcx>,
ty: Ty<'tcx>,
) -> Option<Ty<'tcx>> {
ty.visit_with(&mut Search { tcx, span, seen: FxHashSet::default(), adt_const_param: true })
.break_value()
ty.visit_with(&mut Search { tcx, span, seen: FxHashSet::default() }).break_value()
}
/// This implements the traversal over the structure of a given type to try to
@ -65,11 +48,6 @@ struct Search<'tcx> {
/// Tracks ADTs previously encountered during search, so that
/// we will not recur on them again.
seen: FxHashSet<hir::def_id::DefId>,
// Additionally deny things that have been allowed in patterns,
// but are not allowed in adt const params, such as floats and
// fn ptrs.
adt_const_param: bool,
}
impl<'tcx> Search<'tcx> {
@ -124,15 +102,10 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for Search<'tcx> {
}
ty::FnPtr(..) => {
if !self.adt_const_param {
return ControlFlow::Continue(());
} else {
return ControlFlow::Break(ty);
}
}
ty::RawPtr(..) => {
if !self.adt_const_param {
// structural-match ignores substructure of
// `*const _`/`*mut _`, so skip `super_visit_with`.
//
@ -148,17 +121,10 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for Search<'tcx> {
// structural equality on `T` does not recur into the raw
// pointer. Therefore, one can still use `C` in a pattern.
return ControlFlow::Continue(());
} else {
return ControlFlow::Break(ty);
}
}
ty::Float(_) => {
if !self.adt_const_param {
return ControlFlow::Continue(());
} else {
return ControlFlow::Break(ty);
}
}
ty::Array(..) | ty::Slice(_) | ty::Ref(..) | ty::Tuple(..) => {