Skip to content

Commit

Permalink
Conver reborrows to .iter() calls where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
Veedrac committed Jun 11, 2015
1 parent ca7418b commit d7f5fa4
Show file tree
Hide file tree
Showing 47 changed files with 109 additions and 109 deletions.
2 changes: 1 addition & 1 deletion src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
//! gadget_owner.gadgets.borrow_mut().push(gadget2.clone().downgrade());
//!
//! // Iterate over our Gadgets, printing their details out
//! for gadget_opt in &*gadget_owner.gadgets.borrow() {
//! for gadget_opt in gadget_owner.gadgets.borrow().iter() {
//!
//! // gadget_opt is a Weak<Gadget>. Since weak pointers can't guarantee
//! // that their object is still allocated, we need to call upgrade()
Expand Down
2 changes: 1 addition & 1 deletion src/libarena/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl<'longer_than_self> Drop for Arena<'longer_than_self> {
fn drop(&mut self) {
unsafe {
destroy_chunk(&*self.head.borrow());
for chunk in &*self.chunks.borrow() {
for chunk in self.chunks.borrow().iter() {
if !chunk.is_copy.get() {
destroy_chunk(chunk);
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1639,7 +1639,7 @@ impl<T> Drop for Vec<T> {
// zeroed (when moving out, because of #[unsafe_no_drop_flag]).
if self.cap != 0 && self.cap != mem::POST_DROP_USIZE {
unsafe {
for x in &*self {
for x in self.iter() {
ptr::read(x);
}
dealloc(*self.ptr, self.cap)
Expand Down
4 changes: 2 additions & 2 deletions src/libgraphviz/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ pub fn render_opts<'a, N:Clone+'a, E:Clone+'a, G:Labeller<'a,N,E>+GraphWalk<'a,N
}

try!(writeln(w, &["digraph ", g.graph_id().as_slice(), " {"]));
for n in &*g.nodes() {
for n in g.nodes().iter() {
try!(indent(w));
let id = g.node_id(n);
if options.contains(&RenderOption::NoNodeLabels) {
Expand All @@ -570,7 +570,7 @@ pub fn render_opts<'a, N:Clone+'a, E:Clone+'a, G:Labeller<'a,N,E>+GraphWalk<'a,N
}
}

for e in &*g.edges() {
for e in g.edges().iter() {
let escaped_label = g.edge_label(e).escape();
try!(indent(w));
let source = g.source(e);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ast_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
}
}
ItemTrait(_, _, ref bounds, ref trait_items) => {
for b in &**bounds {
for b in bounds.iter() {
if let TraitTyParamBound(ref t, TraitBoundModifier::None) = *b {
self.insert(t.trait_ref.ref_id, NodeItem(i));
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ pub fn check_crate(tcx: &ty::ctxt,

// If we missed any lints added to the session, then there's a bug somewhere
// in the iteration code.
for (id, v) in &*tcx.sess.lints.borrow() {
for (id, v) in tcx.sess.lints.borrow().iter() {
for &(lint, span, ref msg) in v {
tcx.sess.span_bug(span,
&format!("unprocessed lint {} at {}: {}",
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ pub fn import_codemap(local_codemap: &codemap::CodeMap,
return false;
}

for (&line1, &line2) in lines1.iter().zip(&*lines2) {
for (&line1, &line2) in lines1.iter().zip(lines2.iter()) {
if (line1 - fm1.start_pos) != (line2 - fm2.start_pos) {
return false;
}
Expand All @@ -711,7 +711,7 @@ pub fn import_codemap(local_codemap: &codemap::CodeMap,
return false;
}

for (mb1, mb2) in multibytes1.iter().zip(&*multibytes2) {
for (mb1, mb2) in multibytes1.iter().zip(multibytes2.iter()) {
if (mb1.bytes != mb2.bytes) ||
((mb1.pos - fm1.start_pos) != (mb2.pos - fm2.start_pos)) {
return false;
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/metadata/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl CStore {
pub fn iter_crate_data<I>(&self, mut i: I) where
I: FnMut(ast::CrateNum, &crate_metadata),
{
for (&k, v) in &*self.metas.borrow() {
for (&k, v) in self.metas.borrow().iter() {
i(k, &**v);
}
}
Expand All @@ -136,7 +136,7 @@ impl CStore {
pub fn iter_crate_data_origins<I>(&self, mut i: I) where
I: FnMut(ast::CrateNum, &crate_metadata, Option<CrateSource>),
{
for (&k, v) in &*self.metas.borrow() {
for (&k, v) in self.metas.borrow().iter() {
let origin = self.get_used_crate_source(k);
origin.as_ref().map(|cs| { assert!(k == cs.cnum); });
i(k, &**v, origin);
Expand Down Expand Up @@ -185,7 +185,7 @@ impl CStore {
}
ordering.push(cnum);
};
for (&num, _) in &*self.metas.borrow() {
for (&num, _) in self.metas.borrow().iter() {
visit(self, num, &mut ordering);
}
ordering.reverse();
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ fn encode_reexported_static_base_methods(ecx: &EncodeContext,
let impl_items = ecx.tcx.impl_items.borrow();
match ecx.tcx.inherent_impls.borrow().get(&exp.def_id) {
Some(implementations) => {
for base_impl_did in &**implementations {
for base_impl_did in implementations.iter() {
for &method_did in impl_items.get(base_impl_did).unwrap() {
let impl_item = ty::impl_or_trait_item(
ecx.tcx,
Expand All @@ -403,7 +403,7 @@ fn encode_reexported_static_trait_methods(ecx: &EncodeContext,
-> bool {
match ecx.tcx.trait_items_cache.borrow().get(&exp.def_id) {
Some(trait_items) => {
for trait_item in &**trait_items {
for trait_item in trait_items.iter() {
if let ty::MethodTraitItem(ref m) = *trait_item {
encode_reexported_static_method(rbml_w,
exp,
Expand Down Expand Up @@ -981,7 +981,7 @@ fn encode_inherent_implementations(ecx: &EncodeContext,
match ecx.tcx.inherent_impls.borrow().get(&def_id) {
None => {}
Some(implementations) => {
for &impl_def_id in &**implementations {
for &impl_def_id in implementations.iter() {
rbml_w.start_tag(tag_items_data_item_inherent_impl);
encode_def_id(rbml_w, impl_def_id);
rbml_w.end_tag();
Expand Down Expand Up @@ -1348,7 +1348,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_attributes(rbml_w, &item.attrs);
encode_visibility(rbml_w, vis);
encode_stability(rbml_w, stab);
for &method_def_id in &*ty::trait_item_def_ids(tcx, def_id) {
for &method_def_id in ty::trait_item_def_ids(tcx, def_id).iter() {
rbml_w.start_tag(tag_item_trait_item);
match method_def_id {
ty::ConstTraitItemId(const_def_id) => {
Expand Down Expand Up @@ -1822,8 +1822,8 @@ fn encode_lang_items(ecx: &EncodeContext, rbml_w: &mut Encoder) {
fn encode_native_libraries(ecx: &EncodeContext, rbml_w: &mut Encoder) {
rbml_w.start_tag(tag_native_libraries);

for &(ref lib, kind) in &*ecx.tcx.sess.cstore.get_used_libraries()
.borrow() {
for &(ref lib, kind) in ecx.tcx.sess.cstore.get_used_libraries()
.borrow().iter() {
match kind {
cstore::NativeStatic => {} // these libraries are not propagated
cstore::NativeFramework | cstore::NativeUnknown => {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,8 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
match self.tcx.inherent_impls.borrow().get(&local_def(id)) {
None => (),
Some(impl_list) => {
for impl_did in &**impl_list {
for item_did in &*impl_items.get(impl_did).unwrap() {
for impl_did in impl_list.iter() {
for item_did in impl_items.get(impl_did).unwrap().iter() {
if self.live_symbols.contains(&item_did.def_id()
.node) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/dependency_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub type Dependencies = FnvHashMap<config::CrateType, DependencyList>;

pub fn calculate(tcx: &ty::ctxt) {
let mut fmts = tcx.dependency_formats.borrow_mut();
for &ty in &*tcx.sess.crate_types.borrow() {
for &ty in tcx.sess.crate_types.borrow().iter() {
fmts.insert(ty, calculate_type(&tcx.sess, ty));
}
tcx.sess.abort_if_errors();
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/infer/region_inference/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
errors: &mut Vec<RegionResolutionError<'tcx>>)
{
let mut reg_reg_dups = FnvHashSet();
for verify in &*self.verifys.borrow() {
for verify in self.verifys.borrow().iter() {
match *verify {
VerifyRegSubReg(ref origin, sub, sup) => {
if free_regions.is_subregion_of(self.tcx, sub, sup) {
Expand Down Expand Up @@ -1350,7 +1350,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
}
let dummy_idx = graph.add_node(());

for (constraint, _) in &*constraints {
for (constraint, _) in constraints.iter() {
match *constraint {
ConstrainVarSubVar(a_id, b_id) => {
graph.add_edge(NodeIndex(a_id.index as usize),
Expand Down Expand Up @@ -1575,7 +1575,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
changed = false;
iteration += 1;
debug!("---- {} Iteration {}{}", "#", tag, iteration);
for (constraint, _) in &*self.constraints.borrow() {
for (constraint, _) in self.constraints.borrow().iter() {
let edge_changed = body(constraint);
if edge_changed {
debug!("Updated due to constraint {}",
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/reachable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
// this properly would result in the necessity of computing *type*
// reachability, which might result in a compile time loss.
fn mark_destructors_reachable(&mut self) {
for (_, destructor_def_id) in &*self.tcx.destructor_for_type.borrow() {
for (_, destructor_def_id) in self.tcx.destructor_for_type.borrow().iter() {
if destructor_def_id.krate == ast::LOCAL_CRATE {
self.reachable_symbols.insert(destructor_def_id.node);
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,22 +372,22 @@ struct RegionResolutionVisitor<'a> {

impl RegionMaps {
pub fn each_encl_scope<E>(&self, mut e:E) where E: FnMut(&CodeExtent, &CodeExtent) {
for (child, parent) in &*self.scope_map.borrow() {
for (child, parent) in self.scope_map.borrow().iter() {
e(child, parent)
}
}
pub fn each_var_scope<E>(&self, mut e:E) where E: FnMut(&ast::NodeId, &CodeExtent) {
for (child, parent) in &*self.var_map.borrow() {
for (child, parent) in self.var_map.borrow().iter() {
e(child, parent)
}
}
pub fn each_rvalue_scope<E>(&self, mut e:E) where E: FnMut(&ast::NodeId, &CodeExtent) {
for (child, parent) in &*self.rvalue_scopes.borrow() {
for (child, parent) in self.rvalue_scopes.borrow().iter() {
e(child, parent)
}
}
pub fn each_terminating_scope<E>(&self, mut e:E) where E: FnMut(&CodeExtent) {
for scope in &*self.terminating_scopes.borrow() {
for scope in self.terminating_scopes.borrow().iter() {
e(scope)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
}

fn visit_generics(&mut self, generics: &ast::Generics) {
for ty_param in &*generics.ty_params {
for ty_param in generics.ty_params.iter() {
visit::walk_ty_param_bounds_helper(self, &ty_param.bounds);
match ty_param.default {
Some(ref ty) => self.visit_ty(&**ty),
Expand Down Expand Up @@ -773,7 +773,7 @@ fn early_bound_lifetime_names(generics: &ast::Generics) -> Vec<ast::Name> {
let mut collector =
FreeLifetimeCollector { early_bound: &mut early_bound,
late_bound: &mut late_bound };
for ty_param in &*generics.ty_params {
for ty_param in generics.ty_params.iter() {
visit::walk_ty_param_bounds_helper(&mut collector, &ty_param.bounds);
}
for predicate in &generics.where_clause.predicates {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn report_on_unimplemented<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
span: Span) -> Option<String> {
let def_id = trait_ref.def_id;
let mut report = None;
for item in &*ty::get_attrs(infcx.tcx, def_id) {
for item in ty::get_attrs(infcx.tcx, def_id).iter() {
if item.check_name("rustc_on_unimplemented") {
let err_sp = if item.meta().span == DUMMY_SP {
span
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ fn confirm_impl_candidate<'cx,'tcx>(

// It is not in the impl - get the default from the trait.
let trait_ref = obligation.predicate.trait_ref;
for trait_item in &*ty::trait_items(selcx.tcx(), trait_ref.def_id) {
for trait_item in ty::trait_items(selcx.tcx(), trait_ref.def_id).iter() {
if let &ty::TypeTraitItem(ref assoc_ty) = trait_item {
if assoc_ty.name == obligation.predicate.item_name {
if let Some(ty) = assoc_ty.ty {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/traits/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ pub fn get_vtable_index_of_object_method<'tcx>(tcx: &ty::ctxt<'tcx>,
}

let trait_items = ty::trait_items(tcx, bound_ref.def_id());
for trait_item in &**trait_items {
for trait_item in trait_items.iter() {
match *trait_item {
ty::MethodTraitItem(_) => method_count += 1,
_ => {}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ macro_rules! sty_debug_print {
$(let mut $variant = total;)*


for (_, t) in &*tcx.interner.borrow() {
for (_, t) in tcx.interner.borrow().iter() {
let variant = match t.sty {
ty::ty_bool | ty::ty_char | ty::ty_int(..) | ty::ty_uint(..) |
ty::ty_float(..) | ty::ty_str => continue,
Expand Down Expand Up @@ -2571,7 +2571,7 @@ impl<'tcx> TraitDef<'tcx> {
pub fn for_each_impl<F: FnMut(DefId)>(&self, tcx: &ctxt<'tcx>, mut f: F) {
ty::populate_implementations_for_trait_if_necessary(tcx, self.trait_ref.def_id);

for &impl_def_id in &*self.blanket_impls.borrow() {
for &impl_def_id in self.blanket_impls.borrow().iter() {
f(impl_def_id);
}

Expand All @@ -2589,7 +2589,7 @@ impl<'tcx> TraitDef<'tcx> {
{
ty::populate_implementations_for_trait_if_necessary(tcx, self.trait_ref.def_id);

for &impl_def_id in &*self.blanket_impls.borrow() {
for &impl_def_id in self.blanket_impls.borrow().iter() {
f(impl_def_id);
}

Expand Down Expand Up @@ -7207,7 +7207,7 @@ pub fn can_type_implement_copy<'a,'tcx>(param_env: &ParameterEnvironment<'a, 'tc
}
ty::ty_enum(enum_did, substs) => {
let enum_variants = ty::enum_variants(tcx, enum_did);
for variant in &*enum_variants {
for variant in enum_variants.iter() {
for variant_arg_type in &variant.args {
let substd_arg_type =
variant_arg_type.subst(tcx, substs);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_borrowck/borrowck/move_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,14 +478,14 @@ impl<'tcx> MoveData<'tcx> {
KillFrom::Execution, dfcx_moves);
}

for assignment in &*self.path_assignments.borrow() {
for assignment in self.path_assignments.borrow().iter() {
self.kill_moves(assignment.path, assignment.id,
KillFrom::Execution, dfcx_moves);
}

// Kill all moves related to a variable `x` when
// it goes out of scope:
for path in &*self.paths.borrow() {
for path in self.paths.borrow().iter() {
match path.loan_path.kind {
LpVar(..) | LpUpvar(..) | LpDowncast(..) => {
let kill_scope = path.loan_path.kill_scope(tcx);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ fn write_out_deps(sess: &Session,
let file = outputs.path(*output_type);
match *output_type {
config::OutputTypeExe => {
for output in &*sess.crate_types.borrow() {
for output in sess.crate_types.borrow().iter() {
let p = link::filename_for_input(sess, *output,
id, &file);
out_filenames.push(p);
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ impl LintPass for UnusedAttributes {
}

let plugin_attributes = cx.sess().plugin_attributes.borrow_mut();
for &(ref name, ty) in &*plugin_attributes {
for &(ref name, ty) in plugin_attributes.iter() {
if ty == AttributeType::Whitelisted && attr.check_name(&*name) {
break;
}
Expand Down Expand Up @@ -860,7 +860,7 @@ impl LintPass for NonCamelCaseTypes {
}

fn check_generics(&mut self, cx: &Context, it: &ast::Generics) {
for gen in &*it.ty_params {
for gen in it.ty_params.iter() {
self.check_case(cx, "type parameter", gen.ident, gen.span);
}
}
Expand Down Expand Up @@ -2249,7 +2249,7 @@ impl LintPass for DropWithReprExtern {
lint_array!(DROP_WITH_REPR_EXTERN)
}
fn check_crate(&mut self, ctx: &Context, _: &ast::Crate) {
for dtor_did in &*ctx.tcx.destructors.borrow() {
for dtor_did in ctx.tcx.destructors.borrow().iter() {
let (drop_impl_did, dtor_self_type) =
if dtor_did.krate == ast::LOCAL_CRATE {
let impl_did = ctx.tcx.map.get_parent_did(dtor_did.node);
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_privacy/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
return
}

for bound in &**bounds {
for bound in bounds.iter() {
self.check_ty_param_bound(bound)
}
}
Expand Down Expand Up @@ -1466,15 +1466,15 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
}

fn visit_generics(&mut self, generics: &ast::Generics) {
for ty_param in &*generics.ty_params {
for bound in &*ty_param.bounds {
for ty_param in generics.ty_params.iter() {
for bound in ty_param.bounds.iter() {
self.check_ty_param_bound(bound)
}
}
for predicate in &generics.where_clause.predicates {
match predicate {
&ast::WherePredicate::BoundPredicate(ref bound_pred) => {
for bound in &*bound_pred.bounds {
for bound in bound_pred.bounds.iter() {
self.check_ty_param_bound(bound)
}
}
Expand Down
Loading

0 comments on commit d7f5fa4

Please sign in to comment.