Skip to content

Commit e905d5d

Browse files
committed
Move structural_match to rustc::traits.
1 parent 73667af commit e905d5d

File tree

5 files changed

+45
-45
lines changed

5 files changed

+45
-45
lines changed

src/librustc/traits/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub mod query;
1717
mod select;
1818
mod specialize;
1919
mod structural_impls;
20+
mod structural_match;
2021
mod util;
2122
pub mod wf;
2223

@@ -63,6 +64,9 @@ pub use self::specialize::find_associated_item;
6364
pub use self::specialize::specialization_graph::FutureCompatOverlapError;
6465
pub use self::specialize::specialization_graph::FutureCompatOverlapErrorKind;
6566
pub use self::specialize::{specialization_graph, translate_substs, OverlapError};
67+
pub use self::structural_match::search_for_structural_match_violation;
68+
pub use self::structural_match::type_marked_structural;
69+
pub use self::structural_match::NonStructuralMatchTy;
6670
pub use self::util::{elaborate_predicates, elaborate_trait_ref, elaborate_trait_refs};
6771
pub use self::util::{expand_trait_aliases, TraitAliasExpander};
6872
pub use self::util::{

src/librustc/ty/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ pub use self::context::{
8787

8888
pub use self::instance::{Instance, InstanceDef};
8989

90-
pub use self::structural_match::search_for_structural_match_violation;
91-
pub use self::structural_match::type_marked_structural;
92-
pub use self::structural_match::NonStructuralMatchTy;
93-
9490
pub use self::trait_def::TraitDef;
9591

9692
pub use self::query::queries;
@@ -124,7 +120,6 @@ mod context;
124120
mod diagnostics;
125121
mod instance;
126122
mod structural_impls;
127-
mod structural_match;
128123
mod sty;
129124

130125
// Data types

src/librustc_mir/hair/pattern/const_to_pat.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc::infer::InferCtxt;
44
use rustc::lint;
55
use rustc::mir::Field;
66
use rustc::traits::predicate_for_trait_def;
7-
use rustc::traits::{ObligationCause, PredicateObligation};
7+
use rustc::traits::{self, ObligationCause, PredicateObligation};
88
use rustc::ty::{self, Ty, TyCtxt};
99
use rustc_hir as hir;
1010

@@ -76,12 +76,12 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
7676
fn search_for_structural_match_violation(
7777
&self,
7878
ty: Ty<'tcx>,
79-
) -> Option<ty::NonStructuralMatchTy<'tcx>> {
80-
ty::search_for_structural_match_violation(self.id, self.span, self.tcx(), ty)
79+
) -> Option<traits::NonStructuralMatchTy<'tcx>> {
80+
traits::search_for_structural_match_violation(self.id, self.span, self.tcx(), ty)
8181
}
8282

8383
fn type_marked_structural(&self, ty: Ty<'tcx>) -> bool {
84-
ty::type_marked_structural(self.id, self.span, &self.infcx, ty)
84+
traits::type_marked_structural(self.id, self.span, &self.infcx, ty)
8585
}
8686

8787
fn to_pat(&mut self, cv: &'tcx ty::Const<'tcx>) -> Pat<'tcx> {
@@ -105,8 +105,8 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
105105
);
106106
if let Some(non_sm_ty) = structural {
107107
let adt_def = match non_sm_ty {
108-
ty::NonStructuralMatchTy::Adt(adt_def) => adt_def,
109-
ty::NonStructuralMatchTy::Param => {
108+
traits::NonStructuralMatchTy::Adt(adt_def) => adt_def,
109+
traits::NonStructuralMatchTy::Param => {
110110
bug!("use of constant whose type is a parameter inside a pattern")
111111
}
112112
};

src/librustc_typeck/collect.rs

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use crate::middle::weak_lang_items;
2323
use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
2424
use rustc::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
2525
use rustc::mir::mono::Linkage;
26+
use rustc::traits;
2627
use rustc::ty::query::Providers;
2728
use rustc::ty::subst::GenericArgKind;
2829
use rustc::ty::subst::{InternalSubsts, Subst};
@@ -1509,48 +1510,48 @@ fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
15091510
}
15101511
}
15111512

1512-
Node::GenericParam(param) => {
1513-
match &param.kind {
1514-
hir::GenericParamKind::Type { default: Some(ref ty), .. } => icx.to_ty(ty),
1515-
hir::GenericParamKind::Const { ty: ref hir_ty, .. } => {
1516-
let ty = icx.to_ty(hir_ty);
1517-
if !tcx.features().const_compare_raw_pointers {
1518-
let err = match ty.peel_refs().kind {
1519-
ty::FnPtr(_) => Some("function pointers"),
1520-
ty::RawPtr(_) => Some("raw pointers"),
1521-
_ => None,
1522-
};
1523-
if let Some(unsupported_type) = err {
1524-
feature_gate::feature_err(
1525-
&tcx.sess.parse_sess,
1526-
sym::const_compare_raw_pointers,
1527-
hir_ty.span,
1528-
&format!(
1529-
"using {} as const generic parameters is unstable",
1530-
unsupported_type
1531-
),
1532-
)
1533-
.emit();
1534-
};
1535-
}
1536-
if ty::search_for_structural_match_violation(param.hir_id, param.span, tcx, ty)
1537-
.is_some()
1538-
{
1539-
struct_span_err!(
1513+
Node::GenericParam(param) => match &param.kind {
1514+
hir::GenericParamKind::Type { default: Some(ref ty), .. } => icx.to_ty(ty),
1515+
hir::GenericParamKind::Const { ty: ref hir_ty, .. } => {
1516+
let ty = icx.to_ty(hir_ty);
1517+
if !tcx.features().const_compare_raw_pointers {
1518+
let err = match ty.peel_refs().kind {
1519+
ty::FnPtr(_) => Some("function pointers"),
1520+
ty::RawPtr(_) => Some("raw pointers"),
1521+
_ => None,
1522+
};
1523+
if let Some(unsupported_type) = err {
1524+
feature_gate::feature_err(
1525+
&tcx.sess.parse_sess,
1526+
sym::const_compare_raw_pointers,
1527+
hir_ty.span,
1528+
&format!(
1529+
"using {} as const generic parameters is unstable",
1530+
unsupported_type
1531+
),
1532+
)
1533+
.emit();
1534+
};
1535+
}
1536+
if traits::search_for_structural_match_violation(param.hir_id, param.span, tcx, ty)
1537+
.is_some()
1538+
{
1539+
struct_span_err!(
15401540
tcx.sess,
15411541
hir_ty.span,
15421542
E0741,
15431543
"the types of const generic parameters must derive `PartialEq` and `Eq`",
1544-
).span_label(
1544+
)
1545+
.span_label(
15451546
hir_ty.span,
15461547
format!("`{}` doesn't derive both `PartialEq` and `Eq`", ty),
1547-
).emit();
1548-
}
1549-
ty
1548+
)
1549+
.emit();
15501550
}
1551-
x => bug!("unexpected non-type Node::GenericParam: {:?}", x),
1551+
ty
15521552
}
1553-
}
1553+
x => bug!("unexpected non-type Node::GenericParam: {:?}", x),
1554+
},
15541555

15551556
x => {
15561557
bug!("unexpected sort of node in type_of_def_id(): {:?}", x);

0 commit comments

Comments
 (0)