Intermediate formatting and such

This commit is contained in:
Jack Huey 2020-12-23 13:16:25 -05:00
parent 8278314a8b
commit 4cb3d6f983
7 changed files with 63 additions and 74 deletions

View File

@ -205,13 +205,8 @@ fn add_kind(&mut self, kind: &ty::TyKind<'_>) {
}
fn add_predicate_kind(&mut self, kind: ty::PredicateKind<'_>) {
match kind {
ty::PredicateKind::ForAll(binder) => {
self.bound_computation(binder, |computation, atom| {
computation.add_predicate_atom(atom)
});
}
}
let ty::PredicateKind::ForAll(binder) = kind;
self.bound_computation(binder, |computation, atom| computation.add_predicate_atom(atom));
}
fn add_predicate_atom(&mut self, atom: ty::PredicateAtom<'_>) {

View File

@ -1072,9 +1072,8 @@ pub fn kind(self) -> &'tcx PredicateKind<'tcx> {
///
/// Note that this method panics in case this predicate has unbound variables.
pub fn skip_binders(self) -> PredicateAtom<'tcx> {
match self.kind() {
&PredicateKind::ForAll(binder) => binder.skip_binder(),
}
let &PredicateKind::ForAll(binder) = self.kind();
binder.skip_binder()
}
/// Returns the inner `PredicateAtom`.
@ -1084,25 +1083,22 @@ pub fn skip_binders(self) -> PredicateAtom<'tcx> {
/// Rebinding the returned atom can causes the previously bound variables
/// to end up at the wrong binding level.
pub fn skip_binders_unchecked(self) -> PredicateAtom<'tcx> {
match self.kind() {
&PredicateKind::ForAll(binder) => binder.skip_binder(),
}
let &PredicateKind::ForAll(binder) = self.kind();
binder.skip_binder()
}
/// Converts this to a `Binder<PredicateAtom<'tcx>>`. If the value was an
/// `Atom`, then it is not allowed to contain escaping bound vars.
pub fn bound_atom(self) -> Binder<PredicateAtom<'tcx>> {
match self.kind() {
&PredicateKind::ForAll(binder) => binder,
}
let &PredicateKind::ForAll(binder) = self.kind();
binder
}
/// Allows using a `Binder<PredicateAtom<'tcx>>` even if the given predicate previously
/// contained unbound variables by shifting these variables outwards.
pub fn bound_atom_with_opt_escaping(self, _tcx: TyCtxt<'tcx>) -> Binder<PredicateAtom<'tcx>> {
match self.kind() {
&PredicateKind::ForAll(binder) => binder,
}
let &PredicateKind::ForAll(binder) = self.kind();
binder
}
}

View File

@ -2068,9 +2068,8 @@ pub fn print_only_trait_path(self) -> ty::Binder<TraitRefPrintOnlyTraitPath<'tcx
}
ty::Predicate<'tcx> {
match self.kind() {
ty::PredicateKind::ForAll(binder) => p!(print(binder)),
}
let ty::PredicateKind::ForAll(binder) = self.kind();
p!(print(binder))
}
ty::PredicateAtom<'tcx> {

View File

