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

View File

@ -2068,9 +2068,8 @@ pub fn print_only_trait_path(self) -> ty::Binder<TraitRefPrintOnlyTraitPath<'tcx
} }
ty::Predicate<'tcx> { ty::Predicate<'tcx> {
match self.kind() { let ty::PredicateKind::ForAll(binder) = self.kind();
ty::PredicateKind::ForAll(binder) => p!(print(binder)), p!(print(binder))
}
} }
ty::PredicateAtom<'tcx> { 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> { impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self { 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) folder.tcx().reuse_or_mk_predicate(self, new)
} }
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> { 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> { 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(); let infcx = self.selcx.infcx();
match *obligation.predicate.kind() { let ty::PredicateKind::ForAll(binder) = *obligation.predicate.kind();
ty::PredicateKind::ForAll(binder) if binder.skip_binder().has_escaping_bound_vars() => { if binder.skip_binder().has_escaping_bound_vars() {
match binder.skip_binder() { match binder.skip_binder() {
// Evaluation will discard candidates using the leak check. // Evaluation will discard candidates using the leak check.
// This means we need to pass it the bound version of our // This means we need to pass it the bound version of our
// predicate. // predicate.
ty::PredicateAtom::Trait(trait_ref, _constness) => { ty::PredicateAtom::Trait(trait_ref, _constness) => {
let trait_obligation = obligation.with(binder.rebind(trait_ref)); let trait_obligation = obligation.with(binder.rebind(trait_ref));
self.process_trait_obligation( self.process_trait_obligation(
obligation, obligation,
trait_obligation, trait_obligation,
&mut pending_obligation.stalled_on, &mut pending_obligation.stalled_on,
) )
} }
ty::PredicateAtom::Projection(data) => { ty::PredicateAtom::Projection(data) => {
let project_obligation = obligation.with(binder.rebind(data)); let project_obligation = obligation.with(binder.rebind(data));
self.process_projection_obligation( self.process_projection_obligation(
project_obligation, project_obligation,
&mut pending_obligation.stalled_on, &mut pending_obligation.stalled_on,
) )
} }
ty::PredicateAtom::RegionOutlives(_) ty::PredicateAtom::RegionOutlives(_)
| ty::PredicateAtom::TypeOutlives(_) | ty::PredicateAtom::TypeOutlives(_)
| ty::PredicateAtom::WellFormed(_) | ty::PredicateAtom::WellFormed(_)
| ty::PredicateAtom::ObjectSafe(_) | ty::PredicateAtom::ObjectSafe(_)
| ty::PredicateAtom::ClosureKind(..) | ty::PredicateAtom::ClosureKind(..)
| ty::PredicateAtom::Subtype(_) | ty::PredicateAtom::Subtype(_)
| ty::PredicateAtom::ConstEvaluatable(..) | ty::PredicateAtom::ConstEvaluatable(..)
| ty::PredicateAtom::ConstEquate(..) => { | ty::PredicateAtom::ConstEquate(..) => {
let pred = infcx.replace_bound_vars_with_placeholders(binder); let pred = infcx.replace_bound_vars_with_placeholders(binder);
ProcessResult::Changed(mk_pending(vec![ ProcessResult::Changed(mk_pending(vec![
obligation.with(pred.to_predicate(self.selcx.tcx())), obligation.with(pred.to_predicate(self.selcx.tcx())),
])) ]))
} }
ty::PredicateAtom::TypeWellFormedFromEnv(..) => { ty::PredicateAtom::TypeWellFormedFromEnv(..) => {
bug!("TypeWellFormedFromEnv is only used for Chalk") bug!("TypeWellFormedFromEnv is only used for Chalk")
}
} }
} }
ty::PredicateKind::ForAll(binder) => match binder.skip_binder() { } else {
match binder.skip_binder() {
ty::PredicateAtom::Trait(data, _) => { ty::PredicateAtom::Trait(data, _) => {
let trait_obligation = obligation.with(Binder::dummy(data)); let trait_obligation = obligation.with(Binder::dummy(data));
@ -598,7 +598,7 @@ fn progress_changed_obligations(
ty::PredicateAtom::TypeWellFormedFromEnv(..) => { ty::PredicateAtom::TypeWellFormedFromEnv(..) => {
bug!("TypeWellFormedFromEnv is only used for Chalk") bug!("TypeWellFormedFromEnv is only used for Chalk")
} }
}, }
} }
} }

View File

@ -94,13 +94,11 @@ fn compute_implied_outlives_bounds<'tcx>(
// region relationships. // region relationships.
implied_bounds.extend(obligations.into_iter().flat_map(|obligation| { implied_bounds.extend(obligations.into_iter().flat_map(|obligation| {
assert!(!obligation.has_escaping_bound_vars()); assert!(!obligation.has_escaping_bound_vars());
match obligation.predicate.kind() { let ty::PredicateKind::ForAll(binder) = obligation.predicate.kind();
&ty::PredicateKind::ForAll(binder) if binder.skip_binder().has_escaping_bound_vars() {
if binder.skip_binder().has_escaping_bound_vars() => vec![]
{ } else {
vec![] match binder.skip_binder() {
}
&ty::PredicateKind::ForAll(binder) => match binder.skip_binder() {
ty::PredicateAtom::Trait(..) ty::PredicateAtom::Trait(..)
| ty::PredicateAtom::Subtype(..) | ty::PredicateAtom::Subtype(..)
| ty::PredicateAtom::Projection(..) | ty::PredicateAtom::Projection(..)
@ -124,7 +122,7 @@ fn compute_implied_outlives_bounds<'tcx>(
tcx.push_outlives_components(ty_a, &mut components); tcx.push_outlives_components(ty_a, &mut components);
implied_bounds_from_components(r_b, 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) { if tcx.has_attr(item_def_id, sym::rustc_outlives) {
let mut pred: Vec<String> = predicates let mut pred: Vec<String> = predicates
.iter() .iter()
.map(|(out_pred, _)| match out_pred.kind() { .map(|(out_pred, _)| {
ty::PredicateKind::ForAll(binder) => match binder.skip_binder() { let ty::PredicateKind::ForAll(binder) = out_pred.kind();
match binder.skip_binder() {
ty::PredicateAtom::RegionOutlives(p) => p.to_string(), ty::PredicateAtom::RegionOutlives(p) => p.to_string(),
ty::PredicateAtom::TypeOutlives(p) => p.to_string(), ty::PredicateAtom::TypeOutlives(p) => p.to_string(),
err => bug!("unexpected predicate {:?}", err), err => bug!("unexpected predicate {:?}", err),
}, }
}) })
.collect(); .collect();
pred.sort(); pred.sort();