Skip to content

Commit 6e539ec

Browse files
committed
get rid of to_poly_trait_predicate
1 parent af63e3b commit 6e539ec

File tree

12 files changed

+40
-49
lines changed

12 files changed

+40
-49
lines changed

compiler/rustc_hir_typeck/src/coercion.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -792,8 +792,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
792792
self.param_env,
793793
ty::Binder::dummy(
794794
self.tcx.at(self.cause.span).mk_trait_ref(hir::LangItem::PointerSized, [a]),
795-
)
796-
.to_poly_trait_predicate(),
795+
),
797796
));
798797

799798
Ok(InferOk {

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1096,8 +1096,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10961096
ty::Binder::dummy(self.tcx.mk_trait_ref(
10971097
into_def_id,
10981098
[expr_ty, expected_ty]
1099-
))
1100-
.to_poly_trait_predicate(),
1099+
)),
11011100
))
11021101
{
11031102
let sugg = if expr.precedence().order() >= PREC_POSTFIX {

compiler/rustc_hir_typeck/src/method/probe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1430,7 +1430,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14301430
trait_ref: ty::TraitRef<'tcx>,
14311431
) -> traits::SelectionResult<'tcx, traits::Selection<'tcx>> {
14321432
let cause = traits::ObligationCause::misc(self.span, self.body_id);
1433-
let predicate = ty::Binder::dummy(trait_ref).to_poly_trait_predicate();
1433+
let predicate = ty::Binder::dummy(trait_ref);
14341434
let obligation = traits::Obligation::new(self.tcx, cause, self.param_env, predicate);
14351435
traits::SelectionContext::new(self).select(&obligation)
14361436
}

compiler/rustc_middle/src/ty/mod.rs

+19
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,25 @@ impl<'tcx> ToPredicate<'tcx, Predicate<'tcx>> for Binder<'tcx, PredicateKind<'tc
11531153
}
11541154
}
11551155

1156+
impl<'tcx> ToPredicate<'tcx, Predicate<'tcx>> for Binder<'tcx, TraitRef<'tcx>> {
1157+
#[inline(always)]
1158+
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
1159+
let pred: PolyTraitPredicate<'tcx> = self.to_predicate(tcx);
1160+
pred.to_predicate(tcx)
1161+
}
1162+
}
1163+
1164+
impl<'tcx> ToPredicate<'tcx, PolyTraitPredicate<'tcx>> for Binder<'tcx, TraitRef<'tcx>> {
1165+
#[inline(always)]
1166+
fn to_predicate(self, _: TyCtxt<'tcx>) -> PolyTraitPredicate<'tcx> {
1167+
self.map_bound(|trait_ref| TraitPredicate {
1168+
trait_ref,
1169+
constness: ty::BoundConstness::NotConst,
1170+
polarity: ty::ImplPolarity::Positive,
1171+
})
1172+
}
1173+
}
1174+
11561175
impl<'tcx> ToPredicate<'tcx, Predicate<'tcx>> for PolyTraitPredicate<'tcx> {
11571176
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
11581177
self.map_bound(PredicateKind::Trait).to_predicate(tcx)

compiler/rustc_middle/src/ty/sty.rs

-17
Original file line numberDiff line numberDiff line change
@@ -853,23 +853,6 @@ impl<'tcx> PolyTraitRef<'tcx> {
853853
pub fn def_id(&self) -> DefId {
854854
self.skip_binder().def_id
855855
}
856-
857-
pub fn to_poly_trait_predicate(&self) -> ty::PolyTraitPredicate<'tcx> {
858-
self.map_bound(|trait_ref| ty::TraitPredicate {
859-
trait_ref,
860-
constness: ty::BoundConstness::NotConst,
861-
polarity: ty::ImplPolarity::Positive,
862-
})
863-
}
864-
865-
/// Same as [`PolyTraitRef::to_poly_trait_predicate`] but sets a negative polarity instead.
866-
pub fn to_poly_trait_predicate_negative_polarity(&self) -> ty::PolyTraitPredicate<'tcx> {
867-
self.map_bound(|trait_ref| ty::TraitPredicate {
868-
trait_ref,
869-
constness: ty::BoundConstness::NotConst,
870-
polarity: ty::ImplPolarity::Negative,
871-
})
872-
}
873856
}
874857

875858
impl rustc_errors::IntoDiagnosticArg for PolyTraitRef<'_> {

compiler/rustc_trait_selection/src/traits/auto_trait.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::traits::project::ProjectAndUnifyResult;
1010
use rustc_middle::mir::interpret::ErrorHandled;
1111
use rustc_middle::ty::fold::{TypeFolder, TypeSuperFoldable};
1212
use rustc_middle::ty::visit::TypeVisitable;
13-
use rustc_middle::ty::{PolyTraitRef, Region, RegionVid};
13+
use rustc_middle::ty::{ImplPolarity, Region, RegionVid};
1414

1515
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
1616

