Skip to content

Commit 412dc28

Browse files
Make P parameter explicit
1 parent 11ec3ec commit 412dc28

File tree

14 files changed

+62
-49
lines changed

14 files changed

+62
-49
lines changed

compiler/rustc_borrowck/src/type_check/canonical.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
115115

116116
pub(super) fn prove_predicates(
117117
&mut self,
118-
predicates: impl IntoIterator<Item: Upcast<'tcx> + std::fmt::Debug>,
118+
predicates: impl IntoIterator<Item: Upcast<'tcx, ty::Predicate<'tcx>> + std::fmt::Debug>,
119119
locations: Locations,
120120
category: ConstraintCategory<'tcx>,
121121
) {
@@ -127,7 +127,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
127127
#[instrument(skip(self), level = "debug")]
128128
pub(super) fn prove_predicate(
129129
&mut self,
130-
predicate: impl Upcast<'tcx> + std::fmt::Debug,
130+
predicate: impl Upcast<'tcx, ty::Predicate<'tcx>> + std::fmt::Debug,
131131
locations: Locations,
132132
category: ConstraintCategory<'tcx>,
133133
) {

compiler/rustc_borrowck/src/type_check/relate_tys.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,10 @@ impl<'bccx, 'tcx> ObligationEmittingRelation<'tcx> for NllTypeRelating<'_, 'bccx
546546
self.type_checker.param_env
547547
}
548548

549-
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ty::Upcast<'tcx>>) {
549+
fn register_predicates(
550+
&mut self,
551+
obligations: impl IntoIterator<Item: ty::Upcast<'tcx, ty::Predicate<'tcx>>>,
552+
) {
550553
self.register_obligations(
551554
obligations
552555
.into_iter()

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ pub(super) fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredic
4040
// `tcx.def_span(def_id);`
4141
let span = DUMMY_SP;
4242

43-
result.predicates =
44-
tcx.arena.alloc_from_iter(result.predicates.iter().copied().chain(std::iter::once((
45-
ty::TraitRef::identity(tcx, def_id).upcast(tcx),
46-
span,
47-
))));
43+
result.predicates = tcx.arena.alloc_from_iter(
44+
result
45+
.predicates
46+
.iter()
47+
.copied()
48+
.chain(std::iter::once((ty::TraitRef::identity(tcx, def_id).upcast(tcx), span))),
49+
);
4850
}
4951
debug!("predicates_of(def_id={:?}) = {:?}", def_id, result);
5052
result
@@ -196,10 +198,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
196198
.no_bound_vars()
197199
.expect("const parameters cannot be generic");
198200
let ct = icx.lowerer().lower_const_param(param.hir_id, ct_ty);
199-
predicates.insert((
200-
ty::ClauseKind::ConstArgHasType(ct, ct_ty).upcast(tcx),
201-
param.span,
202-
));
201+
predicates
202+
.insert((ty::ClauseKind::ConstArgHasType(ct, ct_ty).upcast(tcx), param.span));
203203
}
204204
}
205205
}
@@ -257,8 +257,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
257257
)
258258
}
259259
};
260-
let pred = ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(r1, r2))
261-
.upcast(tcx);
260+
let pred =
261+
ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(r1, r2)).upcast(tcx);
262262
(pred, span)
263263
}))
264264
}
@@ -354,8 +354,7 @@ fn const_evaluatable_predicates_of(
354354
let ct = ty::Const::from_anon_const(self.tcx, c.def_id);
355355
if let ty::ConstKind::Unevaluated(_) = ct.kind() {
356356
let span = self.tcx.def_span(c.def_id);
357-
self.preds
358-
.insert((ty::ClauseKind::ConstEvaluatable(ct).upcast(self.tcx), span));
357+
self.preds.insert((ty::ClauseKind::ConstEvaluatable(ct).upcast(self.tcx), span));
359358
}
360359
}
361360

compiler/rustc_infer/src/infer/relate/combine.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,10 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
337337
self.obligations.extend(obligations);
338338
}
339339

