From e905d5da93cfdbd49c4dc9c89a1537da726a8d35 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 5 Jan 2020 23:02:07 +0100 Subject: [PATCH] Move structural_match to rustc::traits. --- src/librustc/traits/mod.rs | 4 ++ .../{ty => traits}/structural_match.rs | 0 src/librustc/ty/mod.rs | 5 -- src/librustc_mir/hair/pattern/const_to_pat.rs | 12 ++-- src/librustc_typeck/collect.rs | 69 ++++++++++--------- 5 files changed, 45 insertions(+), 45 deletions(-) rename src/librustc/{ty => traits}/structural_match.rs (100%) diff --git a/src/librustc/traits/mod.rs b/src/librustc/traits/mod.rs index 18653df14b6..3c49d1b6f36 100644 --- a/src/librustc/traits/mod.rs +++ b/src/librustc/traits/mod.rs @@ -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::{ diff --git a/src/librustc/ty/structural_match.rs b/src/librustc/traits/structural_match.rs similarity index 100% rename from src/librustc/ty/structural_match.rs rename to src/librustc/traits/structural_match.rs diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 858535cf4a4..23e4309c1d3 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -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 diff --git a/src/librustc_mir/hair/pattern/const_to_pat.rs b/src/librustc_mir/hair/pattern/const_to_pat.rs index 9631f8004f6..75b25f03ca2 100644 --- a/src/librustc_mir/hair/pattern/const_to_pat.rs +++ b/src/librustc_mir/hair/pattern/const_to_pat.rs @@ -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::search_for_structural_match_violation(self.id, self.span, self.tcx(), ty) + ) -> Option> { + 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") } }; diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 1fefeaf720f..fb9e4ba5ce2 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -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 ¶m.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 ¶m.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);