Rollup merge of #101165 - ldm0:drain_to_iter, r=cjgillot

Use more `into_iter` rather than `drain(..)`

Clearer semantic.
This commit is contained in:
Matthias Krüger 2022-08-31 21:30:13 +02:00 committed by GitHub
commit e5356712b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 16 deletions

View File

@ -555,7 +555,7 @@ impl TokenStreamBuilder {
// Get the first stream, which will become the result stream.
// If it's `None`, create an empty stream.
let mut iter = streams.drain(..);
let mut iter = streams.into_iter();
let mut res_stream_lrc = iter.next().unwrap().0;
// Append the subsequent elements to the result stream, after

View File

@ -164,7 +164,7 @@ impl<K: Ord, V> SortedMap<K, V> {
/// It is up to the caller to make sure that the elements are sorted by key
/// and that there are no duplicates.
#[inline]
pub fn insert_presorted(&mut self, mut elements: Vec<(K, V)>) {
pub fn insert_presorted(&mut self, elements: Vec<(K, V)>) {
if elements.is_empty() {
return;
}
@ -173,28 +173,28 @@ impl<K: Ord, V> SortedMap<K, V> {
let start_index = self.lookup_index_for(&elements[0].0);
let drain = match start_index {
let elements = match start_index {
Ok(index) => {
let mut drain = elements.drain(..);
self.data[index] = drain.next().unwrap();
drain
let mut elements = elements.into_iter();
self.data[index] = elements.next().unwrap();
elements
}
Err(index) => {
if index == self.data.len() || elements.last().unwrap().0 < self.data[index].0 {
// We can copy the whole range without having to mix with
// existing elements.
self.data.splice(index..index, elements.drain(..));
self.data.splice(index..index, elements.into_iter());
return;
}
let mut drain = elements.drain(..);
self.data.insert(index, drain.next().unwrap());
drain
let mut elements = elements.into_iter();
self.data.insert(index, elements.next().unwrap());
elements
}
};
// Insert the rest
for (k, v) in drain {
for (k, v) in elements {
self.insert(k, v);
}
}

View File

@ -974,12 +974,12 @@ impl Diagnostic {
fn sub_with_highlights<M: Into<SubdiagnosticMessage>>(
&mut self,
level: Level,
mut message: Vec<(M, Style)>,
message: Vec<(M, Style)>,
span: MultiSpan,
render_span: Option<MultiSpan>,
) {
let message = message
.drain(..)
.into_iter()
.map(|m| (self.subdiagnostic_message_to_diagnostic_message(m.0), m.1))
.collect();
let sub = SubDiagnostic { level, message, span, render_span };

View File

@ -21,7 +21,7 @@ pub trait Translate {
/// Typically performed once for each diagnostic at the start of `emit_diagnostic` and then
/// passed around as a reference thereafter.
fn to_fluent_args<'arg>(&self, args: &[DiagnosticArg<'arg>]) -> FluentArgs<'arg> {
FromIterator::from_iter(args.to_vec().drain(..))
FromIterator::from_iter(args.iter().cloned())
}
/// Convert `DiagnosticMessage`s to a string, performing translation if necessary.

View File

@ -239,7 +239,7 @@ impl DiagnosticDeriveBuilder {
}
}
Ok(tokens.drain(..).collect())
Ok(tokens.into_iter().collect())
}
fn generate_field_attrs_code(&mut self, binding_info: &BindingInfo<'_>) -> TokenStream {

View File

@ -501,7 +501,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
if !errors_buffer.is_empty() {
errors_buffer.sort_by_key(|diag| diag.span.primary_span());
for mut diag in errors_buffer.drain(..) {
for mut diag in errors_buffer {
self.tcx().sess.diagnostic().emit_diagnostic(&mut diag);
}
}