Skip to content

Commit 974e283

Browse files
committed
Introduce PredicateKind::Clause
1 parent 42cc8e8 commit 974e283

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+568
-407
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -666,15 +666,17 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
666666
let tcx = self.infcx.tcx;
667667

668668
// Find out if the predicates show that the type is a Fn or FnMut
669-
let find_fn_kind_from_did =
670-
|predicates: ty::EarlyBinder<&[(ty::Predicate<'tcx>, Span)]>, substs| {
671-
predicates.0.iter().find_map(|(pred, _)| {
669+
let find_fn_kind_from_did = |predicates: ty::EarlyBinder<
670+
&[(ty::Predicate<'tcx>, Span)],
671+
>,
672+
substs| {
673+
predicates.0.iter().find_map(|(pred, _)| {
672674
let pred = if let Some(substs) = substs {
673675
predicates.rebind(*pred).subst(tcx, substs).kind().skip_binder()
674676
} else {
675677
pred.kind().skip_binder()
676678
};
677-
if let ty::PredicateKind::Trait(pred) = pred && pred.self_ty() == ty {
679+
if let ty::PredicateKind::Clause(ty::Clause::Trait(pred)) = pred && pred.self_ty() == ty {
678680
if Some(pred.def_id()) == tcx.lang_items().fn_trait() {
679681
return Some(hir::Mutability::Not);
680682
} else if Some(pred.def_id()) == tcx.lang_items().fn_mut_trait() {
@@ -683,7 +685,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
683685
}
684686
None
685687
})
686-
};
688+
};
687689

688690
// If the type is opaque/param/closure, and it is Fn or FnMut, let's suggest (mutably)
689691
// borrowing the type, since `&mut F: FnMut` iff `F: FnMut` and similarly for `Fn`.
@@ -784,13 +786,15 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
784786
let predicates: Result<Vec<_>, _> = errors
785787
.into_iter()
786788
.map(|err| match err.obligation.predicate.kind().skip_binder() {
787-
PredicateKind::Trait(predicate) => match predicate.self_ty().kind() {
788-
ty::Param(param_ty) => Ok((
789-
generics.type_param(param_ty, tcx),
790-
predicate.trait_ref.print_only_trait_path().to_string(),
791-
)),
792-
_ => Err(()),
793-
},
789+
PredicateKind::Clause(ty::Clause::Trait(predicate)) => {
790+
match predicate.self_ty().kind() {
791+
ty::Param(param_ty) => Ok((
792+
generics.type_param(param_ty, tcx),
793+
predicate.trait_ref.print_only_trait_path().to_string(),
794+
)),
795+
_ => Err(()),
796+
}
797+
}
794798
_ => Err(()),
795799
})
796800
.collect();

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -959,8 +959,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
959959
{
960960
predicates.iter().any(|pred| {
961961
match pred.kind().skip_binder() {
962-
ty::PredicateKind::Trait(data) if data.self_ty() == ty => {}
963-
ty::PredicateKind::Projection(data) if data.projection_ty.self_ty() == ty => {}
962+
ty::PredicateKind::Clause(ty::Clause::Trait(data)) if data.self_ty() == ty => {}
963+
ty::PredicateKind::Clause(ty::Clause::Projection(data)) if data.projection_ty.self_ty() == ty => {}
964964
_ => return false,
965965
}
966966
tcx.any_free_region_meets(pred, |r| {

compiler/rustc_borrowck/src/type_check/canonical.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
8888
category: ConstraintCategory<'tcx>,
8989
) {
9090
self.prove_predicate(
91-
ty::Binder::dummy(ty::PredicateKind::Trait(ty::TraitPredicate {
91+
ty::Binder::dummy(ty::PredicateKind::Clause(ty::Clause::Trait(ty::TraitPredicate {
9292
trait_ref,
9393
constness: ty::BoundConstness::NotConst,
9494
polarity: ty::ImplPolarity::Positive,
95-
})),
95+
}))),
9696
locations,
9797
category,
9898
);

compiler/rustc_borrowck/src/type_check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2013,8 +2013,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
20132013
);
20142014

20152015
let outlives_predicate =
2016-
tcx.mk_predicate(Binder::dummy(ty::PredicateKind::TypeOutlives(
2017-
ty::OutlivesPredicate(self_ty, *region),
2016+
tcx.mk_predicate(Binder::dummy(ty::PredicateKind::Clause(
2017+
ty::Clause::TypeOutlives(ty::OutlivesPredicate(self_ty, *region)),
20182018
)));
20192019
self.prove_predicate(
20202020
outlives_predicate,

compiler/rustc_hir_analysis/src/astconv/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
13781378

13791379
let bound_predicate = obligation.predicate.kind();
13801380
match bound_predicate.skip_binder() {
1381-
ty::PredicateKind::Trait(pred) => {
1381+
ty::PredicateKind::Clause(ty::Clause::Trait(pred)) => {
13821382
let pred = bound_predicate.rebind(pred);
13831383
associated_types.entry(span).or_default().extend(
13841384
tcx.associated_items(pred.def_id())
@@ -1387,7 +1387,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
13871387
.map(|item| item.def_id),
13881388
);
13891389
}
1390-
ty::PredicateKind::Projection(pred) => {
1390+
ty::PredicateKind::Clause(ty::Clause::Projection(pred)) => {
13911391
let pred = bound_predicate.rebind(pred);
13921392
// A `Self` within the original bound will be substituted with a
13931393
// `trait_object_dummy_self`, so check for that.

compiler/rustc_hir_analysis/src/check/dropck.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -183,19 +183,27 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
183183
let predicate = predicate.kind();
184184
let p = p.kind();
185185
match (predicate.skip_binder(), p.skip_binder()) {
186-
(ty::PredicateKind::Trait(a), ty::PredicateKind::Trait(b)) => {
187-
relator.relate(predicate.rebind(a), p.rebind(b)).is_ok()
188-
}
189-
(ty::PredicateKind::Projection(a), ty::PredicateKind::Projection(b)) => {
190-
relator.relate(predicate.rebind(a), p.rebind(b)).is_ok()
191-
}
186+
(
187+
ty::PredicateKind::Clause(ty::Clause::Trait(a)),
188+
ty::PredicateKind::Clause(ty::Clause::Trait(b)),
189+
) => relator.relate(predicate.rebind(a), p.rebind(b)).is_ok(),
190+
(
191+
ty::PredicateKind::Clause(ty::Clause::Projection(a)),
192+
ty::PredicateKind::Clause(ty::Clause::Projection(b)),
193+
) => relator.relate(predicate.rebind(a), p.rebind(b)).is_ok(),
192194
(
193195
ty::PredicateKind::ConstEvaluatable(a),
194196
ty::PredicateKind::ConstEvaluatable(b),
195197
) => relator.relate(predicate.rebind(a), predicate.rebind(b)).is_ok(),
196198
(
197-
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty_a, lt_a)),
198-
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty_b, lt_b)),
199+
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(ty::OutlivesPredicate(
200+
ty_a,
201+
lt_a,
202+
))),
203+
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(ty::OutlivesPredicate(
204+
ty_b,
205+
lt_b,
206+
))),
199207
) => {
200208
relator.relate(predicate.rebind(ty_a), p.rebind(ty_b)).is_ok()
201209
&& relator.relate(predicate.rebind(lt_a), p.rebind(lt_b)).is_ok()

compiler/rustc_hir_analysis/src/check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ fn bounds_from_generic_predicates<'tcx>(
309309
debug!("predicate {:?}", predicate);
310310
let bound_predicate = predicate.kind();
311311
match bound_predicate.skip_binder() {
312-
ty::PredicateKind::Trait(trait_predicate) => {
312+
ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) => {
313313
let entry = types.entry(trait_predicate.self_ty()).or_default();
314314
let def_id = trait_predicate.def_id();
315315
if Some(def_id) != tcx.lang_items().sized_trait() {
@@ -318,7 +318,7 @@ fn bounds_from_generic_predicates<'tcx>(
318318
entry.push(trait_predicate.def_id());
319319
}
320320
}
321-
ty::PredicateKind::Projection(projection_pred) => {
321+
ty::PredicateKind::Clause(ty::Clause::Projection(projection_pred)) => {
322322
projections.push(bound_predicate.rebind(projection_pred));
323323
}
324324
_ => {}

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -462,12 +462,16 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
462462
let mut unsatisfied_bounds: Vec<_> = required_bounds
463463
.into_iter()
464464
.filter(|clause| match clause.kind().skip_binder() {
465-
ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => {
465+
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(ty::OutlivesPredicate(
466+
a,
467+
b,
468+
))) => {
466469
!region_known_to_outlive(tcx, gat_hir, param_env, &FxIndexSet::default(), a, b)
467470
}
468-
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(a, b)) => {
469-
!ty_known_to_outlive(tcx, gat_hir, param_env, &FxIndexSet::default(), a, b)
470-
}
471+
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(ty::OutlivesPredicate(
472+
a,
473+
b,
474+
))) => !ty_known_to_outlive(tcx, gat_hir, param_env, &FxIndexSet::default(), a, b),
471475
_ => bug!("Unexpected PredicateKind"),
472476
})
473477
.map(|clause| clause.to_string())
@@ -599,8 +603,9 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<'tcx>>(
599603
}));
600604
// The predicate we expect to see. (In our example,
601605
// `Self: 'me`.)
602-
let clause =
603-
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty_param, region_param));
606+
let clause = ty::PredicateKind::Clause(ty::Clause::TypeOutlives(
607+
ty::OutlivesPredicate(ty_param, region_param),
608+
));
604609
let clause = tcx.mk_predicate(ty::Binder::dummy(clause));
605610
bounds.insert(clause);
606611
}
@@ -636,9 +641,8 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<'tcx>>(
636641
name: region_b_param.name,
637642
}));
638643
// The predicate we expect to see.
639-
let clause = ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(
640-
region_a_param,
641-
region_b_param,
644+
let clause = ty::PredicateKind::Clause(ty::Clause::RegionOutlives(
645+
ty::OutlivesPredicate(region_a_param, region_b_param),
642646
));
643647
let clause = tcx.mk_predicate(ty::Binder::dummy(clause));
644648
bounds.insert(clause);

compiler/rustc_hir_analysis/src/coherence/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
128128
.or_default()
129129
.push(error.obligation.cause.span);
130130
}
131-
if let ty::PredicateKind::Trait(ty::TraitPredicate {
131+
if let ty::PredicateKind::Clause(ty::Clause::Trait(ty::TraitPredicate {
132132
trait_ref,
133133
polarity: ty::ImplPolarity::Positive,
134134
..
135-
}) = error_predicate.kind().skip_binder()
135+
})) = error_predicate.kind().skip_binder()
136136
{
137137
let ty = trait_ref.self_ty();
138138
if let ty::Param(_) = ty.kind() {

compiler/rustc_hir_analysis/src/collect/item_bounds.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ fn associated_type_bounds<'tcx>(
3535

3636
let bounds_from_parent = trait_predicates.predicates.iter().copied().filter(|(pred, _)| {
3737
match pred.kind().skip_binder() {
38-
ty::PredicateKind::Trait(tr) => tr.self_ty() == item_ty,
39-
ty::PredicateKind::Projection(proj) => proj.projection_ty.self_ty() == item_ty,
40-
ty::PredicateKind::TypeOutlives(outlives) => outlives.0 == item_ty,
38+
ty::PredicateKind::Clause(ty::Clause::Trait(tr)) => tr.self_ty() == item_ty,
39+
ty::PredicateKind::Clause(ty::Clause::Projection(proj)) => {
40+
proj.projection_ty.self_ty() == item_ty
41+
}
42+
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(outlives)) => outlives.0 == item_ty,
4143
_ => false,
4244
}
4345
});

compiler/rustc_hir_analysis/src/collect/lifetimes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
15581558
let obligations = predicates.predicates.iter().filter_map(|&(pred, _)| {
15591559
let bound_predicate = pred.kind();
15601560
match bound_predicate.skip_binder() {
1561-
ty::PredicateKind::Trait(data) => {
1561+
ty::PredicateKind::Clause(ty::Clause::Trait(data)) => {
15621562
// The order here needs to match what we would get from `subst_supertrait`
15631563
let pred_bound_vars = bound_predicate.bound_vars();
15641564
let mut all_bound_vars = bound_vars.clone();

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+15-13
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
233233
}
234234
_ => bug!(),
235235
};
236-
let pred = ty::Binder::dummy(ty::PredicateKind::RegionOutlives(
237-
ty::OutlivesPredicate(r1, r2),
236+
let pred = ty::Binder::dummy(ty::PredicateKind::Clause(
237+
ty::Clause::RegionOutlives(ty::OutlivesPredicate(r1, r2)),
238238
))
239239
.to_predicate(icx.tcx);
240240

@@ -299,17 +299,15 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
299299
name: duplicate.name.ident().name,
300300
}));
301301
predicates.push((
302-
ty::Binder::dummy(ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(
303-
orig_region,
304-
dup_region,
302+
ty::Binder::dummy(ty::PredicateKind::Clause(ty::Clause::RegionOutlives(
303+
ty::OutlivesPredicate(orig_region, dup_region),
305304
)))
306305
.to_predicate(icx.tcx),
307306
duplicate.span,
308307
));
309308
predicates.push((
310-
ty::Binder::dummy(ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(
311-
dup_region,
312-
orig_region,
309+
ty::Binder::dummy(ty::PredicateKind::Clause(ty::Clause::RegionOutlives(
310+
ty::OutlivesPredicate(dup_region, orig_region),
313311
)))
314312
.to_predicate(icx.tcx),
315313
duplicate.span,
@@ -426,11 +424,13 @@ pub(super) fn explicit_predicates_of<'tcx>(
426424
.iter()
427425
.copied()
428426
.filter(|(pred, _)| match pred.kind().skip_binder() {
429-
ty::PredicateKind::Trait(tr) => !is_assoc_item_ty(tr.self_ty()),
430-
ty::PredicateKind::Projection(proj) => {
427+
ty::PredicateKind::Clause(ty::Clause::Trait(tr)) => !is_assoc_item_ty(tr.self_ty()),
428+
ty::PredicateKind::Clause(ty::Clause::Projection(proj)) => {
431429
!is_assoc_item_ty(proj.projection_ty.self_ty())
432430
}
433-
ty::PredicateKind::TypeOutlives(outlives) => !is_assoc_item_ty(outlives.0),
431+
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(outlives)) => {
432+
!is_assoc_item_ty(outlives.0)
433+
}
434434
_ => true,
435435
})
436436
.collect();
@@ -566,7 +566,9 @@ pub(super) fn super_predicates_that_define_assoc_type(
566566
// which will, in turn, reach indirect supertraits.
567567
for &(pred, span) in superbounds {
568568
debug!("superbound: {:?}", pred);
569-
if let ty::PredicateKind::Trait(bound) = pred.kind().skip_binder() {
569+
if let ty::PredicateKind::Clause(ty::Clause::Trait(bound)) =
570+
pred.kind().skip_binder()
571+
{
570572
tcx.at(span).super_predicates_of(bound.def_id());
571573
}
572574
}
@@ -666,7 +668,7 @@ pub(super) fn type_param_predicates(
666668
)
667669
.into_iter()
668670
.filter(|(predicate, _)| match predicate.kind().skip_binder() {
669-
ty::PredicateKind::Trait(data) => data.self_ty().is_param(index),
671+
ty::PredicateKind::Clause(ty::Clause::Trait(data)) => data.self_ty().is_param(index),
670672
_ => false,
671673
}),
672674
);

compiler/rustc_hir_analysis/src/constrained_generic_params.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ pub fn setup_constraining_predicates<'tcx>(
187187
for j in i..predicates.len() {
188188
// Note that we don't have to care about binders here,
189189
// as the impl trait ref never contains any late-bound regions.
190-
if let ty::PredicateKind::Projection(projection) = predicates[j].0.kind().skip_binder()
190+
if let ty::PredicateKind::Clause(ty::Clause::Projection(projection)) =
191+
predicates[j].0.kind().skip_binder()
191192
{
192193
// Special case: watch out for some kind of sneaky attempt
193194
// to project out an associated type defined by this very

0 commit comments

Comments
 (0)