Skip to content

Commit be76bdf

Browse files
committed
Remove ToPredicate impls that use Binder::dummy
1 parent 2c7bc5e commit be76bdf

File tree

27 files changed

+99
-85
lines changed

27 files changed

+99
-85
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
@@ -1078,7 +1078,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
10781078
}
10791079

10801080
self.prove_predicate(
1081-
ty::PredicateKind::WellFormed(inferred_ty.into()).to_predicate(self.tcx()),
1081+
ty::Binder::dummy(ty::PredicateKind::WellFormed(inferred_ty.into()))
1082+
.to_predicate(self.tcx()),
10821083
Locations::All(span),
10831084
ConstraintCategory::TypeAnnotation,
10841085
);
@@ -1314,7 +1315,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
13141315
obligations.obligations.push(traits::Obligation::new(
13151316
ObligationCause::dummy(),
13161317
param_env,
1317-
ty::PredicateKind::WellFormed(revealed_ty.into()).to_predicate(infcx.tcx),
1318+
ty::Binder::dummy(ty::PredicateKind::WellFormed(revealed_ty.into()))
1319+
.to_predicate(infcx.tcx),
13181320
));
13191321
obligations.add(
13201322
infcx
@@ -1584,7 +1586,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
15841586
self.check_call_dest(body, term, &sig, destination, term_location);
15851587

15861588
self.prove_predicates(
1587-
sig.inputs_and_output.iter().map(|ty| ty::PredicateKind::WellFormed(ty.into())),
1589+
sig.inputs_and_output
1590+
.iter()
1591+
.map(|ty| ty::Binder::dummy(ty::PredicateKind::WellFormed(ty.into()))),
15881592
term_location.to_locations(),
15891593
ConstraintCategory::Boring,
15901594
);

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
@@ -34,7 +34,7 @@ pub trait TraitEngine<'tcx>: 'tcx {
3434
cause,
3535
recursion_depth: 0,
3636
param_env,
37-
predicate: trait_ref.without_const().to_predicate(infcx.tcx),
37+
predicate: ty::Binder::dummy(trait_ref).without_const().to_predicate(infcx.tcx),
3838
},
3939
);
4040
}

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 & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -792,23 +792,6 @@ impl ToPredicate<'tcx> for Binder<'tcx, PredicateKind<'tcx>> {
792792
}
793793
}
794794

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-
812795
impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<PolyTraitRef<'tcx>> {
813796
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
814797
self.value

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");

compiler/rustc_trait_selection/src/infer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
120120
cause: traits::ObligationCause::dummy(),
121121
param_env,
122122
recursion_depth: 0,
123-
predicate: trait_ref.without_const().to_predicate(self.tcx),
123+
predicate: ty::Binder::dummy(trait_ref).without_const().to_predicate(self.tcx),
124124
};
125125
self.evaluate_obligation(&obligation).unwrap_or(traits::EvaluationResult::EvaluatedToErr)
126126
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
724724
let new_obligation = Obligation::new(
725725
ObligationCause::dummy(),
726726
param_env,
727-
new_trait_ref.without_const().to_predicate(self.tcx),
727+
ty::Binder::dummy(new_trait_ref).without_const().to_predicate(self.tcx),
728728
);
729729

730730
if self.predicate_must_hold_modulo_regions(&new_obligation) {

compiler/rustc_trait_selection/src/traits/fulfill.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,8 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
405405
| ty::PredicateKind::Coerce(_)
406406
| ty::PredicateKind::ConstEvaluatable(..)
407407
| ty::PredicateKind::ConstEquate(..) => {
408-
let pred = infcx.replace_bound_vars_with_placeholders(binder);
408+
let pred =
409+
ty::Binder::dummy(infcx.replace_bound_vars_with_placeholders(binder));
409410
ProcessResult::Changed(mk_pending(vec![
410411
obligation.with(pred.to_predicate(self.selcx.tcx())),
411412
]))

compiler/rustc_trait_selection/src/traits/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ pub fn type_known_to_meet_bound_modulo_regions<'a, 'tcx>(
139139
infcx.tcx.def_path_str(def_id)
140140
);
141141

142-
let trait_ref = ty::TraitRef { def_id, substs: infcx.tcx.mk_substs_trait(ty, &[]) };
142+
let trait_ref =
143+
ty::Binder::dummy(ty::TraitRef { def_id, substs: infcx.tcx.mk_substs_trait(ty, &[]) });
143144
let obligation = Obligation {
144145
param_env,
145146
cause: ObligationCause::misc(span, hir::CRATE_HIR_ID),

compiler/rustc_trait_selection/src/traits/object_safety.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -671,10 +671,10 @@ fn receiver_is_dispatchable<'tcx>(
671671
let param_env = tcx.param_env(method.def_id);
672672

673673
// Self: Unsize<U>
674-
let unsize_predicate = ty::TraitRef {
674+
let unsize_predicate = ty::Binder::dummy(ty::TraitRef {
675675
def_id: unsize_did,
676676
substs: tcx.mk_substs_trait(tcx.types.self_param, &[unsized_self_ty.into()]),
677-
}
677+
})
678678
.without_const()
679679
.to_predicate(tcx);
680680

@@ -689,7 +689,9 @@ fn receiver_is_dispatchable<'tcx>(
689689
}
690690
});
691691

