diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index c1bbc601560..ecaafd0fc26 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -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); diff --git a/compiler/rustc_parse/src/parser/attr_wrapper.rs b/compiler/rustc_parse/src/parser/attr_wrapper.rs index ed54af9f53f..b564f4ad92c 100644 --- a/compiler/rustc_parse/src/parser/attr_wrapper.rs +++ b/compiler/rustc_parse/src/parser/attr_wrapper.rs @@ -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( 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) }) diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index f2d79ce756c..f0ea1dfe297 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -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] { diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index b08d2b376a6..d41edea6a25 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -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, ); diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index 6b230210888..4bab9935501 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -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, diff --git a/compiler/rustc_typeck/src/astconv/generics.rs b/compiler/rustc_typeck/src/astconv/generics.rs index 40aa27a29e9..ad0da4bed45 100644 --- a/compiler/rustc_typeck/src/astconv/generics.rs +++ b/compiler/rustc_typeck/src/astconv/generics.rs @@ -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::>(); param_types_present.sort_by_key(|(ord, _)| *ord); let (mut param_types_present, ordered_params): ( diff --git a/compiler/rustc_typeck/src/check/upvar.rs b/compiler/rustc_typeck/src/check/upvar.rs index dd8f943b985..0afc153300b 100644 --- a/compiler/rustc_typeck/src/check/upvar.rs +++ b/compiler/rustc_typeck/src/check/upvar.rs @@ -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, diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 5441a7bd29e..756e4f3b127 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -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, diff --git a/src/librustdoc/html/render/search_index.rs b/src/librustdoc/html/render/search_index.rs index d672f0bb599..8eb9c07f8a7 100644 --- a/src/librustdoc/html/render/search_index.rs +++ b/src/librustdoc/html/render/search_index.rs @@ -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) } diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index 7b1b059e14d..b78f8f2b4f1 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -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 { diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index e168a81890c..11d0798d553 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1703,7 +1703,7 @@ fn build_all_auxiliary(&self, rustc: &mut Command) -> PathBuf { fn compose_and_run_compiler(&self, mut rustc: Command, input: Option) -> 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, diff --git a/src/tools/unicode-table-generator/src/raw_emitter.rs b/src/tools/unicode-table-generator/src/raw_emitter.rs index 5aca86ba089..13eed7b1099 100644 --- a/src/tools/unicode-table-generator/src/raw_emitter.rs +++ b/src/tools/unicode-table-generator/src/raw_emitter.rs @@ -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::>(); + let chunk_map = + chunks.iter().enumerate().map(|(idx, &chunk)| (chunk, idx)).collect::>(); let mut chunk_indices = Vec::new(); for chunk in compressed_words.chunks(chunk_length) { chunk_indices.push(chunk_map[chunk]);