Skip to content

Commit 626abc7

Browse files
committed
ty: remove {Existential,}Trait{Ref,Predicate}::input_types.
1 parent b7fdc7b commit 626abc7

File tree

7 files changed

+103
-107
lines changed

7 files changed

+103
-107
lines changed

src/librustc_middle/ty/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1365,10 +1365,6 @@ impl<'tcx> TraitPredicate<'tcx> {
13651365
self.trait_ref.def_id
13661366
}
13671367

1368-
pub fn input_types<'a>(&'a self) -> impl DoubleEndedIterator<Item = Ty<'tcx>> + 'a {
1369-
self.trait_ref.input_types()
1370-
}
1371-
13721368
pub fn self_ty(&self) -> Ty<'tcx> {
13731369
self.trait_ref.self_ty()
13741370
}

src/librustc_middle/ty/sty.rs

-16
Original file line numberDiff line numberDiff line change
@@ -754,14 +754,6 @@ impl<'tcx> TraitRef<'tcx> {
754754
self.substs.type_at(0)
755755
}
756756

757-
pub fn input_types<'a>(&'a self) -> impl DoubleEndedIterator<Item = Ty<'tcx>> + 'a {
758-
// Select only the "input types" from a trait-reference. For
759-
// now this is all the types that appear in the
760-
// trait-reference, but it should eventually exclude
761-
// associated types.
762-
self.substs.types()
763-
}
764-
765757
pub fn from_method(
766758
tcx: TyCtxt<'tcx>,
767759
trait_id: DefId,
@@ -805,14 +797,6 @@ pub struct ExistentialTraitRef<'tcx> {
805797
}
806798

807799
impl<'tcx> ExistentialTraitRef<'tcx> {
808-
pub fn input_types<'b>(&'b self) -> impl DoubleEndedIterator<Item = Ty<'tcx>> + 'b {
809-
// Select only the "input types" from a trait-reference. For
810-
// now this is all the types that appear in the
811-
// trait-reference, but it should eventually exclude
812-
// associated types.
813-
self.substs.types()
814-
}
815-
816800
pub fn erase_self_ty(
817801
tcx: TyCtxt<'tcx>,
818802
trait_ref: ty::TraitRef<'tcx>,

src/librustc_trait_selection/traits/coherence.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,11 @@ fn orphan_check_trait_ref<'tcx>(
393393
}
394394

