Skip to content

Commit 506f430

Browse files
committed
progress
1 parent 4c3b1e8 commit 506f430

File tree

7 files changed

+54
-46
lines changed

7 files changed

+54
-46
lines changed

src/librustc_infer/traits/util.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use smallvec::smallvec;
33
use crate::traits::{Obligation, ObligationCause, PredicateObligation};
44
use rustc_data_structures::fx::FxHashSet;
55
use rustc_middle::ty::outlives::Component;
6-
use rustc_middle::ty::{self, ToPolyTraitRef, ToPredicate, TyCtxt, WithConstness};
6+
use rustc_middle::ty::{self, ToPredicate, TyCtxt, WithConstness};
77
use rustc_span::Span;
88

99
pub fn anonymize_predicate<'tcx>(
@@ -330,8 +330,8 @@ impl<'tcx, I: Iterator<Item = PredicateObligation<'tcx>>> Iterator for FilterToT
330330

331331
fn next(&mut self) -> Option<ty::PolyTraitRef<'tcx>> {
332332
while let Some(obligation) = self.base_iterator.next() {
333-
if let ty::PredicateKind::Trait(data, _) = obligation.predicate.kind() {
334-
return Some(data.to_poly_trait_ref());
333+
if let Some(data) = obligation.predicate.to_opt_poly_trait_ref() {
334+
return Some(data);
335335
}
336336
}
337337
None

src/librustc_lint/builtin.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,13 +1202,15 @@ declare_lint_pass!(
12021202
impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
12031203
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
12041204
use rustc_middle::ty::fold::TypeFoldable;
1205-
use rustc_middle::ty::PredicateKind::*;
1205+
use rustc_middle::ty::PredicateKint::*;
12061206

12071207
if cx.tcx.features().trivial_bounds {
12081208
let def_id = cx.tcx.hir().local_def_id(item.hir_id);
12091209
let predicates = cx.tcx.predicates_of(def_id);
12101210
for &(predicate, span) in predicates.predicates {
1211-
let predicate_kind_name = match predicate.kind() {
1211+
// We don't actually look inside of the predicate,
1212+
// so it is safe to skip this binder here.
1213+
let predicate_kind_name = match predicate.kint(cx.tcx).ignore_qualifiers().skip_binder() {
12121214
Trait(..) => "Trait",
12131215
TypeOutlives(..) |
12141216
RegionOutlives(..) => "Lifetime",
@@ -1223,6 +1225,7 @@ impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
12231225
Subtype(..) |
12241226
ConstEvaluatable(..) |
12251227
ConstEquate(..) => continue,
1228+
ForAll(_) => bug!("unexpected predicate: {:?}", predicate)
12261229
};
12271230
if predicate.is_global() {
12281231
cx.struct_span_lint(TRIVIAL_BOUNDS, span, |lint| {

src/librustc_lint/unused.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
146146
ty::Opaque(def, _) => {
147147
let mut has_emitted = false;
148148
for (predicate, _) in cx.tcx.predicates_of(def).predicates {
149-
if let ty::PredicateKind::Trait(ref poly_trait_predicate, _) =
150-
predicate.kind()
149+
// We only look at the `DefId`, so it is safe to skip the binder here.
150+
if let ty::PredicateKint::Trait(ref poly_trait_predicate, _) =
151+
predicate.kint(cx.tcx).ignore_qualifiers().skip_binder()
151152
{
152-
let trait_ref = poly_trait_predicate.skip_binder().trait_ref;
153-
let def_id = trait_ref.def_id;
153+
let def_id = poly_trait_predicate.trait_ref.def_id;
154154
let descr_pre =
155155
&format!("{}implementer{} of ", descr_pre, plural_suffix,);
156156
if check_must_use_def(cx, def_id, span, descr_pre, descr_post) {

src/librustc_middle/ty/mod.rs

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,16 @@ pub enum PredicateKind<'tcx> {
12171217
ConstEquate(&'tcx Const<'tcx>, &'tcx Const<'tcx>),
12181218
}
12191219

1220+
impl<'tcx> PredicateKint<'tcx> {
1221+
/// Skips `PredicateKint::ForAll`.
1222+
pub fn ignore_qualifiers(&'tcx self) -> Binder<&'tcx PredicateKint<'tcx>> {
1223+
match self {
1224+
&PredicateKint::ForAll(binder) => binder,
1225+
pred => Binder::dummy(pred),
1226+
}
1227+
}
1228+
}
1229+
12201230
/// The crate outlives map is computed during typeck and contains the
12211231
/// outlives of every item in the local crate. You should not use it
12221232
/// directly, because to do so will make your pass dependent on the
@@ -1513,34 +1523,37 @@ impl ToPredicate<'tcx> for PredicateKint<'tcx> {
15131523

15141524
impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<TraitRef<'tcx>> {
15151525
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
1516-
ty::PredicateKind::Trait(
1517-
ty::Binder::dummy(ty::TraitPredicate { trait_ref: self.value }),
1518-
self.constness,
1519-
)
1520-
.to_predicate(tcx)
1521-
}
1522-
}
1523-
1524-
impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<&TraitRef<'tcx>> {
1525-
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
1526-
ty::PredicateKind::Trait(
1527-
ty::Binder::dummy(ty::TraitPredicate { trait_ref: *self.value }),
1528-
self.constness,
1529-
)
1530-
.to_predicate(tcx)
1526+
ty::PredicateKint::Trait(ty::TraitPredicate { trait_ref: self.value }, self.constness)
1527+
.to_predicate(tcx)
15311528
}
15321529
}
15331530

15341531
impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<PolyTraitRef<'tcx>> {
15351532
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
1536-
ty::PredicateKind::Trait(self.value.to_poly_trait_predicate(), self.constness)
1537-
.to_predicate(tcx)
1533+
if let Some(trait_ref) = self.value.no_bound_vars() {
1534+
ty::PredicateKint::Trait(ty::TraitPredicate { trait_ref }, self.constness)
1535+
} else {
1536+
ty::PredicateKint::ForAll(self.value.map_bound(|trait_ref| {
1537+
tcx.intern_predicate_kint(ty::PredicateKint::Trait(
1538+
ty::TraitPredicate { trait_ref },
1539+
self.constness,
1540+
))
1541+
}))
1542+
}
1543+
.to_predicate(tcx)
15381544
}
15391545
}
15401546

15411547
impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> {
15421548
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
1543-
PredicateKind::RegionOutlives(self).to_predicate(tcx)
1549+
if let Some(outlives) = self.no_bound_vars() {
1550+
PredicateKint::RegionOutlives(outlives)
1551+
} else {
1552+
ty::PredicateKint::ForAll(self.map_bound(|outlives| {
1553+
tcx.intern_predicate_kint(PredicateKint::RegionOutlives(outlives))
1554+
}))
1555+
}
1556+
.to_predicate(tcx)
15441557
}
15451558
}
15461559

src/librustc_middle/ty/sty.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,8 +652,7 @@ impl<'tcx> Binder<ExistentialPredicate<'tcx>> {
652652
Binder(tr).with_self_ty(tcx, self_ty).without_const().to_predicate(tcx)
653653
}
654654
ExistentialPredicate::Projection(p) => {
655-
ty::PredicateKind::Projection(Binder(p.with_self_ty(tcx, self_ty)))
656-
.to_predicate(tcx)
655+
Binder(p.with_self_ty(tcx, self_ty)).to_predicate(tcx)
657656
}
658657
ExistentialPredicate::AutoTrait(did) => {
659658
let trait_ref =

src/librustc_mir/borrow_check/type_check/mod.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use rustc_middle::ty::fold::TypeFoldable;
2828
use rustc_middle::ty::subst::{GenericArgKind, Subst, SubstsRef, UserSubsts};
2929
use rustc_middle::ty::{
3030
self, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, RegionVid, ToPredicate, Ty,
31-
TyCtxt, UserType, UserTypeAnnotationIndex,
31+
TyCtxt, UserType, UserTypeAnnotationIndex, WithConstness,
3232
};
3333
use rustc_span::{Span, DUMMY_SP};
3434
use rustc_target::abi::VariantIdx;
@@ -2022,18 +2022,14 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
20222022
traits::ObligationCauseCode::RepeatVec(should_suggest),
20232023
),
20242024
self.param_env,
2025-
ty::PredicateKind::Trait(
2026-
ty::Binder::bind(ty::TraitPredicate {
2027-
trait_ref: ty::TraitRef::new(
2028-
self.tcx().require_lang_item(
2029-
CopyTraitLangItem,
2030-
Some(self.last_span),
2031-
),
2032-
tcx.mk_substs_trait(ty, &[]),
2033-
),
2034-
}),
2035-
hir::Constness::NotConst,
2036-
)
2025+
ty::Binder::bind(ty::TraitRef::new(
2026+
self.tcx().require_lang_item(
2027+
CopyTraitLangItem,
2028+
Some(self.last_span),
2029+
),
2030+
tcx.mk_substs_trait(ty, &[]),
2031+
))
2032+
.without_const()
20372033
.to_predicate(self.tcx()),
20382034
),
20392035
&traits::SelectionError::Unimplemented,

src/librustc_privacy/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,7 @@ trait DefIdVisitor<'tcx> {
6868
}
6969
}
7070

71-
struct DefIdVisitorSkeleton<'v, 'tcx, V>
72-
where
73-
V: DefIdVisitor<'tcx> + ?Sized,
74-
{
71+
struct DefIdVisitorSkeleton<'v, 'tcx, V: ?Sized> {
7572
def_id_visitor: &'v mut V,
7673
visited_opaque_tys: FxHashSet<DefId>,
7774
dummy: PhantomData<TyCtxt<'tcx>>,

0 commit comments

Comments
 (0)