340-
pub fn register_predicates(&mut self, obligations: impl IntoIterator<Item: Upcast<'tcx>>) {
340+
pub fn register_predicates(
341+
&mut self,
342+
obligations: impl IntoIterator<Item: Upcast<'tcx, ty::Predicate<'tcx>>>,
343+
) {
341344
self.obligations.extend(obligations.into_iter().map(|to_pred| {
342345
Obligation::new(self.infcx.tcx, self.trace.cause.clone(), self.param_env, to_pred)
343346
}))
@@ -360,7 +363,10 @@ pub trait ObligationEmittingRelation<'tcx>: TypeRelation<'tcx> {
360363
/// Register predicates that must hold in order for this relation to hold. Uses
361364
/// a default obligation cause, [`ObligationEmittingRelation::register_obligations`] should
362365
/// be used if control over the obligation causes is required.
363-
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: Upcast<'tcx>>);
366+
fn register_predicates(
367+
&mut self,
368+
obligations: impl IntoIterator<Item: Upcast<'tcx, ty::Predicate<'tcx>>>,
369+
);
364370

365371
/// Register `AliasRelate` obligation(s) that both types must be related to each other.
366372
fn register_type_relate_obligation(&mut self, a: Ty<'tcx>, b: Ty<'tcx>);

compiler/rustc_infer/src/infer/relate/glb.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ impl<'tcx> ObligationEmittingRelation<'tcx> for Glb<'_, '_, 'tcx> {
140140
self.fields.param_env
141141
}
142142

143-
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ty::Upcast<'tcx>>) {
143+
fn register_predicates(
144+
&mut self,
145+
obligations: impl IntoIterator<Item: ty::Upcast<'tcx, ty::Predicate<'tcx>>>,
146+
) {
144147
self.fields.register_predicates(obligations);
145148
}
146149

compiler/rustc_infer/src/infer/relate/lub.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ impl<'tcx> ObligationEmittingRelation<'tcx> for Lub<'_, '_, 'tcx> {
140140
self.fields.param_env
141141
}
142142

143-
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ty::Upcast<'tcx>>) {
143+
fn register_predicates(
144+
&mut self,
145+
obligations: impl IntoIterator<Item: ty::Upcast<'tcx, ty::Predicate<'tcx>>>,
146+
) {
144147
self.fields.register_predicates(obligations);
145148
}
146149

compiler/rustc_infer/src/infer/relate/type_relating.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,10 @@ impl<'tcx> ObligationEmittingRelation<'tcx> for TypeRelating<'_, '_, 'tcx> {
312312
self.structurally_relate_aliases
313313
}
314314

315-
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ty::Upcast<'tcx>>) {
315+
fn register_predicates(
316+
&mut self,
317+
obligations: impl IntoIterator<Item: ty::Upcast<'tcx, ty::Predicate<'tcx>>>,
318+
) {
316319
self.fields.register_predicates(obligations);
317320
}
318321

compiler/rustc_infer/src/traits/util.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,7 @@ impl<'tcx, O: Elaboratable<'tcx>> Elaborator<'tcx, O> {
357357
None
358358
}
359359
})
360-
.map(|clause| {
361-
elaboratable.child(bound_clause.rebind(clause).upcast(tcx))
362-
}),
360+
.map(|clause| elaboratable.child(bound_clause.rebind(clause).upcast(tcx))),
363361
);
364362
}
365363
ty::ClauseKind::RegionOutlives(..) => {

compiler/rustc_middle/src/ty/predicate.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,8 @@ impl<'tcx> ToPolyTraitRef<'tcx> for PolyTraitPredicate<'tcx> {
544544
}
545545
}
546546

547-
pub trait Upcast<'tcx, P = Predicate<'tcx>> {
548-
fn upcast(self, tcx: TyCtxt<'tcx>) -> P;
547+
pub trait Upcast<'tcx, T> {
548+
fn upcast(self, tcx: TyCtxt<'tcx>) -> T;
549549
}
550550

551551
impl<'tcx, T> Upcast<'tcx, T> for T {
@@ -554,35 +554,35 @@ impl<'tcx, T> Upcast<'tcx, T> for T {
554554
}
555555
}
556556

557-
impl<'tcx> Upcast<'tcx> for PredicateKind<'tcx> {
557+
impl<'tcx> Upcast<'tcx, ty::Predicate<'tcx>> for PredicateKind<'tcx> {
558558
#[inline(always)]
559559
fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
560560
ty::Binder::dummy(self).upcast(tcx)
561561
}
562562
}
563563

564-
impl<'tcx> Upcast<'tcx> for Binder<'tcx, PredicateKind<'tcx>> {
564+
impl<'tcx> Upcast<'tcx, ty::Predicate<'tcx>> for Binder<'tcx, PredicateKind<'tcx>> {
565565
#[inline(always)]
566566
fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
567567
tcx.mk_predicate(self)
568568
}
569569
}
570570

