Skip to content

Commit 4e42f38

Browse files
committed
Move traits::query datatypes to traits::types.
1 parent a77da35 commit 4e42f38

File tree

13 files changed

+353
-249
lines changed

13 files changed

+353
-249
lines changed

src/librustc/traits/query/dropck_outlives.rs

Lines changed: 5 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use crate::infer::at::At;
22
use crate::infer::canonical::OriginalQueryValues;
33
use crate::infer::InferOk;
4-
use crate::ty::subst::GenericArg;
5-
use crate::ty::{self, Ty, TyCtxt};
6-
use rustc_span::source_map::Span;
7-
use std::iter::FromIterator;
4+
5+
use rustc::ty::subst::GenericArg;
6+
use rustc::ty::{self, Ty, TyCtxt};
7+
8+
pub use rustc::traits::query::{DropckOutlivesResult, DtorckConstraint};
89

910
impl<'cx, 'tcx> At<'cx, 'tcx> {
1011
/// Given a type `ty` of some value being dropped, computes a set
@@ -65,76 +66,6 @@ impl<'cx, 'tcx> At<'cx, 'tcx> {
6566
}
6667
}
6768

68-
#[derive(Clone, Debug, Default, HashStable, TypeFoldable, Lift)]
69-
pub struct DropckOutlivesResult<'tcx> {
70-
pub kinds: Vec<GenericArg<'tcx>>,
71-
pub overflows: Vec<Ty<'tcx>>,
72-
}
73-
74-
impl<'tcx> DropckOutlivesResult<'tcx> {
75-
pub fn report_overflows(&self, tcx: TyCtxt<'tcx>, span: Span, ty: Ty<'tcx>) {
76-
if let Some(overflow_ty) = self.overflows.iter().next() {
77-
rustc_errors::struct_span_err!(
78-
tcx.sess,
79-
span,
80-
E0320,
81-
"overflow while adding drop-check rules for {}",
82-
ty,
83-
)
84-
.note(&format!("overflowed on {}", overflow_ty))
85-
.emit();
86-
}
87-
}
88-
89-
pub fn into_kinds_reporting_overflows(
90-
self,
91-
tcx: TyCtxt<'tcx>,
92-
span: Span,
93-
ty: Ty<'tcx>,
94-
) -> Vec<GenericArg<'tcx>> {
95-
self.report_overflows(tcx, span, ty);
96-
let DropckOutlivesResult { kinds, overflows: _ } = self;
97-
kinds
98-
}
99-
}
100-
101-
/// A set of constraints that need to be satisfied in order for
102-
/// a type to be valid for destruction.
103-
#[derive(Clone, Debug, HashStable)]
104-
pub struct DtorckConstraint<'tcx> {
105-
/// Types that are required to be alive in order for this
106-
/// type to be valid for destruction.
107-
pub outlives: Vec<ty::subst::GenericArg<'tcx>>,
108-
109-
/// Types that could not be resolved: projections and params.
110-
pub dtorck_types: Vec<Ty<'tcx>>,
111-
112-
/// If, during the computation of the dtorck constraint, we
113-
/// overflow, that gets recorded here. The caller is expected to
114-
/// report an error.
115-
pub overflows: Vec<Ty<'tcx>>,
116-
}
117-
118-
impl<'tcx> DtorckConstraint<'tcx> {
119-
pub fn empty() -> DtorckConstraint<'tcx> {
120-
DtorckConstraint { outlives: vec![], dtorck_types: vec![], overflows: vec![] }
121-
}
122-
}
123-
124-
impl<'tcx> FromIterator<DtorckConstraint<'tcx>> for DtorckConstraint<'tcx> {
125-
fn from_iter<I: IntoIterator<Item = DtorckConstraint<'tcx>>>(iter: I) -> Self {
126-
let mut result = Self::empty();
127-
128-
for DtorckConstraint { outlives, dtorck_types, overflows } in iter {
129-
result.outlives.extend(outlives);
130-
result.dtorck_types.extend(dtorck_types);
131-
result.overflows.extend(overflows);
132-
}
133-
134-
result
135-
}
136-
}
137-
13869
/// This returns true if the type `ty` is "trivial" for
13970
/// dropck-outlives -- that is, if it doesn't require any types to
14071
/// outlive. This is similar but not *quite* the same as the
Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1 @@
1-
use crate::infer::canonical::{Canonical, QueryResponse};
2-
use crate::ty::Ty;
3-
use rustc_data_structures::sync::Lrc;
4-
5-
#[derive(Debug, HashStable)]
6-
pub struct CandidateStep<'tcx> {
7-
pub self_ty: Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>,
8-
pub autoderefs: usize,
9-
/// `true` if the type results from a dereference of a raw pointer.
10-
/// when assembling candidates, we include these steps, but not when
11-
/// picking methods. This so that if we have `foo: *const Foo` and `Foo` has methods
12-
/// `fn by_raw_ptr(self: *const Self)` and `fn by_ref(&self)`, then
13-
/// `foo.by_raw_ptr()` will work and `foo.by_ref()` won't.
14-
pub from_unsafe_deref: bool,
15-
pub unsize: bool,
16-
}
17-
18-
#[derive(Clone, Debug, HashStable)]
19-
pub struct MethodAutoderefStepsResult<'tcx> {
20-
/// The valid autoderef steps that could be find.
21-
pub steps: Lrc<Vec<CandidateStep<'tcx>>>,
22-
/// If Some(T), a type autoderef reported an error on.
23-
pub opt_bad_ty: Option<Lrc<MethodAutoderefBadTy<'tcx>>>,
24-
/// If `true`, `steps` has been truncated due to reaching the
25-
/// recursion limit.
26-
pub reached_recursion_limit: bool,
27-
}
28-
29-
#[derive(Debug, HashStable)]
30-
pub struct MethodAutoderefBadTy<'tcx> {
31-
pub reached_raw_pointer: bool,
32-
pub ty: Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>,
33-
}
1+
pub use rustc::traits::query::{CandidateStep, MethodAutoderefBadTy, MethodAutoderefStepsResult};

