From d49d5222a9212cdcda35498383d651872d34a825 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 27 Jun 2018 06:53:23 -0400 Subject: [PATCH] merge all the `type_op_foo` modules into one as they are so trivial --- src/librustc_traits/lib.rs | 19 +++---- .../{type_op_normalize.rs => type_op.rs} | 55 ++++++++++++++++++- src/librustc_traits/type_op_eq.rs | 26 --------- .../type_op_prove_predicate.rs | 38 ------------- src/librustc_traits/type_op_subtype.rs | 35 ------------ 5 files changed, 62 insertions(+), 111 deletions(-) rename src/librustc_traits/{type_op_normalize.rs => type_op.rs} (58%) delete mode 100644 src/librustc_traits/type_op_eq.rs delete mode 100644 src/librustc_traits/type_op_prove_predicate.rs delete mode 100644 src/librustc_traits/type_op_subtype.rs diff --git a/src/librustc_traits/lib.rs b/src/librustc_traits/lib.rs index f81b6a2d906..b02d7f6c3f7 100644 --- a/src/librustc_traits/lib.rs +++ b/src/librustc_traits/lib.rs @@ -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 }; } diff --git a/src/librustc_traits/type_op_normalize.rs b/src/librustc_traits/type_op.rs similarity index 58% rename from src/librustc_traits/type_op_normalize.rs rename to src/librustc_traits/type_op.rs index 78e8a0ff3e6..f44cd686b40 100644 --- a/src/librustc_traits/type_op_normalize.rs +++ b/src/librustc_traits/type_op.rs @@ -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>>, 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( 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>>, 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>>, 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, + )], + }) + }) +} diff --git a/src/librustc_traits/type_op_eq.rs b/src/librustc_traits/type_op_eq.rs deleted file mode 100644 index 511203bf2fc..00000000000 --- a/src/librustc_traits/type_op_eq.rs +++ /dev/null @@ -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 or the MIT license -// , 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>>, 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)?) - }) -} diff --git a/src/librustc_traits/type_op_prove_predicate.rs b/src/librustc_traits/type_op_prove_predicate.rs deleted file mode 100644 index 7210d43d9f7..00000000000 --- a/src/librustc_traits/type_op_prove_predicate.rs +++ /dev/null @@ -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 or the MIT license -// , 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>>, 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, - )], - }) - }) -} diff --git a/src/librustc_traits/type_op_subtype.rs b/src/librustc_traits/type_op_subtype.rs deleted file mode 100644 index 30a8550f107..00000000000 --- a/src/librustc_traits/type_op_subtype.rs +++ /dev/null @@ -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 or the MIT license -// , 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>>, 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)?) - }, - ) -}