571-
impl<'tcx> Upcast<'tcx> for ClauseKind<'tcx> {
571+
impl<'tcx> Upcast<'tcx, ty::Predicate<'tcx>> for ClauseKind<'tcx> {
572572
#[inline(always)]
573573
fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
574574
tcx.mk_predicate(ty::Binder::dummy(ty::PredicateKind::Clause(self)))
575575
}
576576
}
577577

578-
impl<'tcx> Upcast<'tcx> for Binder<'tcx, ClauseKind<'tcx>> {
578+
impl<'tcx> Upcast<'tcx, ty::Predicate<'tcx>> for Binder<'tcx, ClauseKind<'tcx>> {
579579
#[inline(always)]
580580
fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
581581
tcx.mk_predicate(self.map_bound(ty::PredicateKind::Clause))
582582
}
583583
}
584584

585-
impl<'tcx> Upcast<'tcx> for Clause<'tcx> {
585+
impl<'tcx> Upcast<'tcx, ty::Predicate<'tcx>> for Clause<'tcx> {
586586
#[inline(always)]
587587
fn upcast(self, _tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
588588
self.as_predicate()
@@ -603,7 +603,7 @@ impl<'tcx> Upcast<'tcx, Clause<'tcx>> for Binder<'tcx, ClauseKind<'tcx>> {
603603
}
604604
}
605605

606-
impl<'tcx> Upcast<'tcx> for TraitRef<'tcx> {
606+
impl<'tcx> Upcast<'tcx, ty::Predicate<'tcx>> for TraitRef<'tcx> {
607607
#[inline(always)]
608608
fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
609609
ty::Binder::dummy(self).upcast(tcx)
@@ -625,7 +625,7 @@ impl<'tcx> Upcast<'tcx, Clause<'tcx>> for TraitRef<'tcx> {
625625
}
626626
}
627627

628-
impl<'tcx> Upcast<'tcx> for Binder<'tcx, TraitRef<'tcx>> {
628+
impl<'tcx> Upcast<'tcx, ty::Predicate<'tcx>> for Binder<'tcx, TraitRef<'tcx>> {
629629
#[inline(always)]
630630
fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
631631
let pred: PolyTraitPredicate<'tcx> = self.upcast(tcx);
@@ -651,13 +651,13 @@ impl<'tcx> Upcast<'tcx, PolyTraitPredicate<'tcx>> for Binder<'tcx, TraitRef<'tcx
651651
}
652652
}
653653

654-
impl<'tcx> Upcast<'tcx> for TraitPredicate<'tcx> {
654+
impl<'tcx> Upcast<'tcx, ty::Predicate<'tcx>> for TraitPredicate<'tcx> {
655655
fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
656656
PredicateKind::Clause(ClauseKind::Trait(self)).upcast(tcx)
657657
}
658658
}
659659

660-
impl<'tcx> Upcast<'tcx> for PolyTraitPredicate<'tcx> {
660+
impl<'tcx> Upcast<'tcx, ty::Predicate<'tcx>> for PolyTraitPredicate<'tcx> {
661661
fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
662662
self.map_bound(|p| PredicateKind::Clause(ClauseKind::Trait(p))).upcast(tcx)
663663
}
@@ -677,25 +677,25 @@ impl<'tcx> Upcast<'tcx, Clause<'tcx>> for PolyTraitPredicate<'tcx> {
677677
}
678678
}
679679

680-
impl<'tcx> Upcast<'tcx> for PolyRegionOutlivesPredicate<'tcx> {
680+
impl<'tcx> Upcast<'tcx, ty::Predicate<'tcx>> for PolyRegionOutlivesPredicate<'tcx> {
681681
fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
682682
self.map_bound(|p| PredicateKind::Clause(ClauseKind::RegionOutlives(p))).upcast(tcx)
683683
}
684684
}
685685

686-
impl<'tcx> Upcast<'tcx> for OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>> {
686+
impl<'tcx> Upcast<'tcx, ty::Predicate<'tcx>> for OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>> {
687687
fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
688688
ty::Binder::dummy(PredicateKind::Clause(ClauseKind::TypeOutlives(self))).upcast(tcx)
689689
}
690690
}
691691

692-
impl<'tcx> Upcast<'tcx> for ProjectionPredicate<'tcx> {
692+
impl<'tcx> Upcast<'tcx, ty::Predicate<'tcx>> for ProjectionPredicate<'tcx> {
693693
fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
694694
ty::Binder::dummy(PredicateKind::Clause(ClauseKind::Projection(self))).upcast(tcx)
695695
}
696696
}
697697

