Skip to content

Commit c6c0d17

Browse files
committed
review
1 parent bbd581c commit c6c0d17

File tree

14 files changed

+45
-75
lines changed

14 files changed

+45
-75
lines changed

src/librustc_infer/traits/util.rs

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,22 @@ pub fn anonymize_predicate<'tcx>(
1111
pred: ty::Predicate<'tcx>,
1212
) -> ty::Predicate<'tcx> {
1313
let kind = pred.kind();
14-
let new = match kind {
14+
match kind {
1515
ty::PredicateKind::ForAll(binder) => {
16-
ty::PredicateKind::ForAll(tcx.anonymize_late_bound_regions(binder))
16+
let new = ty::PredicateKind::ForAll(tcx.anonymize_late_bound_regions(binder));
17+
if new != *kind { new.to_predicate(tcx) } else { pred }
1718
}
18-
&ty::PredicateKind::Trait(data, constness) => ty::PredicateKind::Trait(data, constness),
19-
20-
&ty::PredicateKind::RegionOutlives(data) => ty::PredicateKind::RegionOutlives(data),
21-
22-
&ty::PredicateKind::TypeOutlives(data) => ty::PredicateKind::TypeOutlives(data),
23-
24-
&ty::PredicateKind::Projection(data) => ty::PredicateKind::Projection(data),
25-
26-
&ty::PredicateKind::WellFormed(data) => ty::PredicateKind::WellFormed(data),
27-
28-
&ty::PredicateKind::ObjectSafe(data) => ty::PredicateKind::ObjectSafe(data),
29-
30-
&ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
31-
ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind)
32-
}
33-
34-
&ty::PredicateKind::Subtype(data) => ty::PredicateKind::Subtype(data),
35-
36-
&ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
37-
ty::PredicateKind::ConstEvaluatable(def_id, substs)
38-
}
39-
40-
&ty::PredicateKind::ConstEquate(c1, c2) => ty::PredicateKind::ConstEquate(c1, c2),
41-
};
42-
43-
if new != *kind { new.to_predicate(tcx) } else { pred }
19+
ty::PredicateKind::Trait(_, _)
20+
| ty::PredicateKind::RegionOutlives(_)
21+
| ty::PredicateKind::TypeOutlives(_)
22+
| ty::PredicateKind::Projection(_)
23+
| ty::PredicateKind::WellFormed(_)
24+
| ty::PredicateKind::ObjectSafe(_)
25+
| ty::PredicateKind::ClosureKind(_, _, _)
26+
| ty::PredicateKind::Subtype(_)
27+
| ty::PredicateKind::ConstEvaluatable(_, _)
28+
| ty::PredicateKind::ConstEquate(_, _) => pred,
29+
}
4430
}
4531

4632
struct PredicateSet<'tcx> {

src/librustc_middle/ty/mod.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,20 +1225,10 @@ impl<'tcx> Predicate<'tcx> {
12251225
// substitution code expects equal binding levels in the values
12261226
// from the substitution and the value being substituted into, and
12271227
// this trick achieves that).
1228-
12291228
let substs = trait_ref.skip_binder().substs;
1230-
let kind = match self.kind() {
1231-
PredicateKind::ForAll(binder) => binder.skip_binder().kind(),
1232-
kind => kind,
1233-
};
1234-
1235-
let new = kind.subst(tcx, substs);
1236-
1237-
if new != *kind {
1238-
new.to_predicate(tcx).potentially_qualified(tcx, PredicateKind::ForAll)
1239-
} else {
1240-
self
1241-
}
1229+
let pred = *self.ignore_qualifiers(tcx).skip_binder();
1230+
let new = pred.subst(tcx, substs);
1231+
if new != pred { new.potentially_qualified(tcx, PredicateKind::ForAll) } else { self }
12421232
}
12431233
}
12441234

src/librustc_mir/transform/qualify_min_const_fn.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) -
2424
loop {
2525
let predicates = tcx.predicates_of(current);
2626
for (predicate, _) in predicates.predicates {
27-
// TODO: forall
2827
match predicate.ignore_qualifiers(tcx).skip_binder().kind() {
2928
ty::PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", predicate),
3029
ty::PredicateKind::RegionOutlives(_)

src/librustc_trait_selection/traits/auto_trait.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,6 @@ impl AutoTraitFinder<'tcx> {
639639
// We check this by calling is_of_param on the relevant types
640640
// from the various possible predicates
641641

642-
// TODO: forall
643642
match predicate.ignore_qualifiers(self.tcx).skip_binder().kind() {
644643
&ty::PredicateKind::Trait(p, _) => {
645644
if self.is_param_no_infer(p.trait_ref.substs)

src/librustc_trait_selection/traits/error_reporting/mod.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
256256
return;
257257
}
258258

259-
// TODO: forall
260259
match obligation.predicate.ignore_qualifiers(tcx).skip_binder().kind() {
261260
ty::PredicateKind::ForAll(_) => {
262261
bug!("unexpected predicate: {:?}", obligation.predicate)
@@ -1481,7 +1480,6 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
14811480
return;
14821481
}
14831482

1484-
// TODO: forall
14851483
let mut err = match predicate.ignore_qualifiers(self.tcx).skip_binder().kind() {
14861484
&ty::PredicateKind::Trait(data, _) => {
14871485
let trait_ref = ty::Binder::bind(data.trait_ref);
@@ -1583,8 +1581,6 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
15831581
}
15841582

15851583
ty::PredicateKind::WellFormed(arg) => {
1586-
// TODO: forall
1587-
15881584
// Same hacky approach as above to avoid deluging user
15891585
// with error messages.
15901586
if arg.references_error() || self.tcx.sess.has_errors() {
@@ -1604,7 +1600,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
16041600
}
16051601
}
16061602

1607-
ty::PredicateKind::Subtype(ref data) => {
1603+
ty::PredicateKind::Subtype(data) => {
16081604
if data.references_error() || self.tcx.sess.has_errors() {
16091605
// no need to overload user in such cases
16101606
return;
@@ -1737,14 +1733,16 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
17371733
err: &mut DiagnosticBuilder<'tcx>,
17381734
obligation: &PredicateObligation<'tcx>,
17391735
) {
1740-
let (pred, item_def_id, span) =
1741-
match (obligation.predicate.ignore_qualifiers(self.tcx).skip_binder().kind(), obligation.cause.code.peel_derives()) {
1742-
(
1743-
ty::PredicateKind::Trait(pred, _),
1744-
&ObligationCauseCode::BindingObligation(item_def_id, span),
1745-
) => (pred, item_def_id, span),
1746-
_ => return,
1747-
};
1736+
let (pred, item_def_id, span) = match (
1737+
obligation.predicate.ignore_qualifiers(self.tcx).skip_binder().kind(),
1738+
obligation.cause.code.peel_derives(),
1739+
) {
1740+
(
1741+
ty::PredicateKind::Trait(pred, _),
1742+
&ObligationCauseCode::BindingObligation(item_def_id, span),
1743+
) => (pred, item_def_id, span),
1744+
_ => return,
1745+
};
17481746

17491747
let node = match (
17501748
self.tcx.hir().get_if_local(item_def_id),

src/librustc_trait_selection/traits/object_safety.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ fn predicates_reference_self(
245245
.iter()
246246
.map(|(predicate, sp)| (predicate.subst_supertrait(tcx, &trait_ref), sp))
247247
.filter_map(|(predicate, &sp)| {
248-
// TODO: forall
249248
match predicate.ignore_qualifiers(tcx).skip_binder().kind() {
250249
ty::PredicateKind::Trait(ref data, _) => {
251250
// In the case of a trait predicate, we can skip the "self" type.
@@ -300,7 +299,6 @@ fn generics_require_sized_self(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
300299
let predicates = tcx.predicates_of(def_id);
301300
let predicates = predicates.instantiate_identity(tcx).predicates;
302301
elaborate_predicates(tcx, predicates.into_iter()).any(|obligation| {
303-
// TODO: forall
304302
match obligation.predicate.ignore_qualifiers(tcx).skip_binder().kind() {
305303
ty::PredicateKind::Trait(ref trait_pred, _) => {
306304
trait_pred.def_id() == sized_def_id && trait_pred.self_ty().is_param(0)

src/librustc_trait_selection/traits/project.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,6 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>(
933933
let infcx = selcx.infcx();
934934
for predicate in env_predicates {
935935
debug!("assemble_candidates_from_predicates: predicate={:?}", predicate);
936-
// TODO: forall
937936
if let &ty::PredicateKind::Projection(data) =
938937
predicate.ignore_qualifiers(infcx.tcx).skip_binder().kind()
939938
{
@@ -1228,7 +1227,6 @@ fn confirm_object_candidate<'cx, 'tcx>(
12281227
// select only those projections that are actually projecting an
12291228
// item with the correct name
12301229

1231-
// TODO: forall
12321230
let env_predicates = env_predicates.filter_map(|o| {
12331231
match o.predicate.ignore_qualifiers(selcx.tcx()).skip_binder().kind() {
12341232
&ty::PredicateKind::Projection(data)

src/librustc_trait_selection/traits/select/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
408408
None => self.check_recursion_limit(&obligation, &obligation)?,
409409
}
410410

411-
// TODO: forall
412411
match obligation.predicate.ignore_qualifiers(self.tcx()).skip_binder().kind() {
413412
ty::PredicateKind::ForAll(_) => {
414413
bug!("unexpected predicate: {:?}", obligation.predicate)

src/librustc_traits/chalk/lowering.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,21 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predi
223223
// the environment.
224224
ty::Placeholder(..) => chalk_ir::GoalData::All(chalk_ir::Goals::new(interner)),
225225

226-
_ => chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::WellFormed(
227-
chalk_ir::WellFormed::Ty(ty.lower_into(interner)),
228-
)),
226+
_ => {
227+
let (ty, binders, _named_regions) =
228+
collect_bound_vars(interner, interner.tcx, &ty::Binder::bind(ty));
229+
230+
chalk_ir::GoalData::Quantified(
231+
chalk_ir::QuantifierKind::ForAll,
232+
chalk_ir::Binders::new(
233+
binders,
234+
chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::WellFormed(
235+
chalk_ir::WellFormed::Ty(ty.lower_into(interner)),
236+
))
237+
.intern(interner),
238+
),
239+
)
240+
}
229241
},
230242
// FIXME(chalk): handle well formed consts
231243
GenericArgKind::Const(..) => {

src/librustc_traits/normalize_erasing_regions.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ fn normalize_generic_arg_after_erasing_regions<'tcx>(
4242
}
4343

4444
fn not_outlives_predicate(tcx: TyCtxt<'tcx>, p: &ty::Predicate<'tcx>) -> bool {
45-
// TODO: forall
4645
match p.ignore_qualifiers(tcx).skip_binder().kind() {
4746
ty::PredicateKind::RegionOutlives(..) | ty::PredicateKind::TypeOutlives(..) => false,
4847
ty::PredicateKind::ForAll(_) => bug!("unexpected predicate: {:?}", p),

0 commit comments

Comments
 (0)