rustc: Fix for-range loops that can use iterators
Transform range loops that can be regular iterator loops.
This commit is contained in:
parent
d19ca2c714
commit
bdfdbdd7f6
9 changed files with 21 additions and 29 deletions
|
|
@ -413,8 +413,8 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError],
|
|||
}
|
||||
}
|
||||
|
||||
for i in range(0u, found_flags.len()) {
|
||||
if !found_flags[i] {
|
||||
for (i, &flag) in found_flags.iter().enumerate() {
|
||||
if !flag {
|
||||
let ee = &expected_errors[i];
|
||||
fatal_ProcRes(fmt!("expected %s on line %u not found: %s",
|
||||
ee.kind, ee.line, ee.msg), ProcRes);
|
||||
|
|
|
|||
|
|
@ -159,10 +159,10 @@ impl<'self> CheckLoanCtxt<'self> {
|
|||
true
|
||||
};
|
||||
|
||||
for i in range(0u, new_loan_indices.len()) {
|
||||
let old_loan = &self.all_loans[new_loan_indices[i]];
|
||||
for j in range(i+1, new_loan_indices.len()) {
|
||||
let new_loan = &self.all_loans[new_loan_indices[j]];
|
||||
for (i, &x) in new_loan_indices.iter().enumerate() {
|
||||
let old_loan = &self.all_loans[x];
|
||||
for &y in new_loan_indices.slice_from(i+1).iter() {
|
||||
let new_loan = &self.all_loans[y];
|
||||
self.report_error_if_loans_conflict(old_loan, new_loan);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -983,10 +983,10 @@ fn bitwise(out_vec: &mut [uint],
|
|||
op: &fn(uint, uint) -> uint) -> bool {
|
||||
assert_eq!(out_vec.len(), in_vec.len());
|
||||
let mut changed = false;
|
||||
for i in range(0u, out_vec.len()) {
|
||||
let old_val = out_vec[i];
|
||||
let new_val = op(old_val, in_vec[i]);
|
||||
out_vec[i] = new_val;
|
||||
for (out_elt, in_elt) in out_vec.mut_iter().zip(in_vec.iter()) {
|
||||
let old_val = *out_elt;
|
||||
let new_val = op(old_val, *in_elt);
|
||||
*out_elt = new_val;
|
||||
changed |= (old_val != new_val);
|
||||
}
|
||||
changed
|
||||
|
|
|
|||
|
|
@ -1742,8 +1742,7 @@ pub fn copy_args_to_allocas(fcx: @mut FunctionContext,
|
|||
_ => {}
|
||||
}
|
||||
|
||||
for arg_n in range(0u, arg_tys.len()) {
|
||||
let arg_ty = arg_tys[arg_n];
|
||||
for (arg_n, &arg_ty) in arg_tys.iter().enumerate() {
|
||||
let raw_llarg = raw_llargs[arg_n];
|
||||
|
||||
// For certain mode/type combinations, the raw llarg values are passed
|
||||
|
|
|
|||
|
|
@ -145,8 +145,8 @@ fn classify_ty(ty: Type) -> ~[RegClass] {
|
|||
}
|
||||
|
||||
fn all_mem(cls: &mut [RegClass]) {
|
||||
for i in range(0u, cls.len()) {
|
||||
cls[i] = Memory;
|
||||
for elt in cls.mut_iter() {
|
||||
*elt = Memory;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -205,15 +205,8 @@ pub fn type_uses_for(ccx: @mut CrateContext, fn_id: def_id, n_tps: uint)
|
|||
|
||||
pub fn type_needs(cx: &Context, use_: uint, ty: ty::t) {
|
||||
// Optimization -- don't descend type if all params already have this use
|
||||
let len = {
|
||||
let uses = &*cx.uses;
|
||||
uses.len()
|
||||
};
|
||||
for i in range(0u, len) {
|
||||
if cx.uses[i] & use_ != use_ {
|
||||
type_needs_inner(cx, use_, ty, @Nil);
|
||||
return;
|
||||
}
|
||||
if cx.uses.iter().any(|&elt| elt & use_ != use_) {
|
||||
type_needs_inner(cx, use_, ty, @Nil);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -772,8 +772,8 @@ impl<'self> LookupContext<'self> {
|
|||
self.tcx().sess.span_err(
|
||||
self.expr.span,
|
||||
"multiple applicable methods in scope");
|
||||
for idx in range(0u, relevant_candidates.len()) {
|
||||
self.report_candidate(idx, &relevant_candidates[idx].origin);
|
||||
for (idx, candidate) in relevant_candidates.iter().enumerate() {
|
||||
self.report_candidate(idx, &candidate.origin);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -554,8 +554,8 @@ impl CoherenceChecker {
|
|||
|
||||
let mut provided_names = HashSet::new();
|
||||
// Implemented methods
|
||||
for i in range(0u, all_methods.len()) {
|
||||
provided_names.insert(all_methods[i].ident);
|
||||
for elt in all_methods.iter() {
|
||||
provided_names.insert(elt.ident);
|
||||
}
|
||||
|
||||
let r = ty::trait_methods(tcx, trait_did);
|
||||
|
|
|
|||
|
|
@ -374,8 +374,8 @@ impl RegionVarBindings {
|
|||
pub fn vars_created_since_snapshot(&mut self, snapshot: uint)
|
||||
-> ~[RegionVid] {
|
||||
do vec::build |push| {
|
||||
for i in range(snapshot, self.undo_log.len()) {
|
||||
match self.undo_log[i] {
|
||||
for &elt in self.undo_log.slice_from(snapshot).iter() {
|
||||
match elt {
|
||||
AddVar(vid) => push(vid),
|
||||
_ => ()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue