Skip to content

Commit 0f257a5

Browse files
committed
progress
1 parent 9079926 commit 0f257a5

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
@@ -1206,13 +1206,15 @@ declare_lint_pass!(
12061206
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TrivialConstraints {
12071207
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item<'tcx>) {
12081208
use rustc_middle::ty::fold::TypeFoldable;
1209-
use rustc_middle::ty::PredicateKind::*;
1209+
use rustc_middle::ty::PredicateKint::*;
12101210

12111211
if cx.tcx.features().trivial_bounds {
12121212
let def_id = cx.tcx.hir().local_def_id(item.hir_id);
12131213
let predicates = cx.tcx.predicates_of(def_id);
12141214
for &(predicate, span) in predicates.predicates {
1215-
let predicate_kind_name = match predicate.kind() {
1215+
// We don't actually look inside of the predicate,
1216+
// so it is safe to skip this binder here.
1217+
let predicate_kind_name = match predicate.kint(cx.tcx).ignore_qualifiers().skip_binder() {
12161218
Trait(..) => "Trait",
12171219
TypeOutlives(..) |
12181220
RegionOutlives(..) => "Lifetime",
@@ -1227,6 +1229,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TrivialConstraints {
12271229
Subtype(..) |
12281230
ConstEvaluatable(..) |
12291231
ConstEquate(..) => continue,
1232+
ForAll(_) => bug!("unexpected predicate: {:?}", predicate)
12301233
};
12311234
if predicate.is_global() {
12321235
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<'a, 'tcx> LateLintPass<'a, '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
@@ -1209,6 +1209,16 @@ pub enum PredicateKind<'tcx> {
12091209
ConstEquate(&'tcx Const<'tcx>, &'tcx Const<'tcx>),
12101210
}
12111211

1212+
impl<'tcx> PredicateKint<'tcx> {
1213+
/// Skips `PredicateKint::ForAll`.
1214+
pub fn ignore_qualifiers(&'tcx self) -> Binder<&'tcx PredicateKint<'tcx>> {
1215+
match self {
1216+
&PredicateKint::ForAll(binder) => binder,
1217+
pred => Binder::dummy(pred),
1218+
}
1219+
}
1220+
}
1221+
12121222
/// The crate outlives map is computed during typeck and contains the
12131223
/// outlives of every item in the local crate. You should not use it
12141224
/// directly, because to do so will make your pass dependent on the
@@ -1505,34 +1515,37 @@ impl ToPredicate<'tcx> for PredicateKint<'tcx> {
15051515

15061516
impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<TraitRef<'tcx>> {
15071517
fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
1508-
ty::PredicateKind::Trait(
1509-
ty::Binder::dummy(ty::TraitPredicate { trait_ref: self.value }),
1510-
self.constness,
1511-
)
1512-
.to_predicate(tcx)
1513-
}
1514-
}
1515-
1516-
impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<&TraitRef<'tcx>> {
1517-
fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
1518-
ty::PredicateKind::Trait(
1519-
ty::Binder::dummy(ty::TraitPredicate { trait_ref: *self.value }),
1520-
self.constness,
1521-
)
1522-
.to_predicate(tcx)
1518+
ty::PredicateKint::Trait(ty::TraitPredicate { trait_ref: self.value }, self.constness)
1519+
.to_predicate(tcx)
15231520
}
15241521
}
15251522

15261523
impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<PolyTraitRef<'tcx>> {
15271524
fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
1528-
ty::PredicateKind::Trait(self.value.to_poly_trait_predicate(), self.constness)
1529-
.to_predicate(tcx)
1525+
if let Some(trait_ref) = self.value.no_bound_vars() {
1526+
ty::PredicateKint::Trait(ty::TraitPredicate { trait_ref }, self.constness)
1527+
} else {
1528+
ty::PredicateKint::ForAll(self.value.map_bound(|trait_ref| {
1529+
tcx.intern_predicate_kint(ty::PredicateKint::Trait(
1530+
ty::TraitPredicate { trait_ref },
1531+
self.constness,
1532+
))
1533+
}))
1534+
}
1535+
.to_predicate(tcx)
15301536
}
15311537
}
15321538

15331539
impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> {
15341540
fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
1535-
PredicateKind::RegionOutlives(*self).to_predicate(tcx)
1541+
if let Some(outlives) = self.no_bound_vars() {
1542+
PredicateKint::RegionOutlives(outlives)
1543+
} else {
1544+
ty::PredicateKint::ForAll(self.map_bound(|outlives| {
1545+
tcx.intern_predicate_kint(PredicateKint::RegionOutlives(outlives))
1546+
}))
1547+
}
1548+
.to_predicate(tcx)
15361549
}
15371550
}
15381551

src/librustc_middle/ty/sty.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,7 @@ impl<'tcx> Binder<ExistentialPredicate<'tcx>> {
621621
Binder(tr).with_self_ty(tcx, self_ty).without_const().to_predicate(tcx)
622622
}
623623
ExistentialPredicate::Projection(p) => {
624-
ty::PredicateKind::Projection(Binder(p.with_self_ty(tcx, self_ty)))
625-
.to_predicate(tcx)
624+
Binder(p.with_self_ty(tcx, self_ty)).to_predicate(tcx)
626625
}
627626
ExistentialPredicate::AutoTrait(did) => {
628627
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)