Move has_structural_eq_impls provider to rustc_ty_utils
This commit is contained in:
parent
01fbc5ae78
commit
48270044b0
4 changed files with 46 additions and 49 deletions
|
@ -922,7 +922,6 @@ pub fn vtable_trait_upcasting_coercion_new_vptr_slot<'tcx>(
|
|||
|
||||
pub fn provide(providers: &mut ty::query::Providers) {
|
||||
object_safety::provide(providers);
|
||||
structural_match::provide(providers);
|
||||
*providers = ty::query::Providers {
|
||||
specialization_graph_of: specialize::specialization_graph_provider,
|
||||
specializes: specialize::specializes,
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
use crate::infer::{InferCtxt, TyCtxtInferExt};
|
||||
use crate::traits::{ObligationCause, ObligationCtxt};
|
||||
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::lang_items::LangItem;
|
||||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor};
|
||||
use rustc_span::Span;
|
||||
use std::ops::ControlFlow;
|
||||
|
@ -59,41 +54,6 @@ pub fn search_for_adt_const_param_violation<'tcx>(
|
|||
.break_value()
|
||||
}
|
||||
|
||||
/// This method returns true if and only if `adt_ty` itself has been marked as
|
||||
/// eligible for structural-match: namely, if it implements both
|
||||
/// `StructuralPartialEq` and `StructuralEq` (which are respectively injected by
|
||||
/// `#[derive(PartialEq)]` and `#[derive(Eq)]`).
|
||||
///
|
||||
/// Note that this does *not* recursively check if the substructure of `adt_ty`
|
||||
/// implements the traits.
|
||||
fn type_marked_structural<'tcx>(
|
||||
infcx: &InferCtxt<'tcx>,
|
||||
adt_ty: Ty<'tcx>,
|
||||
cause: ObligationCause<'tcx>,
|
||||
) -> bool {
|
||||
let ocx = ObligationCtxt::new(infcx);
|
||||
// require `#[derive(PartialEq)]`
|
||||
let structural_peq_def_id =
|
||||
infcx.tcx.require_lang_item(LangItem::StructuralPeq, Some(cause.span));
|
||||
ocx.register_bound(cause.clone(), ty::ParamEnv::empty(), adt_ty, structural_peq_def_id);
|
||||
// for now, require `#[derive(Eq)]`. (Doing so is a hack to work around
|
||||
// the type `for<'a> fn(&'a ())` failing to implement `Eq` itself.)
|
||||
let structural_teq_def_id =
|
||||
infcx.tcx.require_lang_item(LangItem::StructuralTeq, Some(cause.span));
|
||||
ocx.register_bound(cause, ty::ParamEnv::empty(), adt_ty, structural_teq_def_id);
|
||||
|
||||
// We deliberately skip *reporting* fulfillment errors (via
|
||||
// `report_fulfillment_errors`), for two reasons:
|
||||
//
|
||||
// 1. The error messages would mention `std::marker::StructuralPartialEq`
|
||||
// (a trait which is solely meant as an implementation detail
|
||||
// for now), and
|
||||
//
|
||||
// 2. We are sometimes doing future-incompatibility lints for
|
||||
// now, so we do not want unconditional errors here.
|
||||
ocx.select_all_or_error().is_empty()
|
||||
}
|
||||
|
||||
/// This implements the traversal over the structure of a given type to try to
|
||||
/// find instances of ADTs (specifically structs or enums) that do not implement
|
||||
/// the structural-match traits (`StructuralPartialEq` and `StructuralEq`).
|
||||
|
@ -249,11 +209,3 @@ impl<'tcx> TypeVisitor<'tcx> for Search<'tcx> {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn provide(providers: &mut Providers) {
|
||||
providers.has_structural_eq_impls = |tcx, ty| {
|
||||
let infcx = tcx.infer_ctxt().build();
|
||||
let cause = ObligationCause::dummy();
|
||||
type_marked_structural(&infcx, ty, cause)
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue