merge all the type_op_foo modules into one as they are so trivial

This commit is contained in:
Niko Matsakis 2018-06-27 06:53:23 -04:00
parent 66c88392b4
commit d49d5222a9
5 changed files with 62 additions and 111 deletions

View File

@ -34,10 +34,7 @@ mod evaluate_obligation;
mod normalize_projection_ty;
mod normalize_erasing_regions;
pub mod lowering;
mod type_op_eq;
mod type_op_normalize;
mod type_op_prove_predicate;
mod type_op_subtype;
mod type_op;
use rustc::ty::query::Providers;
@ -51,13 +48,13 @@ pub fn provide(p: &mut Providers) {
program_clauses_for: lowering::program_clauses_for,
program_clauses_for_env: lowering::program_clauses_for_env,
evaluate_obligation: evaluate_obligation::evaluate_obligation,
type_op_eq: type_op_eq::type_op_eq,
type_op_prove_predicate: type_op_prove_predicate::type_op_prove_predicate,
type_op_subtype: type_op_subtype::type_op_subtype,
type_op_normalize_ty: type_op_normalize::type_op_normalize_ty,
type_op_normalize_predicate: type_op_normalize::type_op_normalize_predicate,
type_op_normalize_fn_sig: type_op_normalize::type_op_normalize_fn_sig,
type_op_normalize_poly_fn_sig: type_op_normalize::type_op_normalize_poly_fn_sig,
type_op_eq: type_op::type_op_eq,
type_op_prove_predicate: type_op::type_op_prove_predicate,
type_op_subtype: type_op::type_op_subtype,
type_op_normalize_ty: type_op::type_op_normalize_ty,
type_op_normalize_predicate: type_op::type_op_normalize_predicate,
type_op_normalize_fn_sig: type_op::type_op_normalize_fn_sig,
type_op_normalize_poly_fn_sig: type_op::type_op_normalize_poly_fn_sig,
..*p
};
}

View File

@ -10,13 +10,26 @@
use rustc::infer::canonical::{Canonical, QueryResult};
use rustc::infer::{InferCtxt, InferOk};
use rustc::traits::query::type_op::eq::Eq;
use rustc::traits::query::type_op::normalize::Normalize;
use rustc::traits::query::type_op::prove_predicate::ProvePredicate;
use rustc::traits::query::type_op::subtype::Subtype;
use rustc::traits::query::{Fallible, NoSolution};
use rustc::traits::{Normalized, ObligationCause};
use rustc::traits::{Obligation, Normalized, ObligationCause};
use rustc::ty::{FnSig, Lift, PolyFnSig, Predicate, Ty, TyCtxt, TypeFoldable};
use rustc_data_structures::sync::Lrc;
use std::fmt;
crate fn type_op_eq<'tcx>(
tcx: TyCtxt<'_, 'tcx, 'tcx>,
canonicalized: Canonical<'tcx, Eq<'tcx>>,
) -> Result<Lrc<Canonical<'tcx, QueryResult<'tcx, ()>>>, NoSolution> {
tcx.infer_ctxt()
.enter_canonical_trait_query(&canonicalized, |infcx, Eq { param_env, a, b }| {
Ok(infcx.at(&ObligationCause::dummy(), param_env).eq(a, b)?)
})
}
fn type_op_normalize<T>(
infcx: &InferCtxt<'_, 'gcx, 'tcx>,
key: Normalize<'tcx, T>,
@ -62,3 +75,43 @@ crate fn type_op_normalize_poly_fn_sig(
tcx.infer_ctxt()
.enter_canonical_trait_query(&canonicalized, type_op_normalize)
}
crate fn type_op_subtype<'tcx>(
tcx: TyCtxt<'_, 'tcx, 'tcx>,
canonicalized: Canonical<'tcx, Subtype<'tcx>>,
) -> Result<Lrc<Canonical<'tcx, QueryResult<'tcx, ()>>>, NoSolution> {
tcx.infer_ctxt().enter_canonical_trait_query(
&canonicalized,
|infcx,
Subtype {
param_env,
sub,
sup,
}| {
Ok(infcx
.at(&ObligationCause::dummy(), param_env)
.sup(sup, sub)?)
},
)
}
crate fn type_op_prove_predicate<'tcx>(
tcx: TyCtxt<'_, 'tcx, 'tcx>,
canonicalized: Canonical<'tcx, ProvePredicate<'tcx>>,
) -> Result<Lrc<Canonical<'tcx, QueryResult<'tcx, ()>>>, NoSolution> {
tcx.infer_ctxt()
.enter_canonical_trait_query(&canonicalized, |_infcx, key| {
let ProvePredicate {
param_env,
predicate,
} = key;
Ok(InferOk {
value: (),
obligations: vec![Obligation::new(
ObligationCause::dummy(),
param_env,
predicate,
)],
})
})
}

View File

@ -1,26 +0,0 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use rustc::infer::canonical::{Canonical, QueryResult};
use rustc::traits::query::type_op::eq::Eq;
use rustc::traits::query::NoSolution;
use rustc::traits::ObligationCause;
use rustc::ty::TyCtxt;
use rustc_data_structures::sync::Lrc;
crate fn type_op_eq<'tcx>(
tcx: TyCtxt<'_, 'tcx, 'tcx>,
canonicalized: Canonical<'tcx, Eq<'tcx>>,
) -> Result<Lrc<Canonical<'tcx, QueryResult<'tcx, ()>>>, NoSolution> {
tcx.infer_ctxt()
.enter_canonical_trait_query(&canonicalized, |infcx, Eq { param_env, a, b }| {
Ok(infcx.at(&ObligationCause::dummy(), param_env).eq(a, b)?)
})
}

View File

@ -1,38 +0,0 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use rustc::infer::InferOk;
use rustc::infer::canonical::{Canonical, QueryResult};
use rustc::traits::query::type_op::prove_predicate::ProvePredicate;
use rustc::traits::query::NoSolution;
use rustc::traits::{Obligation, ObligationCause};
use rustc::ty::TyCtxt;
use rustc_data_structures::sync::Lrc;
crate fn type_op_prove_predicate<'tcx>(
tcx: TyCtxt<'_, 'tcx, 'tcx>,
canonicalized: Canonical<'tcx, ProvePredicate<'tcx>>,
) -> Result<Lrc<Canonical<'tcx, QueryResult<'tcx, ()>>>, NoSolution> {
tcx.infer_ctxt()
.enter_canonical_trait_query(&canonicalized, |_infcx, key| {
let ProvePredicate {
param_env,
predicate,
} = key;
Ok(InferOk {
value: (),
obligations: vec![Obligation::new(
ObligationCause::dummy(),
param_env,
predicate,
)],
})
})
}

View File

@ -1,35 +0,0 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use rustc::infer::canonical::{Canonical, QueryResult};
use rustc::traits::query::type_op::subtype::Subtype;
use rustc::traits::query::NoSolution;
use rustc::traits::ObligationCause;
use rustc::ty::TyCtxt;
use rustc_data_structures::sync::Lrc;
crate fn type_op_subtype<'tcx>(
tcx: TyCtxt<'_, 'tcx, 'tcx>,
canonicalized: Canonical<'tcx, Subtype<'tcx>>,
) -> Result<Lrc<Canonical<'tcx, QueryResult<'tcx, ()>>>, NoSolution> {
tcx.infer_ctxt().enter_canonical_trait_query(
&canonicalized,
|infcx,
Subtype {
param_env,
sub,
sup,
}| {
Ok(infcx
.at(&ObligationCause::dummy(), param_env)
.sup(sup, sub)?)
},
)
}