692-
ty::TraitRef { def_id: unsize_did, substs }.without_const().to_predicate(tcx)
692+
ty::Binder::dummy(ty::TraitRef { def_id: unsize_did, substs })
693+
.without_const()
694+
.to_predicate(tcx)
693695
};
694696

695697
let caller_bounds: Vec<Predicate<'tcx>> = param_env
@@ -703,10 +705,10 @@ fn receiver_is_dispatchable<'tcx>(
703705

704706
// Receiver: DispatchFromDyn<Receiver[Self => U]>
705707
let obligation = {
706-
let predicate = ty::TraitRef {
708+
let predicate = ty::Binder::dummy(ty::TraitRef {
707709
def_id: dispatch_from_dyn_did,
708710
substs: tcx.mk_substs_trait(receiver_ty, &[unsized_receiver_ty.into()]),
709-
}
711+
})
710712
.without_const()
711713
.to_predicate(tcx);
712714

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
646646
obligations.push(Obligation::new(
647647
obligation.cause.clone(),
648648
obligation.param_env,
649-
ty::PredicateKind::ClosureKind(closure_def_id, substs, kind)
649+
ty::Binder::dummy(ty::PredicateKind::ClosureKind(closure_def_id, substs, kind))
650650
.to_predicate(self.tcx()),
651651
));
652652
}
@@ -898,10 +898,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
898898
);
899899

900900
// We can only make objects from sized types.
901-
let tr = ty::TraitRef::new(
901+
let tr = ty::Binder::dummy(ty::TraitRef::new(
902902
tcx.require_lang_item(LangItem::Sized, None),
903903
tcx.mk_substs_trait(source, &[]),
904-
);
904+
));
905905
nested.push(predicate_to_obligation(tr.without_const().to_predicate(tcx)));
906906

907907
// If the type is `Foo + 'a`, ensure that the type

compiler/rustc_trait_selection/src/traits/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ pub fn predicate_for_trait_ref<'tcx>(
248248
cause,
249249
param_env,
250250
recursion_depth,
251-
predicate: trait_ref.without_const().to_predicate(tcx),
251+
predicate: ty::Binder::dummy(trait_ref).without_const().to_predicate(tcx),
252252
}
253253
}
254254

compiler/rustc_trait_selection/src/traits/wf.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
349349
new_cause,
350350
depth,
351351
param_env,
352-
ty::PredicateKind::WellFormed(arg).to_predicate(tcx),
352+
ty::Binder::dummy(ty::PredicateKind::WellFormed(arg)).to_predicate(tcx),
353353
)
354354
}),
355355
);
@@ -399,7 +399,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
399399
cause.clone(),
400400
depth,
401401
param_env,
402-
ty::PredicateKind::WellFormed(arg).to_predicate(tcx),
402+
ty::Binder::dummy(ty::PredicateKind::WellFormed(arg)).to_predicate(tcx),
403403
)
404404
}),
405405
);
@@ -416,7 +416,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
416416
cause,
417417
self.recursion_depth,
418418
self.param_env,
419-
trait_ref.without_const().to_predicate(self.infcx.tcx),
419+
ty::Binder::dummy(trait_ref).without_const().to_predicate(self.infcx.tcx),
420420
));
421421
}
422422
}
@@ -443,9 +443,9 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
443443
let obligations = self.nominal_obligations(uv.def.did, substs);
444444
self.out.extend(obligations);
445445

