Skip to content

Commit 0a756cc

Browse files
committed
get rid of to_poly_trait_predicate
1 parent 008bc1d commit 0a756cc

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
@@ -806,8 +806,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
806806
self.param_env,
807807
ty::Binder::dummy(
808808
self.tcx.at(self.cause.span).mk_trait_ref(hir::LangItem::PointerSized, [a]),
809-
)
810-
.to_poly_trait_predicate(),
809+
),
811810
));
812811
}
813812

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
@@ -1429,7 +1429,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14291429
trait_ref: ty::TraitRef<'tcx>,
14301430
) -> traits::SelectionResult<'tcx, traits::Selection<'tcx>> {
14311431
let cause = traits::ObligationCause::misc(self.span, self.body_id);
1432-
let predicate = ty::Binder::dummy(trait_ref).to_poly_trait_predicate();
1432+
let predicate = ty::Binder::dummy(trait_ref);
14331433
let obligation = traits::Obligation::new(self.tcx, cause, self.param_env, predicate);
14341434
traits::SelectionContext::new(self).select(&obligation)
14351435
}

compiler/rustc_middle/src/ty/mod.rs

+19
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,25 @@ impl<'tcx> ToPredicate<'tcx, Predicate<'tcx>> for Binder<'tcx, PredicateKind<'tc
11471147
}
11481148
}
11491149

1150+
impl<'tcx> ToPredicate<'tcx, Predicate<'tcx>> for Binder<'tcx, TraitRef<'tcx>> {
1151+
#[inline(always)]
1152+
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
1153+
let pred: PolyTraitPredicate<'tcx> = self.to_predicate(tcx);
1154+
pred.to_predicate(tcx)
1155+
}
1156+
}
1157+
1158+
impl<'tcx> ToPredicate<'tcx, PolyTraitPredicate<'tcx>> for Binder<'tcx, TraitRef<'tcx>> {
1159+
#[inline(always)]
1160+
fn to_predicate(self, _: TyCtxt<'tcx>) -> PolyTraitPredicate<'tcx> {
1161+
self.map_bound(|trait_ref| TraitPredicate {
1162+
trait_ref,
1163+
constness: ty::BoundConstness::NotConst,
1164+
polarity: ty::ImplPolarity::Positive,
1165+
})
1166+
}
1167+
}
1168+
11501169
impl<'tcx> ToPredicate<'tcx, Predicate<'tcx>> for PolyTraitPredicate<'tcx> {
11511170
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
11521171
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::with_query_mode(
21162116
&self,
21172117
crate::traits::TraitQueryMode::Standard,

compiler/rustc_trait_selection/src/traits/mod.rs

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

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

compiler/rustc_trait_selection/src/traits/project.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1343,8 +1343,7 @@ fn assemble_candidate_for_impl_trait_in_trait<'cx, 'tcx>(
13431343
obligation.predicate.substs.truncate_to(tcx, tcx.generics_of(trait_def_id));
13441344
// FIXME(named-returns): Binders
13451345
let trait_predicate =
1346-
ty::Binder::dummy(ty::TraitRef { def_id: trait_def_id, substs: trait_substs })
1347-
.to_poly_trait_predicate();
1346+
ty::Binder::dummy(ty::TraitRef { def_id: trait_def_id, substs: trait_substs });
13481347

13491348
let _ = selcx.infcx().commit_if_ok(|_| {
13501349
match selcx.select(&obligation.with(tcx, trait_predicate)) {
@@ -1542,7 +1541,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
15421541
// If we are resolving `<T as TraitRef<...>>::Item == Type`,
15431542
// start out by selecting the predicate `T as TraitRef<...>`:
15441543
let poly_trait_ref = ty::Binder::dummy(obligation.predicate.trait_ref(selcx.tcx()));
1545-
let trait_obligation = obligation.with(selcx.tcx(), poly_trait_ref.to_poly_trait_predicate());
1544+
let trait_obligation = obligation.with(selcx.tcx(), poly_trait_ref);
15461545
let _ = selcx.infcx().commit_if_ok(|_| {
15471546
let impl_source = match selcx.select(&trait_obligation) {
15481547
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
@@ -634,12 +634,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
634634
);
635635
let tr =
636636
ty::Binder::dummy(self.tcx().at(cause.span).mk_trait_ref(LangItem::Sized, [output_ty]));
637-
nested.push(Obligation::new(
638-
self.infcx.tcx,
639-
cause,
640-
obligation.param_env,
641-
tr.to_poly_trait_predicate(),
642-
));
637+
nested.push(Obligation::new(self.infcx.tcx, cause, obligation.param_env, tr));
643638

644639
Ok(ImplSourceFnPointerData { fn_ty: self_ty, nested })
645640
}

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)