Added ExactSizeIterator bound to return types

This reverts commit d97379a96e.
This commit is contained in:
Bartłomiej Kuras 2019-12-09 17:38:24 +01:00
parent d97379a96e
commit 989bf84af3
19 changed files with 31 additions and 53 deletions

View file

@ -574,7 +574,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
param_env: ty::ParamEnv<'tcx>,
unsubstituted_region_constraints: &'a [QueryOutlivesConstraint<'tcx>],
result_subst: &'a CanonicalVarValues<'tcx>,
) -> impl Iterator<Item = PredicateObligation<'tcx>> + ExactSizeIterator + 'a + Captures<'tcx> {
) -> impl Iterator<Item = PredicateObligation<'tcx>> + 'a + Captures<'tcx> {
unsubstituted_region_constraints
.iter()
.map(move |constraint| {

View file

@ -11,7 +11,7 @@ pub struct FreeRegionMap<'tcx> {
}
impl<'tcx> FreeRegionMap<'tcx> {
pub fn elements(&self) -> impl Iterator<Item=&Region<'tcx>> + ExactSizeIterator {
pub fn elements(&self) -> impl Iterator<Item=&Region<'tcx>> {
self.relation.elements()
}

View file

@ -284,7 +284,7 @@ impl<'tcx> Body<'tcx> {
#[inline]
pub fn args_iter(&self) -> impl Iterator<Item = Local> + ExactSizeIterator {
let arg_count = self.arg_count;
(1..arg_count+1).map(Local::new)
(1..arg_count + 1).map(Local::new)
}
/// Returns an iterator over all user-defined variables and compiler-generated temporaries (all

View file

@ -414,9 +414,7 @@ impl<'tcx> Node {
}
/// Iterate over the items defined directly by the given (impl or trait) node.
pub fn items(&self, tcx: TyCtxt<'tcx>)
-> impl Iterator<Item = ty::AssocItem> + ExactSizeIterator + Clone + 'tcx
{
pub fn items(&self, tcx: TyCtxt<'tcx>) -> ty::AssocItemsIterator<'tcx> {
tcx.associated_items(self.def_id())
}

View file

@ -2376,7 +2376,7 @@ impl<'tcx> AdtDef {
pub fn discriminants(
&'tcx self,
tcx: TyCtxt<'tcx>,
) -> impl Iterator<Item = (VariantIdx, Discr<'tcx>)> + ExactSizeIterator + Captures<'tcx> {
) -> impl Iterator<Item = (VariantIdx, Discr<'tcx>)> + Captures<'tcx> {
let repr_type = self.repr.discr_type();
let initial = repr_type.initial_discriminant(tcx);
let mut prev_discr = None::<Discr<'tcx>>;
@ -2740,9 +2740,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// Returns an iterator of the `DefId`s for all body-owners in this
/// crate. If you would prefer to iterate over the bodies
/// themselves, you can do `self.hir().krate().body_ids.iter()`.
pub fn body_owners(self)
-> impl Iterator<Item = DefId> + ExactSizeIterator + Captures<'tcx> + 'tcx
{
pub fn body_owners(self) -> impl Iterator<Item = DefId> + Captures<'tcx> + 'tcx {
self.hir().krate()
.body_ids
.iter()
@ -3118,12 +3116,6 @@ impl Iterator for AssocItemsIterator<'_> {
}
}
impl ExactSizeIterator for AssocItemsIterator<'_> {
fn len(&self) -> usize {
self.def_ids.len() - self.next_index
}
}
fn associated_item(tcx: TyCtxt<'_>, def_id: DefId) -> AssocItem {
let id = tcx.hir().as_local_hir_id(def_id).unwrap();
let parent_id = tcx.hir().get_parent_item(id);

View file

@ -345,7 +345,7 @@ impl<'tcx> ClosureSubsts<'tcx> {
self,
def_id: DefId,
tcx: TyCtxt<'_>,
) -> impl Iterator<Item = Ty<'tcx>> + ExactSizeIterator + 'tcx {
) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
let SplitClosureSubsts { upvar_kinds, .. } = self.split(def_id, tcx);
upvar_kinds.iter().map(|t| {
if let GenericArgKind::Type(ty) = t.unpack() {
@ -433,7 +433,7 @@ impl<'tcx> GeneratorSubsts<'tcx> {
self,
def_id: DefId,
tcx: TyCtxt<'_>,
) -> impl Iterator<Item = Ty<'tcx>> + ExactSizeIterator + 'tcx {
) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
let SplitGeneratorSubsts { upvar_kinds, .. } = self.split(def_id, tcx);
upvar_kinds.iter().map(|t| {
if let GenericArgKind::Type(ty) = t.unpack() {
@ -551,7 +551,7 @@ impl<'tcx> GeneratorSubsts<'tcx> {
self,
def_id: DefId,
tcx: TyCtxt<'tcx>,
) -> impl Iterator<Item = impl Iterator<Item = Ty<'tcx>> + ExactSizeIterator + Captures<'tcx>> {
) -> impl Iterator<Item = impl Iterator<Item = Ty<'tcx>> + Captures<'tcx>> {
let layout = tcx.generator_layout(def_id);
layout.variant_fields.iter().map(move |variant| {
variant.iter().map(move |field| {
@ -563,9 +563,7 @@ impl<'tcx> GeneratorSubsts<'tcx> {
/// This is the types of the fields of a generator which are not stored in a
/// variant.
#[inline]
pub fn prefix_tys(self, def_id: DefId, tcx: TyCtxt<'tcx>)
-> impl Iterator<Item = Ty<'tcx>> + ExactSizeIterator
{
pub fn prefix_tys(self, def_id: DefId, tcx: TyCtxt<'tcx>) -> impl Iterator<Item = Ty<'tcx>> {
self.upvar_tys(def_id, tcx)
}
}
@ -582,7 +580,7 @@ impl<'tcx> UpvarSubsts<'tcx> {
self,
def_id: DefId,
tcx: TyCtxt<'tcx>,
) -> impl Iterator<Item = Ty<'tcx>> + ExactSizeIterator + 'tcx {
) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
let upvar_kinds = match self {
UpvarSubsts::Closure(substs) => substs.as_closure().split(def_id, tcx).upvar_kinds,
UpvarSubsts::Generator(substs) => substs.as_generator().split(def_id, tcx).upvar_kinds,