Skip to content

Commit 9f4cb86

Browse files
committed
Replace Fn impls with RPIT impls in rustc_index
This is cleaner and removes an unstable feature usage
1 parent e98f289 commit 9f4cb86

File tree

5 files changed

+23
-50
lines changed

5 files changed

+23
-50
lines changed

compiler/rustc_borrowck/src/member_constraints.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl<R> MemberConstraintSet<'tcx, R>
144144
where
145145
R: Copy + Hash + Eq,
146146
{
147-
crate fn all_indices(&self) -> impl Iterator<Item = NllMemberConstraintIndex> {
147+
crate fn all_indices(&self) -> impl Iterator<Item = NllMemberConstraintIndex> + '_ {
148148
self.constraints.indices()
149149
}
150150

compiler/rustc_borrowck/src/region_infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
497497
}
498498

499499
/// Returns an iterator over all the region indices.
500-
pub fn regions(&self) -> impl Iterator<Item = RegionVid> {
500+
pub fn regions(&self) -> impl Iterator<Item = RegionVid> + '_ {
501501
self.definitions.indices()
502502
}
503503

compiler/rustc_index/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#![feature(iter_zip)]
55
#![feature(min_specialization)]
66
#![feature(test)]
7-
#![feature(fn_traits)]
87

98
pub mod bit_set;
109
pub mod vec;

compiler/rustc_index/src/vec.rs

+17-44
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
33
use std::fmt;
44
use std::fmt::Debug;
55
use std::hash::Hash;
6-
use std::iter::{self, FromIterator};
6+
use std::iter::FromIterator;
77
use std::marker::PhantomData;
8-
use std::ops::{Index, IndexMut, Range, RangeBounds};
8+
use std::ops::{Index, IndexMut, RangeBounds};
99
use std::slice;
1010
use std::vec;
1111

@@ -518,8 +518,6 @@ impl<I: Idx, T: fmt::Debug> fmt::Debug for IndexVec<I, T> {
518518
}
519519
}
520520

521-
pub type Enumerated<I, J> = iter::Map<iter::Enumerate<J>, IntoIdx<I>>;
522-
523521
impl<I: Idx, T> IndexVec<I, T> {
524522
#[inline]
525523
pub fn new() -> Self {
@@ -596,8 +594,10 @@ impl<I: Idx, T> IndexVec<I, T> {
596594
}
597595

598596
#[inline]
599-
pub fn into_iter_enumerated(self) -> Enumerated<I, vec::IntoIter<T>> {
600-
self.raw.into_iter().enumerate().map(IntoIdx { _marker: PhantomData })
597+
pub fn into_iter_enumerated(
598+
self,
599+
) -> impl DoubleEndedIterator<Item = (I, T)> + ExactSizeIterator {
600+
self.raw.into_iter().enumerate().map(|(n, t)| (I::new(n), t))
601601
}
602602

603603
#[inline]
@@ -606,13 +606,15 @@ impl<I: Idx, T> IndexVec<I, T> {
606606
}
607607

608608
#[inline]
609-
pub fn iter_enumerated(&self) -> Enumerated<I, slice::Iter<'_, T>> {
610-
self.raw.iter().enumerate().map(IntoIdx { _marker: PhantomData })
609+
pub fn iter_enumerated(
610+
&self,
611+
) -> impl DoubleEndedIterator<Item = (I, &T)> + ExactSizeIterator + '_ {
612+
self.raw.iter().enumerate().map(|(n, t)| (I::new(n), t))
611613
}
612614

613615
#[inline]
614-
pub fn indices(&self) -> iter::Map<Range<usize>, IntoIdx<I>> {
615-
(0..self.len()).map(IntoIdx { _marker: PhantomData })
616+
pub fn indices(&self) -> impl DoubleEndedIterator<Item = I> + ExactSizeIterator + 'static {
617+
(0..self.len()).map(|n| I::new(n))
616618
}
617619

618620
#[inline]
@@ -621,8 +623,10 @@ impl<I: Idx, T> IndexVec<I, T> {
621623
}
622624

623625
#[inline]
624-
pub fn iter_enumerated_mut(&mut self) -> Enumerated<I, slice::IterMut<'_, T>> {
625-
self.raw.iter_mut().enumerate().map(IntoIdx { _marker: PhantomData })
626+
pub fn iter_enumerated_mut(
627+
&mut self,
628+
) -> impl DoubleEndedIterator<Item = (I, &mut T)> + ExactSizeIterator + '_ {
629+
self.raw.iter_mut().enumerate().map(|(n, t)| (I::new(n), t))
626630
}
627631

628632
#[inline]
@@ -638,7 +642,7 @@ impl<I: Idx, T> IndexVec<I, T> {
638642
&'a mut self,
639643
range: R,
640644
) -> impl Iterator<Item = (I, T)> + 'a {
641-
self.raw.drain(range).enumerate().map(IntoIdx { _marker: PhantomData })
645+
self.raw.drain(range).enumerate().map(|(n, t)| (I::new(n), t))
642646
}
643647

644648
#[inline]
@@ -832,36 +836,5 @@ impl<'a, I: Idx, T> IntoIterator for &'a mut IndexVec<I, T> {
832836
}
833837
}
834838

835-
pub struct IntoIdx<I: Idx> {
836-
_marker: PhantomData<fn(&I)>,
837-
}
838-
impl<I: Idx, T> FnOnce<((usize, T),)> for IntoIdx<I> {
839-
type Output = (I, T);
840-
841-
extern "rust-call" fn call_once(self, ((n, t),): ((usize, T),)) -> Self::Output {
842-
(I::new(n), t)
843-
}
844-
}
845-
846-
impl<I: Idx, T> FnMut<((usize, T),)> for IntoIdx<I> {
847-
extern "rust-call" fn call_mut(&mut self, ((n, t),): ((usize, T),)) -> Self::Output {
848-
(I::new(n), t)
849-
}
850-
}
851-
852-
impl<I: Idx> FnOnce<(usize,)> for IntoIdx<I> {
853-
type Output = I;
854-
855-
extern "rust-call" fn call_once(self, (n,): (usize,)) -> Self::Output {
856-
I::new(n)
857-
}
858-
}
859-
860-
impl<I: Idx> FnMut<(usize,)> for IntoIdx<I> {
861-
extern "rust-call" fn call_mut(&mut self, (n,): (usize,)) -> Self::Output {
862-
I::new(n)
863-
}
864-
}
865-
866839
#[cfg(test)]
867840
mod tests;

compiler/rustc_mir_dataflow/src/move_paths/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use core::slice::Iter;
21
use rustc_data_structures::fx::FxHashMap;
3-
use rustc_index::vec::{Enumerated, IndexVec};
2+
use rustc_index::vec::IndexVec;
43
use rustc_middle::mir::*;
54
use rustc_middle::ty::{ParamEnv, Ty, TyCtxt};
65
use rustc_span::Span;
@@ -337,7 +336,9 @@ impl MovePathLookup {
337336

338337
/// An enumerated iterator of `local`s and their associated
339338
/// `MovePathIndex`es.
340-
pub fn iter_locals_enumerated(&self) -> Enumerated<Local, Iter<'_, MovePathIndex>> {
339+
pub fn iter_locals_enumerated(
340+
&self,
341+
) -> impl DoubleEndedIterator<Item = (Local, &MovePathIndex)> + ExactSizeIterator {
341342
self.locals.iter_enumerated()
342343
}
343344
}

0 commit comments

Comments
 (0)