Skip to content

Commit fd70270

Browse files
author
Jorge Aparicio
committed
for x in xs.into_iter() -> for x in xs
Also `for x in option.into_iter()` -> `if let Some(x) = option`
1 parent d5f61b4 commit fd70270

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+78
-78
lines changed

src/compiletest/procsrv.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn run(lib_path: &str,
4040
let mut cmd = Command::new(prog);
4141
cmd.args(args);
4242
add_target_env(&mut cmd, lib_path, aux_path);
43-
for (key, val) in env.into_iter() {
43+
for (key, val) in env {
4444
cmd.env(key, val);
4545
}
4646

@@ -72,7 +72,7 @@ pub fn run_background(lib_path: &str,
7272
let mut cmd = Command::new(prog);
7373
cmd.args(args);
7474
add_target_env(&mut cmd, lib_path, aux_path);
75-
for (key, val) in env.into_iter() {
75+
for (key, val) in env {
7676
cmd.env(key, val);
7777
}
7878

src/compiletest/runtest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1503,7 +1503,7 @@ fn _arm_exec_compiled_test(config: &Config,
15031503

15041504
// run test via adb_run_wrapper
15051505
runargs.push("shell".to_string());
1506-
for (key, val) in env.into_iter() {
1506+
for (key, val) in env {
15071507
runargs.push(format!("{}={}", key, val));
15081508
}
15091509
runargs.push(format!("{}/adb_run_wrapper.sh", config.adb_test_dir));

src/libcollections/btree/map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
197197
pub fn clear(&mut self) {
198198
let b = self.b;
199199
// avoid recursive destructors by manually traversing the tree
200-
for _ in mem::replace(self, BTreeMap::with_b(b)).into_iter() {};
200+
for _ in mem::replace(self, BTreeMap::with_b(b)) {};
201201
}
202202

203203
// Searching in a B-Tree is pretty straightforward.

src/libcollections/dlist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ mod tests {
10611061
let mut sum = v;
10621062
sum.push_all(u.as_slice());
10631063
assert_eq!(sum.len(), m.len());
1064-
for elt in sum.into_iter() {
1064+
for elt in sum {
10651065
assert_eq!(m.pop_front(), Some(elt))
10661066
}
10671067
assert_eq!(n.len(), 0);

src/libcollections/slice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2699,7 +2699,7 @@ mod tests {
26992699
}
27002700
assert_eq!(cnt, 8);
27012701

2702-
for f in v.into_iter() {
2702+
for f in v {
27032703
assert!(f == Foo);
27042704
cnt += 1;
27052705
}

src/libcollections/vec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2333,7 +2333,7 @@ mod tests {
23332333
fn test_move_items() {
23342334
let vec = vec![1, 2, 3];
23352335
let mut vec2 : Vec<i32> = vec![];
2336-
for i in vec.into_iter() {
2336+
for i in vec {
23372337
vec2.push(i);
23382338
}
23392339
assert!(vec2 == vec![1, 2, 3]);
@@ -2353,7 +2353,7 @@ mod tests {
23532353
fn test_move_items_zero_sized() {
23542354
let vec = vec![(), (), ()];
23552355
let mut vec2 : Vec<()> = vec![];
2356-
for i in vec.into_iter() {
2356+
for i in vec {
23572357
vec2.push(i);
23582358
}
23592359
assert!(vec2 == vec![(), (), ()]);

src/libcollections/vec_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ mod test_map {
984984
let mut m = VecMap::new();
985985
m.insert(1, box 2);
986986
let mut called = false;
987-
for (k, v) in m.into_iter() {
987+
for (k, v) in m {
988988
assert!(!called);
989989
called = true;
990990
assert_eq!(k, 1);

src/libcore/fmt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ impl<'a> Formatter<'a> {
482482

483483
// Writes the sign if it exists, and then the prefix if it was requested
484484
let write_prefix = |&: f: &mut Formatter| {
485-
for c in sign.into_iter() {
485+
if let Some(c) = sign {
486486
let mut b = [0; 4];
487487
let n = c.encode_utf8(&mut b).unwrap_or(0);
488488
let b = unsafe { str::from_utf8_unchecked(&b[..n]) };

src/librustc/lint/context.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,11 @@ pub fn raw_emit_lint(sess: &Session, lint: &'static Lint,
417417
_ => sess.bug("impossible level in raw_emit_lint"),
418418
}
419419

420-
for note in note.into_iter() {
420+
if let Some(note) = note {
421421
sess.note(&note[]);
422422
}
423423

424-
for span in def.into_iter() {
424+
if let Some(span) = def {
425425
sess.span_note(span, "lint level defined here");
426426
}
427427
}
@@ -492,7 +492,7 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
492492
// specified closure
493493
let mut pushed = 0;
494494

495-
for result in gather_attrs(attrs).into_iter() {
495+
for result in gather_attrs(attrs) {
496496
let v = match result {
497497
Err(span) => {
498498
self.tcx.sess.span_err(span, "malformed lint attribute");
@@ -519,7 +519,7 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
519519
}
520520
};
521521

522-
for (lint_id, level, span) in v.into_iter() {
522+
for (lint_id, level, span) in v {
523523
let now = self.lints.get_level_source(lint_id).0;
524524
if now == Forbid && level != Forbid {
525525
let lint_name = lint_id.as_str();
@@ -727,7 +727,7 @@ impl<'a, 'tcx> IdVisitingOperation for Context<'a, 'tcx> {
727727
match self.tcx.sess.lints.borrow_mut().remove(&id) {
728728
None => {}
729729
Some(lints) => {
730-
for (lint_id, span, msg) in lints.into_iter() {
730+
for (lint_id, span, msg) in lints {
731731
self.span_lint(lint_id.lint, span, &msg[])
732732
}
733733
}

src/librustc/metadata/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,7 @@ fn encode_index<T, F>(rbml_w: &mut Encoder, index: Vec<entry<T>>, mut write_fn:
15891589
T: Hash<SipHasher>,
15901590
{
15911591
let mut buckets: Vec<Vec<entry<T>>> = (0..256u16).map(|_| Vec::new()).collect();
1592-
for elt in index.into_iter() {
1592+
for elt in index {
15931593
let mut s = SipHasher::new();
15941594
elt.val.hash(&mut s);
15951595
let h = s.finish() as uint;

src/librustc/metadata/loader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ impl<'a> Context<'a> {
425425
// libraries corresponds to the crate id and hash criteria that this
426426
// search is being performed for.
427427
let mut libraries = Vec::new();
428-
for (_hash, (rlibs, dylibs)) in candidates.into_iter() {
428+
for (_hash, (rlibs, dylibs)) in candidates {
429429
let mut metadata = None;
430430
let rlib = self.extract_one(rlibs, "rlib", &mut metadata);
431431
let dylib = self.extract_one(dylibs, "dylib", &mut metadata);
@@ -501,7 +501,7 @@ impl<'a> Context<'a> {
501501
}
502502
}
503503

504-
for (lib, kind) in m.into_iter() {
504+
for (lib, kind) in m {
505505
info!("{} reading metadata from: {}", flavor, lib.display());
506506
let metadata = match get_metadata_section(self.target.options.is_like_osx,
507507
&lib) {

src/librustc/middle/check_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl<'a> fmt::Debug for Matrix<'a> {
7777
let total_width = column_widths.iter().map(|n| *n).sum() + column_count * 3 + 1;
7878
let br = repeat('+').take(total_width).collect::<String>();
7979
try!(write!(f, "{}\n", br));
80-
for row in pretty_printed_matrix.into_iter() {
80+
for row in pretty_printed_matrix {
8181
try!(write!(f, "+"));
8282
for (column, pat_str) in row.into_iter().enumerate() {
8383
try!(write!(f, " "));

src/librustc/middle/dead.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ fn has_allow_dead_code_or_lang_attr(attrs: &[ast::Attribute]) -> bool {
318318
}
319319

320320
let dead_code = lint::builtin::DEAD_CODE.name_lower();
321-
for attr in lint::gather_attrs(attrs).into_iter() {
321+
for attr in lint::gather_attrs(attrs) {
322322
match attr {
323323
Ok((ref name, lint::Allow, _))
324324
if name.get() == dead_code => return true,

src/librustc/middle/subst.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ impl<T> VecPerParamSpace<T> {
352352
pub fn replace(&mut self, space: ParamSpace, elems: Vec<T>) {
353353
// FIXME (#15435): slow; O(n^2); could enhance vec to make it O(n).
354354
self.truncate(space, 0);
355-
for t in elems.into_iter() {
355+
for t in elems {
356356
self.push(space, t);
357357
}
358358
}

src/librustc/middle/traits/fulfill.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl<'tcx> FulfillmentContext<'tcx> {
125125
let mut selcx = SelectionContext::new(infcx, typer);
126126
let normalized = project::normalize_projection_type(&mut selcx, projection_ty, cause, 0);
127127

128-
for obligation in normalized.obligations.into_iter() {
128+
for obligation in normalized.obligations {
129129
self.register_predicate_obligation(infcx, obligation);
130130
}
131131

@@ -289,7 +289,7 @@ impl<'tcx> FulfillmentContext<'tcx> {
289289

290290
// Now go through all the successful ones,
291291
// registering any nested obligations for the future.
292-
for new_obligation in new_obligations.into_iter() {
292+
for new_obligation in new_obligations {
293293
self.register_predicate_obligation(selcx.infcx(), new_obligation);
294294
}
295295
}

src/librustc/middle/traits/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ pub fn normalize_param_env<'a,'tcx>(param_env: &ty::ParameterEnvironment<'a,'tcx
438438
let mut fulfill_cx = FulfillmentContext::new();
439439
let Normalized { value: predicates, obligations } =
440440
project::normalize(selcx, cause, &param_env.caller_bounds);
441-
for obligation in obligations.into_iter() {
441+
for obligation in obligations {
442442
fulfill_cx.register_predicate_obligation(selcx.infcx(), obligation);
443443
}
444444
try!(fulfill_cx.select_all_or_error(selcx.infcx(), param_env));

src/librustc/plugin/load.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl<'a> PluginLoader<'a> {
204204
}
205205
}
206206

207-
for mut def in macros.into_iter() {
207+
for mut def in macros {
208208
let name = token::get_ident(def.ident);
209209
def.use_locally = match macro_selection.as_ref() {
210210
None => true,

src/librustc/session/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ macro_rules! options {
300300
pub fn $buildfn(matches: &getopts::Matches) -> $struct_name
301301
{
302302
let mut op = $defaultfn();
303-
for option in matches.opt_strs($prefix).into_iter() {
303+
for option in matches.opt_strs($prefix) {
304304
let mut iter = option.splitn(1, '=');
305305
let key = iter.next().unwrap();
306306
let value = iter.next();
@@ -831,7 +831,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
831831
let mut describe_lints = false;
832832

833833
for &level in &[lint::Allow, lint::Warn, lint::Deny, lint::Forbid] {
834-
for lint_name in matches.opt_strs(level.as_str()).into_iter() {
834+
for lint_name in matches.opt_strs(level.as_str()) {
835835
if lint_name == "help" {
836836
describe_lints = true;
837837
} else {

src/librustc_driver/driver.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
424424
diagnostics::plugin::expand_build_diagnostic_array);
425425
}
426426

427-
for registrar in registrars.into_iter() {
427+
for registrar in registrars {
428428
registry.args_hidden = Some(registrar.args);
429429
(registrar.fun)(&mut registry);
430430
}
@@ -434,11 +434,11 @@ pub fn phase_2_configure_and_expand(sess: &Session,
434434

435435
{
436436
let mut ls = sess.lint_store.borrow_mut();
437-
for pass in lint_passes.into_iter() {
437+
for pass in lint_passes {
438438
ls.register_pass(Some(sess), true, pass);
439439
}
440440

441-
for (name, to) in lint_groups.into_iter() {
441+
for (name, to) in lint_groups {
442442
ls.register_group(Some(sess), true, name, to);
443443
}
444444
}

src/librustc_driver/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ Available lint options:
373373
println!(" {} {:7.7} {}", padded("----"), "-------", "-------");
374374

375375
let print_lints = |&: lints: Vec<&Lint>| {
376-
for lint in lints.into_iter() {
376+
for lint in lints {
377377
let name = lint.name_lower().replace("_", "-");
378378
println!(" {} {:7.7} {}",
379379
padded(&name[]), lint.default_level.as_str(), lint.desc);
@@ -400,7 +400,7 @@ Available lint options:
400400
println!(" {} {}", padded("----"), "---------");
401401

402402
let print_lint_groups = |&: lints: Vec<(&'static str, Vec<lint::LintId>)>| {
403-
for (name, to) in lints.into_iter() {
403+
for (name, to) in lints {
404404
let name = name.chars().map(|x| x.to_lowercase())
405405
.collect::<String>().replace("_", "-");
406406
let desc = to.into_iter().map(|x| x.as_str().replace("_", "-"))

src/librustc_resolve/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3607,10 +3607,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
36073607
TyQPath(ref qpath) => {
36083608
self.resolve_type(&*qpath.self_type);
36093609
self.resolve_trait_reference(ty.id, &*qpath.trait_ref, TraitQPath);
3610-
for ty in qpath.item_path.parameters.types().into_iter() {
3610+
for ty in qpath.item_path.parameters.types() {
36113611
self.resolve_type(&**ty);
36123612
}
3613-
for binding in qpath.item_path.parameters.bindings().into_iter() {
3613+
for binding in qpath.item_path.parameters.bindings() {
36143614
self.resolve_type(&*binding.ty);
36153615
}
36163616
}

src/librustc_trans/back/link.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,7 @@ fn add_upstream_native_libraries(cmd: &mut Command, sess: &Session) {
12751275
// we're just getting an ordering of crate numbers, we're not worried about
12761276
// the paths.
12771277
let crates = sess.cstore.get_used_crates(cstore::RequireStatic);
1278-
for (cnum, _) in crates.into_iter() {
1278+
for (cnum, _) in crates {
12791279
let libs = csearch::get_native_libraries(&sess.cstore, cnum);
12801280
for &(kind, ref lib) in &libs {
12811281
match kind {

src/librustc_trans/back/lto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub fn run(sess: &session::Session, llmod: ModuleRef,
4848
// load the bitcode from the archive. Then merge it into the current LLVM
4949
// module that we've got.
5050
let crates = sess.cstore.get_used_crates(cstore::RequireStatic);
51-
for (cnum, path) in crates.into_iter() {
51+
for (cnum, path) in crates {
5252
let name = sess.cstore.get_crate_data(cnum).name.clone();
5353
let path = match path {
5454
Some(p) => p,

src/librustc_trans/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ fn run_work_multithreaded(sess: &Session,
941941
}
942942

943943
let mut panicked = false;
944-
for rx in futures.into_iter() {
944+
for rx in futures {
945945
match rx.recv() {
946946
Ok(()) => {},
947947
Err(_) => {

src/librustc_trans/trans/callee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ pub fn trans_args<'a, 'blk, 'tcx>(cx: Block<'blk, 'tcx>,
10451045
}));
10461046

10471047
assert_eq!(arg_tys.len(), 1 + rhs.len());
1048-
for (rhs, rhs_id) in rhs.into_iter() {
1048+
for (rhs, rhs_id) in rhs {
10491049
llargs.push(unpack_result!(bcx, {
10501050
trans_arg_datum(bcx, arg_tys[1], rhs,
10511051
arg_cleanup_scope,

src/librustc_trans/trans/monomorphize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ pub fn normalize_associated_type<'tcx,T>(tcx: &ty::ctxt<'tcx>, value: &T) -> T
333333
obligations.repr(tcx));
334334

335335
let mut fulfill_cx = traits::FulfillmentContext::new();
336-
for obligation in obligations.into_iter() {
336+
for obligation in obligations {
337337
fulfill_cx.register_predicate_obligation(&infcx, obligation);
338338
}
339339
let result = drain_fulfillment_cx(DUMMY_SP, &infcx, &mut fulfill_cx, &result);

src/librustc_typeck/astconv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ pub fn instantiate_poly_trait_ref<'tcx>(
537537
instantiate_trait_ref(this, &shifted_rscope, &ast_trait_ref.trait_ref,
538538
self_ty, Some(&mut projections));
539539

540-
for projection in projections.into_iter() {
540+
for projection in projections {
541541
poly_projections.push(ty::Binder(projection));
542542
}
543543

src/librustc_typeck/check/assoc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub fn normalize_associated_types_in<'a,'tcx,T>(infcx: &InferCtxt<'a,'tcx>,
3333
debug!("normalize_associated_types_in: result={} predicates={}",
3434
result.repr(infcx.tcx),
3535
obligations.repr(infcx.tcx));
36-
for obligation in obligations.into_iter() {
36+
for obligation in obligations {
3737
fulfillment_cx.register_predicate_obligation(infcx, obligation);
3838
}
3939
result

src/librustc_typeck/check/compare_method.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ pub fn compare_impl_method<'tcx>(tcx: &ty::ctxt<'tcx>,
248248

249249
let mut selcx = traits::SelectionContext::new(&infcx, &trait_param_env);
250250

251-
for predicate in impl_pred.fns.into_iter() {
251+
for predicate in impl_pred.fns {
252252
let traits::Normalized { value: predicate, .. } =
253253
traits::normalize(&mut selcx, normalize_cause.clone(), &predicate);
254254

src/librustc_typeck/check/method/probe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
448448
{
449449
let mut duplicates = HashSet::new();
450450
let opt_applicable_traits = self.fcx.ccx.trait_map.get(&expr_id);
451-
for applicable_traits in opt_applicable_traits.into_iter() {
451+
if let Some(applicable_traits) = opt_applicable_traits {
452452
for &trait_did in applicable_traits {
453453
if duplicates.insert(trait_did) {
454454
try!(self.assemble_extension_candidates_for_trait(trait_did));

src/librustc_typeck/check/vtable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub fn check_object_safety<'tcx>(tcx: &ty::ctxt<'tcx>,
142142
ty::item_path_str(tcx, object_trait_ref.def_id()));
143143

144144
let violations = traits::object_safety_violations(tcx, object_trait_ref.clone());
145-
for violation in violations.into_iter() {
145+
for violation in violations {
146146
match violation {
147147
ObjectSafetyViolation::SizedSelf => {
148148
tcx.sess.span_note(
@@ -269,7 +269,7 @@ fn check_object_type_binds_all_associated_types<'tcx>(tcx: &ty::ctxt<'tcx>,
269269
associated_types.remove(&pair);
270270
}
271271

272-
for (trait_def_id, name) in associated_types.into_iter() {
272+
for (trait_def_id, name) in associated_types {
273273
span_err!(tcx.sess, span, E0191,
274274
"the value of the associated type `{}` (from the trait `{}`) must be specified",
275275
name.user_string(tcx),

0 commit comments

Comments
 (0)