mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-16 17:03:35 +00:00
Use more into_iter
rather than drain(..)
This commit is contained in:
parent
b96fa1a25c
commit
97b1a6146c
@ -555,7 +555,7 @@ impl TokenStreamBuilder {
|
|||||||
|
|
||||||
// Get the first stream, which will become the result stream.
|
// Get the first stream, which will become the result stream.
|
||||||
// If it's `None`, create an empty 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;
|
let mut res_stream_lrc = iter.next().unwrap().0;
|
||||||
|
|
||||||
// Append the subsequent elements to the result stream, after
|
// Append the subsequent elements to the result stream, after
|
||||||
|
@ -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
|
/// It is up to the caller to make sure that the elements are sorted by key
|
||||||
/// and that there are no duplicates.
|
/// and that there are no duplicates.
|
||||||
#[inline]
|
#[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() {
|
if elements.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -173,28 +173,28 @@ impl<K: Ord, V> SortedMap<K, V> {
|
|||||||
|
|
||||||
let start_index = self.lookup_index_for(&elements[0].0);
|
let start_index = self.lookup_index_for(&elements[0].0);
|
||||||
|
|
||||||
let drain = match start_index {
|
let elements = match start_index {
|
||||||
Ok(index) => {
|
Ok(index) => {
|
||||||
let mut drain = elements.drain(..);
|
let mut elements = elements.into_iter();
|
||||||
self.data[index] = drain.next().unwrap();
|
self.data[index] = elements.next().unwrap();
|
||||||
drain
|
elements
|
||||||
}
|
}
|
||||||
Err(index) => {
|
Err(index) => {
|
||||||
if index == self.data.len() || elements.last().unwrap().0 < self.data[index].0 {
|
if index == self.data.len() || elements.last().unwrap().0 < self.data[index].0 {
|
||||||
// We can copy the whole range without having to mix with
|
// We can copy the whole range without having to mix with
|
||||||
// existing elements.
|
// existing elements.
|
||||||
self.data.splice(index..index, elements.drain(..));
|
self.data.splice(index..index, elements.into_iter());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut drain = elements.drain(..);
|
let mut elements = elements.into_iter();
|
||||||
self.data.insert(index, drain.next().unwrap());
|
self.data.insert(index, elements.next().unwrap());
|
||||||
drain
|
elements
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Insert the rest
|
// Insert the rest
|
||||||
for (k, v) in drain {
|
for (k, v) in elements {
|
||||||
self.insert(k, v);
|
self.insert(k, v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -981,12 +981,12 @@ impl Diagnostic {
|
|||||||
fn sub_with_highlights<M: Into<SubdiagnosticMessage>>(
|
fn sub_with_highlights<M: Into<SubdiagnosticMessage>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
level: Level,
|
level: Level,
|
||||||
mut message: Vec<(M, Style)>,
|
message: Vec<(M, Style)>,
|
||||||
span: MultiSpan,
|
span: MultiSpan,
|
||||||
render_span: Option<MultiSpan>,
|
render_span: Option<MultiSpan>,
|
||||||
) {
|
) {
|
||||||
let message = message
|
let message = message
|
||||||
.drain(..)
|
.into_iter()
|
||||||
.map(|m| (self.subdiagnostic_message_to_diagnostic_message(m.0), m.1))
|
.map(|m| (self.subdiagnostic_message_to_diagnostic_message(m.0), m.1))
|
||||||
.collect();
|
.collect();
|
||||||
let sub = SubDiagnostic { level, message, span, render_span };
|
let sub = SubDiagnostic { level, message, span, render_span };
|
||||||
|
@ -21,7 +21,7 @@ pub trait Translate {
|
|||||||
/// Typically performed once for each diagnostic at the start of `emit_diagnostic` and then
|
/// Typically performed once for each diagnostic at the start of `emit_diagnostic` and then
|
||||||
/// passed around as a reference thereafter.
|
/// passed around as a reference thereafter.
|
||||||
fn to_fluent_args<'arg>(&self, args: &[DiagnosticArg<'arg>]) -> FluentArgs<'arg> {
|
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.
|
/// Convert `DiagnosticMessage`s to a string, performing translation if necessary.
|
||||||
|
@ -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 {
|
fn generate_field_attrs_code(&mut self, binding_info: &BindingInfo<'_>) -> TokenStream {
|
||||||
|
@ -501,7 +501,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
|||||||
|
|
||||||
if !errors_buffer.is_empty() {
|
if !errors_buffer.is_empty() {
|
||||||
errors_buffer.sort_by_key(|diag| diag.span.primary_span());
|
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);
|
self.tcx().sess.diagnostic().emit_diagnostic(&mut diag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user