Skip to content

Commit

Permalink
Remove fns from rust-lang#20664
Browse files Browse the repository at this point in the history
  • Loading branch information
tmandry committed Apr 20, 2018
1 parent 6e0408d commit 4741e2b
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 21 deletions.
7 changes: 4 additions & 3 deletions src/librustc/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -849,9 +849,10 @@ fn vtable_methods<'a, 'tcx>(

// the method may have some early-bound lifetimes, add
// regions for those
let substs = Substs::for_item(tcx, def_id,
|_, _| tcx.types.re_erased,
|def, _| trait_ref.substs().type_for_def(def));
let substs = Substs::for_item(
tcx, def_id,
|_, _| tcx.types.re_erased,
|def, _| trait_ref.skip_binder().substs.type_for_def(def));

This comment has been minimized.

Copy link
@nikomatsakis

nikomatsakis Apr 24, 2018

This use is OK but convoluted. If you look a few lines below, you will see that this substs result is actually placed back inside a binder. It would be better to write this using map_bound, something like:

let substs = trait_ref.map_bound(|trait_ref| Substs:for_item(...));
let substs = tcx.normalize_erasing_late_bound_regions(...);

// the trait type may have higher-ranked lifetimes in it;
// so erase them if they appear, so that we get the type
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
// This suffices to allow chains like `FnMut` implemented in
// terms of `Fn` etc, but we could probably make this more
// precise still.
let unbound_input_types = stack.fresh_trait_ref.input_types().any(|ty| ty.is_fresh());
let unbound_input_types = stack.fresh_trait_ref.skip_binder().input_types().any(|ty| ty.is_fresh());

This comment has been minimized.

Copy link
@nikomatsakis

nikomatsakis Apr 24, 2018

this use is OK -- is_fresh doesn't look for anything that is affected by binders

// this check was an imperfect workaround for a bug n the old
// intercrate mode, it should be removed when that goes away.
if unbound_input_types &&
Expand Down
15 changes: 0 additions & 15 deletions src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,16 +574,6 @@ impl<'tcx> PolyTraitRef<'tcx> {
self.skip_binder().def_id
}

pub fn substs(&self) -> &'tcx Substs<'tcx> {
// FIXME(#20664) every use of this fn is probably a bug, it should yield Binder<>
self.skip_binder().substs
}

pub fn input_types<'a>(&'a self) -> impl DoubleEndedIterator<Item=Ty<'tcx>> + 'a {
// FIXME(#20664) every use of this fn is probably a bug, it should yield Binder<>
self.skip_binder().input_types()
}

pub fn to_poly_trait_predicate(&self) -> ty::PolyTraitPredicate<'tcx> {
// Note that we preserve binding levels
Binder(ty::TraitPredicate { trait_ref: self.skip_binder().clone() })
Expand Down Expand Up @@ -635,11 +625,6 @@ impl<'tcx> PolyExistentialTraitRef<'tcx> {
pub fn def_id(&self) -> DefId {
self.skip_binder().def_id
}

pub fn input_types<'a>(&'a self) -> impl DoubleEndedIterator<Item=Ty<'tcx>> + 'a {
// FIXME(#20664) every use of this fn is probably a bug, it should yield Binder<>
self.skip_binder().input_types()
}
}

/// Binder is a binder for higher-ranked lifetimes. It is part of the
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
return None;
}

let arg_param_ty = trait_ref.substs().type_at(1);
let arg_param_ty = trait_ref.skip_binder().substs.type_at(1);

This comment has been minimized.

Copy link
@nikomatsakis