Skip to content

Commit d1c4375

Browse files
committed
happy accidents
1 parent f48b061 commit d1c4375

File tree

9 files changed

+25
-19
lines changed

9 files changed

+25
-19
lines changed

src/librustc_middle/ty/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,12 @@ impl<'tcx> Predicate<'tcx> {
10541054
| ty::PredicateKind::TypeOutlives(..)
10551055
| ty::PredicateKind::ConstEvaluatable(..)
10561056
| ty::PredicateKind::ConstEquate(..)
1057-
| ty::PredicateKind::RegionOutlives(..) => Binder::dummy(self),
1057+
| ty::PredicateKind::RegionOutlives(..) => {
1058+
// We can't use `Binder::dummy` here, as predicates can
1059+
// contain unbound variables in rare cases, for example when
1060+
// dealing with opaque types.
1061+
Binder::bind(self)
1062+
}
10581063
}
10591064
}
10601065

@@ -1065,9 +1070,7 @@ impl<'tcx> Predicate<'tcx> {
10651070
qualifier: impl FnOnce(Binder<Predicate<'tcx>>) -> PredicateKind<'tcx>,
10661071
) -> Predicate<'tcx> {
10671072
if self.has_escaping_bound_vars() {
1068-
let qualified = qualifier(Binder::bind(self)).to_predicate(tcx);
1069-
debug_assert!(!qualified.has_escaping_bound_vars(), "qualified: {:?}", qualified);
1070-
qualified
1073+
qualifier(Binder::bind(self)).to_predicate(tcx)
10711074
} else {
10721075
self
10731076
}

src/librustc_trait_selection/traits/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ pub fn normalize_param_env_or_error<'tcx>(
328328
// This works fairly well because trait matching does not actually care about param-env
329329
// TypeOutlives predicates - these are normally used by regionck.
330330
let outlives_predicates: Vec<_> = predicates
331-
.drain_filter(|predicate| match predicate.kind() {
331+
.drain_filter(|predicate| match predicate.ignore_qualifiers().skip_binder().kind() {
332332
ty::PredicateKind::TypeOutlives(..) => true,
333333
_ => false,
334334
})

src/librustc_trait_selection/traits/project.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ fn prune_cache_value_obligations<'a, 'tcx>(
663663
let mut obligations: Vec<_> = result
664664
.obligations
665665
.iter()
666-
.filter(|obligation| match obligation.predicate.kind() {
666+
.filter(|obligation| match obligation.predicate.ignore_qualifiers().skip_binder().kind() {
667667
// We found a `T: Foo<X = U>` predicate, let's check
668668
// if `U` references any unresolved type
669669
// variables. In principle, we only care if this
@@ -673,8 +673,8 @@ fn prune_cache_value_obligations<'a, 'tcx>(
673673
// indirect obligations (e.g., we project to `?0`,
674674
// but we have `T: Foo<X = ?1>` and `?1: Bar<X =
675675
// ?0>`).
676-
ty::PredicateKind::Projection(ref data) => {
677-
infcx.unresolved_type_vars(&data.ty).is_some()
676+
&ty::PredicateKind::Projection(data) => {
677+
infcx.unresolved_type_vars(&ty::Binder::bind(data.ty)).is_some()
678678
}
679679

680680
// We are only interested in `T: Foo<X = U>` predicates, whre

src/librustc_trait_selection/traits/select/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
793793
}
794794

795795
fn coinductive_predicate(&self, predicate: ty::Predicate<'tcx>) -> bool {
796-
let result = match predicate.kind() {
796+
let result = match predicate.ignore_qualifiers().skip_binder().kind() {
797797
ty::PredicateKind::Trait(ref data, _) => self.tcx().trait_is_auto(data.def_id()),
798798
_ => false,
799799
};

src/librustc_typeck/check/dropck.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,15 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
226226
// could be extended easily also to the other `Predicate`.
227227
let predicate_matches_closure = |p: Predicate<'tcx>| {
228228
let mut relator: SimpleEqRelation<'tcx> = SimpleEqRelation::new(tcx, self_param_env);
229-
match (predicate.kind(), p.kind()) {
230-
(ty::PredicateKind::Trait(a, _), ty::PredicateKind::Trait(b, _)) => {
231-
relator.relate(a, b).is_ok()
229+
match (
230+
predicate.ignore_qualifiers().skip_binder().kind(),
231+
p.ignore_qualifiers().skip_binder().kind(),
232+
) {
233+
(&ty::PredicateKind::Trait(a, _), &ty::PredicateKind::Trait(b, _)) => {
234+
relator.relate(&ty::Binder::bind(a), &ty::Binder::bind(b)).is_ok()
232235
}
233-
(ty::PredicateKind::Projection(a), ty::PredicateKind::Projection(b)) => {
234-
relator.relate(a, b).is_ok()
236+
(&ty::PredicateKind::Projection(a), &ty::PredicateKind::Projection(b)) => {
237+
relator.relate(&ty::Binder::bind(a), &ty::Binder::bind(b)).is_ok()
235238
}
236239
_ => predicate == p,
237240
}

src/librustc_typeck/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ fn super_predicates_of(tcx: TyCtxt<'_>, trait_def_id: DefId) -> ty::GenericPredi
993993
// which will, in turn, reach indirect supertraits.
994994
for &(pred, span) in superbounds {
995995
debug!("superbound: {:?}", pred);
996-
if let ty::PredicateKind::Trait(bound, _) = pred.kind() {
996+
if let ty::PredicateKind::Trait(bound, _) = pred.ignore_qualifiers().skip_binder().kind() {
997997
tcx.at(span).super_predicates_of(bound.def_id());
998998
}
999999
}

src/librustc_typeck/impl_wf_check/min_specialization.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ fn check_predicates<'tcx>(
361361

362362
fn check_specialization_on<'tcx>(tcx: TyCtxt<'tcx>, predicate: ty::Predicate<'tcx>, span: Span) {
363363
debug!("can_specialize_on(predicate = {:?})", predicate);
364-
match predicate.kind() {
364+
match predicate.ignore_qualifiers().skip_binder().kind() {
365365
// Global predicates are either always true or always false, so we
366366
// are fine to specialize on.
367367
_ if predicate.is_global() => (),
@@ -394,7 +394,7 @@ fn trait_predicate_kind<'tcx>(
394394
tcx: TyCtxt<'tcx>,
395395
predicate: ty::Predicate<'tcx>,
396396
) -> Option<TraitSpecializationKind> {
397-
match predicate.kind() {
397+
match predicate.ignore_qualifiers().skip_binder().kind() {
398398
ty::PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", predicate),
399399
ty::PredicateKind::Trait(pred, hir::Constness::NotConst) => {
400400
Some(tcx.trait_def(pred.def_id()).specialization_kind)

src/librustdoc/clean/auto_trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
465465
.iter()
466466
.filter(|p| {
467467
!orig_bounds.contains(p)
468-
|| match p.kind() {
468+
|| match p.ignore_qualifiers().skip_binder().kind() {
469469
ty::PredicateKind::Trait(pred, _) => pred.def_id() == sized_trait,
470470
_ => false,
471471
}

src/test/ui/specialization/min_specialization/repeated_projection_type.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: cannot specialize on `Binder(ProjectionPredicate(ProjectionTy { substs: [V], item_def_id: DefId(0:6 ~ repeated_projection_type[317d]::Id[0]::This[0]) }, (I,)))`
1+
error: cannot specialize on `ProjectionPredicate(ProjectionTy { substs: [V], item_def_id: DefId(0:6 ~ repeated_projection_type[317d]::Id[0]::This[0]) }, (I,))`
22
--> $DIR/repeated_projection_type.rs:19:1
33
|
44
LL | / impl<I, V: Id<This = (I,)>> X for V {

0 commit comments

Comments
 (0)