src/librustc/traits/query/mod.rs

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,11 @@
55
//! The providers for the queries defined here can be found in
66
//! `librustc_traits`.
77
8-
use crate::infer::canonical::Canonical;
9-
use crate::ty::error::TypeError;
10-
use crate::ty::{self, Ty};
11-
128
pub mod dropck_outlives;
139
pub mod evaluate_obligation;
1410
pub mod method_autoderef;
1511
pub mod normalize;
1612
pub mod outlives_bounds;
1713
pub mod type_op;
1814

19-
pub type CanonicalProjectionGoal<'tcx> =
20-
Canonical<'tcx, ty::ParamEnvAnd<'tcx, ty::ProjectionTy<'tcx>>>;
21-
22-
pub type CanonicalTyGoal<'tcx> = Canonical<'tcx, ty::ParamEnvAnd<'tcx, Ty<'tcx>>>;
23-
24-
pub type CanonicalPredicateGoal<'tcx> = Canonical<'tcx, ty::ParamEnvAnd<'tcx, ty::Predicate<'tcx>>>;
25-
26-
pub type CanonicalTypeOpAscribeUserTypeGoal<'tcx> =
27-
Canonical<'tcx, ty::ParamEnvAnd<'tcx, type_op::ascribe_user_type::AscribeUserType<'tcx>>>;
28-
29-
pub type CanonicalTypeOpEqGoal<'tcx> =
30-
Canonical<'tcx, ty::ParamEnvAnd<'tcx, type_op::eq::Eq<'tcx>>>;
31-
32-
pub type CanonicalTypeOpSubtypeGoal<'tcx> =
33-
Canonical<'tcx, ty::ParamEnvAnd<'tcx, type_op::subtype::Subtype<'tcx>>>;
34-
35-
pub type CanonicalTypeOpProvePredicateGoal<'tcx> =
36-
Canonical<'tcx, ty::ParamEnvAnd<'tcx, type_op::prove_predicate::ProvePredicate<'tcx>>>;
37-
38-
pub type CanonicalTypeOpNormalizeGoal<'tcx, T> =
39-
Canonical<'tcx, ty::ParamEnvAnd<'tcx, type_op::normalize::Normalize<T>>>;
40-
41-
#[derive(Clone, Debug, HashStable)]
42-
pub struct NoSolution;
43-
44-
pub type Fallible<T> = Result<T, NoSolution>;
45-
46-
impl<'tcx> From<TypeError<'tcx>> for NoSolution {
47-
fn from(_: TypeError<'tcx>) -> NoSolution {
48-
NoSolution
49-
}
50-
}
15+
pub use rustc::traits::types::query::*;

src/librustc/traits/query/normalize.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use crate::ty::{self, Ty, TyCtxt};
1313

1414
use super::NoSolution;
1515

16+
pub use rustc::traits::query::NormalizationResult;
17+
1618
impl<'cx, 'tcx> At<'cx, 'tcx> {
1719
/// Normalize `value` in the context of the inference context,
1820
/// yielding a resulting type, or an error if `value` cannot be
@@ -59,13 +61,6 @@ impl<'cx, 'tcx> At<'cx, 'tcx> {
5961
}
6062
}
6163

62-
/// Result from the `normalize_projection_ty` query.
63-
#[derive(Clone, Debug, HashStable, TypeFoldable, Lift)]
64-
pub struct NormalizationResult<'tcx> {
65-
/// Result of normalization.
66-
pub normalized_ty: Ty<'tcx>,
67-
}
68-
6964
struct QueryNormalizer<'cx, 'tcx> {
7065
infcx: &'cx InferCtxt<'cx, 'tcx>,
7166
cause: &'cx ObligationCause<'tcx>,

src/librustc/traits/query/outlives_bounds.rs

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,7 @@ use crate::ty::{self, Ty};
66
use rustc_hir as hir;
77
use rustc_span::source_map::Span;
88

9-
use crate::ich::StableHashingContext;
10-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
11-
use std::mem;
12-
13-
/// Outlives bounds are relationships between generic parameters,
14-
/// whether they both be regions (`'a: 'b`) or whether types are
15-
/// involved (`T: 'a`). These relationships can be extracted from the
16-
/// full set of predicates we understand or also from types (in which
17-
/// case they are called implied bounds). They are fed to the
18-
/// `OutlivesEnv` which in turn is supplied to the region checker and
19-
/// other parts of the inference system.
20-
#[derive(Clone, Debug, TypeFoldable, Lift)]
21-
pub enum OutlivesBound<'tcx> {
22-
RegionSubRegion(ty::Region<'tcx>, ty::Region<'tcx>),
23-
RegionSubParam(ty::Region<'tcx>, ty::ParamTy),
24-
RegionSubProjection(ty::Region<'tcx>, ty::ProjectionTy<'tcx>),
25-
}
26-
27-
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for OutlivesBound<'tcx> {
28-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
29-
mem::discriminant(self).hash_stable(hcx, hasher);
30-
match *self {
31-
OutlivesBound::RegionSubRegion(ref a, ref b) => {
32-
a.hash_stable(hcx, hasher);
33-
b.hash_stable(hcx, hasher);
34-
}
35-
OutlivesBound::RegionSubParam(ref a, ref b) => {
36-
a.hash_stable(hcx, hasher);
37-
b.hash_stable(hcx, hasher);
38-
}
39-
OutlivesBound::RegionSubProjection(ref a, ref b) => {
40-
a.hash_stable(hcx, hasher);
41-
b.hash_stable(hcx, hasher);
42-
}
43-
}
44-
}
45-
}
9+
pub use rustc::traits::query::OutlivesBound;
4610

4711
impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
4812
/// Implied bounds are region relationships that we deduce

