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.
This commit is contained in:
commit
f19684c7cf
@ -234,7 +234,7 @@ impl BoundNamesCollector {
|
||||
start = false;
|
||||
write!(fmt, "{}", r)?;
|
||||
}
|
||||
for (_, t) in &self.types {
|
||||
for t in self.types.values() {
|
||||
if !start {
|
||||
write!(fmt, ", ")?;
|
||||
}
|
||||
|
@ -1382,10 +1382,8 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||
|
||||
// Write down the order of our locals that will be promoted to the prefix.
|
||||
{
|
||||
let mut idx = 0u32;
|
||||
for local in ineligible_locals.iter() {
|
||||
assignments[local] = Ineligible(Some(idx));
|
||||
idx += 1;
|
||||
for (idx, local) in ineligible_locals.iter().enumerate() {
|
||||
assignments[local] = Ineligible(Some(idx as u32));
|
||||
}
|
||||
}
|
||||
debug!("generator saved local assignments: {:?}", assignments);
|
||||
|
@ -188,7 +188,7 @@ fn parse_args<'a>(
|
||||
let mut err = ecx
|
||||
.struct_span_err(e.span, "positional arguments cannot follow named arguments");
|
||||
err.span_label(e.span, "positional arguments must be before named arguments");
|
||||
for (_, pos) in &names {
|
||||
for pos in names.values() {
|
||||
err.span_label(args[*pos].span, "named argument");
|
||||
}
|
||||
err.emit();
|
||||
|
@ -1574,9 +1574,9 @@ impl EmitterWriter {
|
||||
|
||||
let line_start = sm.lookup_char_pos(parts[0].span.lo()).line;
|
||||
draw_col_separator_no_space(&mut buffer, 1, max_line_num_len + 1);
|
||||
let mut line_pos = 0;
|
||||
let mut lines = complete.lines();
|
||||
for line in lines.by_ref().take(MAX_SUGGESTION_HIGHLIGHT_LINES) {
|
||||
for (line_pos, line) in lines.by_ref().take(MAX_SUGGESTION_HIGHLIGHT_LINES).enumerate()
|
||||
{
|
||||
// Print the span column to avoid confusion
|
||||
buffer.puts(
|
||||
row_num,
|
||||
@ -1587,7 +1587,6 @@ impl EmitterWriter {
|
||||
// print the suggestion
|
||||
draw_col_separator(&mut buffer, row_num, max_line_num_len + 1);
|
||||
buffer.append(row_num, line, Style::NoStyle);
|
||||
line_pos += 1;
|
||||
row_num += 1;
|
||||
}
|
||||
|
||||
|
@ -679,15 +679,15 @@ impl Crate<'_> {
|
||||
where
|
||||
V: itemlikevisit::ItemLikeVisitor<'hir>,
|
||||
{
|
||||
for (_, item) in &self.items {
|
||||
for item in self.items.values() {
|
||||
visitor.visit_item(item);
|
||||
}
|
||||
|
||||
for (_, trait_item) in &self.trait_items {
|
||||
for trait_item in self.trait_items.values() {
|
||||
visitor.visit_trait_item(trait_item);
|
||||
}
|
||||
|
||||
for (_, impl_item) in &self.impl_items {
|
||||
for impl_item in self.impl_items.values() {
|
||||
visitor.visit_impl_item(impl_item);
|
||||
}
|
||||
}
|
||||
|
@ -751,7 +751,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
||||
let dummy_source = graph.add_node(());
|
||||
let dummy_sink = graph.add_node(());
|
||||
|
||||
for (constraint, _) in &self.data.constraints {
|
||||
for constraint in self.data.constraints.keys() {
|
||||
match *constraint {
|
||||
Constraint::VarSubVar(a_id, b_id) => {
|
||||
graph.add_edge(
|
||||
|
@ -34,7 +34,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
|
||||
assert!(self.in_snapshot());
|
||||
|
||||
// Go through each placeholder that we created.
|
||||
for (_, &placeholder_region) in placeholder_map {
|
||||
for &placeholder_region in placeholder_map.values() {
|
||||
// Find the universe this placeholder inhabits.
|
||||
let placeholder = match placeholder_region {
|
||||
ty::RePlaceholder(p) => p,
|
||||
|
@ -347,7 +347,7 @@ fn krate(tcx: TyCtxt<'_>) -> NamedRegionMap {
|
||||
lifetime_uses: &mut Default::default(),
|
||||
missing_named_lifetime_spots: vec![],
|
||||
};
|
||||
for (_, item) in &krate.items {
|
||||
for item in krate.items.values() {
|
||||
visitor.visit_item(item);
|
||||
}
|
||||
}
|
||||
|
@ -1652,7 +1652,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
}
|
||||
|
||||
for (projection_bound, _) in &bounds.projection_bounds {
|
||||
for (_, def_ids) in &mut associated_types {
|
||||
for def_ids in associated_types.values_mut() {
|
||||
def_ids.remove(&projection_bound.projection_def_id());
|
||||
}
|
||||
}
|
||||
|
@ -526,7 +526,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
// we may want to suggest removing a `&`.
|
||||
if !sm.span_to_filename(expr.span).is_real() {
|
||||
if let Ok(code) = sm.span_to_snippet(sp) {
|
||||
if code.chars().next() == Some('&') {
|
||||
if code.starts_with('&') {
|
||||
return Some((
|
||||
sp,
|
||||
"consider removing the borrow",
|
||||
|
@ -280,7 +280,7 @@ impl Socket {
|
||||
};
|
||||
let mut timeout = libc::timeval {
|
||||
tv_sec: secs,
|
||||
tv_usec: (dur.subsec_nanos() / 1000) as libc::suseconds_t,
|
||||
tv_usec: dur.subsec_micros() as libc::suseconds_t,
|
||||
};
|
||||
if timeout.tv_sec == 0 && timeout.tv_usec == 0 {
|
||||
timeout.tv_usec = 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user