Skip to content

Commit 7d43997

Browse files
authored
Rollup merge of #69572 - matthiaskrgr:try_err_and_iter_on_ref, r=Centril
use .iter() instead of .into_iter() on references
2 parents b22631b + de7c40c commit 7d43997

File tree

20 files changed

+27
-31
lines changed

20 files changed

+27
-31
lines changed

src/librustc/ty/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2291,13 +2291,13 @@ impl<'tcx> TyCtxt<'tcx> {
22912291

22922292
#[inline]
22932293
pub fn intern_tup(self, ts: &[Ty<'tcx>]) -> Ty<'tcx> {
2294-
let kinds: Vec<_> = ts.into_iter().map(|&t| GenericArg::from(t)).collect();
2294+
let kinds: Vec<_> = ts.iter().map(|&t| GenericArg::from(t)).collect();
22952295
self.mk_ty(Tuple(self.intern_substs(&kinds)))
22962296
}
22972297

22982298
pub fn mk_tup<I: InternAs<[Ty<'tcx>], Ty<'tcx>>>(self, iter: I) -> I::Output {
22992299
iter.intern_with(|ts| {
2300-
let kinds: Vec<_> = ts.into_iter().map(|&t| GenericArg::from(t)).collect();
2300+
let kinds: Vec<_> = ts.iter().map(|&t| GenericArg::from(t)).collect();
23012301
self.mk_ty(Tuple(self.intern_substs(&kinds)))
23022302
})
23032303
}

src/librustc_builtin_macros/proc_macro_harness.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<'a> CollectProcMacros<'a> {
149149
.span_err(attr.span(), "attribute must be of form: `attributes(foo, bar)`");
150150
&[]
151151
})
152-
.into_iter()
152+
.iter()
153153
.filter_map(|attr| {
154154
let attr = match attr.meta_item() {
155155
Some(meta_item) => meta_item,

src/librustc_infer/infer/canonical/query_response.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ pub fn make_query_region_constraints<'tcx>(
630630
assert!(givens.is_empty());
631631

632632
let outlives: Vec<_> = constraints
633-
.into_iter()
633+
.iter()
634634
.map(|(k, _)| match *k {
635635
// Swap regions because we are going from sub (<=) to outlives
636636
// (>=).

src/librustc_infer/traits/on_unimplemented.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,8 @@ impl<'tcx> OnUnimplementedDirective {
237237
}
238238
}
239239

240-
let options: FxHashMap<Symbol, String> = options
241-
.into_iter()
242-
.filter_map(|(k, v)| v.as_ref().map(|v| (*k, v.to_owned())))
243-
.collect();
240+
let options: FxHashMap<Symbol, String> =
241+
options.iter().filter_map(|(k, v)| v.as_ref().map(|v| (*k, v.to_owned()))).collect();
244242
OnUnimplementedNote {
245243
label: label.map(|l| l.format(tcx, trait_ref, &options)),
246244
message: message.map(|m| m.format(tcx, trait_ref, &options)),

src/librustc_infer/traits/select.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2411,7 +2411,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
24112411

24122412
types
24132413
.skip_binder()
2414-
.into_iter()
2414+
.iter()
24152415
.flat_map(|ty| {
24162416
// binder moved -\
24172417
let ty: ty::Binder<Ty<'tcx>> = ty::Binder::bind(ty); // <----/

src/librustc_lint/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ impl EarlyLintPass for DeprecatedAttr {
739739
}
740740

741741
fn warn_if_doc(cx: &EarlyContext<'_>, node_span: Span, node_kind: &str, attrs: &[ast::Attribute]) {
742-
let mut attrs = attrs.into_iter().peekable();
742+
let mut attrs = attrs.iter().peekable();
743743

744744
// Accumulate a single span for sugared doc comments.
745745
let mut sugared_span: Option<Span> = None;

src/librustc_mir/borrow_check/diagnostics/move_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
519519
}
520520

521521
fn add_move_error_details(&self, err: &mut DiagnosticBuilder<'a>, binds_to: &[Local]) {
522-
for (j, local) in binds_to.into_iter().enumerate() {
522+
for (j, local) in binds_to.iter().enumerate() {
523523
let bind_to = &self.body.local_decls[*local];
524524
let binding_span = bind_to.source_info.span;
525525

src/librustc_mir/dataflow/generic/engine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ impl RustcMirAttrs {
419419
let mut ret = RustcMirAttrs::default();
420420

421421
let rustc_mir_attrs = attrs
422-
.into_iter()
422+
.iter()
423423
.filter(|attr| attr.check_name(sym::rustc_mir))
424424
.flat_map(|attr| attr.meta_item_list().into_iter().flat_map(|v| v.into_iter()));
425425

src/librustc_mir/dataflow/impls/borrows.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
195195
.local_map
196196
.get(&place.local)
197197
.into_iter()
198-
.flat_map(|bs| bs.into_iter())
198+
.flat_map(|bs| bs.iter())
199199
.copied();
200200

201201
// If the borrowed place is a local with no projections, all other borrows of this

src/librustc_mir/interpret/operand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
509509
&self,
510510
ops: &[mir::Operand<'tcx>],
511511
) -> InterpResult<'tcx, Vec<OpTy<'tcx, M::PointerTag>>> {
512-
ops.into_iter().map(|op| self.eval_operand(op, None)).collect()
512+
ops.iter().map(|op| self.eval_operand(op, None)).collect()
513513
}
514514

515515
// Used when the miri-engine runs into a constant and for extracting information from constants

src/librustc_mir/monomorphize/collector.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,8 @@ fn record_accesses<'tcx>(
401401
// We collect this into a `SmallVec` to avoid calling `is_inlining_candidate` in the lock.
402402
// FIXME: Call `is_inlining_candidate` when pushing to `neighbors` in `collect_items_rec`
403403
// instead to avoid creating this `SmallVec`.
404-
let accesses: SmallVec<[_; 128]> = callees
405-
.into_iter()
406-
.map(|mono_item| (*mono_item, is_inlining_candidate(mono_item)))
407-
.collect();
404+
let accesses: SmallVec<[_; 128]> =
405+
callees.iter().map(|mono_item| (*mono_item, is_inlining_candidate(mono_item))).collect();
408406

409407
inlining_map.lock_mut().record_accesses(caller, &accesses);
410408
}

src/librustc_mir/transform/check_unsafety.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) {
644644
}
645645
}
646646

647-
let mut unsafe_blocks: Vec<_> = unsafe_blocks.into_iter().collect();
647+
let mut unsafe_blocks: Vec<_> = unsafe_blocks.iter().collect();
648648
unsafe_blocks.sort_by_cached_key(|(hir_id, _)| tcx.hir().hir_to_node_id(*hir_id));
649649
let used_unsafe: FxHashSet<_> =
650650
unsafe_blocks.iter().flat_map(|&&(id, used)| used.then_some(id)).collect();

src/librustc_mir/transform/uninhabited_enum_branching.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<'tcx> MirPass<'tcx> for UninhabitedEnumBranching {
100100
&mut body.basic_blocks_mut()[bb].terminator_mut().kind
101101
{
102102
let vals = &*values;
103-
let zipped = vals.iter().zip(targets.into_iter());
103+
let zipped = vals.iter().zip(targets.iter());
104104

105105
let mut matched_values = Vec::with_capacity(allowed_variants.len());
106106
let mut matched_targets = Vec::with_capacity(allowed_variants.len() + 1);

src/librustc_resolve/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1426,7 +1426,7 @@ crate fn show_candidates(
14261426
// we want consistent results across executions, but candidates are produced
14271427
// by iterating through a hash map, so make sure they are ordered:
14281428
let mut path_strings: Vec<_> =
1429-
candidates.into_iter().map(|c| path_names_to_string(&c.path)).collect();
1429+
candidates.iter().map(|c| path_names_to_string(&c.path)).collect();
14301430
path_strings.sort();
14311431
path_strings.dedup();
14321432

src/librustc_save_analysis/sig.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ impl Sig for ast::Item {
430430
sig.text.push_str(" = ");
431431
let ty = match ty {
432432
Some(ty) => ty.make(offset + sig.text.len(), id, scx)?,
433-
None => Err("Ty")?,
433+
None => return Err("Ty"),
434434
};
435435
sig.text.push_str(&ty.text);
436436
sig.text.push(';');

src/librustc_span/source_map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ impl SourceMap {
395395
.unwrap_or_else(|x| x);
396396
let special_chars = end_width_idx - start_width_idx;
397397
let non_narrow: usize = f.non_narrow_chars[start_width_idx..end_width_idx]
398-
.into_iter()
398+
.iter()
399399
.map(|x| x.width())
400400
.sum();
401401
col.0 - special_chars + non_narrow
@@ -413,7 +413,7 @@ impl SourceMap {
413413
.binary_search_by_key(&pos, |x| x.pos())
414414
.unwrap_or_else(|x| x);
415415
let non_narrow: usize =
416-
f.non_narrow_chars[0..end_width_idx].into_iter().map(|x| x.width()).sum();
416+
f.non_narrow_chars[0..end_width_idx].iter().map(|x| x.width()).sum();
417417
chpos.0 - end_width_idx + non_narrow
418418
};
419419
Loc { file: f, line: 0, col: chpos, col_display }

src/librustc_traits/lowering/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ fn program_clauses_for_trait(tcx: TyCtxt<'_>, def_id: DefId) -> Clauses<'_> {
256256

257257
// `WellFormed(WC)`
258258
let wf_conditions = where_clauses
259-
.into_iter()
259+
.iter()
260260
.map(|wc| wc.subst(tcx, bound_vars))
261261
.map(|wc| wc.map_bound(|goal| goal.into_well_formed_goal()));
262262

src/librustdoc/clean/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2388,9 +2388,9 @@ impl Clean<TypeBindingKind> for hir::TypeBindingKind<'_> {
23882388
hir::TypeBindingKind::Equality { ref ty } => {
23892389
TypeBindingKind::Equality { ty: ty.clean(cx) }
23902390
}
2391-
hir::TypeBindingKind::Constraint { ref bounds } => TypeBindingKind::Constraint {
2392-
bounds: bounds.into_iter().map(|b| b.clean(cx)).collect(),
2393-
},
2391+
hir::TypeBindingKind::Constraint { ref bounds } => {
2392+
TypeBindingKind::Constraint { bounds: bounds.iter().map(|b| b.clean(cx)).collect() }
2393+
}
23942394
}
23952395
}
23962396
}

src/librustdoc/html/markdown.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ impl Markdown<'_> {
738738
return String::new();
739739
}
740740
let replacer = |_: &str, s: &str| {
741-
if let Some(&(_, ref replace)) = links.into_iter().find(|link| &*link.0 == s) {
741+
if let Some(&(_, ref replace)) = links.iter().find(|link| &*link.0 == s) {
742742
Some((replace.clone(), s.to_owned()))
743743
} else {
744744
None
@@ -816,7 +816,7 @@ impl MarkdownSummaryLine<'_> {
816816
}
817817

818818
let replacer = |_: &str, s: &str| {
819-
if let Some(&(_, ref replace)) = links.into_iter().find(|link| &*link.0 == s) {
819+
if let Some(&(_, ref replace)) = links.iter().find(|link| &*link.0 == s) {
820820
Some((replace.clone(), s.to_owned()))
821821
} else {
822822
None

src/librustdoc/html/render/cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ fn get_index_type_name(clean_type: &clean::Type, accept_generic: bool) -> Option
670670
match *clean_type {
671671
clean::ResolvedPath { ref path, .. } => {
672672
let segments = &path.segments;
673-
let path_segment = segments.into_iter().last().unwrap_or_else(|| panic!(
673+
let path_segment = segments.iter().last().unwrap_or_else(|| panic!(
674674
"get_index_type_name(clean_type: {:?}, accept_generic: {:?}) had length zero path",
675675
clean_type, accept_generic
676676
));

0 commit comments

Comments
 (0)