Skip to content

Commit

Permalink
A few tweaks to iterations/collecting
Browse files Browse the repository at this point in the history
  • Loading branch information
ljedrz committed Nov 13, 2018
1 parent c4371c8 commit 0c08529
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 16 deletions.
3 changes: 1 addition & 2 deletions src/librustc/cfg/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ impl<'a> dot::GraphWalk<'a> for &'a cfg::CFG {
type Node = Node<'a>;
type Edge = Edge<'a>;
fn nodes(&'a self) -> dot::Nodes<'a, Node<'a>> {
let mut v = Vec::new();
self.graph.each_node(|i, nd| { v.push((i, nd)); true });
let v: Vec<_> = self.graph.enumerated_nodes().collect();
v.into()
}
fn edges(&'a self) -> dot::Edges<'a, Edge<'a>> {
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1062,8 +1062,7 @@ impl<'a> LoweringContext<'a> {
attrs
.iter()
.map(|a| self.lower_attr(a))
.collect::<Vec<_>>()
.into()
.collect()
}

fn lower_attr(&mut self, attr: &Attribute) -> Attribute {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/query/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ impl<'sess> OnDiskCache<'sess> {
// otherwise, abort
break;
}
interpret_alloc_index.reserve(new_n);
interpret_alloc_index.reserve(new_n - n);
for idx in n..new_n {
let id = encoder.interpret_allocs_inverse[idx];
let pos = encoder.position() as u32;
Expand Down
2 changes: 1 addition & 1 deletion src/libserialize/hex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl FromHex for str {
}

match modulus {
0 => Ok(b.into_iter().collect()),
0 => Ok(b),
_ => Err(InvalidHexLength),
}
}
Expand Down
18 changes: 8 additions & 10 deletions src/libsyntax_ext/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1200,16 +1200,14 @@ impl<'a> MethodDef<'a> {
let sp = trait_.span;
let variants = &enum_def.variants;

let self_arg_names = self_args.iter()
.enumerate()
.map(|(arg_count, _self_arg)| {
if arg_count == 0 {
"__self".to_string()
} else {
let self_arg_names = iter::once("__self".to_string()).chain(
self_args.iter()
.enumerate()
.skip(1)
.map(|(arg_count, _self_arg)|
format!("__arg_{}", arg_count)
}
})
.collect::<Vec<String>>();
)
).collect::<Vec<String>>();

let self_arg_idents = self_arg_names.iter()
.map(|name| cx.ident_of(&name[..]))
Expand All @@ -1218,7 +1216,7 @@ impl<'a> MethodDef<'a> {
// The `vi_idents` will be bound, solely in the catch-all, to
// a series of let statements mapping each self_arg to an int
// value corresponding to its discriminant.
let vi_idents: Vec<ast::Ident> = self_arg_names.iter()
let vi_idents = self_arg_names.iter()
.map(|name| {
let vi_suffix = format!("{}_vi", &name[..]);
cx.ident_of(&vi_suffix[..]).gensym()
Expand Down

0 comments on commit 0c08529

Please sign in to comment.