Skip to content

Commit e65b888

Browse files
committed
remove unneeded .iter()
1 parent 14ebf02 commit e65b888

File tree

6 files changed

+30
-31
lines changed

6 files changed

+30
-31
lines changed

benchmark/carsales.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl crate::TestCase for CarSales {
155155
mut response: total_value::Builder,
156156
) -> ::capnp::Result<()> {
157157
let mut result = 0;
158-
for car in request.get_cars()?.iter() {
158+
for car in request.get_cars()? {
159159
result += car.car_value()?;
160160
}
161161
response.set_amount(result);

benchmark/catrank.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl crate::TestCase for CatRank {
139139
) -> ::capnp::Result<()> {
140140
let mut good_count: i32 = 0;
141141
let results = response.get_results()?;
142-
for result in results.iter() {
142+
for result in results {
143143
if result.get_score() > 1001.0 {
144144
good_count += 1;
145145
} else {

capnp-rpc/src/rpc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ fn to_pipeline_ops(
341341
ops: ::capnp::struct_list::Reader<promised_answer::op::Owned>,
342342
) -> ::capnp::Result<Vec<PipelineOp>> {
343343
let mut result = Vec::new();
344-
for op in ops.iter() {
344+
for op in ops {
345345
match op.which()? {
346346
promised_answer::op::Noop(()) => {
347347
result.push(PipelineOp::Noop);

capnpc/src/codegen.rs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl CodeGenerationCommand {
9191
&message,
9292
)?;
9393

94-
for requested_file in gen.request.get_requested_files()?.iter() {
94+
for requested_file in gen.request.get_requested_files()? {
9595
let id = requested_file.get_id();
9696
let mut filepath = self.output_directory.to_path_buf();
9797
let requested = ::std::path::PathBuf::from(requested_file.get_filename()?);
@@ -182,15 +182,14 @@ impl<'a> GeneratorContext<'a> {
182182
scope_map: collections::hash_map::HashMap::<u64, Vec<String>>::new(),
183183
};
184184

185-
for node in gen.request.get_nodes()?.iter() {
185+
for node in gen.request.get_nodes()? {
186186
gen.node_map.insert(node.get_id(), node);
187187
}
188188

189-
for requested_file in gen.request.get_requested_files()?.iter() {
189+
for requested_file in gen.request.get_requested_files()? {
190190
let id = requested_file.get_id();
191191

192-
let imports = requested_file.get_imports()?;
193-
for import in imports.iter() {
192+
for import in requested_file.get_imports()? {
194193
let importpath = ::std::path::Path::new(import.get_name()?);
195194
let root_name: String = format!(
196195
"{}_capnp",
@@ -236,7 +235,7 @@ impl<'a> GeneratorContext<'a> {
236235
// unused nodes in imported files might be omitted from the node map
237236
let Some(&node_reader) = self.node_map.get(&node_id) else { return Ok(()) };
238237

239-
for annotation in node_reader.get_annotations()?.iter() {
238+
for annotation in node_reader.get_annotations()? {
240239
if annotation.get_id() == NAME_ANNOTATION_ID {
241240
current_node_name = name_annotation_value(annotation)?.to_string();
242241
} else if annotation.get_id() == PARENT_MODULE_ANNOTATION_ID {
@@ -254,7 +253,7 @@ impl<'a> GeneratorContext<'a> {
254253
self.scope_map.insert(node_id, scope_names.clone());
255254

256255
let nested_nodes = node_reader.get_nested_nodes()?;
257-
for nested_node in nested_nodes.iter() {
256+
for nested_node in nested_nodes {
258257
let nested_node_id = nested_node.get_id();
259258
match self.node_map.get(&nested_node_id) {
260259
None => {}
@@ -281,7 +280,7 @@ impl<'a> GeneratorContext<'a> {
281280

282281
if let Ok(schema_capnp::node::Struct(struct_reader)) = node_reader.which() {
283282
let fields = struct_reader.get_fields()?;
284-
for field in fields.iter() {
283+
for field in fields {
285284
if let Ok(schema_capnp::field::Group(group)) = field.which() {
286285
self.populate_scope_map(
287286
scope_names.clone(),
@@ -396,7 +395,7 @@ fn to_lines(ft: &FormattedText, indent: usize) -> Vec<String> {
396395
Indent(ft) => to_lines(ft, indent + 1),
397396
Branch(fts) => {
398397
let mut result = Vec::new();
399-
for ft in fts.iter() {
398+
for ft in fts {
400399
for line in &to_lines(ft, indent) {
401400
result.push(line.clone()); // TODO there's probably a better way to do this.
402401
}
@@ -458,7 +457,7 @@ fn name_annotation_value(annotation: schema_capnp::annotation::Reader) -> capnp:
458457
}
459458

460459
fn get_field_name(field: schema_capnp::field::Reader) -> capnp::Result<&str> {
461-
for annotation in field.get_annotations()?.iter() {
460+
for annotation in field.get_annotations()? {
462461
if annotation.get_id() == NAME_ANNOTATION_ID {
463462
return name_annotation_value(annotation);
464463
}
@@ -467,7 +466,7 @@ fn get_field_name(field: schema_capnp::field::Reader) -> capnp::Result<&str> {
467466
}
468467

469468
fn get_enumerant_name(enumerant: schema_capnp::enumerant::Reader) -> capnp::Result<&str> {
470-
for annotation in enumerant.get_annotations()?.iter() {
469+
for annotation in enumerant.get_annotations()? {
471470
if annotation.get_id() == NAME_ANNOTATION_ID {
472471
return name_annotation_value(annotation);
473472
}
@@ -748,7 +747,7 @@ fn zero_fields_of_group(
748747
)));
749748
}
750749
let fields = st.get_fields()?;
751-
for field in fields.iter() {
750+
for field in fields {
752751
match field.which()? {
753752
field::Group(group) => {
754753
result.push(zero_fields_of_group(gen, group.get_type_id(), clear)?);
@@ -1057,7 +1056,7 @@ fn used_params_of_group(
10571056
let node = gen.node_map[&group_id];
10581057
match node.which()? {
10591058
schema_capnp::node::Struct(st) => {
1060-
for field in st.get_fields()?.iter() {
1059+
for field in st.get_fields()? {
10611060
match field.which()? {
10621061
schema_capnp::field::Group(group) => {
10631062
used_params_of_group(gen, group.get_type_id(), used_params)?;
@@ -1123,7 +1122,7 @@ fn used_params_of_brand(
11231122
use schema_capnp::brand;
11241123
let scopes = brand.get_scopes()?;
11251124
let mut brand_scopes = HashMap::new();
1126-
for scope in scopes.iter() {
1125+
for scope in scopes {
11271126
brand_scopes.insert(scope.get_scope_id(), scope);
11281127
}
11291128
let brand_scopes = brand_scopes; // freeze
@@ -1135,14 +1134,14 @@ fn used_params_of_brand(
11351134
None => (),
11361135
Some(scope) => match scope.which()? {
11371136
brand::scope::Inherit(()) => {
1138-
for param in params.iter() {
1137+
for param in params {
11391138
used_params.insert(param.get_name()?.to_string());
11401139
}
11411140
}
11421141
brand::scope::Bind(bindings_list_opt) => {
11431142
let bindings_list = bindings_list_opt?;
11441143
assert_eq!(bindings_list.len(), params.len());
1145-
for binding in bindings_list.iter() {
1144+
for binding in bindings_list {
11461145
match binding.which()? {
11471146
brand::binding::Unbound(()) => (),
11481147
brand::binding::Type(t) => {
@@ -1191,7 +1190,7 @@ fn generate_union(
11911190

11921191
let doffset = discriminant_offset as usize;
11931192

1194-
for field in fields.iter() {
1193+
for field in fields {
11951194
let dvalue = field.get_discriminant_value() as usize;
11961195

11971196
let field_name = get_field_name(*field)?;
@@ -1500,11 +1499,11 @@ fn get_ty_params_of_brand_helper(
15001499
accumulator: &mut HashSet<(u64, u16)>,
15011500
brand: crate::schema_capnp::brand::Reader,
15021501
) -> ::capnp::Result<()> {
1503-
for scope in brand.get_scopes()?.iter() {
1502+
for scope in brand.get_scopes()? {
15041503
let scope_id = scope.get_scope_id();
15051504
match scope.which()? {
15061505
crate::schema_capnp::brand::scope::Bind(bind) => {
1507-
for binding in bind?.iter() {
1506+
for binding in bind? {
15081507
match binding.which()? {
15091508
crate::schema_capnp::brand::binding::Unbound(()) => {}
15101509
crate::schema_capnp::brand::binding::Type(t) => {
@@ -1539,7 +1538,7 @@ fn generate_node(
15391538

15401539
let node_reader = &gen.node_map[&node_id];
15411540
let nested_nodes = node_reader.get_nested_nodes()?;
1542-
for nested_node in nested_nodes.iter() {
1541+
for nested_node in nested_nodes {
15431542
let id = nested_node.get_id();
15441543
nested_output.push(generate_node(gen, id, gen.get_last_name(id)?, None)?);
15451544
}
@@ -1582,7 +1581,7 @@ fn generate_node(
15821581
let discriminant_offset = struct_reader.get_discriminant_offset();
15831582

15841583
let fields = struct_reader.get_fields()?;
1585-
for field in fields.iter() {
1584+
for field in fields {
15861585
let name = get_field_name(field)?;
15871586
let styled_name = camel_to_snake_case(name);
15881587

capnpc/src/codegen_types.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ pub fn do_branding(
360360
) -> Result<String, Error> {
361361
let scopes = brand.get_scopes()?;
362362
let mut brand_scopes = HashMap::new();
363-
for scope in scopes.iter() {
363+
for scope in scopes {
364364
brand_scopes.insert(scope.get_scope_id(), scope);
365365
}
366366
let brand_scopes = brand_scopes; // freeze
@@ -372,20 +372,20 @@ pub fn do_branding(
372372
let mut arguments: Vec<String> = Vec::new();
373373
match brand_scopes.get(&current_node_id) {
374374
None => {
375-
for _ in params.iter() {
375+
for _ in params {
376376
arguments.push("::capnp::any_pointer::Owned".to_string());
377377
}
378378
}
379379
Some(scope) => match scope.which()? {
380380
brand::scope::Inherit(()) => {
381-
for param in params.iter() {
381+
for param in params {
382382
arguments.push(param.get_name()?.to_string());
383383
}
384384
}
385385
brand::scope::Bind(bindings_list_opt) => {
386386
let bindings_list = bindings_list_opt?;
387387
assert_eq!(bindings_list.len(), params.len());
388-
for binding in bindings_list.iter() {
388+
for binding in bindings_list {
389389
match binding.which()? {
390390
brand::binding::Unbound(()) => {
391391
arguments.push("::capnp::any_pointer::Owned".to_string());
@@ -443,7 +443,7 @@ pub fn get_type_parameters(
443443
break
444444
};
445445
let mut params = Vec::new();
446-
for param in current_node.get_parameters().unwrap().iter() {
446+
for param in current_node.get_parameters().unwrap() {
447447
params.push(param.get_name().unwrap().to_string());
448448
}
449449

example/addressbook/addressbook.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ pub mod addressbook {
8383
)?;
8484
let address_book = message_reader.get_root::<address_book::Reader>()?;
8585

86-
for person in address_book.get_people()?.iter() {
86+
for person in address_book.get_people()? {
8787
println!("{}: {}", person.get_name()?, person.get_email()?);
88-
for phone in person.get_phones()?.iter() {
88+
for phone in person.get_phones()? {
8989
let type_name = match phone.get_type() {
9090
Ok(person::phone_number::Type::Mobile) => "mobile",
9191
Ok(person::phone_number::Type::Home) => "home",

0 commit comments

Comments
 (0)