1
Fork 0

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>) { fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) {
let tcx = self.visited.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() { match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(data, _) => { ty::PredicateAtom::Trait(data, _) => {
// Get predicates declared on the trait. // 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 /// 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, _tcx: TyCtxt<'tcx>) -> Binder<PredicateAtom<'tcx>> { pub fn bound_atom(self) -> Binder<PredicateAtom<'tcx>> {
match self.kind() { match self.kind() {
&PredicateKind::ForAll(binder) => binder, &PredicateKind::ForAll(binder) => binder,
&PredicateKind::Atom(atom) => { &PredicateKind::Atom(atom) => {
assert!(!atom.has_escaping_bound_vars()); debug_assert!(!atom.has_escaping_bound_vars());
Binder::dummy(atom) 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* /// current `Binder`. This should not be used if the new value *changes*
/// the bound variables. Note: the (old or new) value itself does not /// the bound variables. Note: the (old or new) value itself does not
/// necessarily need to *name* all the bound variables. /// 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> { pub fn rebind<U>(&self, value: U) -> Binder<U> {
Binder(value) Binder(value)
} }

View file

@ -642,7 +642,7 @@ impl AutoTraitFinder<'tcx> {
// We check this by calling is_of_param on the relevant types // We check this by calling is_of_param on the relevant types
// from the various possible predicates // 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() { match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(p, _) => { ty::PredicateAtom::Trait(p, _) => {
if self.is_param_no_infer(p.trait_ref.substs) 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; return;
} }
let bound_predicate = obligation.predicate.bound_atom(self.tcx); let bound_predicate = obligation.predicate.bound_atom();
match bound_predicate.skip_binder() { match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(trait_predicate, _) => { ty::PredicateAtom::Trait(trait_predicate, _) => {
let trait_predicate = bound_predicate.rebind(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. // 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()) { let (cond, error) = match (cond.skip_binders(), bound_error.skip_binder()) {
(ty::PredicateAtom::Trait(..), ty::PredicateAtom::Trait(error, _)) => { (ty::PredicateAtom::Trait(..), ty::PredicateAtom::Trait(error, _)) => {
(cond, bound_error.rebind(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)) { 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() { if let ty::PredicateAtom::Trait(implication, _) = bound_predicate.skip_binder() {
let error = error.to_poly_trait_ref(); let error = error.to_poly_trait_ref();
let implication = bound_predicate.rebind(implication.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 // this can fail if the problem was higher-ranked, in which
// cause I have no idea for a good error message. // 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() { if let ty::PredicateAtom::Projection(data) = bound_predicate.skip_binder() {
let mut selcx = SelectionContext::new(self); let mut selcx = SelectionContext::new(self);
let (data, _) = self.replace_bound_vars_with_fresh_vars( let (data, _) = self.replace_bound_vars_with_fresh_vars(
@ -1459,7 +1459,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
return; return;
} }
let bound_predicate = predicate.bound_atom(self.tcx); let bound_predicate = predicate.bound_atom();
let mut err = match bound_predicate.skip_binder() { let mut err = match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(data, _) => { ty::PredicateAtom::Trait(data, _) => {
let self_ty = data.trait_ref.self_ty(); let self_ty = data.trait_ref.self_ty();

View file

@ -623,7 +623,7 @@ fn prune_cache_value_obligations<'a, 'tcx>(
.obligations .obligations
.iter() .iter()
.filter(|obligation| { .filter(|obligation| {
let bound_predicate = obligation.predicate.bound_atom(infcx.tcx); let bound_predicate = obligation.predicate.bound_atom();
match bound_predicate.skip_binder() { match bound_predicate.skip_binder() {
// We found a `T: Foo<X = U>` predicate, let's check // We found a `T: Foo<X = U>` predicate, let's check
// if `U` references any unresolved type // if `U` references any unresolved type
@ -908,7 +908,7 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>(
let infcx = selcx.infcx(); let infcx = selcx.infcx();
for predicate in env_predicates { for predicate in env_predicates {
debug!(?predicate); 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() { if let ty::PredicateAtom::Projection(data) = predicate.skip_binders() {
let data = bound_predicate.rebind(data); let data = bound_predicate.rebind(data);
let same_def_id = data.projection_def_id() == obligation.predicate.item_def_id; 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 result = ensure_sufficient_stack(|| {
let bound_predicate = let bound_predicate = obligation.predicate.bound_atom();
obligation.predicate.bound_atom_with_opt_escaping(self.infcx().tcx);
match bound_predicate.skip_binder() { match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(t, _) => { ty::PredicateAtom::Trait(t, _) => {
let t = bound_predicate.rebind(t); let t = bound_predicate.rebind(t);
@ -1176,7 +1175,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
.iter() .iter()
.enumerate() .enumerate()
.filter_map(|(idx, bound)| { .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() { if let ty::PredicateAtom::Trait(pred, _) = bound_predicate.skip_binder() {
let bound = bound_predicate.rebind(pred.trait_ref); let bound = bound_predicate.rebind(pred.trait_ref);
if self.infcx.probe(|_| { if self.infcx.probe(|_| {
@ -1568,7 +1567,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
use self::BuiltinImplConditions::{Ambiguous, None, Where}; use self::BuiltinImplConditions::{Ambiguous, None, Where};
match self_ty.kind() { match *self_ty.kind() {
ty::Infer(ty::IntVar(_)) ty::Infer(ty::IntVar(_))
| ty::Infer(ty::FloatVar(_)) | ty::Infer(ty::FloatVar(_))
| ty::FnDef(..) | ty::FnDef(..)
@ -1597,7 +1596,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ty::Array(element_ty, _) => { ty::Array(element_ty, _) => {
// (*) binder moved here // (*) binder moved here
Where(obligation.predicate.rebind(vec![*element_ty])) Where(obligation.predicate.rebind(vec![element_ty]))
} }
ty::Tuple(tys) => { ty::Tuple(tys) => {

View file

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

View file

@ -192,7 +192,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
obligation.predicate 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) = if let ty::PredicateAtom::Projection(proj_predicate) =
obligation.predicate.skip_binders() obligation.predicate.skip_binders()
{ {

View file

@ -583,7 +583,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
while !queue.is_empty() { while !queue.is_empty() {
let obligation = queue.remove(0); let obligation = queue.remove(0);
debug!("coerce_unsized resolve step: {:?}", obligation); 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() { let trait_pred = match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(trait_pred, _) ty::PredicateAtom::Trait(trait_pred, _)
if traits.contains(&trait_pred.def_id()) => 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`. // could be extended easily also to the other `Predicate`.
let predicate_matches_closure = |p: Predicate<'tcx>| { let predicate_matches_closure = |p: Predicate<'tcx>| {
let mut relator: SimpleEqRelation<'tcx> = SimpleEqRelation::new(tcx, self_param_env); let mut relator: SimpleEqRelation<'tcx> = SimpleEqRelation::new(tcx, self_param_env);
let bound_predicate = predicate.bound_atom(tcx); let predicate = predicate.bound_atom();
let bound_p = p.bound_atom(tcx); let p = p.bound_atom();
match (predicate.skip_binders(), p.skip_binders()) { match (predicate.skip_binder(), p.skip_binder()) {
(ty::PredicateAtom::Trait(a, _), ty::PredicateAtom::Trait(b, _)) => { (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)) => { (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, _ => 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? // FIXME: do we want to commit to this behavior for param bounds?
debug!("assemble_inherent_candidates_from_param(param_ty={:?})", param_ty); 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 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() { match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(trait_predicate, _) => { ty::PredicateAtom::Trait(trait_predicate, _) => {
match trait_predicate.trait_ref.self_ty().kind() { match *trait_predicate.trait_ref.self_ty().kind() {
ty::Param(ref p) if *p == param_ty => { ty::Param(p) if p == param_ty => {
Some(bound_predicate.rebind(trait_predicate.trait_ref)) Some(bound_predicate.rebind(trait_predicate.trait_ref))
} }
_ => None, _ => None,

View file

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

View file

@ -850,7 +850,7 @@ fn bounds_from_generic_predicates<'tcx>(
let mut projections = vec![]; let mut projections = vec![];
for (predicate, _) in predicates.predicates { for (predicate, _) in predicates.predicates {
debug!("predicate {:?}", predicate); debug!("predicate {:?}", predicate);
let bound_predicate = predicate.bound_atom(tcx); let bound_predicate = predicate.bound_atom();
match bound_predicate.skip_binder() { match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(trait_predicate, _) => { ty::PredicateAtom::Trait(trait_predicate, _) => {
let entry = types.entry(trait_predicate.self_ty()).or_default(); 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>, tcx: TyCtxt<'tcx>,
pred: ty::Predicate<'tcx>, pred: ty::Predicate<'tcx>,
) -> FxHashSet<GenericParamDef> { ) -> FxHashSet<GenericParamDef> {
let bound_predicate = pred.bound_atom(tcx); let bound_predicate = pred.bound_atom();
let regions = match bound_predicate.skip_binder() { let regions = match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(poly_trait_pred, _) => { ty::PredicateAtom::Trait(poly_trait_pred, _) => {
tcx.collect_referenced_late_bound_regions(&bound_predicate.rebind(poly_trait_pred)) tcx.collect_referenced_late_bound_regions(&bound_predicate.rebind(poly_trait_pred))