Skip to content

use .iter() instead of .into_iter() on references #69572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2291,13 +2291,13 @@ impl<'tcx> TyCtxt<'tcx> {

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

pub fn mk_tup<I: InternAs<[Ty<'tcx>], Ty<'tcx>>>(self, iter: I) -> I::Output {
iter.intern_with(|ts| {
let kinds: Vec<_> = ts.into_iter().map(|&t| GenericArg::from(t)).collect();
let kinds: Vec<_> = ts.iter().map(|&t| GenericArg::from(t)).collect();
self.mk_ty(Tuple(self.intern_substs(&kinds)))
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_builtin_macros/proc_macro_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl<'a> CollectProcMacros<'a> {
.span_err(attr.span(), "attribute must be of form: `attributes(foo, bar)`");
&[]
})
.into_iter()
.iter()
.filter_map(|attr| {
let attr = match attr.meta_item() {
Some(meta_item) => meta_item,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_infer/infer/canonical/query_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ pub fn make_query_region_constraints<'tcx>(
assert!(givens.is_empty());

let outlives: Vec<_> = constraints
.into_iter()
.iter()
.map(|(k, _)| match *k {
// Swap regions because we are going from sub (<=) to outlives
// (>=).
Expand Down
6 changes: 2 additions & 4 deletions src/librustc_infer/traits/on_unimplemented.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,8 @@ impl<'tcx> OnUnimplementedDirective {
}
}

let options: FxHashMap<Symbol, String> = options
.into_iter()
.filter_map(|(k, v)| v.as_ref().map(|v| (*k, v.to_owned())))
.collect();
let options: FxHashMap<Symbol, String> =
options.iter().filter_map(|(k, v)| v.as_ref().map(|v| (*k, v.to_owned()))).collect();
OnUnimplementedNote {
label: label.map(|l| l.format(tcx, trait_ref, &options)),
message: message.map(|m| m.format(tcx, trait_ref, &options)),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_infer/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2411,7 +2411,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {

types
.skip_binder()
.into_iter()
.iter()
.flat_map(|ty| {
// binder moved -\
let ty: ty::Binder<Ty<'tcx>> = ty::Binder::bind(ty); // <----/
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ impl EarlyLintPass for DeprecatedAttr {
}

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

// Accumulate a single span for sugared doc comments.
let mut sugared_span: Option<Span> = None;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/diagnostics/move_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/dataflow/generic/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ impl RustcMirAttrs {
let mut ret = RustcMirAttrs::default();

let rustc_mir_attrs = attrs
.into_iter()
.iter()
.filter(|attr| attr.check_name(sym::rustc_mir))
.flat_map(|attr| attr.meta_item_list().into_iter().flat_map(|v| v.into_iter()));

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/dataflow/impls/borrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
.local_map
.get(&place.local)
.into_iter()
.flat_map(|bs| bs.into_iter())
.flat_map(|bs| bs.iter())
.copied();

// If the borrowed place is a local with no projections, all other borrows of this
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
&self,
ops: &[mir::Operand<'tcx>],
) -> InterpResult<'tcx, Vec<OpTy<'tcx, M::PointerTag>>> {
ops.into_iter().map(|op| self.eval_operand(op, None)).collect()
ops.iter().map(|op| self.eval_operand(op, None)).collect()
}

// Used when the miri-engine runs into a constant and for extracting information from constants
Expand Down
6 changes: 2 additions & 4 deletions src/librustc_mir/monomorphize/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,8 @@ fn record_accesses<'tcx>(
// We collect this into a `SmallVec` to avoid calling `is_inlining_candidate` in the lock.
// FIXME: Call `is_inlining_candidate` when pushing to `neighbors` in `collect_items_rec`
// instead to avoid creating this `SmallVec`.
let accesses: SmallVec<[_; 128]> = callees
.into_iter()
.map(|mono_item| (*mono_item, is_inlining_candidate(mono_item)))
.collect();
let accesses: SmallVec<[_; 128]> =
callees.iter().map(|mono_item| (*mono_item, is_inlining_candidate(mono_item))).collect();

inlining_map.lock_mut().record_accesses(caller, &accesses);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/check_unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) {
}
}

let mut unsafe_blocks: Vec<_> = unsafe_blocks.into_iter().collect();
let mut unsafe_blocks: Vec<_> = unsafe_blocks.iter().collect();
unsafe_blocks.sort_by_cached_key(|(hir_id, _)| tcx.hir().hir_to_node_id(*hir_id));
let used_unsafe: FxHashSet<_> =
unsafe_blocks.iter().flat_map(|&&(id, used)| used.then_some(id)).collect();
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/uninhabited_enum_branching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl<'tcx> MirPass<'tcx> for UninhabitedEnumBranching {
&mut body.basic_blocks_mut()[bb].terminator_mut().kind
{
let vals = &*values;
let zipped = vals.iter().zip(targets.into_iter());
let zipped = vals.iter().zip(targets.iter());

let mut matched_values = Vec::with_capacity(allowed_variants.len());
let mut matched_targets = Vec::with_capacity(allowed_variants.len() + 1);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1425,7 +1425,7 @@ crate fn show_candidates(
// we want consistent results across executions, but candidates are produced
// by iterating through a hash map, so make sure they are ordered:
let mut path_strings: Vec<_> =
candidates.into_iter().map(|c| path_names_to_string(&c.path)).collect();
candidates.iter().map(|c| path_names_to_string(&c.path)).collect();
path_strings.sort();
path_strings.dedup();

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_save_analysis/sig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ impl Sig for ast::Item {
sig.text.push_str(" = ");
let ty = match ty {
Some(ty) => ty.make(offset + sig.text.len(), id, scx)?,
None => Err("Ty")?,
None => return Err("Ty"),
};
sig.text.push_str(&ty.text);
sig.text.push(';');
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_span/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ impl SourceMap {
.unwrap_or_else(|x| x);
let special_chars = end_width_idx - start_width_idx;
let non_narrow: usize = f.non_narrow_chars[start_width_idx..end_width_idx]
.into_iter()
.iter()
.map(|x| x.width())
.sum();
col.0 - special_chars + non_narrow
Expand All @@ -413,7 +413,7 @@ impl SourceMap {
.binary_search_by_key(&pos, |x| x.pos())
.unwrap_or_else(|x| x);
let non_narrow: usize =
f.non_narrow_chars[0..end_width_idx].into_iter().map(|x| x.width()).sum();
f.non_narrow_chars[0..end_width_idx].iter().map(|x| x.width()).sum();
chpos.0 - end_width_idx + non_narrow
};
Loc { file: f, line: 0, col: chpos, col_display }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_traits/lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ fn program_clauses_for_trait(tcx: TyCtxt<'_>, def_id: DefId) -> Clauses<'_> {

// `WellFormed(WC)`
let wf_conditions = where_clauses
.into_iter()
.iter()
.map(|wc| wc.subst(tcx, bound_vars))
.map(|wc| wc.map_bound(|goal| goal.into_well_formed_goal()));

Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2388,9 +2388,9 @@ impl Clean<TypeBindingKind> for hir::TypeBindingKind<'_> {
hir::TypeBindingKind::Equality { ref ty } => {
TypeBindingKind::Equality { ty: ty.clean(cx) }
}
hir::TypeBindingKind::Constraint { ref bounds } => TypeBindingKind::Constraint {
bounds: bounds.into_iter().map(|b| b.clean(cx)).collect(),
},
hir::TypeBindingKind::Constraint { ref bounds } => {
TypeBindingKind::Constraint { bounds: bounds.iter().map(|b| b.clean(cx)).collect() }
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ impl Markdown<'_> {
return String::new();
}
let replacer = |_: &str, s: &str| {
if let Some(&(_, ref replace)) = links.into_iter().find(|link| &*link.0 == s) {
if let Some(&(_, ref replace)) = links.iter().find(|link| &*link.0 == s) {
Some((replace.clone(), s.to_owned()))
} else {
None
Expand Down Expand Up @@ -816,7 +816,7 @@ impl MarkdownSummaryLine<'_> {
}

let replacer = |_: &str, s: &str| {
if let Some(&(_, ref replace)) = links.into_iter().find(|link| &*link.0 == s) {
if let Some(&(_, ref replace)) = links.iter().find(|link| &*link.0 == s) {
Some((replace.clone(), s.to_owned()))
} else {
None
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ fn get_index_type_name(clean_type: &clean::Type, accept_generic: bool) -> Option
match *clean_type {
clean::ResolvedPath { ref path, .. } => {
let segments = &path.segments;
let path_segment = segments.into_iter().last().unwrap_or_else(|| panic!(
let path_segment = segments.iter().last().unwrap_or_else(|| panic!(
"get_index_type_name(clean_type: {:?}, accept_generic: {:?}) had length zero path",
clean_type, accept_generic
));
Expand Down