Skip to content

Commit ee2e97c

Browse files
Rollup merge of #89001 - jackh726:binder-cleanup, r=nikomatsakis
Be explicit about using Binder::dummy This is somewhat of a late followup to the binder refactor PR. It removes `ToPredicate` and `ToPolyTraitImpls` that hide the use of `Binder::dummy`. While this does make code a bit more verbose, it allows us be more careful about where we create binders. Another alternative here might be to add a new trait `ToBinder` or something with a `dummy()` fn. Which could still allow grepping but allows doing something like `trait_ref.dummy()` (but I also wonder if longer-term, it would be better to be even more explicit with a `bind_with_vars(ty::List::empty())` *but* that's not clear yet. r? ``@nikomatsakis``
2 parents 2de7f10 + 553f649 commit ee2e97c

File tree

34 files changed

+127
-121
lines changed

34 files changed

+127
-121
lines changed

compiler/rustc_borrowck/src/type_check/canonical.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
8989
category: ConstraintCategory,
9090
) {
9191
self.prove_predicates(
92-
Some(ty::PredicateKind::Trait(ty::TraitPredicate {
92+
Some(ty::Binder::dummy(ty::PredicateKind::Trait(ty::TraitPredicate {
9393
trait_ref,
9494
constness: ty::BoundConstness::NotConst,
95-
})),
95+
}))),
9696
locations,
9797
category,
9898
);

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
10801080
}
10811081

10821082
self.prove_predicate(
1083-
ty::PredicateKind::WellFormed(inferred_ty.into()).to_predicate(self.tcx()),
1083+
ty::Binder::dummy(ty::PredicateKind::WellFormed(inferred_ty.into()))
1084+
.to_predicate(self.tcx()),
10841085
Locations::All(span),
10851086
ConstraintCategory::TypeAnnotation,
10861087
);
@@ -1316,7 +1317,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
13161317
obligations.obligations.push(traits::Obligation::new(
13171318
ObligationCause::dummy(),
13181319
param_env,
1319-
ty::PredicateKind::WellFormed(revealed_ty.into()).to_predicate(infcx.tcx),
1320+
ty::Binder::dummy(ty::PredicateKind::WellFormed(revealed_ty.into()))
1321+
.to_predicate(infcx.tcx),
13201322
));
13211323
obligations.add(
13221324
infcx
@@ -1599,7 +1601,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
15991601
self.check_call_dest(body, term, &sig, destination, term_location);
16001602

16011603
self.prove_predicates(
1602-
sig.inputs_and_output.iter().map(|ty| ty::PredicateKind::WellFormed(ty.into())),
1604+
sig.inputs_and_output
1605+
.iter()
1606+
.map(|ty| ty::Binder::dummy(ty::PredicateKind::WellFormed(ty.into()))),
16031607
term_location.to_locations(),
16041608
ConstraintCategory::Boring,
16051609
);

compiler/rustc_infer/src/infer/canonical/query_response.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,10 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> {
669669
self.obligations.push(Obligation {
670670
cause: self.cause.clone(),
671671
param_env: self.param_env,
672-
predicate: ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(sup, sub))
673-
.to_predicate(self.infcx.tcx),
672+
predicate: ty::Binder::dummy(ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(
673+
sup, sub,
674+
)))
675+
.to_predicate(self.infcx.tcx),
674676
recursion_depth: 0,
675677
});
676678
}

compiler/rustc_infer/src/infer/combine.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
360360
self.obligations.push(Obligation::new(
361361
self.trace.cause.clone(),
362362
self.param_env,
363-
ty::PredicateKind::WellFormed(b_ty.into()).to_predicate(self.infcx.tcx),
363+
ty::Binder::dummy(ty::PredicateKind::WellFormed(b_ty.into()))
364+
.to_predicate(self.infcx.tcx),
364365
));
365366
}
366367

@@ -463,7 +464,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
463464
self.obligations.push(Obligation::new(
464465
self.trace.cause.clone(),
465466
self.param_env,
466-
predicate.to_predicate(self.tcx()),
467+
ty::Binder::dummy(predicate).to_predicate(self.tcx()),
467468
));
468469
}
469470
}