698-
impl<'tcx> Upcast<'tcx> for PolyProjectionPredicate<'tcx> {
698+
impl<'tcx> Upcast<'tcx, ty::Predicate<'tcx>> for PolyProjectionPredicate<'tcx> {
699699
fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
700700
self.map_bound(|p| PredicateKind::Clause(ClauseKind::Projection(p))).upcast(tcx)
701701
}
@@ -715,7 +715,7 @@ impl<'tcx> Upcast<'tcx, Clause<'tcx>> for PolyProjectionPredicate<'tcx> {
715715
}
716716
}
717717

718-
impl<'tcx> Upcast<'tcx> for NormalizesTo<'tcx> {
718+
impl<'tcx> Upcast<'tcx, ty::Predicate<'tcx>> for NormalizesTo<'tcx> {
719719
fn upcast(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
720720
PredicateKind::NormalizesTo(self).upcast(tcx)
721721
}

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2703,7 +2703,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
27032703
obligated_types: &mut Vec<Ty<'tcx>>,
27042704
seen_requirements: &mut FxHashSet<DefId>,
27052705
) where
2706-
T: Upcast<'tcx>,
2706+
T: Upcast<'tcx, ty::Predicate<'tcx>>,
27072707
{
27082708
let mut long_ty_file = None;
27092709

compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
302302
suggest_increasing_limit: bool,
303303
) -> !
304304
where
305-
T: Upcast<'tcx> + Clone,
305+
T: Upcast<'tcx, ty::Predicate<'tcx>> + Clone,
306306
{
307307
let predicate = obligation.predicate.clone().upcast(self.tcx);
308308
let predicate = self.resolve_vars_if_possible(predicate);

compiler/rustc_trait_selection/src/traits/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub fn type_known_to_meet_bound_modulo_regions<'tcx>(
142142
fn pred_known_to_hold_modulo_regions<'tcx>(
143143
infcx: &InferCtxt<'tcx>,
144144
param_env: ty::ParamEnv<'tcx>,
145-
pred: impl Upcast<'tcx>,
145+
pred: impl Upcast<'tcx, ty::Predicate<'tcx>>,
146146
) -> bool {
147147
let obligation = Obligation::new(infcx.tcx, ObligationCause::dummy(), param_env, pred);
148148

compiler/rustc_trait_selection/src/traits/object_safety.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -752,8 +752,7 @@ fn receiver_is_dispatchable<'tcx>(
752752

753753
// Self: Unsize<U>
754754
let unsize_predicate =
755-
ty::TraitRef::new(tcx, unsize_did, [tcx.types.self_param, unsized_self_ty])
756-
.upcast(tcx);
755+
ty::TraitRef::new(tcx, unsize_did, [tcx.types.self_param, unsized_self_ty]).upcast(tcx);
757756

758757
// U: Trait<Arg1, ..., ArgN>
759758
let trait_predicate = {

compiler/rustc_trait_selection/src/traits/select/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -739,8 +739,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
739739
// stack would be `T: Auto`.
740740
let cycle = stack.iter().take_while(|s| s.depth > stack_arg.1);
741741
let tcx = self.tcx();
742-
let cycle =
743-
cycle.map(|stack| stack.obligation.predicate.upcast(tcx));
742+
let cycle = cycle.map(|stack| stack.obligation.predicate.upcast(tcx));
744743
if self.coinductive_match(cycle) {
745744
stack.update_reached_depth(stack_arg.1);
746745
return Ok(EvaluatedToOk);
@@ -1379,7 +1378,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
13791378
error_obligation: &Obligation<'tcx, T>,
13801379
) -> Result<(), OverflowError>
13811380
where
1382-
T: Upcast<'tcx> + Clone,
1381+
T: Upcast<'tcx, ty::Predicate<'tcx>> + Clone,
13831382
{
13841383
if !self.infcx.tcx.recursion_limit().value_within_limit(depth) {
13851384
match self.query_mode {
@@ -1408,7 +1407,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
14081407
error_obligation: &Obligation<'tcx, V>,
14091408
) -> Result<(), OverflowError>
14101409
where
1411-
V: Upcast<'tcx> + Clone,
1410+
V: Upcast<'tcx, ty::Predicate<'tcx>> + Clone,
14121411
{
14131412
self.check_recursion_depth(obligation.recursion_depth, error_obligation)
14141413
}

0 commit comments

Comments
 (0)