Skip to content

Commit 4e8f637

Browse files
Rollup merge of #115566 - zirconium-n:issue-107250-clean-up-unused-to-predicate, r=oli-obk
clean up unneeded `ToPredicate` impls Part of #107250. Removed all totally unused impls. And inlined two impls not need to satisify trait bound. r? `@oli-obk`
2 parents 78e74d9 + 3c69a10 commit 4e8f637

File tree

6 files changed

+23
-58
lines changed

6 files changed

+23
-58
lines changed

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_middle::ty::util::ExplicitSelf;
1818
use rustc_middle::ty::{
1919
self, GenericArgs, Ty, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt,
2020
};
21-
use rustc_middle::ty::{GenericParamDefKind, ToPredicate, TyCtxt};
21+
use rustc_middle::ty::{GenericParamDefKind, TyCtxt};
2222
use rustc_span::{Span, DUMMY_SP};
2323
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt;
2424
use rustc_trait_selection::traits::outlives_bounds::InferCtxtExt as _;
@@ -2196,16 +2196,16 @@ pub(super) fn check_type_bounds<'tcx>(
21962196
//
21972197
// impl<T> X for T where T: X { type Y = <T as X>::Y; }
21982198
}
2199-
_ => predicates.push(
2199+
_ => predicates.push(ty::Clause::from_projection_clause(
2200+
tcx,
22002201
ty::Binder::bind_with_vars(
22012202
ty::ProjectionPredicate {
22022203
projection_ty: tcx.mk_alias_ty(trait_ty.def_id, rebased_args),
22032204
term: normalize_impl_ty.into(),
22042205
},
22052206
bound_vars,
2206-
)
2207-
.to_predicate(tcx),
2208-
),
2207+
),
2208+
)),
22092209
};
22102210
ty::ParamEnv::new(tcx.mk_clauses(&predicates), Reveal::UserFacing)
22112211
};

compiler/rustc_middle/src/ty/mod.rs

+5-39
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,11 @@ impl rustc_errors::IntoDiagnosticArg for Clause<'_> {
566566
pub struct Clause<'tcx>(Interned<'tcx, WithCachedTypeInfo<ty::Binder<'tcx, PredicateKind<'tcx>>>>);
567567

568568
impl<'tcx> Clause<'tcx> {
569+
pub fn from_projection_clause(tcx: TyCtxt<'tcx>, pred: PolyProjectionPredicate<'tcx>) -> Self {
570+
let pred: Predicate<'tcx> = pred.to_predicate(tcx);
571+
pred.expect_clause()
572+
}
573+
569574
pub fn as_predicate(self) -> Predicate<'tcx> {
570575
Predicate(self.0)
571576
}
@@ -1253,14 +1258,6 @@ impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for TraitRef<'tcx> {
12531258
}
12541259
}
12551260

1256-
impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for TraitPredicate<'tcx> {
1257-
#[inline(always)]
1258-
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> {
1259-
let p: Predicate<'tcx> = self.to_predicate(tcx);
1260-
p.expect_clause()
1261-
}
1262-
}
1263-
12641261
impl<'tcx> ToPredicate<'tcx> for Binder<'tcx, TraitRef<'tcx>> {
12651262
#[inline(always)]
12661263
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
@@ -1287,18 +1284,6 @@ impl<'tcx> ToPredicate<'tcx, PolyTraitPredicate<'tcx>> for Binder<'tcx, TraitRef
12871284
}
12881285
}
12891286

1290-
impl<'tcx> ToPredicate<'tcx, PolyTraitPredicate<'tcx>> for TraitRef<'tcx> {
1291-
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> PolyTraitPredicate<'tcx> {
1292-
ty::Binder::dummy(self).to_predicate(tcx)
1293-
}
1294-
}
1295-
1296-
impl<'tcx> ToPredicate<'tcx, PolyTraitPredicate<'tcx>> for TraitPredicate<'tcx> {
1297-
fn to_predicate(self, _tcx: TyCtxt<'tcx>) -> PolyTraitPredicate<'tcx> {
1298-
ty::Binder::dummy(self)
1299-
}
1300-
}
1301-
13021287
impl<'tcx> ToPredicate<'tcx> for PolyTraitPredicate<'tcx> {
13031288
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
13041289
self.map_bound(|p| PredicateKind::Clause(ClauseKind::Trait(p))).to_predicate(tcx)
@@ -1312,12 +1297,6 @@ impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for PolyTraitPredicate<'tcx> {
13121297
}
13131298
}
13141299

1315-
impl<'tcx> ToPredicate<'tcx> for OutlivesPredicate<ty::Region<'tcx>, ty::Region<'tcx>> {
1316-
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
1317-
ty::Binder::dummy(PredicateKind::Clause(ClauseKind::RegionOutlives(self))).to_predicate(tcx)
1318-
}
1319-
}
1320-
13211300
impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> {
13221301
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
13231302
self.map_bound(|p| PredicateKind::Clause(ClauseKind::RegionOutlives(p))).to_predicate(tcx)
@@ -1330,12 +1309,6 @@ impl<'tcx> ToPredicate<'tcx> for OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>> {
13301309
}
13311310
}
13321311

1333-
impl<'tcx> ToPredicate<'tcx> for PolyTypeOutlivesPredicate<'tcx> {
1334-
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
1335-
self.map_bound(|p| PredicateKind::Clause(ClauseKind::TypeOutlives(p))).to_predicate(tcx)
1336-
}
1337-
}
1338-
13391312
impl<'tcx> ToPredicate<'tcx> for ProjectionPredicate<'tcx> {
13401313
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
13411314
ty::Binder::dummy(PredicateKind::Clause(ClauseKind::Projection(self))).to_predicate(tcx)
@@ -1355,13 +1328,6 @@ impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for ProjectionPredicate<'tcx> {
13551328
}
13561329
}
13571330

1358-
impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for PolyProjectionPredicate<'tcx> {
1359-
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> {
1360-
let p: Predicate<'tcx> = self.to_predicate(tcx);
1361-
p.expect_clause()
1362-
}
1363-
}
1364-
13651331
impl<'tcx> ToPredicate<'tcx> for TraitPredicate<'tcx> {
13661332
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
13671333
PredicateKind::Clause(ClauseKind::Trait(self)).to_predicate(tcx)

compiler/rustc_middle/src/ty/sty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ impl<'tcx> PolyExistentialPredicate<'tcx> {
725725
self.rebind(tr).with_self_ty(tcx, self_ty).to_predicate(tcx)
726726
}
727727
ExistentialPredicate::Projection(p) => {
728-
self.rebind(p.with_self_ty(tcx, self_ty)).to_predicate(tcx)
728+
ty::Clause::from_projection_clause(tcx, self.rebind(p.with_self_ty(tcx, self_ty)))
729729
}
730730
ExistentialPredicate::AutoTrait(did) => {
731731
let generics = tcx.generics_of(did);

compiler/rustc_trait_selection/src/solve/project_goals.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,15 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
346346
ty::TraitRef::from_lang_item(tcx, LangItem::Sized, DUMMY_SP, [output])
347347
});
348348

349-
let pred = tupled_inputs_and_output
350-
.map_bound(|(inputs, output)| ty::ProjectionPredicate {
349+
let pred = ty::Clause::from_projection_clause(
350+
tcx,
351+
tupled_inputs_and_output.map_bound(|(inputs, output)| ty::ProjectionPredicate {
351352
projection_ty: tcx
352353
.mk_alias_ty(goal.predicate.def_id(), [goal.predicate.self_ty(), inputs]),
353354
term: output.into(),
354-
})
355-
.to_predicate(tcx);
355+
}),
356+
);
357+
356358
// A built-in `Fn` impl only holds if the output is sized.
357359
// (FIXME: technically we only need to check this if the type is a fn ptr...)
358360
Self::consider_implied_clause(ecx, goal, pred, [goal.with(tcx, output_is_sized_pred)])

compiler/rustc_trait_selection/src/traits/project.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,7 @@ fn assemble_candidates_from_object_ty<'cx, 'tcx>(
16441644
let env_predicates = data
16451645
.projection_bounds()
16461646
.filter(|bound| bound.item_def_id() == obligation.predicate.def_id)
1647-
.map(|p| p.with_self_ty(tcx, object_ty).to_predicate(tcx));
1647+
.map(|p| ty::Clause::from_projection_clause(tcx, p.with_self_ty(tcx, object_ty)));
16481648

16491649
assemble_candidates_from_predicates(
16501650
selcx,

compiler/rustc_ty_utils/src/ty.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_hir::def::DefKind;
44
use rustc_index::bit_set::BitSet;
55
use rustc_middle::query::Providers;
66
use rustc_middle::ty::{
7-
self, EarlyBinder, ToPredicate, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor,
7+
self, EarlyBinder, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor,
88
};
99
use rustc_span::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
1010
use rustc_span::DUMMY_SP;
@@ -220,13 +220,10 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitFinder<'_, 'tcx> {
220220
// strategy, then just reinterpret the associated type like an opaque :^)
221221
let default_ty = self.tcx.type_of(shifted_alias_ty.def_id).instantiate(self.tcx, shifted_alias_ty.args);
222222

223-
self.predicates.push(
224-
ty::Binder::bind_with_vars(
225-
ty::ProjectionPredicate { projection_ty: shifted_alias_ty, term: default_ty.into() },
226-
self.bound_vars,
227-
)
228-
.to_predicate(self.tcx),
229-
);
223+
self.predicates.push(ty::Clause::from_projection_clause(self.tcx, ty::Binder::bind_with_vars(
224+
ty::ProjectionPredicate { projection_ty: shifted_alias_ty, term: default_ty.into() },
225+
self.bound_vars,
226+
)));
230227

231228
// We walk the *un-shifted* alias ty, because we're tracking the de bruijn
232229
// binder depth, and if we were to walk `shifted_alias_ty` instead, we'd

0 commit comments

Comments
 (0)