compiler/rustc_infer/src/infer/sub.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ impl TypeRelation<'tcx> for Sub<'combine, 'infcx, 'tcx> {
9797
self.fields.obligations.push(Obligation::new(
9898
self.fields.trace.cause.clone(),
9999
self.fields.param_env,
100-
ty::PredicateKind::Subtype(ty::SubtypePredicate {
100+
ty::Binder::dummy(ty::PredicateKind::Subtype(ty::SubtypePredicate {
101101
a_is_expected: self.a_is_expected,
102102
a,
103103
b,
104-
})
104+
}))
105105
.to_predicate(self.tcx()),
106106
));
107107

compiler/rustc_infer/src/traits/engine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub trait TraitEngine<'tcx>: 'tcx {
3535
cause,
3636
recursion_depth: 0,
3737
param_env,
38-
predicate: trait_ref.without_const().to_predicate(infcx.tcx),
38+
predicate: ty::Binder::dummy(trait_ref).without_const().to_predicate(infcx.tcx),
3939
},
4040
);
4141
}

compiler/rustc_infer/src/traits/util.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ impl Elaborator<'tcx> {
231231
None
232232
}
233233
})
234+
.map(ty::Binder::dummy)
234235
.map(|predicate_kind| predicate_kind.to_predicate(tcx))
235236
.filter(|&predicate| visited.insert(predicate))
236237
.map(|predicate| {

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -769,12 +769,6 @@ pub trait ToPolyTraitRef<'tcx> {
769769
fn to_poly_trait_ref(&self) -> PolyTraitRef<'tcx>;
770770
}
771771

772-
impl<'tcx> ToPolyTraitRef<'tcx> for TraitRef<'tcx> {
773-
fn to_poly_trait_ref(&self) -> PolyTraitRef<'tcx> {
774-
ty::Binder::dummy(*self)
775-
}
776-
}
777-
778772
impl<'tcx> ToPolyTraitRef<'tcx> for PolyTraitPredicate<'tcx> {
779773
fn to_poly_trait_ref(&self) -> PolyTraitRef<'tcx> {
780774
self.map_bound_ref(|trait_pred| trait_pred.trait_ref)
@@ -792,23 +786,6 @@ impl ToPredicate<'tcx> for Binder<'tcx, PredicateKind<'tcx>> {
792786
}
793787
}
794788

795-
impl ToPredicate<'tcx> for PredicateKind<'tcx> {
796-
#[inline(always)]
797-
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
798-
tcx.mk_predicate(Binder::dummy(self))
799-
}
800-
}
801-
802-
impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<TraitRef<'tcx>> {
803-
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
804-
PredicateKind::Trait(ty::TraitPredicate {
805-
trait_ref: self.value,
806-
constness: self.constness,
807-
})
808-
.to_predicate(tcx)
809-
}
810-
}
811-
812789
impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<PolyTraitRef<'tcx>> {
813790
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
814791
self.value

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -844,8 +844,11 @@ impl<'tcx> TraitRef<'tcx> {
844844

845845
/// Returns a `TraitRef` of the form `P0: Foo<P1..Pn>` where `Pi`
846846
/// are the parameters defined on trait.
847-
pub fn identity(tcx: TyCtxt<'tcx>, def_id: DefId) -> TraitRef<'tcx> {
848-
TraitRef { def_id, substs: InternalSubsts::identity_for_item(tcx, def_id) }
847+
pub fn identity(tcx: TyCtxt<'tcx>, def_id: DefId) -> Binder<'tcx, TraitRef<'tcx>> {
848+
ty::Binder::dummy(TraitRef {
849+
def_id,
850+
substs: InternalSubsts::identity_for_item(tcx, def_id),
851+
})
849852
}
850853

851854
#[inline]

compiler/rustc_trait_selection/src/autoderef.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
135135
let obligation = traits::Obligation::new(
136136
cause.clone(),
137137
self.param_env,
138-
trait_ref.without_const().to_predicate(tcx),
138+
ty::Binder::dummy(trait_ref).without_const().to_predicate(tcx),
139139
);
140140
if !self.infcx.predicate_may_hold(&obligation) {
141141
debug!("overloaded_deref_ty: cannot match obligation");

0 commit comments

Comments
 (0)