@@ -65,6 +65,7 @@ use crate::collections::TryReserveError;
65
65
use crate :: str:: { self , CharIndices , Chars , Utf8Error , from_utf8_unchecked_mut} ;
66
66
#[ cfg( not( no_global_oom_handling) ) ]
67
67
use crate :: str:: { FromStr , from_boxed_utf8_unchecked} ;
68
+ use crate :: vec;
68
69
use crate :: vec:: Vec ;
69
70
70
71
/// A UTF-8–encoded, growable string.
@@ -3103,7 +3104,7 @@ impl fmt::Write for String {
3103
3104
/// Placeholder docs.
3104
3105
#[ unstable( feature = "into_chars" , reason = "new API" , issue = "none" ) ]
3105
3106
pub struct IntoChars {
3106
- bytes : Vec < u8 > ,
3107
+ bytes : vec :: IntoIter < u8 > ,
3107
3108
}
3108
3109
3109
3110
#[ unstable( feature = "into_chars" , reason = "new API" , issue = "none" ) ]
@@ -3151,7 +3152,8 @@ impl Iterator for IntoChars {
3151
3152
None => None ,
3152
3153
Some ( ( _, ch) ) => {
3153
3154
let offset = iter. offset ( ) ;
3154
- drop ( self . bytes . drain ( ..offset) ) ;
3155
+ // SAFETY: `offset` is a valid index.
3156
+ let _ = self . bytes . advance_by ( offset) ;
3155
3157
Some ( ch)
3156
3158
}
3157
3159
}
@@ -3171,11 +3173,13 @@ impl Iterator for IntoChars {
3171
3173
impl DoubleEndedIterator for IntoChars {
3172
3174
#[ inline]
3173
3175
fn next_back ( & mut self ) -> Option < char > {
3176
+ let len = self . as_str ( ) . len ( ) ;
3174
3177
let mut iter = self . iter ( ) ;
3175
3178
match iter. next_back ( ) {
3176
3179
None => None ,
3177
3180
Some ( ( idx, ch) ) => {
3178
- self . bytes . truncate ( idx) ;
3181
+ // SAFETY: `idx` is a valid index.
3182
+ let _ = self . bytes . advance_back_by ( len - idx) ;
3179
3183
Some ( ch)
3180
3184
}
3181
3185
}
0 commit comments