Skip to content

Commit d6077f8

Browse files
authored
Rollup merge of rust-lang#108350 - compiler-errors:assoc-type-bound-dogfooding, r=oli-obk
Use associated type bounds in some places in the compiler Use associated type bounds for some nested `impl Trait<Assoc = impl Trait2>` cases. I'm generally keen to introduce new lang features that are more mature into the compiler, but maybe let's see what others think? Side-note: I was surprised that the only use-cases of nested impl trait in the compiler are just iterator related?!
2 parents 2011ced + 729cd55 commit d6077f8

File tree

15 files changed

+22
-41
lines changed

15 files changed

+22
-41
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! This query borrow-checks the MIR to (further) ensure it is not broken.
22
33
#![allow(rustc::potential_query_instability)]
4+
#![feature(associated_type_bounds)]
45
#![feature(box_patterns)]
56
#![feature(let_chains)]
67
#![feature(min_specialization)]

compiler/rustc_borrowck/src/type_check/canonical.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
117117

118118
pub(super) fn prove_predicates(
119119
&mut self,
120-
predicates: impl IntoIterator<Item = impl ToPredicate<'tcx> + std::fmt::Debug>,
120+
predicates: impl IntoIterator<Item: ToPredicate<'tcx> + std::fmt::Debug>,
121121
locations: Locations,
122122
category: ConstraintCategory<'tcx>,
123123
) {

compiler/rustc_infer/src/infer/combine.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -478,10 +478,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
478478
self.obligations.extend(obligations.into_iter());
479479
}
480480

481-
pub fn register_predicates(
482-
&mut self,
483-
obligations: impl IntoIterator<Item = impl ToPredicate<'tcx>>,
484-
) {
481+
pub fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ToPredicate<'tcx>>) {
485482
self.obligations.extend(obligations.into_iter().map(|to_pred| {
486483
Obligation::new(self.infcx.tcx, self.trace.cause.clone(), self.param_env, to_pred)
487484
}))
@@ -814,10 +811,7 @@ pub trait ObligationEmittingRelation<'tcx>: TypeRelation<'tcx> {
814811
/// Register predicates that must hold in order for this relation to hold. Uses
815812
/// a default obligation cause, [`ObligationEmittingRelation::register_obligations`] should
816813
/// be used if control over the obligaton causes is required.
817-
fn register_predicates(
818-
&mut self,
819-
obligations: impl IntoIterator<Item = impl ToPredicate<'tcx>>,
820-
);
814+
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ToPredicate<'tcx>>);
821815

822816
/// Register an obligation that both constants must be equal to each other.
823817
///

compiler/rustc_infer/src/infer/equate.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,7 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> {
201201
}
202202

203203
impl<'tcx> ObligationEmittingRelation<'tcx> for Equate<'_, '_, 'tcx> {
204-
fn register_predicates(
205-
&mut self,
206-
obligations: impl IntoIterator<Item = impl ty::ToPredicate<'tcx>>,
207-
) {
204+
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ty::ToPredicate<'tcx>>) {
208205
self.fields.register_predicates(obligations);
209206
}
210207

compiler/rustc_infer/src/infer/glb.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,7 @@ impl<'combine, 'infcx, 'tcx> LatticeDir<'infcx, 'tcx> for Glb<'combine, 'infcx,
148148
}
149149

150150
impl<'tcx> ObligationEmittingRelation<'tcx> for Glb<'_, '_, 'tcx> {
151-
fn register_predicates(
152-
&mut self,
153-
obligations: impl IntoIterator<Item = impl ty::ToPredicate<'tcx>>,
154-
) {
151+
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ty::ToPredicate<'tcx>>) {
155152
self.fields.register_predicates(obligations);
156153
}
157154

compiler/rustc_infer/src/infer/lub.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,7 @@ impl<'combine, 'infcx, 'tcx> LatticeDir<'infcx, 'tcx> for Lub<'combine, 'infcx,
148148
}
149149

150150
impl<'tcx> ObligationEmittingRelation<'tcx> for Lub<'_, '_, 'tcx> {
151-
fn register_predicates(
152-
&mut self,
153-
obligations: impl IntoIterator<Item = impl ty::ToPredicate<'tcx>>,
154-
) {
151+
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ty::ToPredicate<'tcx>>) {
155152
self.fields.register_predicates(obligations);
156153
}
157154