@@ -88,19 +88,22 @@ impl<'tcx> AutoTraitFinder<'tcx> {
8888

8989
let trait_ref = tcx.mk_trait_ref(trait_did, [ty]);
9090

91-
let trait_pred = ty::Binder::dummy(trait_ref);
92-
9391
let infcx = tcx.infer_ctxt().build();
9492
let mut selcx = SelectionContext::new(&infcx);
95-
for f in [
96-
PolyTraitRef::to_poly_trait_predicate,
97-
PolyTraitRef::to_poly_trait_predicate_negative_polarity,
98-
] {
93+
for polarity in [true, false] {
9994
let result = selcx.select(&Obligation::new(
10095
tcx,
10196
ObligationCause::dummy(),
10297
orig_env,
103-
f(&trait_pred),
98+
ty::Binder::dummy(ty::TraitPredicate {
99+
trait_ref,
100+
constness: ty::BoundConstness::NotConst,
101+
polarity: if polarity {
102+
ImplPolarity::Positive
103+
} else {
104+
ImplPolarity::Negative
105+
},
106+
}),
104107
));
105108
if let Ok(Some(ImplSource::UserDefined(_))) = result {
106109
debug!(

compiler/rustc_trait_selection/src/traits/codegen.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ pub fn codegen_select_candidate<'tcx>(
3939
let mut selcx = SelectionContext::new(&infcx);
4040

4141
let obligation_cause = ObligationCause::dummy();
42-
let obligation =
43-
Obligation::new(tcx, obligation_cause, param_env, trait_ref.to_poly_trait_predicate());
42+
let obligation = Obligation::new(tcx, obligation_cause, param_env, trait_ref);
4443

4544
let selection = match selcx.select(&obligation) {
4645
Ok(Some(selection)) => selection,

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2111,7 +2111,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
21112111
)
21122112
};
21132113

2114-
let obligation = obligation.with(self.tcx, trait_ref.to_poly_trait_predicate());
2114+
let obligation = obligation.with(self.tcx, trait_ref);
21152115
let mut selcx = SelectionContext::new(&self);
21162116
match selcx.select_from_obligation(&obligation) {
21172117
Ok(None) => {

compiler/rustc_trait_selection/src/traits/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ fn subst_and_check_impossible_predicates<'tcx>(
477477
// associated items.
478478
if let Some(trait_def_id) = tcx.trait_of_item(key.0) {
479479
let trait_ref = ty::TraitRef::from_method(tcx, trait_def_id, key.1);
480-
predicates.push(ty::Binder::dummy(trait_ref).to_poly_trait_predicate().to_predicate(tcx));
480+
predicates.push(ty::Binder::dummy(trait_ref).to_predicate(tcx));
481481
}
482482

483483
predicates.retain(|predicate| !predicate.needs_subst());

compiler/rustc_trait_selection/src/traits/project.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1328,8 +1328,7 @@ fn assemble_candidate_for_impl_trait_in_trait<'cx, 'tcx>(
13281328
obligation.predicate.substs.truncate_to(tcx, tcx.generics_of(trait_def_id));
13291329
// FIXME(named-returns): Binders
13301330
let trait_predicate =
1331-
ty::Binder::dummy(ty::TraitRef { def_id: trait_def_id, substs: trait_substs })
1332-
.to_poly_trait_predicate();
1331+
ty::Binder::dummy(ty::TraitRef { def_id: trait_def_id, substs: trait_substs });
13331332

13341333
let _ = selcx.infcx().commit_if_ok(|_| {
13351334
match selcx.select(&obligation.with(tcx, trait_predicate)) {
@@ -1527,7 +1526,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
15271526
// If we are resolving `<T as TraitRef<...>>::Item == Type`,
15281527
// start out by selecting the predicate `T as TraitRef<...>`:
15291528
let poly_trait_ref = ty::Binder::dummy(obligation.predicate.trait_ref(selcx.tcx()));
1530-
let trait_obligation = obligation.with(selcx.tcx(), poly_trait_ref.to_poly_trait_predicate());
1529+
let trait_obligation = obligation.with(selcx.tcx(), poly_trait_ref);
15311530
let _ = selcx.infcx().commit_if_ok(|_| {
15321531
let impl_source = match selcx.select(&trait_obligation) {
15331532
Ok(Some(impl_source)) => impl_source,

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

+1-6
Original file line numberDiff line numberDiff line change
@@ -640,12 +640,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
640640
);
641641
let tr =
642642
ty::Binder::dummy(self.tcx().at(cause.span).mk_trait_ref(LangItem::Sized, [output_ty]));
643-
nested.push(Obligation::new(
644-
self.infcx.tcx,
645-
cause,
646-
obligation.param_env,
647-
tr.to_poly_trait_predicate(),
648-
));
643+
nested.push(Obligation::new(self.infcx.tcx, cause, obligation.param_env, tr));
649644

650645
Ok(ImplSourceFnPointerData { fn_ty: self_ty, nested })
651646
}

src/librustdoc/clean/blanket_impl.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
6767
.instantiate(cx.tcx, impl_substs)
6868
.predicates
6969
.into_iter()
70-
.chain(Some(
71-
ty::Binder::dummy(impl_trait_ref)
72-
.to_poly_trait_predicate()
73-
.map_bound(ty::PredicateKind::Trait)
74-
.to_predicate(infcx.tcx),
75-
));
70+
.chain(Some(ty::Binder::dummy(impl_trait_ref).to_predicate(infcx.tcx)));
7671
for predicate in predicates {
7772
debug!("testing predicate {:?}", predicate);
7873
let obligation = traits::Obligation::new(

0 commit comments

Comments
 (0)