@@ -20,6 +20,7 @@ use crate::rustc_serialize::{self as serialize};
20
20
use smallvec:: SmallVec ;
21
21
use std:: borrow:: Cow ;
22
22
use std:: fmt:: { self , Debug , Formatter , Write } ;
23
+ use std:: iter:: FusedIterator ;
23
24
use std:: ops:: { Index , IndexMut } ;
24
25
use std:: slice;
25
26
use std:: vec:: IntoIter ;
@@ -2105,6 +2106,15 @@ pub enum PlaceProjections<'p, 'tcx: 'p> {
2105
2106
}
2106
2107
2107
2108
impl < ' p , ' tcx > PlaceProjections < ' p , ' tcx > {
2109
+ fn iter ( & self ) -> PlaceProjectionsIter < ' _ , ' tcx > {
2110
+ PlaceProjectionsIter { value : self }
2111
+ }
2112
+ }
2113
+
2114
+ impl < ' p , ' tcx > IntoIterator for & ' p PlaceProjections < ' p , ' tcx > {
2115
+ type Item = & ' p PlaceProjection < ' tcx > ;
2116
+ type IntoIter = PlaceProjectionsIter < ' p , ' tcx > ;
2117
+
2108
2118
/// Converts a list of `PlaceProjection` components into an iterator;
2109
2119
/// this iterator yields up a never-ending stream of `Option<&Place>`.
2110
2120
/// These begin with the "innermost" projection and then with each
@@ -2114,8 +2124,8 @@ impl<'p, 'tcx> PlaceProjections<'p, 'tcx> {
2114
2124
/// ```notrust
2115
2125
/// Some(`a`), Some(`a.b`), Some(`a.b.c`), None, None, ...
2116
2126
/// ```
2117
- fn iter ( & self ) -> PlaceProjectionsIter < ' _ , ' tcx > {
2118
- PlaceProjectionsIter { value : self }
2127
+ fn into_iter ( self ) -> Self :: IntoIter {
2128
+ self . iter ( )
2119
2129
}
2120
2130
}
2121
2131
@@ -2129,8 +2139,10 @@ pub struct PlaceProjectionsIter<'p, 'tcx: 'p> {
2129
2139
pub value : & ' p PlaceProjections < ' p , ' tcx > ,
2130
2140
}
2131
2141
2132
- impl < ' p , ' tcx > PlaceProjectionsIter < ' p , ' tcx > {
2133
- pub fn next ( & mut self ) -> Option < & ' p PlaceProjection < ' tcx > > {
2142
+ impl < ' p , ' tcx > Iterator for PlaceProjectionsIter < ' p , ' tcx > {
2143
+ type Item = & ' p PlaceProjection < ' tcx > ;
2144
+
2145
+ fn next ( & mut self ) -> Option < Self :: Item > {
2134
2146
if let & PlaceProjections :: List { projection, next } = self . value {
2135
2147
self . value = next;
2136
2148
Some ( projection)
@@ -2140,6 +2152,8 @@ impl<'p, 'tcx> PlaceProjectionsIter<'p, 'tcx> {
2140
2152
}
2141
2153
}
2142
2154
2155
+ impl < ' p , ' tcx > FusedIterator for PlaceProjectionsIter < ' p , ' tcx > { }
2156
+
2143
2157
impl < ' tcx > Debug for Place < ' tcx > {
2144
2158
fn fmt ( & self , fmt : & mut Formatter < ' _ > ) -> fmt:: Result {
2145
2159
use self :: Place :: * ;
0 commit comments