Rollup merge of #69572 - matthiaskrgr:try_err_and_iter_on_ref, r=Centril

use .iter() instead of .into_iter() on references
This commit is contained in:
Dylan DPC 2020-02-29 18:54:01 +01:00 committed by GitHub
commit 7d43997053
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 27 additions and 31 deletions

View File

@ -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)))
})
}

View File

@ -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,

View File

@ -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
// (>=).

View File

@ -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)),

View File

@ -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); // <----/

View File

@ -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;

View File

@ -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;

View File

@ -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()));

View File

@ -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

View File

@ -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

View File

@ -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);
}

View File

@ -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();

View File

@ -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);

View File

@ -1426,7 +1426,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();

View File

@ -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(';');

View File

@ -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
@ -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 }

View File

@ -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()));

View File

@ -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() }
}
}
}
}

View File

@ -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
@ -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

View File

@ -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
));