Replace Fn impls with RPIT impls in rustc_index
This is cleaner and removes an unstable feature usage
This commit is contained in:
parent
e98f28907e
commit
9f4cb862ca
@ -144,7 +144,7 @@ impl<R> MemberConstraintSet<'tcx, R>
|
||||
where
|
||||
R: Copy + Hash + Eq,
|
||||
{
|
||||
crate fn all_indices(&self) -> impl Iterator<Item = NllMemberConstraintIndex> {
|
||||
crate fn all_indices(&self) -> impl Iterator<Item = NllMemberConstraintIndex> + '_ {
|
||||
self.constraints.indices()
|
||||
}
|
||||
|
||||
|
@ -497,7 +497,7 @@ fn init_free_and_bound_regions(&mut self) {
|
||||
}
|
||||
|
||||
/// Returns an iterator over all the region indices.
|
||||
pub fn regions(&self) -> impl Iterator<Item = RegionVid> {
|
||||
pub fn regions(&self) -> impl Iterator<Item = RegionVid> + '_ {
|
||||
self.definitions.indices()
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
#![feature(iter_zip)]
|
||||
#![feature(min_specialization)]
|
||||
#![feature(test)]
|
||||
#![feature(fn_traits)]
|
||||
|
||||
pub mod bit_set;
|
||||
pub mod vec;
|
||||
|
@ -3,9 +3,9 @@
|
||||
use std::fmt;
|
||||
use std::fmt::Debug;
|
||||
use std::hash::Hash;
|
||||
use std::iter::{self, FromIterator};
|
||||
use std::iter::FromIterator;
|
||||
use std::marker::PhantomData;
|
||||
use std::ops::{Index, IndexMut, Range, RangeBounds};
|
||||
use std::ops::{Index, IndexMut, RangeBounds};
|
||||
use std::slice;
|
||||
use std::vec;
|
||||
|
||||
@ -518,8 +518,6 @@ fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
}
|
||||
}
|
||||
|
||||
pub type Enumerated<I, J> = iter::Map<iter::Enumerate<J>, IntoIdx<I>>;
|
||||
|
||||
impl<I: Idx, T> IndexVec<I, T> {
|
||||
#[inline]
|
||||
pub fn new() -> Self {
|
||||
@ -596,8 +594,10 @@ pub fn into_iter(self) -> vec::IntoIter<T> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn into_iter_enumerated(self) -> Enumerated<I, vec::IntoIter<T>> {
|
||||
self.raw.into_iter().enumerate().map(IntoIdx { _marker: PhantomData })
|
||||
pub fn into_iter_enumerated(
|
||||
self,
|
||||
) -> impl DoubleEndedIterator<Item = (I, T)> + ExactSizeIterator {
|
||||
self.raw.into_iter().enumerate().map(|(n, t)| (I::new(n), t))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -606,13 +606,15 @@ pub fn iter(&self) -> slice::Iter<'_, T> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn iter_enumerated(&self) -> Enumerated<I, slice::Iter<'_, T>> {
|
||||
self.raw.iter().enumerate().map(IntoIdx { _marker: PhantomData })
|
||||
pub fn iter_enumerated(
|
||||
&self,
|
||||
) -> impl DoubleEndedIterator<Item = (I, &T)> + ExactSizeIterator + '_ {
|
||||
self.raw.iter().enumerate().map(|(n, t)| (I::new(n), t))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn indices(&self) -> iter::Map<Range<usize>, IntoIdx<I>> {
|
||||
(0..self.len()).map(IntoIdx { _marker: PhantomData })
|
||||
pub fn indices(&self) -> impl DoubleEndedIterator<Item = I> + ExactSizeIterator + 'static {
|
||||
(0..self.len()).map(|n| I::new(n))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -621,8 +623,10 @@ pub fn iter_mut(&mut self) -> slice::IterMut<'_, T> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn iter_enumerated_mut(&mut self) -> Enumerated<I, slice::IterMut<'_, T>> {
|
||||
self.raw.iter_mut().enumerate().map(IntoIdx { _marker: PhantomData })
|
||||
pub fn iter_enumerated_mut(
|
||||
&mut self,
|
||||
) -> impl DoubleEndedIterator<Item = (I, &mut T)> + ExactSizeIterator + '_ {
|
||||
self.raw.iter_mut().enumerate().map(|(n, t)| (I::new(n), t))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -638,7 +642,7 @@ pub fn drain_enumerated<'a, R: RangeBounds<usize>>(
|
||||
&'a mut self,
|
||||
range: R,
|
||||
) -> impl Iterator<Item = (I, T)> + 'a {
|
||||
self.raw.drain(range).enumerate().map(IntoIdx { _marker: PhantomData })
|
||||
self.raw.drain(range).enumerate().map(|(n, t)| (I::new(n), t))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -832,36 +836,5 @@ fn into_iter(self) -> slice::IterMut<'a, T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct IntoIdx<I: Idx> {
|
||||
_marker: PhantomData<fn(&I)>,
|
||||
}
|
||||
impl<I: Idx, T> FnOnce<((usize, T),)> for IntoIdx<I> {
|
||||
type Output = (I, T);
|
||||
|
||||
extern "rust-call" fn call_once(self, ((n, t),): ((usize, T),)) -> Self::Output {
|
||||
(I::new(n), t)
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: Idx, T> FnMut<((usize, T),)> for IntoIdx<I> {
|
||||
extern "rust-call" fn call_mut(&mut self, ((n, t),): ((usize, T),)) -> Self::Output {
|
||||
(I::new(n), t)
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: Idx> FnOnce<(usize,)> for IntoIdx<I> {
|
||||
type Output = I;
|
||||
|
||||
extern "rust-call" fn call_once(self, (n,): (usize,)) -> Self::Output {
|
||||
I::new(n)
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: Idx> FnMut<(usize,)> for IntoIdx<I> {
|
||||
extern "rust-call" fn call_mut(&mut self, (n,): (usize,)) -> Self::Output {
|
||||
I::new(n)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
@ -1,6 +1,5 @@
|
||||
use core::slice::Iter;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_index::vec::{Enumerated, IndexVec};
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::{ParamEnv, Ty, TyCtxt};
|
||||
use rustc_span::Span;
|
||||
@ -337,7 +336,9 @@ pub fn find_local(&self, local: Local) -> MovePathIndex {
|
||||
|
||||
/// An enumerated iterator of `local`s and their associated
|
||||
/// `MovePathIndex`es.
|
||||
pub fn iter_locals_enumerated(&self) -> Enumerated<Local, Iter<'_, MovePathIndex>> {
|
||||
pub fn iter_locals_enumerated(
|
||||
&self,
|
||||
) -> impl DoubleEndedIterator<Item = (Local, &MovePathIndex)> + ExactSizeIterator {
|
||||
self.locals.iter_enumerated()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user