compiler/rustc_infer/src/infer/nll_relate/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -763,10 +763,7 @@ impl<'tcx, D> ObligationEmittingRelation<'tcx> for TypeRelating<'_, 'tcx, D>
763763
where
764764
D: TypeRelatingDelegate<'tcx>,
765765
{
766-
fn register_predicates(
767-
&mut self,
768-
obligations: impl IntoIterator<Item = impl ty::ToPredicate<'tcx>>,
769-
) {
766+
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ty::ToPredicate<'tcx>>) {
770767
self.delegate.register_obligations(
771768
obligations
772769
.into_iter()

compiler/rustc_infer/src/infer/sub.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,7 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> {
228228
}
229229

230230
impl<'tcx> ObligationEmittingRelation<'tcx> for Sub<'_, '_, 'tcx> {
231-
fn register_predicates(
232-
&mut self,
233-
obligations: impl IntoIterator<Item = impl ty::ToPredicate<'tcx>>,
234-
) {
231+
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ty::ToPredicate<'tcx>>) {
235232
self.fields.register_predicates(obligations);
236233
}
237234

compiler/rustc_infer/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//! This API is completely unstable and subject to change.
1414
1515
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
16+
#![feature(associated_type_bounds)]
1617
#![feature(box_patterns)]
1718
#![feature(control_flow_enum)]
1819
#![feature(extend_one)]

compiler/rustc_middle/src/ty/context.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,7 +1856,7 @@ impl<'tcx> TyCtxt<'tcx> {
18561856
pub fn mk_fn_def(
18571857
self,
18581858
def_id: DefId,
1859-
substs: impl IntoIterator<Item = impl Into<GenericArg<'tcx>>>,
1859+
substs: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
18601860
) -> Ty<'tcx> {
18611861
let substs = self.check_substs(def_id, substs);
18621862
self.mk_ty(FnDef(def_id, substs))
@@ -1866,7 +1866,7 @@ impl<'tcx> TyCtxt<'tcx> {
18661866
fn check_substs(
18671867
self,
18681868
_def_id: DefId,
1869-
substs: impl IntoIterator<Item = impl Into<GenericArg<'tcx>>>,
1869+
substs: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
18701870
) -> SubstsRef<'tcx> {
18711871
let substs = substs.into_iter().map(Into::into);
18721872
#[cfg(debug_assertions)]
@@ -1901,7 +1901,7 @@ impl<'tcx> TyCtxt<'tcx> {
19011901
pub fn mk_projection(
19021902
self,
19031903
item_def_id: DefId,
1904-
substs: impl IntoIterator<Item = impl Into<GenericArg<'tcx>>>,
1904+
substs: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
19051905
) -> Ty<'tcx> {
19061906
self.mk_alias(ty::Projection, self.mk_alias_ty(item_def_id, substs))
19071907
}
@@ -2293,7 +2293,7 @@ impl<'tcx> TyCtxt<'tcx> {
22932293
pub fn mk_trait_ref(
22942294
self,
22952295
trait_def_id: DefId,
2296-
substs: impl IntoIterator<Item = impl Into<GenericArg<'tcx>>>,
2296+
substs: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
22972297
) -> ty::TraitRef<'tcx> {
22982298
let substs = self.check_substs(trait_def_id, substs);
22992299
ty::TraitRef { def_id: trait_def_id, substs, _use_mk_trait_ref_instead: () }
@@ -2302,7 +2302,7 @@ impl<'tcx> TyCtxt<'tcx> {
23022302
pub fn mk_alias_ty(
23032303
self,
23042304
def_id: DefId,
2305-
substs: impl IntoIterator<Item = impl Into<GenericArg<'tcx>>>,
2305+
substs: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
23062306
) -> ty::AliasTy<'tcx> {
23072307
let substs = self.check_substs(def_id, substs);
23082308
ty::AliasTy { def_id, substs, _use_mk_alias_ty_instead: () }
@@ -2472,7 +2472,7 @@ impl<'tcx> TyCtxtAt<'tcx> {
24722472
pub fn mk_trait_ref(
24732473
self,
24742474
trait_lang_item: LangItem,
2475-
substs: impl IntoIterator<Item = impl Into<ty::GenericArg<'tcx>>>,
2475+
substs: impl IntoIterator<Item: Into<ty::GenericArg<'tcx>>>,
24762476
) -> ty::TraitRef<'tcx> {
24772477
let trait_def_id = self.require_lang_item(trait_lang_item, Some(self.span));
24782478
self.tcx.mk_trait_ref(trait_def_id, substs)

0 commit comments

Comments
 (0)