Auto merge of #100497 - kadiwa4:remove_clone_into_iter, r=cjgillot
Avoid cloning a collection only to iterate over it `@rustbot` label: +C-cleanup
This commit is contained in:
commit
ce36e88256
@ -383,8 +383,7 @@ fn visit_ty(&mut self, ty: &'a ast::Ty) {
|
||||
// Place bound generic params on a stack, to extract them when a type is encountered.
|
||||
fn visit_poly_trait_ref(&mut self, trait_ref: &'a ast::PolyTraitRef) {
|
||||
let stack_len = self.bound_generic_params_stack.len();
|
||||
self.bound_generic_params_stack
|
||||
.extend(trait_ref.bound_generic_params.clone().into_iter());
|
||||
self.bound_generic_params_stack.extend(trait_ref.bound_generic_params.iter().cloned());
|
||||
|
||||
visit::walk_poly_trait_ref(self, trait_ref);
|
||||
|
||||
|
@ -117,7 +117,7 @@ fn create_token_stream(&self) -> AttrAnnotatedTokenStream {
|
||||
|
||||
if !self.replace_ranges.is_empty() {
|
||||
let mut tokens: Vec<_> = tokens.collect();
|
||||
let mut replace_ranges = self.replace_ranges.clone();
|
||||
let mut replace_ranges = self.replace_ranges.to_vec();
|
||||
replace_ranges.sort_by_key(|(range, _)| range.start);
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
@ -147,7 +147,7 @@ fn create_token_stream(&self) -> AttrAnnotatedTokenStream {
|
||||
// start position, we ensure that any replace range which encloses
|
||||
// another replace range will capture the *replaced* tokens for the inner
|
||||
// range, not the original tokens.
|
||||
for (range, new_tokens) in replace_ranges.iter().rev() {
|
||||
for (range, new_tokens) in replace_ranges.into_iter().rev() {
|
||||
assert!(!range.is_empty(), "Cannot replace an empty range: {:?}", range);
|
||||
// Replace ranges are only allowed to decrease the number of tokens.
|
||||
assert!(
|
||||
@ -166,7 +166,7 @@ fn create_token_stream(&self) -> AttrAnnotatedTokenStream {
|
||||
|
||||
tokens.splice(
|
||||
(range.start as usize)..(range.end as usize),
|
||||
new_tokens.clone().into_iter().chain(filler),
|
||||
new_tokens.into_iter().chain(filler),
|
||||
);
|
||||
}
|
||||
make_token_stream(tokens.into_iter(), self.break_last_token)
|
||||
@ -322,7 +322,7 @@ pub fn collect_tokens_trailing_token<R: HasAttrs + HasTokens>(
|
||||
self.capture_state.replace_ranges[replace_ranges_start..replace_ranges_end]
|
||||
.iter()
|
||||
.cloned()
|
||||
.chain(inner_attr_replace_ranges.clone().into_iter())
|
||||
.chain(inner_attr_replace_ranges.iter().cloned())
|
||||
.map(|(range, tokens)| {
|
||||
((range.start - start_calls)..(range.end - start_calls), tokens)
|
||||
})
|
||||
|
@ -759,7 +759,7 @@ pub(super) fn diagnostic(&self) -> &'a Handler {
|
||||
/// This is to avoid losing unclosed delims errors `create_snapshot_for_diagnostic` clears.
|
||||
pub(super) fn restore_snapshot(&mut self, snapshot: SnapshotParser<'a>) {
|
||||
*self = snapshot.parser;
|
||||
self.unclosed_delims.extend(snapshot.unclosed_delims.clone());
|
||||
self.unclosed_delims.extend(snapshot.unclosed_delims);
|
||||
}
|
||||
|
||||
pub fn unclosed_delims(&self) -> &[UnmatchedBrace] {
|
||||
|
@ -2350,7 +2350,7 @@ fn add_missing_lifetime_specifiers_label(
|
||||
err.multipart_suggestion_verbose(
|
||||
message,
|
||||
std::iter::once((span, intro_sugg))
|
||||
.chain(spans_suggs.clone())
|
||||
.chain(spans_suggs.iter().cloned())
|
||||
.collect(),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
|
@ -341,7 +341,7 @@ fn evaluate_predicates(
|
||||
}
|
||||
}
|
||||
|
||||
let obligations = impl_source.clone().nested_obligations().into_iter();
|
||||
let obligations = impl_source.borrow_nested_obligations().iter().cloned();
|
||||
|
||||
if !self.evaluate_nested_obligations(
|
||||
ty,
|
||||
|
@ -298,9 +298,8 @@ pub fn create_substs_for_generic_args<'a>(
|
||||
// show that order to the user as a possible order for the parameters
|
||||
let mut param_types_present = defs
|
||||
.params
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|param| (param.kind.to_ord(), param))
|
||||
.iter()
|
||||
.map(|param| (param.kind.to_ord(), param.clone()))
|
||||
.collect::<Vec<(ParamKindOrd, GenericParamDef)>>();
|
||||
param_types_present.sort_by_key(|(ord, _)| *ord);
|
||||
let (mut param_types_present, ordered_params): (
|
||||
|
@ -1217,7 +1217,7 @@ fn compute_2229_migrations(
|
||||
|
||||
// Combine all the reasons of why the root variable should be captured as a result of
|
||||
// auto trait implementation issues
|
||||
auto_trait_migration_reasons.extend(capture_trait_reasons.clone());
|
||||
auto_trait_migration_reasons.extend(capture_trait_reasons.iter().copied());
|
||||
|
||||
diagnostics_info.push(MigrationLintNote {
|
||||
captures_info,
|
||||
|
@ -525,8 +525,8 @@ fn param_env_to_generics(
|
||||
GenericBound::TraitBound(ref mut p, _) => {
|
||||
// Insert regions into the for_generics hash map first, to ensure
|
||||
// that we don't end up with duplicate bounds (e.g., for<'b, 'b>)
|
||||
for_generics.extend(p.generic_params.clone());
|
||||
p.generic_params = for_generics.into_iter().collect();
|
||||
for_generics.extend(p.generic_params.drain(..));
|
||||
p.generic_params.extend(for_generics);
|
||||
self.is_fn_trait(&p.trait_)
|
||||
}
|
||||
_ => false,
|
||||
|
@ -544,10 +544,15 @@ fn get_fn_inputs_and_outputs<'tcx>(
|
||||
(true, _) => (Some(impl_self), &func.generics),
|
||||
(_, true) => (Some(impl_self), impl_generics),
|
||||
(false, false) => {
|
||||
let mut params = func.generics.params.clone();
|
||||
params.extend(impl_generics.params.clone());
|
||||
let mut where_predicates = func.generics.where_predicates.clone();
|
||||
where_predicates.extend(impl_generics.where_predicates.clone());
|
||||
let params =
|
||||
func.generics.params.iter().chain(&impl_generics.params).cloned().collect();
|
||||
let where_predicates = func
|
||||
.generics
|
||||
.where_predicates
|
||||
.iter()
|
||||
.chain(&impl_generics.where_predicates)
|
||||
.cloned()
|
||||
.collect();
|
||||
combined_generics = clean::Generics { params, where_predicates };
|
||||
(Some(impl_self), &combined_generics)
|
||||
}
|
||||
|
@ -106,7 +106,9 @@ fn get_trait_items(&mut self) -> Vec<(types::Id, types::Item)> {
|
||||
// only need to synthesize items for external traits
|
||||
if !id.is_local() {
|
||||
let trait_item = &trait_item.trait_;
|
||||
trait_item.items.clone().into_iter().for_each(|i| self.item(i).unwrap());
|
||||
for item in &trait_item.items {
|
||||
self.item(item.clone()).unwrap();
|
||||
}
|
||||
let item_id = from_item_id(id.into(), self.tcx);
|
||||
Some((
|
||||
item_id.clone(),
|
||||
@ -274,10 +276,9 @@ fn after_krate(&mut self) -> Result<(), Error> {
|
||||
paths: self
|
||||
.cache
|
||||
.paths
|
||||
.clone()
|
||||
.into_iter()
|
||||
.chain(self.cache.external_paths.clone().into_iter())
|
||||
.map(|(k, (path, kind))| {
|
||||
.iter()
|
||||
.chain(&self.cache.external_paths)
|
||||
.map(|(&k, &(ref path, kind))| {
|
||||
(
|
||||
from_item_id(k.into(), self.tcx),
|
||||
types::ItemSummary {
|
||||
|
@ -1703,7 +1703,7 @@ fn build_all_auxiliary(&self, rustc: &mut Command) -> PathBuf {
|
||||
|
||||
fn compose_and_run_compiler(&self, mut rustc: Command, input: Option<String>) -> ProcRes {
|
||||
let aux_dir = self.build_all_auxiliary(&mut rustc);
|
||||
self.props.unset_rustc_env.clone().iter().fold(&mut rustc, |rustc, v| rustc.env_remove(v));
|
||||
self.props.unset_rustc_env.iter().fold(&mut rustc, Command::env_remove);
|
||||
rustc.envs(self.props.rustc_env.clone());
|
||||
self.compose_and_run(
|
||||
rustc,
|
||||
|
@ -121,12 +121,8 @@ fn emit_chunk_map(&mut self, zero_at: u8, compressed_words: &[u8], chunk_length:
|
||||
for chunk in compressed_words.chunks(chunk_length) {
|
||||
chunks.insert(chunk);
|
||||
}
|
||||
let chunk_map = chunks
|
||||
.clone()
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(idx, chunk)| (chunk, idx))
|
||||
.collect::<HashMap<_, _>>();
|
||||
let chunk_map =
|
||||
chunks.iter().enumerate().map(|(idx, &chunk)| (chunk, idx)).collect::<HashMap<_, _>>();
|
||||
let mut chunk_indices = Vec::new();
|
||||
for chunk in compressed_words.chunks(chunk_length) {
|
||||
chunk_indices.push(chunk_map[chunk]);
|
||||
|
Loading…
Reference in New Issue
Block a user