@ -1034,12 +1034,12 @@ fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::Br
impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
let new = ty::PredicateKind::super_fold_with(self.inner.kind, folder);
let new = self.inner.kind.super_fold_with(folder);
folder.tcx().reuse_or_mk_predicate(self, new)
}
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
ty::PredicateKind::super_visit_with(&self.inner.kind, visitor)
self.inner.kind.super_visit_with(visitor)
}
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {

View File

@ -345,48 +345,48 @@ fn progress_changed_obligations(
let infcx = self.selcx.infcx();
match *obligation.predicate.kind() {
ty::PredicateKind::ForAll(binder) if binder.skip_binder().has_escaping_bound_vars() => {
match binder.skip_binder() {
// Evaluation will discard candidates using the leak check.
// This means we need to pass it the bound version of our
// predicate.
ty::PredicateAtom::Trait(trait_ref, _constness) => {
let trait_obligation = obligation.with(binder.rebind(trait_ref));
let ty::PredicateKind::ForAll(binder) = *obligation.predicate.kind();
if binder.skip_binder().has_escaping_bound_vars() {
match binder.skip_binder() {
// Evaluation will discard candidates using the leak check.
// This means we need to pass it the bound version of our
// predicate.
ty::PredicateAtom::Trait(trait_ref, _constness) => {
let trait_obligation = obligation.with(binder.rebind(trait_ref));
self.process_trait_obligation(
obligation,
trait_obligation,
&mut pending_obligation.stalled_on,
)
}
ty::PredicateAtom::Projection(data) => {
let project_obligation = obligation.with(binder.rebind(data));
self.process_trait_obligation(
obligation,
trait_obligation,
&mut pending_obligation.stalled_on,
)
}
ty::PredicateAtom::Projection(data) => {
let project_obligation = obligation.with(binder.rebind(data));
self.process_projection_obligation(
project_obligation,
&mut pending_obligation.stalled_on,
)
}
ty::PredicateAtom::RegionOutlives(_)
| ty::PredicateAtom::TypeOutlives(_)
| ty::PredicateAtom::WellFormed(_)
| ty::PredicateAtom::ObjectSafe(_)
| ty::PredicateAtom::ClosureKind(..)
| ty::PredicateAtom::Subtype(_)
| ty::PredicateAtom::ConstEvaluatable(..)
| ty::PredicateAtom::ConstEquate(..) => {
let pred = infcx.replace_bound_vars_with_placeholders(binder);
ProcessResult::Changed(mk_pending(vec![
obligation.with(pred.to_predicate(self.selcx.tcx())),
]))
}
ty::PredicateAtom::TypeWellFormedFromEnv(..) => {
bug!("TypeWellFormedFromEnv is only used for Chalk")
}
self.process_projection_obligation(
project_obligation,
&mut pending_obligation.stalled_on,
)
}
ty::PredicateAtom::RegionOutlives(_)
| ty::PredicateAtom::TypeOutlives(_)
| ty::PredicateAtom::WellFormed(_)
| ty::PredicateAtom::ObjectSafe(_)
| ty::PredicateAtom::ClosureKind(..)
| ty::PredicateAtom::Subtype(_)
| ty::PredicateAtom::ConstEvaluatable(..)
| ty::PredicateAtom::ConstEquate(..) => {
let pred = infcx.replace_bound_vars_with_placeholders(binder);
ProcessResult::Changed(mk_pending(vec![
obligation.with(pred.to_predicate(self.selcx.tcx())),
]))
}
ty::PredicateAtom::TypeWellFormedFromEnv(..) => {
bug!("TypeWellFormedFromEnv is only used for Chalk")
}
}
ty::PredicateKind::ForAll(binder) => match binder.skip_binder() {
} else {
match binder.skip_binder() {
ty::PredicateAtom::Trait(data, _) => {
let trait_obligation = obligation.with(Binder::dummy(data));
@ -598,7 +598,7 @@ fn progress_changed_obligations(
ty::PredicateAtom::TypeWellFormedFromEnv(..) => {
bug!("TypeWellFormedFromEnv is only used for Chalk")
}
},
}
}
}

View File

@ -94,13 +94,11 @@ fn compute_implied_outlives_bounds<'tcx>(
// region relationships.
implied_bounds.extend(obligations.into_iter().flat_map(|obligation| {
assert!(!obligation.has_escaping_bound_vars());
match obligation.predicate.kind() {
&ty::PredicateKind::ForAll(binder)
if binder.skip_binder().has_escaping_bound_vars() =>
{
vec![]
}
&ty::PredicateKind::ForAll(binder) => match binder.skip_binder() {
let ty::PredicateKind::ForAll(binder) = obligation.predicate.kind();
if binder.skip_binder().has_escaping_bound_vars() {
vec![]
} else {
match binder.skip_binder() {
ty::PredicateAtom::Trait(..)
| ty::PredicateAtom::Subtype(..)
| ty::PredicateAtom::Projection(..)
@ -124,7 +122,7 @@ fn compute_implied_outlives_bounds<'tcx>(
tcx.push_outlives_components(ty_a, &mut components);
implied_bounds_from_components(r_b, components)
}
},
}
}
}));
}

View File

@ -30,12 +30,13 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate
if tcx.has_attr(item_def_id, sym::rustc_outlives) {
let mut pred: Vec<String> = predicates
.iter()
.map(|(out_pred, _)| match out_pred.kind() {
ty::PredicateKind::ForAll(binder) => match binder.skip_binder() {
.map(|(out_pred, _)| {
let ty::PredicateKind::ForAll(binder) = out_pred.kind();
match binder.skip_binder() {
ty::PredicateAtom::RegionOutlives(p) => p.to_string(),
ty::PredicateAtom::TypeOutlives(p) => p.to_string(),
err => bug!("unexpected predicate {:?}", err),
},
}
})
.collect();
pred.sort();