Skip to content

Commit 4cb3d6f

Browse files
committed
Intermediate formatting and such
1 parent 8278314 commit 4cb3d6f

File tree

7 files changed

+64
-75
lines changed

7 files changed

+64
-75
lines changed

compiler/rustc_middle/src/ty/flags.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,8 @@ impl FlagComputation {
205205
}
206206

207207
fn add_predicate_kind(&mut self, kind: ty::PredicateKind<'_>) {
208-
match kind {
209-
ty::PredicateKind::ForAll(binder) => {
210-
self.bound_computation(binder, |computation, atom| {
211-
computation.add_predicate_atom(atom)
212-
});
213-
}
214-
}
208+
let ty::PredicateKind::ForAll(binder) = kind;
209+
self.bound_computation(binder, |computation, atom| computation.add_predicate_atom(atom));
215210
}
216211

217212
fn add_predicate_atom(&mut self, atom: ty::PredicateAtom<'_>) {

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,9 +1072,8 @@ impl<'tcx> Predicate<'tcx> {
10721072
///
10731073
/// Note that this method panics in case this predicate has unbound variables.
10741074
pub fn skip_binders(self) -> PredicateAtom<'tcx> {
1075-
match self.kind() {
1076-
&PredicateKind::ForAll(binder) => binder.skip_binder(),
1077-
}
1075+
let &PredicateKind::ForAll(binder) = self.kind();
1076+
binder.skip_binder()
10781077
}
10791078

10801079
/// Returns the inner `PredicateAtom`.
@@ -1084,25 +1083,22 @@ impl<'tcx> Predicate<'tcx> {
10841083
/// Rebinding the returned atom can causes the previously bound variables
10851084
/// to end up at the wrong binding level.
10861085
pub fn skip_binders_unchecked(self) -> PredicateAtom<'tcx> {
1087-
match self.kind() {
1088-
&PredicateKind::ForAll(binder) => binder.skip_binder(),
1089-
}
1086+
let &PredicateKind::ForAll(binder) = self.kind();
1087+
binder.skip_binder()
10901088
}
10911089

10921090
/// Converts this to a `Binder<PredicateAtom<'tcx>>`. If the value was an
10931091
/// `Atom`, then it is not allowed to contain escaping bound vars.
10941092
pub fn bound_atom(self) -> Binder<PredicateAtom<'tcx>> {
1095-
match self.kind() {
1096-
&PredicateKind::ForAll(binder) => binder,
1097-
}
1093+
let &PredicateKind::ForAll(binder) = self.kind();
1094+
binder
10981095
}
10991096

11001097
/// Allows using a `Binder<PredicateAtom<'tcx>>` even if the given predicate previously
11011098
/// contained unbound variables by shifting these variables outwards.
11021099
pub fn bound_atom_with_opt_escaping(self, _tcx: TyCtxt<'tcx>) -> Binder<PredicateAtom<'tcx>> {
1103-
match self.kind() {
1104-
&PredicateKind::ForAll(binder) => binder,
1105-
}
1100+
let &PredicateKind::ForAll(binder) = self.kind();
1101+
binder
11061102
}
11071103
}
11081104

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,9 +2068,8 @@ define_print_and_forward_display! {
20682068
}
20692069

20702070
ty::Predicate<'tcx> {
2071-
match self.kind() {
2072-
ty::PredicateKind::ForAll(binder) => p!(print(binder)),
2073-
}
2071+
let ty::PredicateKind::ForAll(binder) = self.kind();
2072+
p!(print(binder))
20742073
}
20752074

20762075
ty::PredicateAtom<'tcx> {

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,12 +1034,12 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> {
10341034

10351035
impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
10361036
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
1037-
let new = ty::PredicateKind::super_fold_with(self.inner.kind, folder);
1037+
let new = self.inner.kind.super_fold_with(folder);
10381038
folder.tcx().reuse_or_mk_predicate(self, new)
10391039
}
10401040

10411041
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
1042-
ty::PredicateKind::super_visit_with(&self.inner.kind, visitor)
1042+
self.inner.kind.super_visit_with(visitor)
10431043
}
10441044

