From 729cd55688f0c7e39087b934f1d733813bf0a71a Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 21 Feb 2023 03:49:03 +0000 Subject: [PATCH] Associated type bounds in some places in the compiler --- compiler/rustc_borrowck/src/lib.rs | 1 + compiler/rustc_borrowck/src/type_check/canonical.rs | 2 +- compiler/rustc_infer/src/infer/combine.rs | 10 ++-------- compiler/rustc_infer/src/infer/equate.rs | 5 +---- compiler/rustc_infer/src/infer/glb.rs | 5 +---- compiler/rustc_infer/src/infer/lub.rs | 5 +---- compiler/rustc_infer/src/infer/nll_relate/mod.rs | 5 +---- compiler/rustc_infer/src/infer/sub.rs | 5 +---- compiler/rustc_infer/src/lib.rs | 1 + compiler/rustc_middle/src/ty/context.rs | 12 ++++++------ compiler/rustc_middle/src/ty/sty.rs | 2 +- compiler/rustc_mir_build/src/build/matches/test.rs | 2 +- compiler/rustc_trait_selection/src/infer.rs | 4 ++-- .../src/traits/error_reporting/method_chain.rs | 2 +- compiler/rustc_trait_selection/src/traits/util.rs | 2 +- 15 files changed, 22 insertions(+), 41 deletions(-) diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index 98103af779d8b..84a9ffa7f0dd2 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -1,6 +1,7 @@ //! This query borrow-checks the MIR to (further) ensure it is not broken. #![allow(rustc::potential_query_instability)] +#![feature(associated_type_bounds)] #![feature(box_patterns)] #![feature(let_chains)] #![feature(min_specialization)] diff --git a/compiler/rustc_borrowck/src/type_check/canonical.rs b/compiler/rustc_borrowck/src/type_check/canonical.rs index 2b81a35052d7b..eff6e06ace765 100644 --- a/compiler/rustc_borrowck/src/type_check/canonical.rs +++ b/compiler/rustc_borrowck/src/type_check/canonical.rs @@ -117,7 +117,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { pub(super) fn prove_predicates( &mut self, - predicates: impl IntoIterator + std::fmt::Debug>, + predicates: impl IntoIterator + std::fmt::Debug>, locations: Locations, category: ConstraintCategory<'tcx>, ) { diff --git a/compiler/rustc_infer/src/infer/combine.rs b/compiler/rustc_infer/src/infer/combine.rs index f5504b05dc4e3..4a6a7a15a4c60 100644 --- a/compiler/rustc_infer/src/infer/combine.rs +++ b/compiler/rustc_infer/src/infer/combine.rs @@ -478,10 +478,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> { self.obligations.extend(obligations.into_iter()); } - pub fn register_predicates( - &mut self, - obligations: impl IntoIterator>, - ) { + pub fn register_predicates(&mut self, obligations: impl IntoIterator>) { self.obligations.extend(obligations.into_iter().map(|to_pred| { Obligation::new(self.infcx.tcx, self.trace.cause.clone(), self.param_env, to_pred) })) @@ -814,10 +811,7 @@ pub trait ObligationEmittingRelation<'tcx>: TypeRelation<'tcx> { /// Register predicates that must hold in order for this relation to hold. Uses /// a default obligation cause, [`ObligationEmittingRelation::register_obligations`] should /// be used if control over the obligaton causes is required. - fn register_predicates( - &mut self, - obligations: impl IntoIterator>, - ); + fn register_predicates(&mut self, obligations: impl IntoIterator>); /// Register an obligation that both constants must be equal to each other. /// diff --git a/compiler/rustc_infer/src/infer/equate.rs b/compiler/rustc_infer/src/infer/equate.rs index 742c01efff603..a8d42cb279b11 100644 --- a/compiler/rustc_infer/src/infer/equate.rs +++ b/compiler/rustc_infer/src/infer/equate.rs @@ -201,10 +201,7 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> { } impl<'tcx> ObligationEmittingRelation<'tcx> for Equate<'_, '_, 'tcx> { - fn register_predicates( - &mut self, - obligations: impl IntoIterator>, - ) { + fn register_predicates(&mut self, obligations: impl IntoIterator>) { self.fields.register_predicates(obligations); } diff --git a/compiler/rustc_infer/src/infer/glb.rs b/compiler/rustc_infer/src/infer/glb.rs index 74abca7bbea36..f6221be85cade 100644 --- a/compiler/rustc_infer/src/infer/glb.rs +++ b/compiler/rustc_infer/src/infer/glb.rs @@ -148,10 +148,7 @@ impl<'combine, 'infcx, 'tcx> LatticeDir<'infcx, 'tcx> for Glb<'combine, 'infcx, } impl<'tcx> ObligationEmittingRelation<'tcx> for Glb<'_, '_, 'tcx> { - fn register_predicates( - &mut self, - obligations: impl IntoIterator>, - ) { + fn register_predicates(&mut self, obligations: impl IntoIterator>) { self.fields.register_predicates(obligations); } diff --git a/compiler/rustc_infer/src/infer/lub.rs b/compiler/rustc_infer/src/infer/lub.rs index f997171b97f27..9877c80b4ba22 100644 --- a/compiler/rustc_infer/src/infer/lub.rs +++ b/compiler/rustc_infer/src/infer/lub.rs @@ -148,10 +148,7 @@ impl<'combine, 'infcx, 'tcx> LatticeDir<'infcx, 'tcx> for Lub<'combine, 'infcx, } impl<'tcx> ObligationEmittingRelation<'tcx> for Lub<'_, '_, 'tcx> { - fn register_predicates( - &mut self, - obligations: impl IntoIterator>, - ) { + fn register_predicates(&mut self, obligations: impl IntoIterator>) { self.fields.register_predicates(obligations); } diff --git a/compiler/rustc_infer/src/infer/nll_relate/mod.rs b/compiler/rustc_infer/src/infer/nll_relate/mod.rs index 644774c93c2a4..4a274f3cdd3e7 100644 --- a/compiler/rustc_infer/src/infer/nll_relate/mod.rs +++ b/compiler/rustc_infer/src/infer/nll_relate/mod.rs @@ -759,10 +759,7 @@ impl<'tcx, D> ObligationEmittingRelation<'tcx> for TypeRelating<'_, 'tcx, D> where D: TypeRelatingDelegate<'tcx>, { - fn register_predicates( - &mut self, - obligations: impl IntoIterator>, - ) { + fn register_predicates(&mut self, obligations: impl IntoIterator>) { self.delegate.register_obligations( obligations .into_iter() diff --git a/compiler/rustc_infer/src/infer/sub.rs b/compiler/rustc_infer/src/infer/sub.rs index bf1b34415470c..c294e47671c3b 100644 --- a/compiler/rustc_infer/src/infer/sub.rs +++ b/compiler/rustc_infer/src/infer/sub.rs @@ -228,10 +228,7 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> { } impl<'tcx> ObligationEmittingRelation<'tcx> for Sub<'_, '_, 'tcx> { - fn register_predicates( - &mut self, - obligations: impl IntoIterator>, - ) { + fn register_predicates(&mut self, obligations: impl IntoIterator>) { self.fields.register_predicates(obligations); } diff --git a/compiler/rustc_infer/src/lib.rs b/compiler/rustc_infer/src/lib.rs index 4c119a443555e..4f9b067ff0e95 100644 --- a/compiler/rustc_infer/src/lib.rs +++ b/compiler/rustc_infer/src/lib.rs @@ -13,6 +13,7 @@ //! This API is completely unstable and subject to change. #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] +#![feature(associated_type_bounds)] #![feature(box_patterns)] #![feature(control_flow_enum)] #![feature(extend_one)] diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index e2f32cdca3ca3..e84a40c56714d 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1857,7 +1857,7 @@ impl<'tcx> TyCtxt<'tcx> { pub fn mk_fn_def( self, def_id: DefId, - substs: impl IntoIterator>>, + substs: impl IntoIterator>>, ) -> Ty<'tcx> { let substs = self.check_substs(def_id, substs); self.mk_ty(FnDef(def_id, substs)) @@ -1867,7 +1867,7 @@ impl<'tcx> TyCtxt<'tcx> { fn check_substs( self, _def_id: DefId, - substs: impl IntoIterator>>, + substs: impl IntoIterator>>, ) -> SubstsRef<'tcx> { let substs = substs.into_iter().map(Into::into); #[cfg(debug_assertions)] @@ -1902,7 +1902,7 @@ impl<'tcx> TyCtxt<'tcx> { pub fn mk_projection( self, item_def_id: DefId, - substs: impl IntoIterator>>, + substs: impl IntoIterator>>, ) -> Ty<'tcx> { self.mk_alias(ty::Projection, self.mk_alias_ty(item_def_id, substs)) } @@ -2294,7 +2294,7 @@ impl<'tcx> TyCtxt<'tcx> { pub fn mk_trait_ref( self, trait_def_id: DefId, - substs: impl IntoIterator>>, + substs: impl IntoIterator>>, ) -> ty::TraitRef<'tcx> { let substs = self.check_substs(trait_def_id, substs); ty::TraitRef { def_id: trait_def_id, substs, _use_mk_trait_ref_instead: () } @@ -2303,7 +2303,7 @@ impl<'tcx> TyCtxt<'tcx> { pub fn mk_alias_ty( self, def_id: DefId, - substs: impl IntoIterator>>, + substs: impl IntoIterator>>, ) -> ty::AliasTy<'tcx> { let substs = self.check_substs(def_id, substs); ty::AliasTy { def_id, substs, _use_mk_alias_ty_instead: () } @@ -2469,7 +2469,7 @@ impl<'tcx> TyCtxtAt<'tcx> { pub fn mk_trait_ref( self, trait_lang_item: LangItem, - substs: impl IntoIterator>>, + substs: impl IntoIterator>>, ) -> ty::TraitRef<'tcx> { let trait_def_id = self.require_lang_item(trait_lang_item, Some(self.span)); self.tcx.mk_trait_ref(trait_def_id, substs) diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index f8d17433cf770..4cd14b54e9448 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -570,7 +570,7 @@ impl<'tcx> GeneratorSubsts<'tcx> { self, def_id: DefId, tcx: TyCtxt<'tcx>, - ) -> impl Iterator> + Captures<'tcx>> { + ) -> impl Iterator> + Captures<'tcx>> { let layout = tcx.generator_layout(def_id).unwrap(); layout.variant_fields.iter().map(move |variant| { variant.iter().map(move |field| { diff --git a/compiler/rustc_mir_build/src/build/matches/test.rs b/compiler/rustc_mir_build/src/build/matches/test.rs index 8859f5002e465..2de89f67dfdc7 100644 --- a/compiler/rustc_mir_build/src/build/matches/test.rs +++ b/compiler/rustc_mir_build/src/build/matches/test.rs @@ -832,7 +832,7 @@ fn trait_method<'tcx>( tcx: TyCtxt<'tcx>, trait_def_id: DefId, method_name: Symbol, - substs: impl IntoIterator>>, + substs: impl IntoIterator>>, ) -> ConstantKind<'tcx> { // The unhygienic comparison here is acceptable because this is only // used on known traits. diff --git a/compiler/rustc_trait_selection/src/infer.rs b/compiler/rustc_trait_selection/src/infer.rs index c0bfe152a1e8c..468561b57ac25 100644 --- a/compiler/rustc_trait_selection/src/infer.rs +++ b/compiler/rustc_trait_selection/src/infer.rs @@ -42,7 +42,7 @@ pub trait InferCtxtExt<'tcx> { fn type_implements_trait( &self, trait_def_id: DefId, - params: impl IntoIterator>>, + params: impl IntoIterator>>, param_env: ty::ParamEnv<'tcx>, ) -> traits::EvaluationResult; } @@ -82,7 +82,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> { fn type_implements_trait( &self, trait_def_id: DefId, - params: impl IntoIterator>>, + params: impl IntoIterator>>, param_env: ty::ParamEnv<'tcx>, ) -> traits::EvaluationResult { let trait_ref = self.tcx.mk_trait_ref(trait_def_id, params); diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/method_chain.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/method_chain.rs index 9474c70cb535e..1174efdbfa8fa 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/method_chain.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/method_chain.rs @@ -98,7 +98,7 @@ impl<'tcx> ObligationEmittingRelation<'tcx> for CollectAllMismatches<'_, 'tcx> { fn register_predicates( &mut self, - _obligations: impl IntoIterator>, + _obligations: impl IntoIterator>, ) { // FIXME(deferred_projection_equality) } diff --git a/compiler/rustc_trait_selection/src/traits/util.rs b/compiler/rustc_trait_selection/src/traits/util.rs index b5df583e3f4cb..a0d391f9b1674 100644 --- a/compiler/rustc_trait_selection/src/traits/util.rs +++ b/compiler/rustc_trait_selection/src/traits/util.rs @@ -239,7 +239,7 @@ pub fn predicate_for_trait_def<'tcx>( cause: ObligationCause<'tcx>, trait_def_id: DefId, recursion_depth: usize, - params: impl IntoIterator>>, + params: impl IntoIterator>>, ) -> PredicateObligation<'tcx> { let trait_ref = tcx.mk_trait_ref(trait_def_id, params); predicate_for_trait_ref(tcx, cause, param_env, trait_ref, recursion_depth)