From b2e899f843fd94ed3188f4feceb84c74039a30e2 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 27 Jun 2018 09:42:00 -0400 Subject: [PATCH] move into `provide` methods --- src/librustc_traits/dropck_outlives.rs | 11 +++++++- src/librustc_traits/evaluate_obligation.rs | 10 ++++++- src/librustc_traits/lib.rs | 24 ++++------------ src/librustc_traits/lowering.rs | 9 ++++++ .../normalize_erasing_regions.rs | 10 ++++++- .../normalize_projection_ty.rs | 10 ++++++- src/librustc_traits/type_op.rs | 28 ++++++++++++++----- 7 files changed, 73 insertions(+), 29 deletions(-) diff --git a/src/librustc_traits/dropck_outlives.rs b/src/librustc_traits/dropck_outlives.rs index cd49aa2241b3..eddfee95c8f3 100644 --- a/src/librustc_traits/dropck_outlives.rs +++ b/src/librustc_traits/dropck_outlives.rs @@ -13,13 +13,22 @@ use rustc::infer::canonical::{Canonical, QueryResult}; use rustc::traits::query::dropck_outlives::{DropckOutlivesResult, DtorckConstraint}; use rustc::traits::query::{CanonicalTyGoal, NoSolution}; use rustc::traits::{FulfillmentContext, Normalized, ObligationCause}; +use rustc::ty::query::Providers; use rustc::ty::subst::{Subst, Substs}; use rustc::ty::{self, ParamEnvAnd, Ty, TyCtxt}; use rustc::util::nodemap::FxHashSet; use rustc_data_structures::sync::Lrc; use syntax::codemap::{Span, DUMMY_SP}; -crate fn dropck_outlives<'tcx>( +crate fn provide(p: &mut Providers) { + *p = Providers { + dropck_outlives, + adt_dtorck_constraint, + ..*p + }; +} + +fn dropck_outlives<'tcx>( tcx: TyCtxt<'_, 'tcx, 'tcx>, goal: CanonicalTyGoal<'tcx>, ) -> Result>>>, NoSolution> { diff --git a/src/librustc_traits/evaluate_obligation.rs b/src/librustc_traits/evaluate_obligation.rs index 21259bbcd38f..e8a3447902fd 100644 --- a/src/librustc_traits/evaluate_obligation.rs +++ b/src/librustc_traits/evaluate_obligation.rs @@ -11,10 +11,18 @@ use rustc::traits::{EvaluationResult, Obligation, ObligationCause, OverflowError, SelectionContext, TraitQueryMode}; use rustc::traits::query::CanonicalPredicateGoal; +use rustc::ty::query::Providers; use rustc::ty::{ParamEnvAnd, TyCtxt}; use syntax::codemap::DUMMY_SP; -crate fn evaluate_obligation<'tcx>( +crate fn provide(p: &mut Providers) { + *p = Providers { + evaluate_obligation, + ..*p + }; +} + +fn evaluate_obligation<'tcx>( tcx: TyCtxt<'_, 'tcx, 'tcx>, goal: CanonicalPredicateGoal<'tcx>, ) -> Result { diff --git a/src/librustc_traits/lib.rs b/src/librustc_traits/lib.rs index b02d7f6c3f7b..1da3907915a0 100644 --- a/src/librustc_traits/lib.rs +++ b/src/librustc_traits/lib.rs @@ -39,22 +39,10 @@ mod type_op; use rustc::ty::query::Providers; pub fn provide(p: &mut Providers) { - *p = Providers { - dropck_outlives: dropck_outlives::dropck_outlives, - adt_dtorck_constraint: dropck_outlives::adt_dtorck_constraint, - normalize_projection_ty: normalize_projection_ty::normalize_projection_ty, - normalize_ty_after_erasing_regions: - normalize_erasing_regions::normalize_ty_after_erasing_regions, - 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::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 - }; + dropck_outlives::provide(p); + evaluate_obligation::provide(p); + lowering::provide(p); + normalize_projection_ty::provide(p); + normalize_erasing_regions::provide(p); + type_op::provide(p); } diff --git a/src/librustc_traits/lowering.rs b/src/librustc_traits/lowering.rs index 0270e970976e..16aa63d69999 100644 --- a/src/librustc_traits/lowering.rs +++ b/src/librustc_traits/lowering.rs @@ -14,6 +14,7 @@ use rustc::hir::map::definitions::DefPathData; use rustc::hir::{self, ImplPolarity}; use rustc::traits::{Clause, Clauses, DomainGoal, Goal, PolyDomainGoal, ProgramClause, WhereClause, FromEnv, WellFormed}; +use rustc::ty::query::Providers; use rustc::ty::subst::Substs; use rustc::ty::{self, Slice, TyCtxt}; use rustc_data_structures::fx::FxHashSet; @@ -22,6 +23,14 @@ use syntax::ast; use std::iter; +crate fn provide(p: &mut Providers) { + *p = Providers { + program_clauses_for, + program_clauses_for_env, + ..*p + }; +} + crate trait Lower { /// Lower a rustc construct (e.g. `ty::TraitPredicate`) to a chalk-like type. fn lower(&self) -> T; diff --git a/src/librustc_traits/normalize_erasing_regions.rs b/src/librustc_traits/normalize_erasing_regions.rs index 299433d479dc..a85983d0e9a8 100644 --- a/src/librustc_traits/normalize_erasing_regions.rs +++ b/src/librustc_traits/normalize_erasing_regions.rs @@ -10,10 +10,18 @@ use rustc::traits::{Normalized, ObligationCause}; use rustc::traits::query::NoSolution; +use rustc::ty::query::Providers; use rustc::ty::{self, ParamEnvAnd, Ty, TyCtxt}; use std::sync::atomic::Ordering; -crate fn normalize_ty_after_erasing_regions<'tcx>( +crate fn provide(p: &mut Providers) { + *p = Providers { + normalize_ty_after_erasing_regions, + ..*p + }; +} + +fn normalize_ty_after_erasing_regions<'tcx>( tcx: TyCtxt<'_, 'tcx, 'tcx>, goal: ParamEnvAnd<'tcx, Ty<'tcx>>, ) -> Ty<'tcx> { diff --git a/src/librustc_traits/normalize_projection_ty.rs b/src/librustc_traits/normalize_projection_ty.rs index 473b2c8e9985..1a8899ad8e03 100644 --- a/src/librustc_traits/normalize_projection_ty.rs +++ b/src/librustc_traits/normalize_projection_ty.rs @@ -12,13 +12,21 @@ use rustc::infer::canonical::{Canonical, QueryResult}; use rustc::infer::InferOk; use rustc::traits::query::{normalize::NormalizationResult, CanonicalProjectionGoal, NoSolution}; use rustc::traits::{self, ObligationCause, SelectionContext}; +use rustc::ty::query::Providers; use rustc::ty::{ParamEnvAnd, TyCtxt}; use rustc_data_structures::sync::Lrc; use std::sync::atomic::Ordering; use syntax::ast::DUMMY_NODE_ID; use syntax_pos::DUMMY_SP; -crate fn normalize_projection_ty<'tcx>( +crate fn provide(p: &mut Providers) { + *p = Providers { + normalize_projection_ty, + ..*p + }; +} + +fn normalize_projection_ty<'tcx>( tcx: TyCtxt<'_, 'tcx, 'tcx>, goal: CanonicalProjectionGoal<'tcx>, ) -> Result>>>, NoSolution> { diff --git a/src/librustc_traits/type_op.rs b/src/librustc_traits/type_op.rs index f44cd686b40a..9e8640a32de5 100644 --- a/src/librustc_traits/type_op.rs +++ b/src/librustc_traits/type_op.rs @@ -16,11 +16,25 @@ 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::{Obligation, Normalized, ObligationCause}; +use rustc::ty::query::Providers; 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>( +crate fn provide(p: &mut Providers) { + *p = Providers { + type_op_eq, + type_op_prove_predicate, + type_op_subtype, + type_op_normalize_ty, + type_op_normalize_predicate, + type_op_normalize_fn_sig, + type_op_normalize_poly_fn_sig, + ..*p + }; +} + +fn type_op_eq<'tcx>( tcx: TyCtxt<'_, 'tcx, 'tcx>, canonicalized: Canonical<'tcx, Eq<'tcx>>, ) -> Result>>, NoSolution> { @@ -44,7 +58,7 @@ where Ok(InferOk { value, obligations }) // ugh we should merge these two structs } -crate fn type_op_normalize_ty( +fn type_op_normalize_ty( tcx: TyCtxt<'_, 'tcx, 'tcx>, canonicalized: Canonical<'tcx, Normalize<'tcx, Ty<'tcx>>>, ) -> Result>>>, NoSolution> { @@ -52,7 +66,7 @@ crate fn type_op_normalize_ty( .enter_canonical_trait_query(&canonicalized, type_op_normalize) } -crate fn type_op_normalize_predicate( +fn type_op_normalize_predicate( tcx: TyCtxt<'_, 'tcx, 'tcx>, canonicalized: Canonical<'tcx, Normalize<'tcx, Predicate<'tcx>>>, ) -> Result>>>, NoSolution> { @@ -60,7 +74,7 @@ crate fn type_op_normalize_predicate( .enter_canonical_trait_query(&canonicalized, type_op_normalize) } -crate fn type_op_normalize_fn_sig( +fn type_op_normalize_fn_sig( tcx: TyCtxt<'_, 'tcx, 'tcx>, canonicalized: Canonical<'tcx, Normalize<'tcx, FnSig<'tcx>>>, ) -> Result>>>, NoSolution> { @@ -68,7 +82,7 @@ crate fn type_op_normalize_fn_sig( .enter_canonical_trait_query(&canonicalized, type_op_normalize) } -crate fn type_op_normalize_poly_fn_sig( +fn type_op_normalize_poly_fn_sig( tcx: TyCtxt<'_, 'tcx, 'tcx>, canonicalized: Canonical<'tcx, Normalize<'tcx, PolyFnSig<'tcx>>>, ) -> Result>>>, NoSolution> { @@ -76,7 +90,7 @@ crate fn type_op_normalize_poly_fn_sig( .enter_canonical_trait_query(&canonicalized, type_op_normalize) } -crate fn type_op_subtype<'tcx>( +fn type_op_subtype<'tcx>( tcx: TyCtxt<'_, 'tcx, 'tcx>, canonicalized: Canonical<'tcx, Subtype<'tcx>>, ) -> Result>>, NoSolution> { @@ -95,7 +109,7 @@ crate fn type_op_subtype<'tcx>( ) } -crate fn type_op_prove_predicate<'tcx>( +fn type_op_prove_predicate<'tcx>( tcx: TyCtxt<'_, 'tcx, 'tcx>, canonicalized: Canonical<'tcx, ProvePredicate<'tcx>>, ) -> Result>>, NoSolution> {