Review comments

This commit is contained in:
Jack Huey 2020-10-16 15:14:38 -04:00
parent eba10270c6
commit f6a53b4c69
15 changed files with 34 additions and 31 deletions

View File

@ -126,7 +126,7 @@ impl Elaborator<'tcx> {
fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) {
let tcx = self.visited.tcx;
let bound_predicate = obligation.predicate.bound_atom(tcx);
let bound_predicate = obligation.predicate.bound_atom();
match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(data, _) => {
// Get predicates declared on the trait.

View File

@ -1058,11 +1058,11 @@ impl<'tcx> Predicate<'tcx> {
/// 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, _tcx: TyCtxt<'tcx>) -> Binder<PredicateAtom<'tcx>> {
pub fn bound_atom(self) -> Binder<PredicateAtom<'tcx>> {
match self.kind() {
&PredicateKind::ForAll(binder) => binder,
&PredicateKind::Atom(atom) => {
assert!(!atom.has_escaping_bound_vars());
debug_assert!(!atom.has_escaping_bound_vars());
Binder::dummy(atom)
}
}

View File

@ -1006,6 +1006,11 @@ impl<T> Binder<T> {
/// current `Binder`. This should not be used if the new value *changes*
/// the bound variables. Note: the (old or new) value itself does not
/// necessarily need to *name* all the bound variables.
///
/// This currently doesn't do anything different than `bind`, because we
/// don't actually track bound vars. However, semantically, it is different
/// because bound vars aren't allowed to change here, whereas they are
/// in `bind`. This may be (debug) asserted in the future.
pub fn rebind<U>(&self, value: U) -> Binder<U> {
Binder(value)
}

View File

@ -642,7 +642,7 @@ impl AutoTraitFinder<'tcx> {
// We check this by calling is_of_param on the relevant types
// from the various possible predicates
let bound_predicate = predicate.bound_atom(select.infcx().tcx);
let bound_predicate = predicate.bound_atom();
match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(p, _) => {
if self.is_param_no_infer(p.trait_ref.substs)

View File

@ -255,7 +255,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
return;
}
let bound_predicate = obligation.predicate.bound_atom(self.tcx);
let bound_predicate = obligation.predicate.bound_atom();
match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(trait_predicate, _) => {
let trait_predicate = bound_predicate.rebind(trait_predicate);
@ -1079,7 +1079,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
}
// FIXME: It should be possible to deal with `ForAll` in a cleaner way.
let bound_error = error.bound_atom(self.tcx);
let bound_error = error.bound_atom();
let (cond, error) = match (cond.skip_binders(), bound_error.skip_binder()) {
(ty::PredicateAtom::Trait(..), ty::PredicateAtom::Trait(error, _)) => {
(cond, bound_error.rebind(error))
@ -1091,7 +1091,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
};
for obligation in super::elaborate_predicates(self.tcx, std::iter::once(cond)) {
let bound_predicate = obligation.predicate.bound_atom(self.tcx);
let bound_predicate = obligation.predicate.bound_atom();
if let ty::PredicateAtom::Trait(implication, _) = bound_predicate.skip_binder() {
let error = error.to_poly_trait_ref();
let implication = bound_predicate.rebind(implication.trait_ref);
@ -1172,7 +1172,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
//
// this can fail if the problem was higher-ranked, in which
// cause I have no idea for a good error message.
let bound_predicate = predicate.bound_atom(self.tcx);
let bound_predicate = predicate.bound_atom();
if let ty::PredicateAtom::Projection(data) = bound_predicate.skip_binder() {
let mut selcx = SelectionContext::new(self);
let (data, _) = self.replace_bound_vars_with_fresh_vars(
@ -1459,7 +1459,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
return;
}
let bound_predicate = predicate.bound_atom(self.tcx);
let bound_predicate = predicate.bound_atom();
let mut err = match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(data, _) => {
let self_ty = data.trait_ref.self_ty();

View File

@ -623,7 +623,7 @@ fn prune_cache_value_obligations<'a, 'tcx>(
.obligations
.iter()
.filter(|obligation| {
let bound_predicate = obligation.predicate.bound_atom(infcx.tcx);
let bound_predicate = obligation.predicate.bound_atom();
match bound_predicate.skip_binder() {
// We found a `T: Foo<X = U>` predicate, let's check
// if `U` references any unresolved type
@ -908,7 +908,7 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>(
let infcx = selcx.infcx();
for predicate in env_predicates {
debug!(?predicate);
let bound_predicate = predicate.bound_atom(infcx.tcx);
let bound_predicate = predicate.bound_atom();
if let ty::PredicateAtom::Projection(data) = predicate.skip_binders() {
let data = bound_predicate.rebind(data);
let same_def_id = data.projection_def_id() == obligation.predicate.item_def_id;

View File

@ -449,8 +449,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
let result = ensure_sufficient_stack(|| {
let bound_predicate =
obligation.predicate.bound_atom_with_opt_escaping(self.infcx().tcx);
let bound_predicate = obligation.predicate.bound_atom();
match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(t, _) => {
let t = bound_predicate.rebind(t);
@ -1176,7 +1175,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
.iter()
.enumerate()
.filter_map(|(idx, bound)| {
let bound_predicate = bound.bound_atom(self.infcx.tcx);
let bound_predicate = bound.bound_atom();
if let ty::PredicateAtom::Trait(pred, _) = bound_predicate.skip_binder() {
let bound = bound_predicate.rebind(pred.trait_ref);
if self.infcx.probe(|_| {
@ -1568,7 +1567,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
use self::BuiltinImplConditions::{Ambiguous, None, Where};
match self_ty.kind() {
match *self_ty.kind() {
ty::Infer(ty::IntVar(_))
| ty::Infer(ty::FloatVar(_))
| ty::FnDef(..)
@ -1597,7 +1596,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ty::Array(element_ty, _) => {
// (*) binder moved here
Where(obligation.predicate.rebind(vec![*element_ty]))
Where(obligation.predicate.rebind(vec![element_ty]))
}
ty::Tuple(tys) => {

View File

@ -1095,7 +1095,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
obligation.predicate
);
let bound_predicate = obligation.predicate.bound_atom(tcx);
let bound_predicate = obligation.predicate.bound_atom();
match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(pred, _) => {
let pred = bound_predicate.rebind(pred);

View File

@ -192,7 +192,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
obligation.predicate
);
let bound_predicate = obligation.predicate.bound_atom(self.tcx);
let bound_predicate = obligation.predicate.bound_atom();
if let ty::PredicateAtom::Projection(proj_predicate) =
obligation.predicate.skip_binders()
{

View File

@ -583,7 +583,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
while !queue.is_empty() {
let obligation = queue.remove(0);
debug!("coerce_unsized resolve step: {:?}", obligation);
let bound_predicate = obligation.predicate.bound_atom(self.tcx);
let bound_predicate = obligation.predicate.bound_atom();
let trait_pred = match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(trait_pred, _)
if traits.contains(&trait_pred.def_id()) =>

View File

@ -226,14 +226,14 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
// could be extended easily also to the other `Predicate`.
let predicate_matches_closure = |p: Predicate<'tcx>| {
let mut relator: SimpleEqRelation<'tcx> = SimpleEqRelation::new(tcx, self_param_env);
let bound_predicate = predicate.bound_atom(tcx);
let bound_p = p.bound_atom(tcx);
match (predicate.skip_binders(), p.skip_binders()) {
let predicate = predicate.bound_atom();
let p = p.bound_atom();
match (predicate.skip_binder(), p.skip_binder()) {
(ty::PredicateAtom::Trait(a, _), ty::PredicateAtom::Trait(b, _)) => {
relator.relate(bound_predicate.rebind(a), bound_p.rebind(b)).is_ok()
relator.relate(predicate.rebind(a), p.rebind(b)).is_ok()
}
(ty::PredicateAtom::Projection(a), ty::PredicateAtom::Projection(b)) => {
relator.relate(bound_predicate.rebind(a), bound_p.rebind(b)).is_ok()
relator.relate(predicate.rebind(a), p.rebind(b)).is_ok()
}
_ => predicate == p,
}

View File

@ -796,13 +796,12 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
// FIXME: do we want to commit to this behavior for param bounds?
debug!("assemble_inherent_candidates_from_param(param_ty={:?})", param_ty);
let tcx = self.tcx;
let bounds = self.param_env.caller_bounds().iter().filter_map(|predicate| {
let bound_predicate = predicate.bound_atom(tcx);
let bound_predicate = predicate.bound_atom();
match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(trait_predicate, _) => {
match trait_predicate.trait_ref.self_ty().kind() {
ty::Param(ref p) if *p == param_ty => {
match *trait_predicate.trait_ref.self_ty().kind() {
ty::Param(p) if p == param_ty => {
Some(bound_predicate.rebind(trait_predicate.trait_ref))
}
_ => None,

View File

@ -637,7 +637,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
};
let mut format_pred = |pred: ty::Predicate<'tcx>| {
let bound_predicate = pred.bound_atom(tcx);
let bound_predicate = pred.bound_atom();
match bound_predicate.skip_binder() {
ty::PredicateAtom::Projection(pred) => {
let pred = bound_predicate.rebind(pred);

View File

@ -850,7 +850,7 @@ fn bounds_from_generic_predicates<'tcx>(
let mut projections = vec![];
for (predicate, _) in predicates.predicates {
debug!("predicate {:?}", predicate);
let bound_predicate = predicate.bound_atom(tcx);
let bound_predicate = predicate.bound_atom();
match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(trait_predicate, _) => {
let entry = types.entry(trait_predicate.self_ty()).or_default();

View File

@ -315,7 +315,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
tcx: TyCtxt<'tcx>,
pred: ty::Predicate<'tcx>,
) -> FxHashSet<GenericParamDef> {
let bound_predicate = pred.bound_atom(tcx);
let bound_predicate = pred.bound_atom();
let regions = match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(poly_trait_pred, _) => {
tcx.collect_referenced_late_bound_regions(&bound_predicate.rebind(poly_trait_pred))