395395
let mut non_local_spans = vec![];
396-
for (i, input_ty) in
397-
trait_ref.input_types().flat_map(|ty| uncover_fundamental_ty(tcx, ty, in_crate)).enumerate()
396+
for (i, input_ty) in trait_ref
397+
.substs
398+
.types()
399+
.flat_map(|ty| uncover_fundamental_ty(tcx, ty, in_crate))
400+
.enumerate()
398401
{
399402
debug!("orphan_check_trait_ref: check ty `{:?}`", input_ty);
400403
let non_local_tys = ty_is_non_local(tcx, input_ty, in_crate);
@@ -404,7 +407,8 @@ fn orphan_check_trait_ref<'tcx>(
404407
} else if let ty::Param(_) = input_ty.kind {
405408
debug!("orphan_check_trait_ref: uncovered ty: `{:?}`", input_ty);
406409
let local_type = trait_ref
407-
.input_types()
410+
.substs
411+
.types()
408412
.flat_map(|ty| uncover_fundamental_ty(tcx, ty, in_crate))
409413
.find(|ty| ty_is_non_local_constructor(ty, in_crate).is_none());
410414

src/librustc_trait_selection/traits/object_safety.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::traits::{self, Obligation, ObligationCause};
1616
use rustc_errors::{Applicability, FatalError};
1717
use rustc_hir as hir;
1818
use rustc_hir::def_id::DefId;
19-
use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts, Subst};
19+
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, Subst};
2020
use rustc_middle::ty::{self, Predicate, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness};
2121
use rustc_session::lint::builtin::WHERE_CLAUSES_OBJECT_SAFETY;
2222
use rustc_span::symbol::Symbol;
@@ -234,7 +234,7 @@ fn predicates_reference_self(
234234
tcx.predicates_of(trait_def_id)
235235
};
236236
let self_ty = tcx.types.self_param;
237-
let has_self_ty = |t: Ty<'_>| t.walk().any(|arg| arg == self_ty.into());
237+
let has_self_ty = |arg: &GenericArg<'_>| arg.walk().any(|arg| arg == self_ty.into());
238238
predicates
239239
.predicates
240240
.iter()
@@ -243,7 +243,7 @@ fn predicates_reference_self(
243243
match predicate {
244244
ty::Predicate::Trait(ref data, _) => {
245245
// In the case of a trait predicate, we can skip the "self" type.
246-
if data.skip_binder().input_types().skip(1).any(has_self_ty) {
246+
if data.skip_binder().trait_ref.substs[1..].iter().any(has_self_ty) {
247247
Some(sp)
248248
} else {
249249
None
@@ -262,12 +262,8 @@ fn predicates_reference_self(
262262
//
263263
// This is ALT2 in issue #56288, see that for discussion of the
264264
// possible alternatives.
265-
if data
266-
.skip_binder()
267-
.projection_ty
268-
.trait_ref(tcx)
269-
.input_types()
270-
.skip(1)
265+
if data.skip_binder().projection_ty.trait_ref(tcx).substs[1..]
266+
.iter()
271267
.any(has_self_ty)
272268
{
273269
Some(sp)

src/librustc_trait_selection/traits/select.rs

+27-11
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
652652
&mut self,
653653
stack: &TraitObligationStack<'o, 'tcx>,
654654
) -> Result<EvaluationResult, OverflowError> {
655-
// In intercrate mode, whenever any of the types are unbound,
655+
// In intercrate mode, whenever any of the generics are unbound,
656656
// there can always be an impl. Even if there are no impls in
657657
// this crate, perhaps the type would be unified with
658658
// something from another crate that does provide an impl.
@@ -677,7 +677,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
677677
// terms of `Fn` etc, but we could probably make this more
678678
// precise still.
679679
let unbound_input_types =
680-
stack.fresh_trait_ref.skip_binder().input_types().any(|ty| ty.is_fresh());
680+
stack.fresh_trait_ref.skip_binder().substs.types().any(|ty| ty.is_fresh());
681681
// This check was an imperfect workaround for a bug in the old
682682
// intercrate mode; it should be removed when that goes away.
683683
if unbound_input_types && self.intercrate {
@@ -3262,15 +3262,31 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
32623262
// substitution if we find that any of the input types, when
32633263
// simplified, do not match.
32643264

3265-
obligation.predicate.skip_binder().input_types().zip(impl_trait_ref.input_types()).any(
3266-
|(obligation_ty, impl_ty)| {
3267-
let simplified_obligation_ty =
3268-
fast_reject::simplify_type(self.tcx(), obligation_ty, true);
3269-
let simplified_impl_ty = fast_reject::simplify_type(self.tcx(), impl_ty, false);
3270-
3271-
simplified_obligation_ty.is_some()
3272-
&& simplified_impl_ty.is_some()
3273-
&& simplified_obligation_ty != simplified_impl_ty
3265+
obligation.predicate.skip_binder().trait_ref.substs.iter().zip(impl_trait_ref.substs).any(
3266+
|(obligation_arg, impl_arg)| {
3267+
match (obligation_arg.unpack(), impl_arg.unpack()) {
3268+
(GenericArgKind::Type(obligation_ty), GenericArgKind::Type(impl_ty)) => {
3269+
let simplified_obligation_ty =
3270+
fast_reject::simplify_type(self.tcx(), obligation_ty, true);
3271+
let simplified_impl_ty =
3272+
fast_reject::simplify_type(self.tcx(), impl_ty, false);
3273+
3274+
simplified_obligation_ty.is_some()
3275+
&& simplified_impl_ty.is_some()
3276+
&& simplified_obligation_ty != simplified_impl_ty
3277+
}
3278+
(GenericArgKind::Lifetime(_), GenericArgKind::Lifetime(_)) => {
3279+
// Lifetimes can never cause a rejection.
3280+
false
3281+
}
3282+
(GenericArgKind::Const(_), GenericArgKind::Const(_)) => {
3283+
// Conservatively ignore consts (i.e. assume they might
3284+
// unify later) until we have `fast_reject` support for
3285+
// them (if we'll ever need it, even).
3286+
false
3287+
}
3288+
_ => unreachable!(),
3289+
}
32743290
},
32753291
)
32763292
}

src/librustc_typeck/check/coercion.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -563,30 +563,30 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
563563
while !queue.is_empty() {
564564
let obligation = queue.remove(0);
565565
debug!("coerce_unsized resolve step: {:?}", obligation);
566-
let trait_ref = match obligation.predicate {
567-
ty::Predicate::Trait(ref tr, _) if traits.contains(&tr.def_id()) => {
568-
if unsize_did == tr.def_id() {
569-
let sty = &tr.skip_binder().input_types().nth(1).unwrap().kind;
570-
if let ty::Tuple(..) = sty {
566+
let trait_pred = match obligation.predicate {
567+
ty::Predicate::Trait(trait_pred, _) if traits.contains(&trait_pred.def_id()) => {
568+
if unsize_did == trait_pred.def_id() {
569+
let unsize_ty = trait_pred.skip_binder().trait_ref.substs[1].expect_ty();
570+
if let ty::Tuple(..) = unsize_ty.kind {
571571
debug!("coerce_unsized: found unsized tuple coercion");
572572
has_unsized_tuple_coercion = true;
573573
}
574574
}
575-
*tr
575+
trait_pred
576576
}
577577
_ => {
578578
coercion.obligations.push(obligation);
579579
continue;
580580
}
581581
};
582-
match selcx.select(&obligation.with(trait_ref)) {
582+
match selcx.select(&obligation.with(trait_pred)) {
583583
// Uncertain or unimplemented.
584584
Ok(None) => {
585-
if trait_ref.def_id() == unsize_did {
586-
let trait_ref = self.resolve_vars_if_possible(&trait_ref);
587-
let self_ty = trait_ref.skip_binder().self_ty();
588-
let unsize_ty = trait_ref.skip_binder().input_types().nth(1).unwrap();
589-
debug!("coerce_unsized: ambiguous unsize case for {:?}", trait_ref);
585+
if trait_pred.def_id() == unsize_did {
586+
let trait_pred = self.resolve_vars_if_possible(&trait_pred);
587+
let self_ty = trait_pred.skip_binder().self_ty();
588+
let unsize_ty = trait_pred.skip_binder().trait_ref.substs[1].expect_ty();
589+
debug!("coerce_unsized: ambiguous unsize case for {:?}", trait_pred);
590590
match (&self_ty.kind, &unsize_ty.kind) {
591591
(ty::Infer(ty::TyVar(v)), ty::Dynamic(..))
592592
if self.type_var_is_sized(*v) =>

0 commit comments

Comments
 (0)