remove search_for_adt_const_param_violation
This commit is contained in:
parent
bbf41279fa
commit
8ab10bacdf
2 changed files with 19 additions and 55 deletions
|
@ -62,9 +62,7 @@ pub use self::specialize::specialization_graph::FutureCompatOverlapErrorKind;
|
||||||
pub use self::specialize::{
|
pub use self::specialize::{
|
||||||
specialization_graph, translate_substs, translate_substs_with_cause, OverlapError,
|
specialization_graph, translate_substs, translate_substs_with_cause, OverlapError,
|
||||||
};
|
};
|
||||||
pub use self::structural_match::{
|
pub use self::structural_match::search_for_structural_match_violation;
|
||||||
search_for_adt_const_param_violation, search_for_structural_match_violation,
|
|
||||||
};
|
|
||||||
pub use self::structural_normalize::StructurallyNormalizeExt;
|
pub use self::structural_normalize::StructurallyNormalizeExt;
|
||||||
pub use self::util::elaborate;
|
pub use self::util::elaborate;
|
||||||
pub use self::util::{expand_trait_aliases, TraitAliasExpander};
|
pub use self::util::{expand_trait_aliases, TraitAliasExpander};
|
||||||
|
|
|
@ -34,24 +34,7 @@ pub fn search_for_structural_match_violation<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
) -> Option<Ty<'tcx>> {
|
) -> Option<Ty<'tcx>> {
|
||||||
ty.visit_with(&mut Search { tcx, span, seen: FxHashSet::default(), adt_const_param: false })
|
ty.visit_with(&mut Search { tcx, span, seen: FxHashSet::default() }).break_value()
|
||||||
.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()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This implements the traversal over the structure of a given type to try to
|
/// 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
|
/// Tracks ADTs previously encountered during search, so that
|
||||||
/// we will not recur on them again.
|
/// we will not recur on them again.
|
||||||
seen: FxHashSet<hir::def_id::DefId>,
|
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> {
|
impl<'tcx> Search<'tcx> {
|
||||||
|
@ -124,41 +102,29 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for Search<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::FnPtr(..) => {
|
ty::FnPtr(..) => {
|
||||||
if !self.adt_const_param {
|
return ControlFlow::Continue(());
|
||||||
return ControlFlow::Continue(());
|
|
||||||
} else {
|
|
||||||
return ControlFlow::Break(ty);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::RawPtr(..) => {
|
ty::RawPtr(..) => {
|
||||||
if !self.adt_const_param {
|
// structural-match ignores substructure of
|
||||||
// structural-match ignores substructure of
|
// `*const _`/`*mut _`, so skip `super_visit_with`.
|
||||||
// `*const _`/`*mut _`, so skip `super_visit_with`.
|
//
|
||||||
//
|
// For example, if you have:
|
||||||
// For example, if you have:
|
// ```
|
||||||
// ```
|
// struct NonStructural;
|
||||||
// struct NonStructural;
|
// #[derive(PartialEq, Eq)]
|
||||||
// #[derive(PartialEq, Eq)]
|
// struct T(*const NonStructural);
|
||||||
// struct T(*const NonStructural);
|
// const C: T = T(std::ptr::null());
|
||||||
// const C: T = T(std::ptr::null());
|
// ```
|
||||||
// ```
|
//
|
||||||
//
|
// Even though `NonStructural` does not implement `PartialEq`,
|
||||||
// Even though `NonStructural` does not implement `PartialEq`,
|
// structural equality on `T` does not recur into the raw
|
||||||
// structural equality on `T` does not recur into the raw
|
// pointer. Therefore, one can still use `C` in a pattern.
|
||||||
// pointer. Therefore, one can still use `C` in a pattern.
|
return ControlFlow::Continue(());
|
||||||
return ControlFlow::Continue(());
|
|
||||||
} else {
|
|
||||||
return ControlFlow::Break(ty);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::Float(_) => {
|
ty::Float(_) => {
|
||||||
if !self.adt_const_param {
|
return ControlFlow::Continue(());
|
||||||
return ControlFlow::Continue(());
|
|
||||||
} else {
|
|
||||||
return ControlFlow::Break(ty);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::Array(..) | ty::Slice(_) | ty::Ref(..) | ty::Tuple(..) => {
|
ty::Array(..) | ty::Slice(_) | ty::Ref(..) | ty::Tuple(..) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue