Skip to content

Commit f19684c

Browse files
authored
Rollup merge of #69619 - matthiaskrgr:misc, r=eddyb
more cleanups * use starts_with() instead of chars().next() == Some(x) * use subsec_micros() instead of subsec_nanos() / 1000 * use for (idx, item) in iter.enumerate() instead of manually counting loop iterations with variables * use values() or keys() respectively when iterating only over keys or values of maps.
2 parents 4699b29 + 21affdd commit f19684c

File tree

11 files changed

+15
-18
lines changed

11 files changed

+15
-18
lines changed

src/librustc/traits/structural_impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl BoundNamesCollector {
234234
start = false;
235235
write!(fmt, "{}", r)?;
236236
}
237-
for (_, t) in &self.types {
237+
for t in self.types.values() {
238238
if !start {
239239
write!(fmt, ", ")?;
240240
}

src/librustc/ty/layout.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1382,10 +1382,8 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
13821382

13831383
// Write down the order of our locals that will be promoted to the prefix.
13841384
{
1385-
let mut idx = 0u32;
1386-
for local in ineligible_locals.iter() {
1387-
assignments[local] = Ineligible(Some(idx));
1388-
idx += 1;
1385+
for (idx, local) in ineligible_locals.iter().enumerate() {
1386+
assignments[local] = Ineligible(Some(idx as u32));
13891387
}
13901388
}
13911389
debug!("generator saved local assignments: {:?}", assignments);

src/librustc_builtin_macros/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ fn parse_args<'a>(
188188
let mut err = ecx
189189
.struct_span_err(e.span, "positional arguments cannot follow named arguments");
190190
err.span_label(e.span, "positional arguments must be before named arguments");
191-
for (_, pos) in &names {
191+
for pos in names.values() {
192192
err.span_label(args[*pos].span, "named argument");
193193
}
194194
err.emit();

src/librustc_errors/emitter.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1574,9 +1574,9 @@ impl EmitterWriter {
15741574

15751575
let line_start = sm.lookup_char_pos(parts[0].span.lo()).line;
15761576
draw_col_separator_no_space(&mut buffer, 1, max_line_num_len + 1);
1577-
let mut line_pos = 0;
15781577
let mut lines = complete.lines();
1579-
for line in lines.by_ref().take(MAX_SUGGESTION_HIGHLIGHT_LINES) {
1578+
for (line_pos, line) in lines.by_ref().take(MAX_SUGGESTION_HIGHLIGHT_LINES).enumerate()
1579+
{
15801580
// Print the span column to avoid confusion
15811581
buffer.puts(
15821582
row_num,
@@ -1587,7 +1587,6 @@ impl EmitterWriter {
15871587
// print the suggestion
15881588
draw_col_separator(&mut buffer, row_num, max_line_num_len + 1);
15891589
buffer.append(row_num, line, Style::NoStyle);
1590-
line_pos += 1;
15911590
row_num += 1;
15921591
}
15931592

src/librustc_hir/hir.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -679,15 +679,15 @@ impl Crate<'_> {
679679
where
680680
V: itemlikevisit::ItemLikeVisitor<'hir>,
681681
{
682-
for (_, item) in &self.items {
682+
for item in self.items.values() {
683683
visitor.visit_item(item);
684684
}
685685

686-
for (_, trait_item) in &self.trait_items {
686+
for trait_item in self.trait_items.values() {
687687
visitor.visit_trait_item(trait_item);
688688
}
689689

690-
for (_, impl_item) in &self.impl_items {
690+
for impl_item in self.impl_items.values() {
691691
visitor.visit_impl_item(impl_item);
692692
}
693693
}

src/librustc_infer/infer/lexical_region_resolve/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
751751
let dummy_source = graph.add_node(());
752752
let dummy_sink = graph.add_node(());
753753

754-
for (constraint, _) in &self.data.constraints {
754+
for constraint in self.data.constraints.keys() {
755755
match *constraint {
756756
Constraint::VarSubVar(a_id, b_id) => {
757757
graph.add_edge(

src/librustc_infer/infer/region_constraints/leak_check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
3434
assert!(self.in_snapshot());
3535

3636
// Go through each placeholder that we created.
37-
for (_, &placeholder_region) in placeholder_map {
37+
for &placeholder_region in placeholder_map.values() {
3838
// Find the universe this placeholder inhabits.
3939
let placeholder = match placeholder_region {
4040
ty::RePlaceholder(p) => p,

src/librustc_resolve/late/lifetimes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ fn krate(tcx: TyCtxt<'_>) -> NamedRegionMap {
347347
lifetime_uses: &mut Default::default(),
348348
missing_named_lifetime_spots: vec![],
349349
};
350-
for (_, item) in &krate.items {
350+
for item in krate.items.values() {
351351
visitor.visit_item(item);
352352
}
353353
}

src/librustc_typeck/astconv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1652,7 +1652,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
16521652
}
16531653

16541654
for (projection_bound, _) in &bounds.projection_bounds {
1655-
for (_, def_ids) in &mut associated_types {
1655+
for def_ids in associated_types.values_mut() {
16561656
def_ids.remove(&projection_bound.projection_def_id());
16571657
}
16581658
}

src/librustc_typeck/check/demand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
526526
// we may want to suggest removing a `&`.
527527
if !sm.span_to_filename(expr.span).is_real() {
528528
if let Ok(code) = sm.span_to_snippet(sp) {
529-
if code.chars().next() == Some('&') {
529+
if code.starts_with('&') {
530530
return Some((
531531
sp,
532532
"consider removing the borrow",

src/libstd/sys/unix/net.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl Socket {
280280
};
281281
let mut timeout = libc::timeval {
282282
tv_sec: secs,
283-
tv_usec: (dur.subsec_nanos() / 1000) as libc::suseconds_t,
283+
tv_usec: dur.subsec_micros() as libc::suseconds_t,
284284
};
285285
if timeout.tv_sec == 0 && timeout.tv_usec == 0 {
286286
timeout.tv_usec = 1;

0 commit comments

Comments
 (0)