Skip to content

Commit e535671

Browse files
authored
Rollup merge of #101165 - ldm0:drain_to_iter, r=cjgillot
Use more `into_iter` rather than `drain(..)` Clearer semantic.
2 parents f378155 + 97b1a61 commit e535671

File tree

6 files changed

+16
-16
lines changed

6 files changed

+16
-16
lines changed

compiler/rustc_ast/src/tokenstream.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ impl TokenStreamBuilder {
555555

556556
// Get the first stream, which will become the result stream.
557557
// If it's `None`, create an empty stream.
558-
let mut iter = streams.drain(..);
558+
let mut iter = streams.into_iter();
559559
let mut res_stream_lrc = iter.next().unwrap().0;
560560

561561
// Append the subsequent elements to the result stream, after

compiler/rustc_data_structures/src/sorted_map.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl<K: Ord, V> SortedMap<K, V> {
164164
/// It is up to the caller to make sure that the elements are sorted by key
165165
/// and that there are no duplicates.
166166
#[inline]
167-
pub fn insert_presorted(&mut self, mut elements: Vec<(K, V)>) {
167+
pub fn insert_presorted(&mut self, elements: Vec<(K, V)>) {
168168
if elements.is_empty() {
169169
return;
170170
}
@@ -173,28 +173,28 @@ impl<K: Ord, V> SortedMap<K, V> {
173173

174174
let start_index = self.lookup_index_for(&elements[0].0);
175175

176-
let drain = match start_index {
176+
let elements = match start_index {
177177
Ok(index) => {
178-
let mut drain = elements.drain(..);
179-
self.data[index] = drain.next().unwrap();
180-
drain
178+
let mut elements = elements.into_iter();
179+
self.data[index] = elements.next().unwrap();
180+
elements
181181
}
182182
Err(index) => {
183183
if index == self.data.len() || elements.last().unwrap().0 < self.data[index].0 {
184184
// We can copy the whole range without having to mix with
185185
// existing elements.
186-
self.data.splice(index..index, elements.drain(..));
186+
self.data.splice(index..index, elements.into_iter());
187187
return;
188188
}
189189

190-
let mut drain = elements.drain(..);
191-
self.data.insert(index, drain.next().unwrap());
192-
drain
190+
let mut elements = elements.into_iter();
191+
self.data.insert(index, elements.next().unwrap());
192+
elements
193193
}
194194
};
195195

196196
// Insert the rest
197-
for (k, v) in drain {
197+
for (k, v) in elements {
198198
self.insert(k, v);
199199
}
200200
}

compiler/rustc_errors/src/diagnostic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -974,12 +974,12 @@ impl Diagnostic {
974974
fn sub_with_highlights<M: Into<SubdiagnosticMessage>>(
975975
&mut self,
976976
level: Level,
977-
mut message: Vec<(M, Style)>,
977+
message: Vec<(M, Style)>,
978978
span: MultiSpan,
979979
render_span: Option<MultiSpan>,
980980
) {
981981
let message = message
982-
.drain(..)
982+
.into_iter()
983983
.map(|m| (self.subdiagnostic_message_to_diagnostic_message(m.0), m.1))
984984
.collect();
985985
let sub = SubDiagnostic { level, message, span, render_span };

compiler/rustc_errors/src/translation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub trait Translate {
2121
/// Typically performed once for each diagnostic at the start of `emit_diagnostic` and then
2222
/// passed around as a reference thereafter.
2323
fn to_fluent_args<'arg>(&self, args: &[DiagnosticArg<'arg>]) -> FluentArgs<'arg> {
24-
FromIterator::from_iter(args.to_vec().drain(..))
24+
FromIterator::from_iter(args.iter().cloned())
2525
}
2626

2727
/// Convert `DiagnosticMessage`s to a string, performing translation if necessary.

compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ impl DiagnosticDeriveBuilder {
239239
}
240240
}
241241

242-
Ok(tokens.drain(..).collect())
242+
Ok(tokens.into_iter().collect())
243243
}
244244

245245
fn generate_field_attrs_code(&mut self, binding_info: &BindingInfo<'_>) -> TokenStream {

compiler/rustc_typeck/src/check/writeback.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
501501

502502
if !errors_buffer.is_empty() {
503503
errors_buffer.sort_by_key(|diag| diag.span.primary_span());
504-
for mut diag in errors_buffer.drain(..) {
504+
for mut diag in errors_buffer {
505505
self.tcx().sess.diagnostic().emit_diagnostic(&mut diag);
506506
}
507507
}

0 commit comments

Comments
 (0)