10451045
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {

compiler/rustc_trait_selection/src/traits/fulfill.rs

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -345,48 +345,48 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
345345

346346
let infcx = self.selcx.infcx();
347347

348-
match *obligation.predicate.kind() {
349-
ty::PredicateKind::ForAll(binder) if binder.skip_binder().has_escaping_bound_vars() => {
350-
match binder.skip_binder() {
351-
// Evaluation will discard candidates using the leak check.
352-
// This means we need to pass it the bound version of our
353-
// predicate.
354-
ty::PredicateAtom::Trait(trait_ref, _constness) => {
355-
let trait_obligation = obligation.with(binder.rebind(trait_ref));
356-
357-
self.process_trait_obligation(
358-
obligation,
359-
trait_obligation,
360-
&mut pending_obligation.stalled_on,
361-
)
362-
}
363-
ty::PredicateAtom::Projection(data) => {
364-
let project_obligation = obligation.with(binder.rebind(data));
348+
let ty::PredicateKind::ForAll(binder) = *obligation.predicate.kind();
349+
if binder.skip_binder().has_escaping_bound_vars() {
350+
match binder.skip_binder() {
351+
// Evaluation will discard candidates using the leak check.
352+
// This means we need to pass it the bound version of our
353+
// predicate.
354+
ty::PredicateAtom::Trait(trait_ref, _constness) => {
355+
let trait_obligation = obligation.with(binder.rebind(trait_ref));
365356

366-
self.process_projection_obligation(
367-
project_obligation,
368-
&mut pending_obligation.stalled_on,
369-
)
370-
}
371-
ty::PredicateAtom::RegionOutlives(_)
372-
| ty::PredicateAtom::TypeOutlives(_)
373-
| ty::PredicateAtom::WellFormed(_)
374-
| ty::PredicateAtom::ObjectSafe(_)
375-
| ty::PredicateAtom::ClosureKind(..)
376-
| ty::PredicateAtom::Subtype(_)
377-
| ty::PredicateAtom::ConstEvaluatable(..)
378-
| ty::PredicateAtom::ConstEquate(..) => {
379-
let pred = infcx.replace_bound_vars_with_placeholders(binder);
380-
ProcessResult::Changed(mk_pending(vec![
381-
obligation.with(pred.to_predicate(self.selcx.tcx())),
382-
]))
383-
}
384-
ty::PredicateAtom::TypeWellFormedFromEnv(..) => {
385-
bug!("TypeWellFormedFromEnv is only used for Chalk")
386-
}
357+
self.process_trait_obligation(
358+
obligation,
359+
trait_obligation,
360+
&mut pending_obligation.stalled_on,
361+
)
362+
}
363+
ty::PredicateAtom::Projection(data) => {
364+
let project_obligation = obligation.with(binder.rebind(data));
365+
366+
self.process_projection_obligation(
367+
project_obligation,
368+
&mut pending_obligation.stalled_on,
369+
)
370+
}
371+
ty::PredicateAtom::RegionOutlives(_)
372+
| ty::PredicateAtom::TypeOutlives(_)
373+
| ty::PredicateAtom::WellFormed(_)
374+
| ty::PredicateAtom::ObjectSafe(_)
375+
| ty::PredicateAtom::ClosureKind(..)
376+
| ty::PredicateAtom::Subtype(_)
377+
| ty::PredicateAtom::ConstEvaluatable(..)
378+
| ty::PredicateAtom::ConstEquate(..) => {
379+
let pred = infcx.replace_bound_vars_with_placeholders(binder);
380+
ProcessResult::Changed(mk_pending(vec![
381+
obligation.with(pred.to_predicate(self.selcx.tcx())),
382+
]))
383+
}
384+
ty::PredicateAtom::TypeWellFormedFromEnv(..) => {
385+
bug!("TypeWellFormedFromEnv is only used for Chalk")
387386
}
388387
}
389-
ty::PredicateKind::ForAll(binder) => match binder.skip_binder() {
388+
} else {
389+
match binder.skip_binder() {
390390
ty::PredicateAtom::Trait(data, _) => {
391391
let trait_obligation = obligation.with(Binder::dummy(data));
392392

@@ -598,7 +598,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
598598
ty::PredicateAtom::TypeWellFormedFromEnv(..) => {
599599
bug!("TypeWellFormedFromEnv is only used for Chalk")
600600
}
601-
},
601+
}
602602
}
603603
}
604604

compiler/rustc_traits/src/implied_outlives_bounds.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,11 @@ fn compute_implied_outlives_bounds<'tcx>(
9494
// region relationships.
9595
implied_bounds.extend(obligations.into_iter().flat_map(|obligation| {
9696
assert!(!obligation.has_escaping_bound_vars());
97-
match obligation.predicate.kind() {
98-
&ty::PredicateKind::ForAll(binder)
99-
if binder.skip_binder().has_escaping_bound_vars() =>
100-
{
101-
vec![]
102-
}
103-
&ty::PredicateKind::ForAll(binder) => match binder.skip_binder() {
97+
let ty::PredicateKind::ForAll(binder) = obligation.predicate.kind();
98+
if binder.skip_binder().has_escaping_bound_vars() {
99+
vec![]
100+
} else {
101+
match binder.skip_binder() {
104102
ty::PredicateAtom::Trait(..)
105103
| ty::PredicateAtom::Subtype(..)
106104
| ty::PredicateAtom::Projection(..)
@@ -124,7 +122,7 @@ fn compute_implied_outlives_bounds<'tcx>(
124122
tcx.push_outlives_components(ty_a, &mut components);
125123
implied_bounds_from_components(r_b, components)
126124
}
127-
},
125+
}
128126
}
129127
}));
130128
}

compiler/rustc_typeck/src/outlives/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate
3030
if tcx.has_attr(item_def_id, sym::rustc_outlives) {
3131
let mut pred: Vec<String> = predicates
3232
.iter()
33-
.map(|(out_pred, _)| match out_pred.kind() {
34-
ty::PredicateKind::ForAll(binder) => match binder.skip_binder() {
33+
.map(|(out_pred, _)| {
34+
let ty::PredicateKind::ForAll(binder) = out_pred.kind();
35+
match binder.skip_binder() {
3536
ty::PredicateAtom::RegionOutlives(p) => p.to_string(),
3637
ty::PredicateAtom::TypeOutlives(p) => p.to_string(),
3738
err => bug!("unexpected predicate {:?}", err),
38-
},
39+
}
3940
})
4041
.collect();
4142
pred.sort();

0 commit comments

Comments
 (0)