446-
let predicate = ty::PredicateKind::ConstEvaluatable(
446+
let predicate = ty::Binder::dummy(ty::PredicateKind::ConstEvaluatable(
447447
ty::Unevaluated::new(uv.def, substs),
448-
)
448+
))
449449
.to_predicate(self.tcx());
450450
let cause = self.cause(traits::MiscObligation);
451451
self.out.push(traits::Obligation::with_depth(
@@ -469,8 +469,10 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
469469
cause,
470470
self.recursion_depth,
471471
self.param_env,
472-
ty::PredicateKind::WellFormed(resolved_constant.into())
473-
.to_predicate(self.tcx()),
472+
ty::Binder::dummy(ty::PredicateKind::WellFormed(
473+
resolved_constant.into(),
474+
))
475+
.to_predicate(self.tcx()),
474476
));
475477
}
476478
}
@@ -556,8 +558,10 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
556558
cause,
557559
depth,
558560
param_env,
559-
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(rty, r))
560-
.to_predicate(self.tcx()),
561+
ty::Binder::dummy(ty::PredicateKind::TypeOutlives(
562+
ty::OutlivesPredicate(rty, r),
563+
))
564+
.to_predicate(self.tcx()),
561565
));
562566
}
563567
}
@@ -646,7 +650,8 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
646650
cause.clone(),
647651
depth,
648652
param_env,
649-
ty::PredicateKind::ObjectSafe(did).to_predicate(tcx),
653+
ty::Binder::dummy(ty::PredicateKind::ObjectSafe(did))
654+
.to_predicate(tcx),
650655
)
651656
}));
652657
}
@@ -673,7 +678,8 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
673678
cause,
674679
self.recursion_depth,
675680
param_env,
676-
ty::PredicateKind::WellFormed(ty.into()).to_predicate(self.tcx()),
681+
ty::Binder::dummy(ty::PredicateKind::WellFormed(ty.into()))
682+
.to_predicate(self.tcx()),
677683
));
678684
} else {
679685
// Yes, resolved, proceed with the result.

compiler/rustc_traits/src/type_op.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ impl AscribeUserTypeCx<'me, 'tcx> {
156156
self.relate(self_ty, Variance::Invariant, impl_self_ty)?;
157157

158158
self.prove_predicate(
159-
ty::PredicateKind::WellFormed(impl_self_ty.into()).to_predicate(self.tcx()),
159+
ty::Binder::dummy(ty::PredicateKind::WellFormed(impl_self_ty.into()))
160+
.to_predicate(self.tcx()),
160161
span,
161162
);
162163
}
@@ -173,7 +174,7 @@ impl AscribeUserTypeCx<'me, 'tcx> {
173174
// type were ill-formed but did not appear in `ty`,
174175
// which...could happen with normalization...
175176
self.prove_predicate(
176-
ty::PredicateKind::WellFormed(ty.into()).to_predicate(self.tcx()),
177+
ty::Binder::dummy(ty::PredicateKind::WellFormed(ty.into())).to_predicate(self.tcx()),
177178
span,
178179
);
179180
Ok(())

compiler/rustc_typeck/src/check/_match.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -524,13 +524,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
524524
for o in obligations {
525525
match o.predicate.kind().skip_binder() {
526526
ty::PredicateKind::Trait(t) => {
527-
let pred = ty::PredicateKind::Trait(ty::TraitPredicate {
528-
trait_ref: ty::TraitRef {
529-
def_id: t.def_id(),
530-
substs: self.infcx.tcx.mk_substs_trait(outer_ty, &[]),
531-
},
532-
constness: t.constness,
533-
});
527+
let pred =
528+
ty::Binder::dummy(ty::PredicateKind::Trait(ty::TraitPredicate {
529+
trait_ref: ty::TraitRef {
530+
def_id: t.def_id(),
531+
substs: self.infcx.tcx.mk_substs_trait(outer_ty, &[]),
532+
},
533+
constness: t.constness,
534+
}));
534535
let obl = Obligation::new(
535536
o.cause.clone(),
536537
self.param_env,

compiler/rustc_typeck/src/check/coercion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,10 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
273273
obligations.push(Obligation::new(
274274
self.cause.clone(),
275275
self.param_env,
276-
ty::PredicateKind::Coerce(ty::CoercePredicate {
276+
ty::Binder::dummy(ty::PredicateKind::Coerce(ty::CoercePredicate {
277277
a: source_ty,
278278
b: target_ty,
279-
})
279+
}))
280280
.to_predicate(self.tcx()),
281281
));
282282
}

compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
568568
self.register_predicate(traits::Obligation::new(
569569
cause,
570570
self.param_env,
571-
ty::PredicateKind::WellFormed(arg).to_predicate(self.tcx),
571+
ty::Binder::dummy(ty::PredicateKind::WellFormed(arg)).to_predicate(self.tcx),
572572
));
573573
}
574574

0 commit comments

Comments
 (0)