src/librustc/traits/query/type_op/ascribe_user_type.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
11
use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
22
use crate::traits::query::Fallible;
3-
use crate::ty::subst::UserSubsts;
4-
use crate::ty::{ParamEnvAnd, Ty, TyCtxt};
5-
use rustc_hir::def_id::DefId;
3+
use rustc::ty::{ParamEnvAnd, TyCtxt};
64

7-
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable, TypeFoldable, Lift)]
8-
pub struct AscribeUserType<'tcx> {
9-
pub mir_ty: Ty<'tcx>,
10-
pub def_id: DefId,
11-
pub user_substs: UserSubsts<'tcx>,
12-
}
13-
14-
impl<'tcx> AscribeUserType<'tcx> {
15-
pub fn new(mir_ty: Ty<'tcx>, def_id: DefId, user_substs: UserSubsts<'tcx>) -> Self {
16-
Self { mir_ty, def_id, user_substs }
17-
}
18-
}
5+
pub use rustc::traits::query::type_op::AscribeUserType;
196

207
impl<'tcx> super::QueryTypeOp<'tcx> for AscribeUserType<'tcx> {
218
type QueryResponse = ();

src/librustc/traits/query/type_op/eq.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
22
use crate::traits::query::Fallible;
3-
use crate::ty::{ParamEnvAnd, Ty, TyCtxt};
3+
use crate::ty::{ParamEnvAnd, TyCtxt};
44

5-
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable, TypeFoldable, Lift)]
6-
pub struct Eq<'tcx> {
7-
pub a: Ty<'tcx>,
8-
pub b: Ty<'tcx>,
9-
}
10-
11-
impl<'tcx> Eq<'tcx> {
12-
pub fn new(a: Ty<'tcx>, b: Ty<'tcx>) -> Self {
13-
Self { a, b }
14-
}
15-
}
5+
pub use rustc::traits::query::type_op::Eq;
166

177
impl<'tcx> super::QueryTypeOp<'tcx> for Eq<'tcx> {
188
type QueryResponse = ();

src/librustc/traits/query/type_op/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ pub mod prove_predicate;
1919
use self::prove_predicate::ProvePredicate;
2020
pub mod subtype;
2121

22+
pub use crate::traits::types::query::type_op::*;
23+
2224
/// "Type ops" are used in NLL to perform some particular action and
2325
/// extract out the resulting region constraints (or an error if it
2426
/// cannot be completed).

src/librustc/traits/query/type_op/normalize.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,7 @@ use crate::ty::fold::TypeFoldable;
44
use crate::ty::{self, Lift, ParamEnvAnd, Ty, TyCtxt};
55
use std::fmt;
66

7-
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable, TypeFoldable, Lift)]
8-
pub struct Normalize<T> {
9-
pub value: T,
10-
}
11-
12-
impl<'tcx, T> Normalize<T>
13-
where
14-
T: fmt::Debug + TypeFoldable<'tcx>,
15-
{
16-
pub fn new(value: T) -> Self {
17-
Self { value }
18-
}
19-
}
7+
pub use rustc::traits::query::type_op::Normalize;
208

219
impl<'tcx, T> super::QueryTypeOp<'tcx> for Normalize<T>
2210
where

src/librustc/traits/query/type_op/prove_predicate.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,7 @@ use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
22
use crate::traits::query::Fallible;
33
use crate::ty::{ParamEnvAnd, Predicate, TyCtxt};
44

5-
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable, TypeFoldable, Lift)]
6-
pub struct ProvePredicate<'tcx> {
7-
pub predicate: Predicate<'tcx>,
8-
}
9-
10-
impl<'tcx> ProvePredicate<'tcx> {
11-
pub fn new(predicate: Predicate<'tcx>) -> Self {
12-
ProvePredicate { predicate }
13-
}
14-
}
5+
pub use rustc::traits::query::type_op::ProvePredicate;
156

167
impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> {
178
type QueryResponse = ();

0 commit comments

Comments
 (0)