Skip to content

Commit 6544d7b

Browse files
committed
change Predicate::kind to return a reference
1 parent 57746f9 commit 6544d7b

File tree

13 files changed

+66
-67
lines changed

13 files changed

+66
-67
lines changed

src/librustc_infer/traits/util.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,42 @@ pub fn anonymize_predicate<'tcx>(
1111
pred: &ty::Predicate<'tcx>,
1212
) -> ty::Predicate<'tcx> {
1313
match pred.kind() {
14-
ty::PredicateKind::Trait(ref data, constness) => {
14+
&ty::PredicateKind::Trait(ref data, constness) => {
1515
ty::PredicateKind::Trait(tcx.anonymize_late_bound_regions(data), constness)
1616
.to_predicate(tcx)
1717
}
1818

19-
ty::PredicateKind::RegionOutlives(ref data) => {
19+
ty::PredicateKind::RegionOutlives(data) => {
2020
ty::PredicateKind::RegionOutlives(tcx.anonymize_late_bound_regions(data))
2121
.to_predicate(tcx)
2222
}
2323

24-
ty::PredicateKind::TypeOutlives(ref data) => {
24+
ty::PredicateKind::TypeOutlives(data) => {
2525
ty::PredicateKind::TypeOutlives(tcx.anonymize_late_bound_regions(data))
2626
.to_predicate(tcx)
2727
}
2828

29-
ty::PredicateKind::Projection(ref data) => {
29+
ty::PredicateKind::Projection(data) => {
3030
ty::PredicateKind::Projection(tcx.anonymize_late_bound_regions(data)).to_predicate(tcx)
3131
}
3232

33-
ty::PredicateKind::WellFormed(data) => {
33+
&ty::PredicateKind::WellFormed(data) => {
3434
ty::PredicateKind::WellFormed(data).to_predicate(tcx)
3535
}
3636

37-
ty::PredicateKind::ObjectSafe(data) => {
37+
&ty::PredicateKind::ObjectSafe(data) => {
3838
ty::PredicateKind::ObjectSafe(data).to_predicate(tcx)
3939
}
4040

41-
ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
41+
&ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
4242
ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind).to_predicate(tcx)
4343
}
4444

45-
ty::PredicateKind::Subtype(ref data) => {
45+
ty::PredicateKind::Subtype(data) => {
4646
ty::PredicateKind::Subtype(tcx.anonymize_late_bound_regions(data)).to_predicate(tcx)
4747
}
4848

49-
ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
49+
&ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
5050
ty::PredicateKind::ConstEvaluatable(def_id, substs).to_predicate(tcx)
5151
}
5252

src/librustc_middle/ty/mod.rs

+17-16
Original file line numberDiff line numberDiff line change
@@ -1023,8 +1023,8 @@ pub struct Predicate<'tcx> {
10231023
}
10241024

10251025
impl Predicate<'tcx> {
1026-
pub fn kind(&self) -> PredicateKind<'tcx> {
1027-
*self.kind
1026+
pub fn kind(&self) -> &'tcx PredicateKind<'tcx> {
1027+
self.kind
10281028
}
10291029
}
10301030

@@ -1163,35 +1163,36 @@ impl<'tcx> Predicate<'tcx> {
11631163
// this trick achieves that).
11641164

11651165
let substs = &trait_ref.skip_binder().substs;
1166-
match self.kind() {
1167-
PredicateKind::Trait(ref binder, constness) => {
1166+
let predicate = match self.kind() {
1167+
&PredicateKind::Trait(ref binder, constness) => {
11681168
PredicateKind::Trait(binder.map_bound(|data| data.subst(tcx, substs)), constness)
11691169
}
1170-
PredicateKind::Subtype(ref binder) => {
1170+
PredicateKind::Subtype(binder) => {
11711171
PredicateKind::Subtype(binder.map_bound(|data| data.subst(tcx, substs)))
11721172
}
1173-
PredicateKind::RegionOutlives(ref binder) => {
1173+
PredicateKind::RegionOutlives(binder) => {
11741174
PredicateKind::RegionOutlives(binder.map_bound(|data| data.subst(tcx, substs)))
11751175
}
1176-
PredicateKind::TypeOutlives(ref binder) => {
1176+
PredicateKind::TypeOutlives(binder) => {
11771177
PredicateKind::TypeOutlives(binder.map_bound(|data| data.subst(tcx, substs)))
11781178
}
1179-
PredicateKind::Projection(ref binder) => {
1179+
PredicateKind::Projection(binder) => {
11801180
PredicateKind::Projection(binder.map_bound(|data| data.subst(tcx, substs)))
11811181
}
1182-
PredicateKind::WellFormed(data) => PredicateKind::WellFormed(data.subst(tcx, substs)),
1183-
PredicateKind::ObjectSafe(trait_def_id) => PredicateKind::ObjectSafe(trait_def_id),
1184-
PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
1182+
&PredicateKind::WellFormed(data) => PredicateKind::WellFormed(data.subst(tcx, substs)),
1183+
&PredicateKind::ObjectSafe(trait_def_id) => PredicateKind::ObjectSafe(trait_def_id),
1184+
&PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
11851185
PredicateKind::ClosureKind(closure_def_id, closure_substs.subst(tcx, substs), kind)
11861186
}
1187-
PredicateKind::ConstEvaluatable(def_id, const_substs) => {
1187+
&PredicateKind::ConstEvaluatable(def_id, const_substs) => {
11881188
PredicateKind::ConstEvaluatable(def_id, const_substs.subst(tcx, substs))
11891189
}
11901190
PredicateKind::ConstEquate(c1, c2) => {
11911191
PredicateKind::ConstEquate(c1.subst(tcx, substs), c2.subst(tcx, substs))
11921192
}
1193-
}
1194-
.to_predicate(tcx)
1193+
};
1194+
1195+
predicate.to_predicate(tcx)
11951196
}
11961197
}
11971198

@@ -1370,7 +1371,7 @@ impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> {
13701371
impl<'tcx> Predicate<'tcx> {
13711372
pub fn to_opt_poly_trait_ref(&self) -> Option<PolyTraitRef<'tcx>> {
13721373
match self.kind() {
1373-
PredicateKind::Trait(ref t, _) => Some(t.to_poly_trait_ref()),
1374+
&PredicateKind::Trait(ref t, _) => Some(t.to_poly_trait_ref()),
13741375
PredicateKind::Projection(..)
13751376
| PredicateKind::Subtype(..)
13761377
| PredicateKind::RegionOutlives(..)
@@ -1385,7 +1386,7 @@ impl<'tcx> Predicate<'tcx> {
13851386

13861387
pub fn to_opt_type_outlives(&self) -> Option<PolyTypeOutlivesPredicate<'tcx>> {
13871388
match self.kind() {
1388-
PredicateKind::TypeOutlives(data) => Some(data),
1389+
&PredicateKind::TypeOutlives(data) => Some(data),
13891390
PredicateKind::Trait(..)
13901391
| PredicateKind::Projection(..)
13911392
| PredicateKind::Subtype(..)

src/librustc_middle/ty/print/pretty.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -2032,28 +2032,28 @@ define_print_and_forward_display! {
20322032

20332033
ty::Predicate<'tcx> {
20342034
match self.kind() {
2035-
ty::PredicateKind::Trait(ref data, constness) => {
2035+
&ty::PredicateKind::Trait(ref data, constness) => {
20362036
if let hir::Constness::Const = constness {
20372037
p!(write("const "));
20382038
}
20392039
p!(print(data))
20402040
}
2041-
ty::PredicateKind::Subtype(ref predicate) => p!(print(predicate)),
2042-
ty::PredicateKind::RegionOutlives(ref predicate) => p!(print(predicate)),
2043-
ty::PredicateKind::TypeOutlives(ref predicate) => p!(print(predicate)),
2044-
ty::PredicateKind::Projection(ref predicate) => p!(print(predicate)),
2041+
ty::PredicateKind::Subtype(predicate) => p!(print(predicate)),
2042+
ty::PredicateKind::RegionOutlives(predicate) => p!(print(predicate)),
2043+
ty::PredicateKind::TypeOutlives(predicate) => p!(print(predicate)),
2044+
ty::PredicateKind::Projection(predicate) => p!(print(predicate)),
20452045
ty::PredicateKind::WellFormed(ty) => p!(print(ty), write(" well-formed")),
2046-
ty::PredicateKind::ObjectSafe(trait_def_id) => {
2046+
&ty::PredicateKind::ObjectSafe(trait_def_id) => {
20472047
p!(write("the trait `"),
20482048
print_def_path(trait_def_id, &[]),
20492049
write("` is object-safe"))
20502050
}
2051-
ty::PredicateKind::ClosureKind(closure_def_id, _closure_substs, kind) => {
2051+
&ty::PredicateKind::ClosureKind(closure_def_id, _closure_substs, kind) => {
20522052
p!(write("the closure `"),
20532053
print_value_path(closure_def_id, &[]),
20542054
write("` implements the trait `{}`", kind))
20552055
}
2056-
ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
2056+
&ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
20572057
p!(write("the constant `"),
20582058
print_value_path(def_id, substs),
20592059
write("` can be evaluated"))

src/librustc_mir/transform/qualify_min_const_fn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) -
3939
ty::PredicateKind::Subtype(_) => {
4040
bug!("subtype predicate on function: {:#?}", predicate)
4141
}
42-
ty::PredicateKind::Trait(pred, constness) => {
42+
&ty::PredicateKind::Trait(pred, constness) => {
4343
if Some(pred.def_id()) == tcx.lang_items().sized_trait() {
4444
continue;
4545
}

src/librustc_trait_selection/traits/auto_trait.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ impl AutoTraitFinder<'tcx> {
634634
// We check this by calling is_of_param on the relevant types
635635
// from the various possible predicates
636636
match predicate.kind() {
637-
ty::PredicateKind::Trait(p, _) => {
637+
&ty::PredicateKind::Trait(p, _) => {
638638
if self.is_param_no_infer(p.skip_binder().trait_ref.substs)
639639
&& !only_projections
640640
&& is_new_pred
@@ -643,7 +643,7 @@ impl AutoTraitFinder<'tcx> {
643643
}
644644
predicates.push_back(p);
645645
}
646-
ty::PredicateKind::Projection(p) => {
646+
&ty::PredicateKind::Projection(p) => {
647647
debug!(
648648
"evaluate_nested_obligations: examining projection predicate {:?}",
649649
predicate

src/librustc_trait_selection/traits/error_reporting/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -524,12 +524,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
524524
)
525525
}
526526

527-
ty::PredicateKind::ObjectSafe(trait_def_id) => {
527+
&ty::PredicateKind::ObjectSafe(trait_def_id) => {
528528
let violations = self.tcx.object_safety_violations(trait_def_id);
529529
report_object_safety_error(self.tcx, span, trait_def_id, violations)
530530
}
531531

532-
ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
532+
&ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
533533
let found_kind = self.closure_kind(closure_substs).unwrap();
534534
let closure_span =
535535
self.tcx.sess.source_map().guess_head_span(

src/librustc_trait_selection/traits/fulfill.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -443,15 +443,15 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
443443
}
444444
}
445445

446-
ty::PredicateKind::ObjectSafe(trait_def_id) => {
446+
&ty::PredicateKind::ObjectSafe(trait_def_id) => {
447447
if !self.selcx.tcx().is_object_safe(trait_def_id) {
448448
ProcessResult::Error(CodeSelectionError(Unimplemented))
449449
} else {
450450
ProcessResult::Changed(vec![])
451451
}
452452
}
453453

454-
ty::PredicateKind::ClosureKind(_, closure_substs, kind) => {
454+
&ty::PredicateKind::ClosureKind(_, closure_substs, kind) => {
455455
match self.selcx.infcx().closure_kind(closure_substs) {
456456
Some(closure_kind) => {
457457
if closure_kind.extends(kind) {
@@ -464,7 +464,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
464464
}
465465
}
466466

467-
ty::PredicateKind::WellFormed(ty) => {
467+
&ty::PredicateKind::WellFormed(ty) => {
468468
match wf::obligations(
469469
self.selcx.infcx(),
470470
obligation.param_env,
@@ -481,7 +481,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
481481
}
482482
}
483483

484-
ty::PredicateKind::Subtype(ref subtype) => {
484+
ty::PredicateKind::Subtype(subtype) => {
485485
match self.selcx.infcx().subtype_predicate(
486486
&obligation.cause,
487487
obligation.param_env,
@@ -510,7 +510,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
510510
}
511511
}
512512

513-
ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
513+
&ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
514514
match self.selcx.infcx().const_eval_resolve(
515515
obligation.param_env,
516516
def_id,

src/librustc_trait_selection/traits/project.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>(
930930
let infcx = selcx.infcx();
931931
for predicate in env_predicates {
932932
debug!("assemble_candidates_from_predicates: predicate={:?}", predicate);
933-
if let ty::PredicateKind::Projection(data) = predicate.kind() {
933+
if let &ty::PredicateKind::Projection(data) = predicate.kind() {
934934
let same_def_id = data.projection_def_id() == obligation.predicate.item_def_id;
935935

936936
let is_match = same_def_id
@@ -1167,12 +1167,10 @@ fn confirm_object_candidate<'cx, 'tcx>(
11671167
// select only those projections that are actually projecting an
11681168
// item with the correct name
11691169
let env_predicates = env_predicates.filter_map(|o| match o.predicate.kind() {
1170-
ty::PredicateKind::Projection(data) => {
1171-
if data.projection_def_id() == obligation.predicate.item_def_id {
1172-
Some(data)
1173-
} else {
1174-
None
1175-
}
1170+
&ty::PredicateKind::Projection(data)
1171+
if data.projection_def_id() == obligation.predicate.item_def_id =>
1172+
{
1173+
Some(data)
11761174
}
11771175
_ => None,
11781176
});

src/librustc_trait_selection/traits/select.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -414,13 +414,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
414414
}
415415

416416
match obligation.predicate.kind() {
417-
ty::PredicateKind::Trait(ref t, _) => {
417+
ty::PredicateKind::Trait(t, _) => {
418418
debug_assert!(!t.has_escaping_bound_vars());
419419
let obligation = obligation.with(*t);
420420
self.evaluate_trait_predicate_recursively(previous_stack, obligation)
421421
}
422422

423-
ty::PredicateKind::Subtype(ref p) => {
423+
ty::PredicateKind::Subtype(p) => {
424424
// Does this code ever run?
425425
match self.infcx.subtype_predicate(&obligation.cause, obligation.param_env, p) {
426426
Some(Ok(InferOk { mut obligations, .. })) => {
@@ -435,7 +435,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
435435
}
436436
}
437437

438-
ty::PredicateKind::WellFormed(ty) => match wf::obligations(
438+
&ty::PredicateKind::WellFormed(ty) => match wf::obligations(
439439
self.infcx,
440440
obligation.param_env,
441441
obligation.cause.body_id,
@@ -454,15 +454,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
454454
Ok(EvaluatedToOkModuloRegions)
455455
}
456456

457-
ty::PredicateKind::ObjectSafe(trait_def_id) => {
457+
&ty::PredicateKind::ObjectSafe(trait_def_id) => {
458458
if self.tcx().is_object_safe(trait_def_id) {
459459
Ok(EvaluatedToOk)
460460
} else {
461461
Ok(EvaluatedToErr)
462462
}
463463
}
464464

465-
ty::PredicateKind::Projection(ref data) => {
465+
ty::PredicateKind::Projection(data) => {
466466
let project_obligation = obligation.with(*data);
467467
match project::poly_project_and_unify_type(self, &project_obligation) {
468468
Ok(Some(mut subobligations)) => {
@@ -483,7 +483,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
483483
}
484484
}
485485

486-
ty::PredicateKind::ClosureKind(_, closure_substs, kind) => {
486+
&ty::PredicateKind::ClosureKind(_, closure_substs, kind) => {
487487
match self.infcx.closure_kind(closure_substs) {
488488
Some(closure_kind) => {
489489
if closure_kind.extends(kind) {
@@ -496,7 +496,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
496496
}
497497
}
498498

499-
ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
499+
&ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
500500
match self.tcx().const_eval_resolve(
501501
obligation.param_env,
502502
def_id,

src/librustc_trait_selection/traits/wf.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -73,28 +73,28 @@ pub fn predicate_obligations<'a, 'tcx>(
7373

7474
// (*) ok to skip binders, because wf code is prepared for it
7575
match predicate.kind() {
76-
ty::PredicateKind::Trait(ref t, _) => {
76+
ty::PredicateKind::Trait(t, _) => {
7777
wf.compute_trait_ref(&t.skip_binder().trait_ref, Elaborate::None); // (*)
7878
}
7979
ty::PredicateKind::RegionOutlives(..) => {}
80-
ty::PredicateKind::TypeOutlives(ref t) => {
80+
ty::PredicateKind::TypeOutlives(t) => {
8181
wf.compute(t.skip_binder().0);
8282
}
83-
ty::PredicateKind::Projection(ref t) => {
83+
ty::PredicateKind::Projection(t) => {
8484
let t = t.skip_binder(); // (*)
8585
wf.compute_projection(t.projection_ty);
8686
wf.compute(t.ty);
8787
}
88-
ty::PredicateKind::WellFormed(t) => {
88+
&ty::PredicateKind::WellFormed(t) => {
8989
wf.compute(t);
9090
}
9191
ty::PredicateKind::ObjectSafe(_) => {}
9292
ty::PredicateKind::ClosureKind(..) => {}
93-
ty::PredicateKind::Subtype(ref data) => {
93+
ty::PredicateKind::Subtype(data) => {
9494
wf.compute(data.skip_binder().a); // (*)
9595
wf.compute(data.skip_binder().b); // (*)
9696
}
97-
ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
97+
&ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
9898
let obligations = wf.nominal_obligations(def_id, substs);
9999
wf.out.extend(obligations);
100100

src/librustc_typeck/astconv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
16051605
.map(|item| item.def_id),
16061606
);
16071607
}
1608-
ty::PredicateKind::Projection(pred) => {
1608+
&ty::PredicateKind::Projection(pred) => {
16091609
// A `Self` within the original bound will be substituted with a
16101610
// `trait_object_dummy_self`, so check for that.
16111611
let references_self =

src/librustc_typeck/check/coercion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
597597
let obligation = queue.remove(0);
598598
debug!("coerce_unsized resolve step: {:?}", obligation);
599599
let trait_pred = match obligation.predicate.kind() {
600-
ty::PredicateKind::Trait(trait_pred, _)
600+
&ty::PredicateKind::Trait(trait_pred, _)
601601
if traits.contains(&trait_pred.def_id()) =>
602602
{
603603
if unsize_did == trait_pred.def_id() {

0 commit comments

Comments
 (0)