Move structural_match to rustc::traits.

This commit is contained in:
Camille GILLOT 2020-01-05 23:02:07 +01:00
parent 73667af444
commit e905d5da93
5 changed files with 45 additions and 45 deletions

View File

@ -17,6 +17,7 @@
mod select;
mod specialize;
mod structural_impls;
mod structural_match;
mod util;
pub mod wf;
@ -63,6 +64,9 @@
pub use self::specialize::specialization_graph::FutureCompatOverlapError;
pub use self::specialize::specialization_graph::FutureCompatOverlapErrorKind;
pub use self::specialize::{specialization_graph, translate_substs, OverlapError};
pub use self::structural_match::search_for_structural_match_violation;
pub use self::structural_match::type_marked_structural;
pub use self::structural_match::NonStructuralMatchTy;
pub use self::util::{elaborate_predicates, elaborate_trait_ref, elaborate_trait_refs};
pub use self::util::{expand_trait_aliases, TraitAliasExpander};
pub use self::util::{

View File

@ -87,10 +87,6 @@
pub use self::instance::{Instance, InstanceDef};
pub use self::structural_match::search_for_structural_match_violation;
pub use self::structural_match::type_marked_structural;
pub use self::structural_match::NonStructuralMatchTy;
pub use self::trait_def::TraitDef;
pub use self::query::queries;
@ -124,7 +120,6 @@
mod diagnostics;
mod instance;
mod structural_impls;
mod structural_match;
mod sty;
// Data types

View File

@ -4,7 +4,7 @@
use rustc::lint;
use rustc::mir::Field;
use rustc::traits::predicate_for_trait_def;
use rustc::traits::{ObligationCause, PredicateObligation};
use rustc::traits::{self, ObligationCause, PredicateObligation};
use rustc::ty::{self, Ty, TyCtxt};
use rustc_hir as hir;
@ -76,12 +76,12 @@ fn tcx(&self) -> TyCtxt<'tcx> {
fn search_for_structural_match_violation(
&self,
ty: Ty<'tcx>,
) -> Option<ty::NonStructuralMatchTy<'tcx>> {
ty::search_for_structural_match_violation(self.id, self.span, self.tcx(), ty)
) -> Option<traits::NonStructuralMatchTy<'tcx>> {
traits::search_for_structural_match_violation(self.id, self.span, self.tcx(), ty)
}
fn type_marked_structural(&self, ty: Ty<'tcx>) -> bool {
ty::type_marked_structural(self.id, self.span, &self.infcx, ty)
traits::type_marked_structural(self.id, self.span, &self.infcx, ty)
}
fn to_pat(&mut self, cv: &'tcx ty::Const<'tcx>) -> Pat<'tcx> {
@ -105,8 +105,8 @@ fn to_pat(&mut self, cv: &'tcx ty::Const<'tcx>) -> Pat<'tcx> {
);
if let Some(non_sm_ty) = structural {
let adt_def = match non_sm_ty {
ty::NonStructuralMatchTy::Adt(adt_def) => adt_def,
ty::NonStructuralMatchTy::Param => {
traits::NonStructuralMatchTy::Adt(adt_def) => adt_def,
traits::NonStructuralMatchTy::Param => {
bug!("use of constant whose type is a parameter inside a pattern")
}
};

View File

@ -23,6 +23,7 @@
use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
use rustc::mir::mono::Linkage;
use rustc::traits;
use rustc::ty::query::Providers;
use rustc::ty::subst::GenericArgKind;
use rustc::ty::subst::{InternalSubsts, Subst};
@ -1509,48 +1510,48 @@ fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
}
}
Node::GenericParam(param) => {
match &param.kind {
hir::GenericParamKind::Type { default: Some(ref ty), .. } => icx.to_ty(ty),
hir::GenericParamKind::Const { ty: ref hir_ty, .. } => {
let ty = icx.to_ty(hir_ty);
if !tcx.features().const_compare_raw_pointers {
let err = match ty.peel_refs().kind {
ty::FnPtr(_) => Some("function pointers"),
ty::RawPtr(_) => Some("raw pointers"),
_ => None,
};
if let Some(unsupported_type) = err {
feature_gate::feature_err(
&tcx.sess.parse_sess,
sym::const_compare_raw_pointers,
hir_ty.span,
&format!(
"using {} as const generic parameters is unstable",
unsupported_type
),
)
.emit();
};
}
if ty::search_for_structural_match_violation(param.hir_id, param.span, tcx, ty)
.is_some()
{
struct_span_err!(
Node::GenericParam(param) => match &param.kind {
hir::GenericParamKind::Type { default: Some(ref ty), .. } => icx.to_ty(ty),
hir::GenericParamKind::Const { ty: ref hir_ty, .. } => {
let ty = icx.to_ty(hir_ty);
if !tcx.features().const_compare_raw_pointers {
let err = match ty.peel_refs().kind {
ty::FnPtr(_) => Some("function pointers"),
ty::RawPtr(_) => Some("raw pointers"),
_ => None,
};
if let Some(unsupported_type) = err {
feature_gate::feature_err(
&tcx.sess.parse_sess,
sym::const_compare_raw_pointers,
hir_ty.span,
&format!(
"using {} as const generic parameters is unstable",
unsupported_type
),
)
.emit();
};
}
if traits::search_for_structural_match_violation(param.hir_id, param.span, tcx, ty)
.is_some()
{
struct_span_err!(
tcx.sess,
hir_ty.span,
E0741,
"the types of const generic parameters must derive `PartialEq` and `Eq`",
).span_label(
)
.span_label(
hir_ty.span,
format!("`{}` doesn't derive both `PartialEq` and `Eq`", ty),
).emit();
}
ty
)
.emit();
}
x => bug!("unexpected non-type Node::GenericParam: {:?}", x),
ty
}
}
x => bug!("unexpected non-type Node::GenericParam: {:?}", x),
},
x => {
bug!("unexpected sort of node in type_of_def_id(): {:?}", x);